Commit 3ef27aae authored by Alexander Schnitzler's avatar Alexander Schnitzler Committed by Benni Mack
Browse files

[TASK] Remove dead code from Extbase persistence

This patch removes unused code in the persistence
area of Extbase. Most removed code was part of
internal classes and interfaces, thus they are
removed without notice.

Along with the removal of methods, two methods
have been marked deprecated and for their
removal in the future i.e. TYPO3 12.0.

Releases: master
Resolves: #89938
Change-Id: I66596bff9879a6850a71ada05891f80a551ffb74
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/62616

Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Markus Klein's avatarMarkus Klein <markus.klein@typo3.org>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Markus Klein's avatarMarkus Klein <markus.klein@typo3.org>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent e47dd889
.. include:: ../../Includes.txt
====================================================================
Deprecation: #89938 - Deprecated language mode in Typo3QuerySettings
====================================================================
See :issue:`89938`
Description
===========
The following methods have been deprecated and will be removed in TYPO3 12.0.
- :php:`\TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings::setLanguageMode`
- :php:`\TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings::getLanguageMode`
Impact
======
Calling these methods will trigger a deprecation warning with TYPO3 11.0.
Calling these methods as of 12.0 will result in a fatal error.
Affected Installations
======================
All installations that call the mentioned methods.
Migration
=========
The deprecated methods have been used in combination with the non consistent translation handling of
Extbase. As that handling mode disappeared, there is no need to migrate these method calls and just
stop calling those instead.
For more information regarding this change, see issue :issue:`87264`
.. index:: PHP-API, FullyScanned, ext:extbase
.. include:: ../../Includes.txt
==============================================================
Important: #89938 - Removed dead code from Extbase persistence
==============================================================
See :issue:`89938`
Description
===========
The following public methods have been removed from Extbase persistence:
- :php:`TYPO3\CMS\Extbase\Persistence\Generic\Backend->getSession()`
- :php:`TYPO3\CMS\Extbase\Persistence\Generic\Backend->getQomFactory()`
- :php:`TYPO3\CMS\Extbase\Persistence\Generic\Backend->getReflectionService()`
- :php:`TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper->isPersistableProperty()`
- :php:`TYPO3\CMS\Core\Session\SessionManager->replaceReconstitutedEntity()`
- :php:`TYPO3\CMS\Core\Session\SessionManager->isReconstitutedEntity()`
- :php:`TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbBackend->getMaxValueFromTable()`
- :php:`TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbBackend->getRowByIdentifier()`
.. index:: PHP-API, FullyScanned, ext:extbase
......@@ -34,7 +34,6 @@ use TYPO3\CMS\Extbase\Persistence\Exception\IllegalRelationTypeException;
use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap;
use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory;
use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper;
use TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory;
use TYPO3\CMS\Extbase\Persistence\ObjectMonitoringInterface;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
use TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface;
......@@ -84,11 +83,6 @@ class Backend implements BackendInterface, SingletonInterface
*/
protected $reflectionService;
/**
* @var \TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory
*/
protected $qomFactory;
/**
* @var \TYPO3\CMS\Extbase\Persistence\Generic\Storage\BackendInterface
*/
......@@ -127,7 +121,6 @@ class Backend implements BackendInterface, SingletonInterface
* @param \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager
* @param Session $session
* @param \TYPO3\CMS\Extbase\Reflection\ReflectionService $reflectionService
* @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory $qomFactory
* @param \TYPO3\CMS\Extbase\Persistence\Generic\Storage\BackendInterface $storageBackend
* @param \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory $dataMapFactory
* @param EventDispatcherInterface $eventDispatcher
......@@ -136,7 +129,6 @@ class Backend implements BackendInterface, SingletonInterface
ConfigurationManagerInterface $configurationManager,
Session $session,
ReflectionService $reflectionService,
QueryObjectModelFactory $qomFactory,
\TYPO3\CMS\Extbase\Persistence\Generic\Storage\BackendInterface $storageBackend,
DataMapFactory $dataMapFactory,
EventDispatcherInterface $eventDispatcher
......@@ -144,7 +136,6 @@ class Backend implements BackendInterface, SingletonInterface
$this->configurationManager = $configurationManager;
$this->session = $session;
$this->reflectionService = $reflectionService;
$this->qomFactory = $qomFactory;
$this->storageBackend = $storageBackend;
$this->dataMapFactory = $dataMapFactory;
$this->eventDispatcher = $eventDispatcher;
......@@ -163,36 +154,6 @@ class Backend implements BackendInterface, SingletonInterface
$this->persistenceManager = $persistenceManager;
}
/**
* Returns the repository session
*
* @return \TYPO3\CMS\Extbase\Persistence\Generic\Session
*/
public function getSession()
{
return $this->session;
}
/**
* Returns the current QOM factory
*
* @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory
*/
public function getQomFactory()
{
return $this->qomFactory;
}
/**
* Returns the reflection service
*
* @return \TYPO3\CMS\Extbase\Reflection\ReflectionService
*/
public function getReflectionService()
{
return $this->reflectionService;
}
/**
* Returns the number of records matching the query.
*
......@@ -813,62 +774,6 @@ class Backend implements BackendInterface, SingletonInterface
return true;
}
/**
* Fetches maximal value currently used for sorting field in parent table
*
* @param \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface $parentObject The parent object
* @param string $parentPropertyName The name of the parent object's property where the related objects are stored in
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalRelationTypeException
* @return mixed the max value
*/
protected function fetchMaxSortingFromParentTable(DomainObjectInterface $parentObject, $parentPropertyName)
{
$parentDataMap = $this->dataMapFactory->buildDataMap(get_class($parentObject));
$parentColumnMap = $parentDataMap->getColumnMap($parentPropertyName);
if ($parentColumnMap->getTypeOfRelation() === ColumnMap::RELATION_HAS_MANY) {
$tableName = $parentColumnMap->getChildTableName();
$sortByFieldName = $parentColumnMap->getChildSortByFieldName();
if (empty($sortByFieldName)) {
return false;
}
$matchFields = [];
$parentKeyFieldName = $parentColumnMap->getParentKeyFieldName();
if ($parentKeyFieldName !== null) {
$matchFields[$parentKeyFieldName] = $parentObject->getUid();
$parentTableFieldName = $parentColumnMap->getParentTableFieldName();
if ($parentTableFieldName !== null) {
$matchFields[$parentTableFieldName] = $parentDataMap->getTableName();
}
}
if (empty($matchFields)) {
return false;
}
} elseif ($parentColumnMap->getTypeOfRelation() === ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY) {
$tableName = $parentColumnMap->getRelationTableName();
$sortByFieldName = $parentColumnMap->getChildSortByFieldName();
$matchFields = [
$parentColumnMap->getParentKeyFieldName() => (int)$parentObject->getUid()
];
$relationTableMatchFields = $parentColumnMap->getRelationTableMatchFields();
if (is_array($relationTableMatchFields)) {
$matchFields = array_merge($relationTableMatchFields, $matchFields);
}
} else {
throw new IllegalRelationTypeException('Unexpected parent column relation type: ' . $parentColumnMap->getTypeOfRelation(), 1345368106);
}
$result = $this->storageBackend->getMaxValueFromTable(
$tableName,
$matchFields,
$sortByFieldName
);
return $result;
}
/**
* Updates a given object in the storage
*
......
......@@ -622,20 +622,6 @@ class DataMapper
return $query->execute()->count();
}
/**
* Delegates the call to the Data Map.
* Returns TRUE if the property is persistable (configured in $TCA)
*
* @param string $className The property name
* @param string $propertyName The property name
* @return bool TRUE if the property is persistable (configured in $TCA)
*/
public function isPersistableProperty($className, $propertyName)
{
$dataMap = $this->getDataMap($className);
return $dataMap->isPersistableProperty($propertyName);
}
/**
* Returns a data map for a given class name
*
......
......@@ -17,7 +17,6 @@ namespace TYPO3\CMS\Extbase\Persistence\Generic;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException;
use TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
use TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface;
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
......@@ -222,17 +221,6 @@ class PersistenceManager implements PersistenceManagerInterface, SingletonInterf
$this->changedObjects->attach($object);
}
/**
* Injects the Extbase settings, called by Extbase.
*
* @param array $settings
* @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException
*/
public function injectSettings(array $settings)
{
throw new NotImplementedException(__METHOD__, 1476108078);
}
/**
* Initializes the persistence manager, called by Extbase.
* @internal only to be used within Extbase, not part of TYPO3 Core API.
......@@ -289,30 +277,6 @@ class PersistenceManager implements PersistenceManagerInterface, SingletonInterf
$this->newObjects[$identifier] = $object;
}
/**
* Converts the given object into an array containing the identity of the domain object.
*
* @param object $object The object to be converted
* @throws Exception\NotImplementedException
*/
public function convertObjectToIdentityArray($object)
{
throw new NotImplementedException(__METHOD__, 1476108103);
}
/**
* Recursively iterates through the given array and turns objects
* into arrays containing the identity of the domain object.
*
* @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException
* @param array $array The array to be iterated over
* @see convertObjectToIdentityArray()
*/
public function convertObjectsToIdentityArrays(array $array)
{
throw new NotImplementedException(__METHOD__, 1476108111);
}
/**
* Tear down the persistence
*
......
......@@ -19,7 +19,6 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
use TYPO3\CMS\Extbase\Persistence\Generic\Exception\InvalidNumberOfConstraintsException;
use TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException;
use TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnexpectedTypeException;
use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory;
use TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface;
......@@ -644,16 +643,4 @@ class Query implements QueryInterface
{
return $this->execute()->count();
}
/**
* Returns an "isEmpty" criterion used for matching objects against a query.
* It matches if the multivalued property contains no values or is NULL.
*
* @param string $propertyName The name of the multivalued property to compare against
* @throws Exception\NotImplementedException
*/
public function isEmpty($propertyName)
{
throw new NotImplementedException(__METHOD__, 1476122265);
}
}
......@@ -70,18 +70,6 @@ class Session implements SingletonInterface
$this->reconstitutedEntities->attach($entity);
}
/**
* Replace a reconstituted object, leaves the clean data unchanged.
*
* @param object $oldEntity
* @param object $newEntity
*/
public function replaceReconstitutedEntity($oldEntity, $newEntity)
{
$this->reconstitutedEntities->detach($oldEntity);
$this->reconstitutedEntities->attach($newEntity);
}
/**
* Unregisters data for a reconstituted object
*
......@@ -104,17 +92,6 @@ class Session implements SingletonInterface
return $this->reconstitutedEntities;
}
/**
* Tells whether the given object is a reconstituted entity.
*
* @param object $entity
* @return bool
*/
public function isReconstitutedEntity($entity)
{
return $this->reconstitutedEntities->contains($entity);
}
// @todo implement the is dirty checking behaviour of the Flow persistence session here
/**
......
......@@ -61,16 +61,6 @@ interface BackendInterface
*/
public function removeRow(string $tableName, array $where, bool $isRelation = false): void;
/**
* Fetches maximal value for given table column
*
* @param string $tableName The database table name
* @param array $where An array of where array('fieldname' => value). This array will be transformed to a WHERE clause
* @param string $columnName column name to get the max value from
* @return mixed the max value
*/
public function getMaxValueFromTable(string $tableName, array $where, string $columnName);
/**
* Returns the number of items matching the query.
*
......
......@@ -269,71 +269,6 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
}
}
/**
* Fetches maximal value for given table column from database.
*
* @param string $tableName The database table name
* @param array $where An array of where array('fieldname' => value).
* @param string $columnName column name to get the max value from
* @return mixed the max value
* @throws SqlErrorException
*/
public function getMaxValueFromTable(string $tableName, array $where, string $columnName)
{
try {
$queryBuilder = $this->connectionPool->getQueryBuilderForTable($tableName);
$queryBuilder->getRestrictions()->removeAll();
$queryBuilder
->select($columnName)
->from($tableName)
->orderBy($columnName, 'DESC')
->setMaxResults(1);
foreach ($where as $fieldName => $value) {
$queryBuilder->andWhere(
$queryBuilder->expr()->eq($fieldName, $queryBuilder->createNamedParameter($value, \PDO::PARAM_STR))
);
}
$result = $queryBuilder->execute()->fetchColumn(0);
} catch (DBALException $e) {
throw new SqlErrorException($e->getPrevious()->getMessage(), 1470230770, $e);
}
return $result;
}
/**
* Fetches row data from the database
*
* @param string $tableName
* @param array $where An array of where array('fieldname' => value).
* @return array|bool
* @throws SqlErrorException
*/
public function getRowByIdentifier(string $tableName, array $where)
{
// todo: this method is not in use, consider removing it.
try {
$queryBuilder = $this->connectionPool->getQueryBuilderForTable($tableName);
$queryBuilder->getRestrictions()->removeAll();
$queryBuilder
->select('*')
->from($tableName);
foreach ($where as $fieldName => $value) {
$queryBuilder->andWhere(
$queryBuilder->expr()->eq($fieldName, $queryBuilder->createNamedParameter($value, \PDO::PARAM_STR))
);
}
$row = $queryBuilder->execute()->fetch();
return is_array($row) ? $row : false;
} catch (DBALException $e) {
throw new SqlErrorException($e->getPrevious()->getMessage(), 1470230771, $e);
}
}
/**
* Returns the object data matching the $query.
*
......
......@@ -211,9 +211,14 @@ class Typo3QuerySettings implements QuerySettingsInterface
*
* @param string $languageMode
* @return QuerySettingsInterface instance of $this to allow method chaining
* @deprecated since TYPO3 11.0, will be removed in version 12.0
*/
public function setLanguageMode($languageMode = '')
{
trigger_error(
__METHOD__ . ' does not have any functionality any more, stop calling it.',
E_USER_DEPRECATED
);
return $this;
}
......@@ -221,9 +226,14 @@ class Typo3QuerySettings implements QuerySettingsInterface
* Language Mode is NOT used anymore, so just avoid using it. Will be deprecated in the future.
*
* @return string NULL, "content_fallback", "strict" or "ignore"
* @deprecated since TYPO3 11.0, will be removed in version 12.0
*/
public function getLanguageMode()
{
trigger_error(
__METHOD__ . ' does not have any functionality any more, stop calling it.',
E_USER_DEPRECATED
);
return null;
}
......
......@@ -113,33 +113,6 @@ interface PersistenceManagerInterface
*/
public function update($object);
/**
* Injects the Extbase settings, called by Extbase.
*
* @param array $settings
*/
public function injectSettings(array $settings);
/**
* Converts the given object into an array containing the identity of the domain object.
*
* @param object $object The object to be converted
* @return array The identity array in the format array('__identity' => '...')
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException if the given object is not known to the Persistence Manager
*/
public function convertObjectToIdentityArray($object);
/**
* Recursively iterates through the given array and turns objects
* into arrays containing the identity of the domain object.
*
* @param array $array The array to be iterated over
* @return array The modified array without objects
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException if array contains objects that are not known to the Persistence Manager
* @see convertObjectToIdentityArray()
*/
public function convertObjectsToIdentityArrays(array $array);
/**
* Return a query object for the given type.
*
......
......@@ -333,16 +333,6 @@ interface QueryInterface
*/
public function getConstraint();
/**
* Returns an "isEmpty" criterion used for matching objects against a query.
* It matches if the multivalued property contains no values or is NULL.
*
* @param string $propertyName The name of the multivalued property to compare against
* @return bool
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a single-valued property
*/
public function isEmpty($propertyName);
/**
* Sets the source to fetch the result from
*
......
......@@ -4718,4 +4718,74 @@ return [
'Breaking-93108-ReworkedInternalUserGroupFetchingForFrontendUsers.rst'
],
],
'TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings->setLanguageMode' => [
'numberOfMandatoryArguments' => 0,
'maximumNumberOfArguments' => 1,
'restFiles' => [
'Deprecation-89938-DeprecatedLanguageModeInTypo3QuerySettings.rst',
],
],
'TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings->getLanguageMode' => [
'numberOfMandatoryArguments' => 0,
'maximumNumberOfArguments' => 0,
'restFiles' => [
'Deprecation-89938-DeprecatedLanguageModeInTypo3QuerySettings.rst',
],
],
'TYPO3\CMS\Extbase\Persistence\Generic\Backend->getSession' => [
'numberOfMandatoryArguments' => 0,
'maximumNumberOfArguments' => 0,
'restFiles' => [
'Important-89938-RemovedDeadCodeFromExtbasePersistence.rst',
],
],
'TYPO3\CMS\Extbase\Persistence\Generic\Backend->getQomFactory' => [
'numberOfMandatoryArguments' => 0,
'maximumNumberOfArguments' => 0,
'restFiles' => [
'Important-89938-RemovedDeadCodeFromExtbasePersistence.rst',
],
],
'TYPO3\CMS\Extbase\Persistence\Generic\Backend->getReflectionService' => [
'numberOfMandatoryArguments' => 0,
'maximumNumberOfArguments' => 0,
'restFiles' => [
'Important-89938-RemovedDeadCodeFromExtbasePersistence.rst',
],
],
'TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper->isPersistableProperty' => [
'numberOfMandatoryArguments' => 2,
'maximumNumberOfArguments' => 2,
'restFiles' => [
'Important-89938-RemovedDeadCodeFromExtbasePersistence.rst',
],
],
'TYPO3\CMS\Extbase\Persistence\Generic\Session->replaceReconstitutedEntity' => [
'numberOfMandatoryArguments' => 2,
'maximumNumberOfArguments' => 2,
'restFiles' => [
'Important-89938-RemovedDeadCodeFromExtbasePersistence.rst',
],
],
'TYPO3\CMS\Extbase\Persistence\Generic\Session->isReconstitutedEntity' => [
'numberOfMandatoryArguments' => 1,
'maximumNumberOfArguments' => 1,
'restFiles' => [
'Important-89938-RemovedDeadCodeFromExtbasePersistence.rst',
],
],
'TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbBackend->getMaxValueFromTable' => [
'numberOfMandatoryArguments' => 3,
'maximumNumberOfArguments' => 3,
'restFiles' => [
'Important-89938-RemovedDeadCodeFromExtbasePersistence.rst',
],
],
'TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbBackend->getRowByIdentifier' => [
'numberOfMandatoryArguments' => 2,