Commit e636910f authored by Markus Klein's avatar Markus Klein
Browse files

[CLEANUP] Extbase persistence classes

The classes contain wrong type hints and miss a lot of
checks whether the correct object is present.

Resolves: #57031
Releases: 6.2
Change-Id: I3d03c838b05529daf0da444119dd7f8dba6d5b8a
Reviewed-on: https://review.typo3.org/28489
Reviewed-by: Felix Oertel
Tested-by: Felix Oertel
Reviewed-by: Markus Klein
Tested-by: Markus Klein
parent 6bf26d96
......@@ -2281,11 +2281,6 @@ class Tx_Extbase_Persistence_QOM_Comparison extends \TYPO3\CMS\Extbase\Persisten
*/
interface Tx_Extbase_Persistence_QOM_ComparisonInterface extends \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface {}
/**
* @deprecated since 6.0 will be removed in 7.0
*/
class Tx_Extbase_Persistence_QOM_Constraint extends \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Constraint {}
/**
* @deprecated since 6.0 will be removed in 7.0
*/
......
......@@ -243,7 +243,7 @@ abstract class AbstractDomainObject implements \TYPO3\CMS\Extbase\DomainObject\D
* Returns the clean value of the given property. The returned value will be NULL if the clean state was not memorized before, or
* if the clean value is NULL.
*
* @param string $propertyName The name of the property to be memorized. If omittet all persistable properties are memorized.
* @param string $propertyName The name of the property to be memorized.
* @return mixed The clean property value or NULL
*/
public function _getCleanProperty($propertyName) {
......
......@@ -89,4 +89,31 @@ interface DomainObjectInterface {
* @return array The properties
*/
public function _getProperties();
/**
* Returns the clean value of the given property. The returned value will be NULL if the clean state was not memorized before, or
* if the clean value is NULL.
*
* @param string $propertyName The name of the property to be memorized.
* @return mixed The clean property value or NULL
*/
public function _getCleanProperty($propertyName);
/**
* Returns TRUE if the properties were modified after reconstitution
*
* @param string $propertyName An optional name of a property to be checked if its value is dirty
* @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\TooDirtyException
* @return boolean
*/
public function _isDirty($propertyName = NULL);
/**
* Register an object's clean state, e.g. after it has been reconstituted
* from the database.
*
* @param string $propertyName The name of the property to be memorized. If omitted all persistable properties are memorized.
* @return void
*/
public function _memorizeCleanState($propertyName = NULL);
}
......@@ -28,6 +28,8 @@ namespace TYPO3\CMS\Extbase\Persistence\Generic;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface;
/**
* A persistence backend. This backend maps objects to the relational model of the storage backend.
* It persists all added, removed and changed objects.
......@@ -111,7 +113,6 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
* Constructs the backend
*
* @param \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager
* @return void
*/
public function __construct(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager) {
$this->configurationManager = $configurationManager;
......@@ -316,6 +317,7 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
protected function persistObjects() {
$this->visitedDuringPersistence = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
foreach ($this->aggregateRootObjects as $object) {
/** @var DomainObjectInterface $object */
if ($object->_isNew()) {
$this->insertObject($object);
}
......@@ -426,6 +428,7 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
$updateSortingOfFollowing = FALSE;
foreach ($objectStorage as $object) {
/** @var DomainObjectInterface $object */
if (empty($currentUids)) {
$sortingPosition = 1;
} else {
......@@ -507,7 +510,7 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
* Updates the fields defining the relation between the object and the parent object.
*
* @param \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $object
* @param \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $parentObject
* @param \TYPO3\CMS\Extbase\DomainObject\AbstractEntity $parentObject
* @param string $parentPropertyName
* @param integer $sortingPosition
* @return void
......@@ -1015,5 +1018,6 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
} else {
return $input;
}
return NULL;
}
}
......@@ -101,4 +101,21 @@ interface BackendInterface {
*/
public function isNewObject($object);
/**
* Returns the number of records matching the query.
*
* @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query
* @return integer
* @api
*/
public function getObjectCountByQuery(\TYPO3\CMS\Extbase\Persistence\QueryInterface $query);
/**
* Returns the object data matching the $query.
*
* @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query
* @return array
* @api
*/
public function getObjectDataByQuery(\TYPO3\CMS\Extbase\Persistence\QueryInterface $query);
}
......@@ -166,7 +166,7 @@ class LazyObjectStorage extends \TYPO3\CMS\Extbase\Persistence\ObjectStorage imp
public function count() {
$columnMap = $this->dataMapper->getDataMap(get_class($this->parentObject))->getColumnMap($this->propertyName);
$numberOfElements = NULL;
if (!$this->isInitialized && $columnMap->getTypeOfRelation() === \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_HAS_MANY) {
if (!$this->isInitialized && $columnMap->getTypeOfRelation() === Mapper\ColumnMap::RELATION_HAS_MANY) {
$numberOfElements = $this->dataMapper->countRelated($this->parentObject, $this->propertyName, $this->fieldValue);
} else {
$this->initialize();
......
......@@ -234,7 +234,7 @@ class DataMap {
* @param \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap $columnMap The column map
* @return void
*/
public function addColumnMap(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap $columnMap) {
public function addColumnMap(ColumnMap $columnMap) {
$this->columnMaps[$columnMap->getPropertyName()] = $columnMap;
}
......
......@@ -27,7 +27,6 @@ namespace TYPO3\CMS\Extbase\Persistence\Generic\Mapper;
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap;
/**
* A factory for a data map to map a single table configured in $TCA on a domain object.
......
......@@ -27,7 +27,7 @@ namespace TYPO3\CMS\Extbase\Persistence\Generic\Mapper;
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Core\Type\TypeInterface;
use TYPO3\CMS\Extbase\Utility\TypeHandlingUtility;
/**
......@@ -473,6 +473,7 @@ class DataMapper implements \TYPO3\CMS\Core\SingletonInterface {
* @return mixed
*/
public function mapResultToPropertyValue(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $parentObject, $propertyName, $result) {
$propertyValue = NULL;
if ($result instanceof \TYPO3\CMS\Extbase\Persistence\Generic\LoadingStrategyInterface) {
$propertyValue = $result;
} else {
......
......@@ -27,6 +27,9 @@ namespace TYPO3\CMS\Extbase\Persistence\Generic;
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
/**
* The Extbase Persistence Manager
*
......@@ -40,17 +43,17 @@ class PersistenceManager implements \TYPO3\CMS\Extbase\Persistence\PersistenceMa
protected $newObjects = array();
/**
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage
* @var ObjectStorage
*/
protected $changedObjects;
/**
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage
* @var ObjectStorage
*/
protected $addedObjects;
/**
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage
* @var ObjectStorage
*/
protected $removedObjects;
......@@ -76,9 +79,9 @@ class PersistenceManager implements \TYPO3\CMS\Extbase\Persistence\PersistenceMa
* Create new instance
*/
public function __construct() {
$this->addedObjects = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
$this->removedObjects = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
$this->changedObjects = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
$this->addedObjects = new ObjectStorage();
$this->removedObjects = new ObjectStorage();
$this->changedObjects = new ObjectStorage();
}
/**
......@@ -94,22 +97,22 @@ class PersistenceManager implements \TYPO3\CMS\Extbase\Persistence\PersistenceMa
/**
* Returns the number of records matching the query.
*
* @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query
* @param QueryInterface $query
* @return integer
* @api
*/
public function getObjectCountByQuery(\TYPO3\CMS\Extbase\Persistence\QueryInterface $query) {
public function getObjectCountByQuery(QueryInterface $query) {
return $this->backend->getObjectCountByQuery($query);
}
/**
* Returns the object data matching the $query.
*
* @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query
* @param QueryInterface $query
* @return array
* @api
*/
public function getObjectDataByQuery(\TYPO3\CMS\Extbase\Persistence\QueryInterface $query) {
public function getObjectDataByQuery(QueryInterface $query) {
return $this->backend->getObjectDataByQuery($query);
}
......@@ -167,16 +170,16 @@ class PersistenceManager implements \TYPO3\CMS\Extbase\Persistence\PersistenceMa
$this->backend->setDeletedEntities($this->removedObjects);
$this->backend->commit();
$this->addedObjects = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
$this->removedObjects = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
$this->changedObjects = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
$this->addedObjects = new ObjectStorage();
$this->removedObjects = new ObjectStorage();
$this->changedObjects = new ObjectStorage();
}
/**
* Return a query object for the given type.
*
* @param string $type
* @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
* @return QueryInterface
*/
public function createQueryForType($type) {
return $this->queryFactory->create($type);
......@@ -256,9 +259,9 @@ class PersistenceManager implements \TYPO3\CMS\Extbase\Persistence\PersistenceMa
*/
public function clearState() {
$this->newObjects = array();
$this->addedObjects = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
$this->removedObjects = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
$this->changedObjects = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
$this->addedObjects = new ObjectStorage();
$this->removedObjects = new ObjectStorage();
$this->changedObjects = new ObjectStorage();
$this->persistenceSession->destroy();
}
......@@ -295,6 +298,7 @@ class PersistenceManager implements \TYPO3\CMS\Extbase\Persistence\PersistenceMa
*
* @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException
* @param object $object The object to be converted
* @return array
* @api
*/
public function convertObjectToIdentityArray($object) {
......@@ -307,6 +311,7 @@ class PersistenceManager implements \TYPO3\CMS\Extbase\Persistence\PersistenceMa
*
* @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException
* @param array $array The array to be iterated over
* @return array
* @api
* @see convertObjectToIdentityArray()
*/
......
......@@ -215,8 +215,6 @@ class PropertyType {
/**
* Make instantiation impossible...
*
* @return void
*/
private function __construct() {
}
......@@ -354,8 +352,6 @@ class PropertyType {
case 'double':
$value = \TYPO3\CMS\Extbase\Persistence\Generic\PropertyType::DOUBLE;
break;
case 'integer':
case 'int':
$value = \TYPO3\CMS\Extbase\Persistence\Generic\PropertyType::INTEGER;
break;
......
......@@ -30,7 +30,7 @@ namespace TYPO3\CMS\Extbase\Persistence\Generic\Qom;
/**
* Evaluates to the value of a bind variable.
*/
class BindVariableValue extends \TYPO3\CMS\Extbase\Persistence\Generic\Qom\StaticOperand implements \TYPO3\CMS\Extbase\Persistence\Generic\Qom\BindVariableValueInterface {
class BindVariableValue implements \TYPO3\CMS\Extbase\Persistence\Generic\Qom\BindVariableValueInterface {
/**
* @var string
......
......@@ -27,6 +27,8 @@ namespace TYPO3\CMS\Extbase\Persistence\Generic\Qom;
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
/**
* Filters node-tuples based on the outcome of a binary operation.
*
......@@ -70,10 +72,10 @@ namespace TYPO3\CMS\Extbase\Persistence\Generic\Qom;
* the string "\x" matches the character "x", and
* all other characters match themselves.
*/
class Comparison implements \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface {
class Comparison implements ComparisonInterface {
/**
* @var \TYPO3\CMS\Extbase\Persistence\Generic\Qom\DynamicOperandInterface
* @var PropertyValueInterface
*/
protected $operand1;
......@@ -87,7 +89,7 @@ class Comparison implements \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Compariso
*/
protected $operand2;
/*
/**
* @var string
*/
protected $parameterIdentifier;
......@@ -95,11 +97,11 @@ class Comparison implements \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Compariso
/**
* Constructs this Comparison instance
*
* @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\DynamicOperandInterface $operand1
* @param integer $operator one of \TYPO3\CMS\Extbase\Persistence\QueryInterface.OPERATOR_*
* @param PropertyValueInterface $operand1
* @param integer $operator one of QueryInterface::OPERATOR_*
* @param mixed $operand2
*/
public function __construct(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\DynamicOperandInterface $operand1, $operator, $operand2) {
public function __construct(PropertyValueInterface $operand1, $operator, $operand2) {
$this->operand1 = $operand1;
$this->operator = $operator;
$this->operand2 = $operand2;
......@@ -108,7 +110,7 @@ class Comparison implements \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Compariso
/**
* Gets the first operand.
*
* @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\DynamicOperandInterface the operand; non-null
* @return PropertyValueInterface the operand; non-null
*/
public function getOperand1() {
return $this->operand1;
......@@ -117,16 +119,16 @@ class Comparison implements \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Compariso
/**
* Gets the operator.
*
* @return string one of \TYPO3\CMS\Extbase\Persistence\QueryInterface.OPERATOR_*
* @return string One of QueryInterface::OPERATOR_*
*/
public function getOperator() {
$operator = $this->operator;
if ($this->getOperand2() === NULL) {
if ($operator === \TYPO3\CMS\Extbase\Persistence\QueryInterface::OPERATOR_EQUAL_TO) {
$operator = \TYPO3\CMS\Extbase\Persistence\QueryInterface::OPERATOR_EQUAL_TO_NULL;
} elseif ($operator === \TYPO3\CMS\Extbase\Persistence\QueryInterface::OPERATOR_NOT_EQUAL_TO) {
$operator = \TYPO3\CMS\Extbase\Persistence\QueryInterface::OPERATOR_NOT_EQUAL_TO_NULL;
if ($operator === QueryInterface::OPERATOR_EQUAL_TO) {
$operator = QueryInterface::OPERATOR_EQUAL_TO_NULL;
} elseif ($operator === QueryInterface::OPERATOR_NOT_EQUAL_TO) {
$operator = QueryInterface::OPERATOR_NOT_EQUAL_TO_NULL;
}
}
......@@ -156,4 +158,13 @@ class Comparison implements \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Compariso
public function getParameterIdentifier() {
return $this->parameterIdentifier;
}
/**
* Fills an array with the names of all bound variables in the constraints
*
* @param array &$boundVariables
* @return void
*/
public function collectBoundVariableNames(&$boundVariables) {
}
}
......@@ -72,26 +72,37 @@ namespace TYPO3\CMS\Extbase\Persistence\Generic\Qom;
*
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
*/
interface ComparisonInterface extends \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface {
interface ComparisonInterface extends ConstraintInterface {
/**
* Gets the first operand.
*
* @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\DynamicOperandInterface the operand; non-null
* @return PropertyValueInterface the operand; non-null
*/
public function getOperand1();
/**
* Gets the operator.
*
* @return string one of \TYPO3\CMS\Extbase\Persistence\QueryObjectModelConstantsInterface.OPERATOR_*
* @return string one of \TYPO3\CMS\Extbase\Persistence\QueryInterface::*
*/
public function getOperator();
/**
* Gets the second operand.
*
* @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\StaticOperandInterface the operand; non-null
* @return StaticOperandInterface the operand; non-null
*/
public function getOperand2();
/**
* @param string $parameterIdentifier
* @return void
*/
public function setParameterIdentifier($parameterIdentifier);
/**
* @return string
*/
public function getParameterIdentifier();
}
<?php
namespace TYPO3\CMS\Extbase\Persistence\Generic\Qom;
/***************************************************************
* Copyright notice
*
* (c) 2010-2013 Extbase Team (http://forge.typo3.org/projects/typo3v4-mvc)
* Extbase is a backport of TYPO3 Flow. All credits go to the TYPO3 Flow team.
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the text file GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Base class for constraints in the QOM.
*
* @api
*/
class Constraint implements \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface {
}
......@@ -35,4 +35,11 @@ namespace TYPO3\CMS\Extbase\Persistence\Generic\Qom;
*/
interface ConstraintInterface {
/**
* Fills an array with the names of all bound variables in the constraints
*
* @param array &$boundVariables
* @return void
*/
public function collectBoundVariableNames(&$boundVariables);
}
<?php
namespace TYPO3\CMS\Extbase\Persistence\Generic\Qom;
/***************************************************************
* Copyright notice
*
* (c) 2010-2013 Extbase Team (http://forge.typo3.org/projects/typo3v4-mvc)
* Extbase is a backport of TYPO3 Flow. All credits go to the TYPO3 Flow team.
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the text file GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* An operand whose value can only be determined in evaluating the query.
*/
class DynamicOperand extends \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Operand implements \TYPO3\CMS\Extbase\Persistence\Generic\Qom\DynamicOperandInterface {
}
......@@ -30,6 +30,6 @@ namespace TYPO3\CMS\Extbase\Persistence\Generic\Qom;
/**
* An operand whose value can only be determined in evaluating the query.
*/
interface DynamicOperandInterface extends \TYPO3\CMS\Extbase\Persistence\Generic\Qom\OperandInterface {
interface DynamicOperandInterface extends OperandInterface {
}
......@@ -34,7 +34,7 @@ namespace TYPO3\CMS\Extbase\Persistence\Generic\Qom;
* the selector2Name node has a property named property2Name, and
* the value of property property1Name is equal to the value of property property2Name.
*/
class EquiJoinCondition implements \TYPO3\CMS\Extbase\Persistence\Generic\Qom\JoinConditionInterface {
class EquiJoinCondition implements EquiJoinConditionInterface {
/**
* @var string
......@@ -107,4 +107,22 @@ class EquiJoinCondition implements \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Jo
public function getProperty2Name() {
return $this->property2Name;
}
/**
* Gets the name of the child selector.
*
* @return string the selector name; non-null
*/
public function getChildSelectorName() {
return '';
}
/**
* Gets the name of the parent selector.
*
* @return string the selector name; non-null
*/
public function getParentSelectorName() {
return '';
}
}
......@@ -34,7 +34,7 @@ namespace TYPO3\CMS\Extbase\Persistence\Generic\Qom;
* would return true, where childSelectorNode is the node for childSelector and
* parentSelectorNode is the node for parentSelector.
*/
interface EquiJoinConditionInterface extends \TYPO3\CMS\Extbase\Persistence\Generic\Qom\JoinConditionInterface {
interface EquiJoinConditionInterface extends JoinConditionInterface {
/**
* Gets the name of the child selector.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment