Enforce a consistent processing by id
authorAlexander Ebert <ebert@woltlab.com>
Sun, 9 Jun 2024 10:31:12 +0000 (12:31 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 9 Jun 2024 10:31:12 +0000 (12:31 +0200)
wcfsetup/install/files/lib/system/worker/AbstractLinearRebuildDataWorker.class.php

index feecf2578bd55509b16c278cfe1ba921eb642c41..858183ed390ae114ed09bee0c7c31cfe3c4b4254 100644 (file)
@@ -29,21 +29,23 @@ abstract class AbstractLinearRebuildDataWorker extends AbstractRebuildDataWorker
     #[\Override]
     public function countObjects()
     {
-        if ($this->count === null) {
-            if ($this->objectList === null) {
-                $this->initObjectList();
-            }
-
-            $sql = \sprintf(
-                "SELECT MAX(%s) FROM %s",
-                $this->objectList->getDatabaseTableIndexName(),
-                $this->objectList->getDatabaseTableName(),
-            );
-            $statement = WCF::getDB()->prepare($sql);
-            $statement->execute([]);
-
-            $this->count = $statement->fetchSingleColumn();
+        if ($this->count !== null) {
+            return;
+        }
+
+        if ($this->objectList === null) {
+            $this->initObjectList();
         }
+
+        $sql = \sprintf(
+            "SELECT MAX(%s) FROM %s",
+            $this->objectList->getDatabaseTableIndexName(),
+            $this->objectList->getDatabaseTableName(),
+        );
+        $statement = WCF::getDB()->prepare($sql);
+        $statement->execute();
+
+        $this->count = $statement->fetchSingleColumn();
     }
 
     #[\Override]
@@ -72,17 +74,21 @@ abstract class AbstractLinearRebuildDataWorker extends AbstractRebuildDataWorker
         }
 
         $this->objectList = new $this->objectListClassName();
+
+        $indexName = \sprintf(
+            '%s.%s',
+            $this->objectList->getDatabaseTableAlias(),
+            $this->objectList->getDatabaseTableIndexName(),
+        );
+
         $this->objectList->getConditionBuilder()->add(
-            \sprintf(
-                "%s.%s BETWEEN ? AND ?",
-                $this->objectList->getDatabaseTableAlias(),
-                $this->objectList->getDatabaseTableIndexName(),
-            ),
+            "{$indexName} BETWEEN ? AND ?",
             [
                 $this->limit * $this->loopCount + 1,
                 $this->limit * $this->loopCount + $this->limit,
             ]
         );
+        $this->objectList->sqlOrderBy = $indexName;
     }
 
     #[\Override]