‪TYPO3CMS  11.5
IntegrityService.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use TYPO3\CMS\Backend\Utility\BackendUtility;
22 
27 {
33  public const ‪STATUS_Succes = 100;
39  public const ‪STATUS_Info = 101;
45  public const ‪STATUS_Warning = 102;
51  public const ‪STATUS_Error = 103;
55  protected ‪$statusRepresentation = [
56  self::STATUS_Succes => 'success',
57  self::STATUS_Info => 'info',
58  self::STATUS_Warning => 'warning',
59  self::STATUS_Error => 'error',
60  ];
61 
65  protected ‪$affectedElements;
66 
81  protected ‪$issues = [];
82 
88  public function ‪setAffectedElements(array ‪$affectedElements)
89  {
90  $this->affectedElements = ‪$affectedElements;
91  }
92 
96  public function ‪check()
97  {
98  foreach ($this->affectedElements as $affectedElement) {
99  $this->‪checkElement($affectedElement);
100  }
101  }
102 
108  public function ‪checkElement(CombinedRecord $element)
109  {
110  $this->‪checkLocalization($element);
111  }
112 
121  protected function ‪checkLocalization(CombinedRecord $element)
122  {
123  $table = $element->getTable();
124  if (BackendUtility::isTableLocalizable($table)) {
125  $languageField = ‪$GLOBALS['TCA'][$table]['ctrl']['languageField'];
126  $languageParentField = ‪$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'];
127  $versionRow = $element->getVersionRecord()->getRow();
128  // If element is a localization:
129  if ($versionRow[$languageField] > 0) {
130  // Get localization parent from live workspace
131  $languageParentRecord = BackendUtility::getRecord($table, $versionRow[$languageParentField], 'uid,t3ver_state');
132  // If localization parent is a new version....
133  if (is_array($languageParentRecord) && ‪VersionState::cast($languageParentRecord['t3ver_state'])->equals(‪VersionState::NEW_PLACEHOLDER)) {
134  $title = BackendUtility::getRecordTitle($table, $versionRow);
135  $languageService = $this->‪getLanguageService();
136  // Add warning for current versionized record:
137  $this->‪addIssue(
138  $element->getLiveRecord()->getIdentifier(),
139  self::STATUS_Warning,
140  sprintf($languageService->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:integrity.dependsOnDefaultLanguageRecord'), $title)
141  );
142  // Add info for related localization parent record:
143  $this->‪addIssue(
144  $table . ':' . $languageParentRecord['uid'],
145  self::STATUS_Info,
146  sprintf($languageService->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:integrity.isDefaultLanguageRecord'), $title)
147  );
148  }
149  }
150  }
151  }
152 
160  public function ‪getStatus($identifier = null)
161  {
162  $status = ‪self::STATUS_Succes;
163  if ($identifier === null) {
164  foreach ($this->issues as $idenfieriferIssues) {
165  foreach ($idenfieriferIssues as $issue) {
166  if ($status < $issue['status']) {
167  $status = $issue['status'];
168  }
169  }
170  }
171  } else {
172  foreach ($this->‪getIssues($identifier) as $issue) {
173  if ($status < $issue['status']) {
174  $status = $issue['status'];
175  }
176  }
177  }
178  return $status;
179  }
180 
188  public function ‪getStatusRepresentation($identifier = null)
189  {
190  return $this->statusRepresentation[$this->‪getStatus($identifier)];
191  }
192 
199  public function ‪getIssues($identifier = null)
200  {
201  if ($identifier === null) {
202  return ‪$this->issues;
203  }
204  if (isset($this->issues[$identifier])) {
205  return $this->issues[$identifier];
206  }
207  return [];
208  }
209 
217  public function ‪getIssueMessages($identifier = null, $asString = false)
218  {
219  $messages = [];
220  if ($identifier === null) {
221  foreach ($this->issues as $idenfieriferIssues) {
222  foreach ($idenfieriferIssues as $issue) {
223  $messages[] = $issue['message'];
224  }
225  }
226  } else {
227  foreach ($this->‪getIssues($identifier) as $issue) {
228  $messages[] = $issue['message'];
229  }
230  }
231  if ($asString) {
232  $messages = implode('<br/>', $messages);
233  }
234  return $messages;
235  }
236 
244  protected function ‪addIssue($identifier, $status, $message)
245  {
246  if (!isset($this->issues[$identifier])) {
247  $this->issues[$identifier] = [];
248  }
249  $this->issues[$identifier][] = [
250  'status' => $status,
251  'message' => $message,
252  ];
253  }
254 
255  protected function ‪getLanguageService(): ‪LanguageService
256  {
257  return ‪$GLOBALS['LANG'];
258  }
259 }
‪TYPO3\CMS\Workspaces\Service\IntegrityService\addIssue
‪addIssue($identifier, $status, $message)
Definition: IntegrityService.php:241
‪TYPO3\CMS\Workspaces\Service\IntegrityService\checkElement
‪checkElement(CombinedRecord $element)
Definition: IntegrityService.php:105
‪TYPO3\CMS\Core\Versioning\VersionState\NEW_PLACEHOLDER
‪const NEW_PLACEHOLDER
Definition: VersionState.php:53
‪TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord
Definition: CombinedRecord.php:24
‪TYPO3\CMS\Workspaces\Service\IntegrityService\STATUS_Warning
‪const STATUS_Warning
Definition: IntegrityService.php:45
‪TYPO3\CMS\Workspaces\Domain\Model\DatabaseRecord\getIdentifier
‪string getIdentifier()
Definition: DatabaseRecord.php:142
‪TYPO3\CMS\Workspaces\Service
‪TYPO3\CMS\Workspaces\Service\IntegrityService\STATUS_Succes
‪const STATUS_Succes
Definition: IntegrityService.php:33
‪TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord\getTable
‪string getTable()
Definition: CombinedRecord.php:86
‪TYPO3\CMS\Workspaces\Service\IntegrityService\STATUS_Error
‪const STATUS_Error
Definition: IntegrityService.php:51
‪TYPO3\CMS\Workspaces\Service\IntegrityService\getStatusRepresentation
‪string getStatusRepresentation($identifier=null)
Definition: IntegrityService.php:185
‪TYPO3\CMS\Workspaces\Service\IntegrityService\$statusRepresentation
‪array $statusRepresentation
Definition: IntegrityService.php:54
‪TYPO3\CMS\Workspaces\Service\IntegrityService\$affectedElements
‪CombinedRecord[] $affectedElements
Definition: IntegrityService.php:63
‪TYPO3\CMS\Workspaces\Service\IntegrityService\getIssueMessages
‪array string getIssueMessages($identifier=null, $asString=false)
Definition: IntegrityService.php:214
‪TYPO3\CMS\Workspaces\Service\IntegrityService\getLanguageService
‪getLanguageService()
Definition: IntegrityService.php:252
‪TYPO3\CMS\Core\Type\Enumeration\cast
‪static static cast($value)
Definition: Enumeration.php:186
‪TYPO3\CMS\Workspaces\Service\IntegrityService\STATUS_Info
‪const STATUS_Info
Definition: IntegrityService.php:39
‪TYPO3\CMS\Workspaces\Service\IntegrityService\getIssues
‪array getIssues($identifier=null)
Definition: IntegrityService.php:196
‪TYPO3\CMS\Workspaces\Service\IntegrityService
Definition: IntegrityService.php:27
‪TYPO3\CMS\Workspaces\Service\IntegrityService\getStatus
‪string getStatus($identifier=null)
Definition: IntegrityService.php:157
‪TYPO3\CMS\Core\Versioning\VersionState
Definition: VersionState.php:24
‪TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord\getLiveRecord
‪DatabaseRecord getLiveRecord()
Definition: CombinedRecord.php:106
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Workspaces\Domain\Model\DatabaseRecord\getRow
‪array getRow()
Definition: DatabaseRecord.php:121
‪TYPO3\CMS\Workspaces\Service\IntegrityService\check
‪check()
Definition: IntegrityService.php:93
‪TYPO3\CMS\Workspaces\Service\IntegrityService\setAffectedElements
‪setAffectedElements(array $affectedElements)
Definition: IntegrityService.php:85
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord\getVersionRecord
‪DatabaseRecord getVersionRecord()
Definition: CombinedRecord.php:126
‪TYPO3\CMS\Workspaces\Service\IntegrityService\checkLocalization
‪checkLocalization(CombinedRecord $element)
Definition: IntegrityService.php:118
‪TYPO3\CMS\Workspaces\Service\IntegrityService\$issues
‪array $issues
Definition: IntegrityService.php:78