[BUGFIX] Updating "current_version" fails with some DBMS 65/32065/4
authorAndreas Fernandez <andreas.fernandez@aspedia.de>
Fri, 8 Aug 2014 14:00:19 +0000 (16:00 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Wed, 13 Aug 2014 17:50:45 +0000 (19:50 +0200)
Updating the field "current_version" fails with some DMBS because
$uidsOfCurrentVersion has too many elements. This patch chunks
the array into multiple parts and updates the uids in each part.

Resolves: #60859
Releases: 6.2, 6.3
Change-Id: If63f855b250bf7c9b6cd7112f60392cfc8ccfd67
Reviewed-on: http://review.typo3.org/32065
Reviewed-by: Markus Klein <klein.t3@reelworx.at>
Tested-by: Markus Klein <klein.t3@reelworx.at>
Reviewed-by: Xavier Perseguers <xavier@typo3.org>
Tested-by: Xavier Perseguers <xavier@typo3.org>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/extensionmanager/Classes/Domain/Repository/ExtensionRepository.php

index 11014fd..a7c5cbf 100644 (file)
@@ -26,6 +26,15 @@ class ExtensionRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {
        const TABLE_NAME = 'tx_extensionmanager_domain_model_extension';
 
        /**
+        * Oracle has a limit of 1000 values in an IN clause. Set the size of a chunk
+        * being updated to 500 to make sure it does not collide with a limit in any
+        * other DBMS.
+        *
+        * @var integer
+        */
+       const CHUNK_SIZE = 500;
+
+       /**
         * @var \TYPO3\CMS\Core\Database\DatabaseConnection
         */
        protected $databaseConnection;
@@ -288,13 +297,18 @@ class ExtensionRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {
        protected function markExtensionWithMaximumVersionAsCurrent($repositoryUid) {
                $uidsOfCurrentVersion = $this->fetchMaximalVersionsForAllExtensions($repositoryUid);
 
-               $this->databaseConnection->exec_UPDATEquery(
-                       self::TABLE_NAME,
-                       'uid IN (' . implode(',', $uidsOfCurrentVersion) . ')',
-                       array(
-                               'current_version' => 1,
-                       )
-               );
+               // some DBMS limit the amount of expressions, apply the update in chunks
+               $chunks = array_chunk($uidsOfCurrentVersion, self::CHUNK_SIZE);
+               $chunkCount = count($chunks);
+               for ($i = 0; $i < $chunkCount; ++$i) {
+                       $this->databaseConnection->exec_UPDATEquery(
+                               self::TABLE_NAME,
+                               'uid IN (' . implode(',', $chunks[$i]) . ')',
+                               array(
+                                       'current_version' => 1,
+                               )
+                       );
+               }
        }
 
        /**