‪TYPO3CMS  ‪main
IntegrityService.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use TYPO3\CMS\Backend\Utility\BackendUtility;
24 
29 {
35  public const ‪STATUS_Success = 100;
41  public const ‪STATUS_Info = 101;
47  public const ‪STATUS_Warning = 102;
53  public const ‪STATUS_Error = 103;
54 
55  protected array ‪$statusRepresentation = [
56  self::STATUS_Success => 'success',
57  self::STATUS_Info => 'info',
58  self::STATUS_Warning => 'warning',
59  self::STATUS_Error => 'error',
60  ];
61 
65  protected array ‪$affectedElements = [];
66 
79  protected array ‪$issues = [];
80 
86  public function ‪setAffectedElements(array ‪$affectedElements): void
87  {
88  $this->affectedElements = ‪$affectedElements;
89  }
90 
94  public function ‪check(): void
95  {
96  foreach ($this->affectedElements as $affectedElement) {
97  $this->‪checkElement($affectedElement);
98  }
99  }
100 
104  public function ‪checkElement(‪CombinedRecord $element): void
105  {
106  $this->‪checkLocalization($element);
107  }
108 
115  protected function ‪checkLocalization(‪CombinedRecord $element): void
116  {
117  $table = $element->‪getTable();
118  if (BackendUtility::isTableLocalizable($table)) {
119  $languageField = ‪$GLOBALS['TCA'][$table]['ctrl']['languageField'];
120  $languageParentField = ‪$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'];
121  $versionRow = $element->‪getVersionRecord()->getRow();
122  // If element is a localization:
123  if ($versionRow[$languageField] > 0) {
124  // Get localization parent from live workspace
125  $languageParentRecord = BackendUtility::getRecord($table, $versionRow[$languageParentField], 'uid,t3ver_state');
126  // If localization parent is a new version....
127  if (is_array($languageParentRecord) && VersionState::tryFrom($languageParentRecord['t3ver_state'] ?? 0) === VersionState::NEW_PLACEHOLDER) {
128  $title = BackendUtility::getRecordTitle($table, $versionRow);
129  $languageService = $this->‪getLanguageService();
130  // Add warning for current versionized record:
131  $this->‪addIssue(
132  $element->‪getLiveRecord()->getIdentifier(),
133  self::STATUS_Warning,
134  sprintf($languageService->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:integrity.dependsOnDefaultLanguageRecord'), $title)
135  );
136  // Add info for related localization parent record:
137  $this->‪addIssue(
138  $table . ':' . $languageParentRecord['uid'],
139  self::STATUS_Info,
140  sprintf($languageService->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:integrity.isDefaultLanguageRecord'), $title)
141  );
142  }
143  }
144  }
145  }
146 
153  public function ‪getStatus(string ‪$identifier = null): int
154  {
155  $status = ‪self::STATUS_Success;
156  if (‪$identifier === null) {
157  foreach ($this->issues as $idenfieriferIssues) {
158  foreach ($idenfieriferIssues as $issue) {
159  if ($status < $issue['status']) {
160  $status = $issue['status'];
161  }
162  }
163  }
164  } else {
165  foreach ($this->‪getIssues(‪$identifier) as $issue) {
166  if ($status < $issue['status']) {
167  $status = $issue['status'];
168  }
169  }
170  }
171  return $status;
172  }
173 
181  public function ‪getStatusRepresentation(string ‪$identifier = null): string
182  {
183  return $this->statusRepresentation[$this->‪getStatus(‪$identifier)];
184  }
185 
191  public function ‪getIssues(string ‪$identifier = null): array
192  {
193  if (‪$identifier === null) {
194  return ‪$this->issues;
195  }
196  if (isset($this->issues[‪$identifier])) {
197  return $this->issues[‪$identifier];
198  }
199  return [];
200  }
201 
207  public function ‪getIssueMessages(string ‪$identifier = null): array
208  {
209  $messages = [];
210  if (‪$identifier === null) {
211  foreach ($this->issues as $idenfieriferIssues) {
212  foreach ($idenfieriferIssues as $issue) {
213  $messages[] = $issue['message'];
214  }
215  }
216  } else {
217  foreach ($this->‪getIssues(‪$identifier) as $issue) {
218  $messages[] = $issue['message'];
219  }
220  }
221  return $messages;
222  }
223 
231  protected function ‪addIssue(string ‪$identifier, int $status, string $message): void
232  {
233  if (!isset($this->issues[‪$identifier])) {
234  $this->issues[‪$identifier] = [];
235  }
236  $this->issues[‪$identifier][] = [
237  'status' => $status,
238  'message' => $message,
239  ];
240  }
241 
243  {
244  return ‪$GLOBALS['LANG'];
245  }
246 }
‪TYPO3\CMS\Workspaces\Service\IntegrityService\checkElement
‪checkElement(CombinedRecord $element)
Definition: IntegrityService.php:104
‪TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord\getVersionRecord
‪getVersionRecord()
Definition: CombinedRecord.php:103
‪TYPO3\CMS\Workspaces\Service\IntegrityService\getStatus
‪getStatus(string $identifier=null)
Definition: IntegrityService.php:153
‪TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord
Definition: CombinedRecord.php:28
‪TYPO3\CMS\Workspaces\Service\IntegrityService\getIssues
‪getIssues(string $identifier=null)
Definition: IntegrityService.php:191
‪TYPO3\CMS\Workspaces\Service\IntegrityService\STATUS_Warning
‪const STATUS_Warning
Definition: IntegrityService.php:47
‪TYPO3\CMS\Workspaces\Service
‪TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord\getLiveRecord
‪getLiveRecord()
Definition: CombinedRecord.php:87
‪TYPO3\CMS\Workspaces\Service\IntegrityService\STATUS_Success
‪const STATUS_Success
Definition: IntegrityService.php:35
‪TYPO3\CMS\Core\Versioning\VersionState
‪VersionState
Definition: VersionState.php:22
‪TYPO3\CMS\Workspaces\Service\IntegrityService\STATUS_Error
‪const STATUS_Error
Definition: IntegrityService.php:53
‪TYPO3\CMS\Workspaces\Service\IntegrityService\$statusRepresentation
‪array $statusRepresentation
Definition: IntegrityService.php:55
‪TYPO3\CMS\Workspaces\Service\IntegrityService\getLanguageService
‪getLanguageService()
Definition: IntegrityService.php:242
‪TYPO3\CMS\Workspaces\Service\IntegrityService\STATUS_Info
‪const STATUS_Info
Definition: IntegrityService.php:41
‪TYPO3\CMS\Workspaces\Service\IntegrityService\$affectedElements
‪array $affectedElements
Definition: IntegrityService.php:65
‪TYPO3\CMS\Workspaces\Service\IntegrityService\getIssueMessages
‪getIssueMessages(string $identifier=null)
Definition: IntegrityService.php:207
‪TYPO3\CMS\Workspaces\Service\IntegrityService
Definition: IntegrityService.php:29
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Workspaces\Service\IntegrityService\check
‪check()
Definition: IntegrityService.php:94
‪TYPO3\CMS\Workspaces\Service\IntegrityService\setAffectedElements
‪setAffectedElements(array $affectedElements)
Definition: IntegrityService.php:86
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Workspaces\Service\IntegrityService\addIssue
‪addIssue(string $identifier, int $status, string $message)
Definition: IntegrityService.php:231
‪TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord\getTable
‪getTable()
Definition: CombinedRecord.php:71
‪TYPO3\CMS\Workspaces\Service\IntegrityService\getStatusRepresentation
‪string getStatusRepresentation(string $identifier=null)
Definition: IntegrityService.php:181
‪TYPO3\CMS\Workspaces\Service\IntegrityService\checkLocalization
‪checkLocalization(CombinedRecord $element)
Definition: IntegrityService.php:115
‪TYPO3\CMS\Workspaces\Service\IntegrityService\$issues
‪array $issues
Definition: IntegrityService.php:79
‪TYPO3\CMS\Webhooks\Message\$identifier
‪identifier readonly string $identifier
Definition: FileAddedMessage.php:37