2 declare(strict_types = 1);
50 L10nModeUpdater::class,
51 ImageCropUpdater::class,
52 RteLinkSyntaxUpdater::class,
69 return 'databaseRowsUpdateWizard';
77 return 'Execute database migrations on single rows';
87 $description =
'Row updaters that have not been executed:';
88 foreach ($rowUpdaterNotExecuted as $rowUpdateClassName) {
89 $rowUpdater = GeneralUtility::makeInstance($rowUpdateClassName);
91 throw new \RuntimeException(
92 'Row updater must implement RowUpdaterInterface',
115 DatabaseUpdatedPrerequisite::class
128 $registry = GeneralUtility::makeInstance(Registry::class);
133 $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
134 $connectionForSysRegistry = $connectionPool->getConnectionForTable(
'sys_registry');
137 $rowUpdaterInstances = [];
142 $rowUpdaterInstance = GeneralUtility::makeInstance(
$rowUpdater);
144 throw new \RuntimeException(
145 'Row updater must implement RowUpdaterInterface',
149 $rowUpdaterInstances[] = $rowUpdaterInstance;
154 $listOfAllTables = array_keys(
$GLOBALS[
'TCA']);
158 sort($listOfAllTables);
159 reset($listOfAllTables);
160 $firstTable = current($listOfAllTables);
162 foreach ($listOfAllTables as $key => $table) {
163 if ($table === $startPosition[
'table']) {
166 unset($listOfAllTables[$key]);
170 $tableToUpdaterList = [];
171 foreach ($listOfAllTables as $table) {
172 foreach ($rowUpdaterInstances as $updater) {
173 if ($updater->hasPotentialUpdateForTable($table)) {
174 if (!is_array($tableToUpdaterList[$table])) {
175 $tableToUpdaterList[$table] = [];
177 $tableToUpdaterList[$table][] = $updater;
185 foreach ($tableToUpdaterList as $table => $updaters) {
187 $connectionForTable = $connectionPool->getConnectionForTable($table);
188 $queryBuilder = $connectionPool->getQueryBuilderForTable($table);
189 $queryBuilder->getRestrictions()->removeAll();
190 $queryBuilder->select(
'*')
193 if ($table === $startPosition[
'table']) {
194 $queryBuilder->where(
195 $queryBuilder->expr()->gt(
'uid', $queryBuilder->createNamedParameter($startPosition[
'uid']))
198 $statement = $queryBuilder->execute();
199 $rowCountWithoutUpdate = 0;
200 while ($row = $rowBefore = $statement->fetch()) {
201 foreach ($updaters as $updater) {
202 $row = $updater->updateTableRow($table, $row);
204 $updatedFields = array_diff_assoc($row, $rowBefore);
205 if (empty($updatedFields)) {
207 $rowCountWithoutUpdate++;
208 if ($rowCountWithoutUpdate >= 200) {
212 'uid' => $row[
'uid'],
214 $registry->set(
'installUpdateRows',
'rowUpdatePosition', $startPosition);
215 $rowCountWithoutUpdate = 0;
218 $rowCountWithoutUpdate = 0;
221 'uid' => $rowBefore[
'uid'],
223 if ($connectionForSysRegistry === $connectionForTable) {
225 $connectionForTable->beginTransaction();
227 $connectionForTable->update(
231 'uid' => $rowBefore[
'uid'],
234 $connectionForTable->update(
237 'entry_value' => serialize($startPosition),
240 'entry_namespace' =>
'installUpdateRows',
241 'entry_key' =>
'rowUpdatePosition',
244 $connectionForTable->commit();
246 $connectionForTable->rollBack();
252 $connectionForTable->update(
256 'uid' => $rowBefore[
'uid'],
259 $connectionForSysRegistry->update(
262 'entry_value' => serialize($startPosition),
265 'entry_namespace' =>
'installUpdateRows',
266 'entry_key' =>
'rowUpdatePosition',
275 $registry->remove(
'installUpdateRows',
'rowUpdatePosition');
277 foreach ($rowUpdaterInstances as $updater) {
291 $doneRowUpdater = GeneralUtility::makeInstance(Registry::class)->get(
'installUpdateRows',
'rowUpdatersDone', []);
292 return array_diff($this->rowUpdater, $doneRowUpdater);
302 $registry = GeneralUtility::makeInstance(Registry::class);
303 $doneRowUpdater = $registry->get(
'installUpdateRows',
'rowUpdatersDone', []);
304 $doneRowUpdater[] = get_class($updater);
305 $registry->set(
'installUpdateRows',
'rowUpdatersDone', $doneRowUpdater);
317 $registry = GeneralUtility::makeInstance(Registry::class);
318 $startPosition = $registry->get(
'installUpdateRows',
'rowUpdatePosition', []);
319 if (empty($startPosition)) {
321 'table' => $firstTable,
324 $registry->set(
'installUpdateRows',
'rowUpdatePosition', $startPosition);
326 return $startPosition;