TYPO3 CMS  TYPO3_8-7
FillTranslationSourceField.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
19 
24 {
28  protected $title = 'Fill translation source field (l10n_source)';
29 
36  public function checkForUpdate(&$description)
37  {
38  if ($this->isWizardDone()) {
39  return false;
40  }
41  $connection = GeneralUtility::makeInstance(ConnectionPool::class)
42  ->getConnectionForTable('tt_content');
43  $queryBuilder = $connection->createQueryBuilder();
44  $queryBuilder->getRestrictions()->removeAll();
45  $query = $queryBuilder->count('uid')
46  ->from('tt_content')
47  ->where($queryBuilder->expr()->andX(
48  $queryBuilder->expr()->gt('l18n_parent', $queryBuilder->createNamedParameter(0)),
49  $queryBuilder->expr()->eq('l10n_source', $queryBuilder->createNamedParameter(0))
50  ));
51  $count = (int)$query->execute()->fetchColumn(0);
52 
53  if ($count > 0) {
54  $description = 'Fill translation source field (l10n_source) for tt_contents which have l18n_parent set.';
55  }
56  return (bool)$count;
57  }
58 
66  public function performUpdate(array &$databaseQueries, &$customMessage)
67  {
68  $connection = GeneralUtility::makeInstance(ConnectionPool::class)
69  ->getConnectionForTable('tt_content');
70  $queryBuilder = $connection->createQueryBuilder();
71  $queryBuilder->getRestrictions()->removeAll();
72  $queryBuilder->update('tt_content', 't')
73  ->set('t.l10n_source', 't.l18n_parent', false)
74  ->where($queryBuilder->expr()->andX(
75  $queryBuilder->expr()->gt('t.l18n_parent', $queryBuilder->createNamedParameter(0)),
76  $queryBuilder->expr()->eq('t.l10n_source', $queryBuilder->createNamedParameter(0))
77  ));
78  $databaseQueries[] = $queryBuilder->getSQL();
79  $queryBuilder->execute();
80  $this->markWizardAsDone();
81  return true;
82  }
83 }
performUpdate(array &$databaseQueries, &$customMessage)
static makeInstance($className,... $constructorArguments)