‪TYPO3CMS  10.4
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 
22 
27 {
33  const ‪STATUS_Succes = 100;
39  const ‪STATUS_Info = 101;
45  const ‪STATUS_Warning = 102;
51  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();
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 placeholder" record:
133  if (‪VersionState::cast($languageParentRecord['t3ver_state'])->equals(‪VersionState::NEW_PLACEHOLDER)) {
134  $title = ‪BackendUtility::getRecordTitle($table, $versionRow);
135  // Add warning for current versionized record:
136  $this->‪addIssue($element->getLiveRecord()->getIdentifier(), self::STATUS_Warning, sprintf(‪LocalizationUtility::translate('integrity.dependsOnDefaultLanguageRecord', 'workspaces'), $title));
137  // Add info for related localization parent record:
138  $this->‪addIssue($table . ':' . $languageParentRecord['uid'], self::STATUS_Info, sprintf(‪LocalizationUtility::translate('integrity.isDefaultLanguageRecord', 'workspaces'), $title));
139  }
140  }
141  }
142  }
143 
151  public function ‪getStatus($identifier = null)
152  {
153  $status = ‪self::STATUS_Succes;
154  if ($identifier === null) {
155  foreach ($this->issues as $idenfieriferIssues) {
156  foreach ($idenfieriferIssues as $issue) {
157  if ($status < $issue['status']) {
158  $status = $issue['status'];
159  }
160  }
161  }
162  } else {
163  foreach ($this->‪getIssues($identifier) as $issue) {
164  if ($status < $issue['status']) {
165  $status = $issue['status'];
166  }
167  }
168  }
169  return $status;
170  }
171 
179  public function ‪getStatusRepresentation($identifier = null)
180  {
181  return $this->statusRepresentation[$this->‪getStatus($identifier)];
182  }
183 
190  public function ‪getIssues($identifier = null)
191  {
192  if ($identifier === null) {
193  return ‪$this->issues;
194  }
195  if (isset($this->issues[$identifier])) {
196  return $this->issues[$identifier];
197  }
198  return [];
199  }
200 
208  public function ‪getIssueMessages($identifier = null, $asString = false)
209  {
210  $messages = [];
211  if ($identifier === null) {
212  foreach ($this->issues as $idenfieriferIssues) {
213  foreach ($idenfieriferIssues as $issue) {
214  $messages[] = $issue['message'];
215  }
216  }
217  } else {
218  foreach ($this->‪getIssues($identifier) as $issue) {
219  $messages[] = $issue['message'];
220  }
221  }
222  if ($asString) {
223  $messages = implode('<br/>', $messages);
224  }
225  return $messages;
226  }
227 
235  protected function ‪addIssue($identifier, $status, $message)
236  {
237  if (!isset($this->issues[$identifier])) {
238  $this->issues[$identifier] = [];
239  }
240  $this->issues[$identifier][] = [
241  'status' => $status,
242  'message' => $message
243  ];
244  }
245 }
‪TYPO3\CMS\Workspaces\Service\IntegrityService\addIssue
‪addIssue($identifier, $status, $message)
Definition: IntegrityService.php:232
‪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:47
‪TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord
Definition: CombinedRecord.php:24
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility
Definition: LocalizationUtility.php:33
‪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
Definition: AdditionalColumnService.php:16
‪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:176
‪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:205
‪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\Backend\Utility\BackendUtility\getRecordTitle
‪static string getRecordTitle($table, $row, $prep=false, $forceResult=true)
Definition: BackendUtility.php:1541
‪TYPO3\CMS\Workspaces\Service\IntegrityService\getIssues
‪array getIssues($identifier=null)
Definition: IntegrityService.php:187
‪TYPO3\CMS\Workspaces\Service\IntegrityService
Definition: IntegrityService.php:27
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility\translate
‪static string null translate(string $key, ?string $extensionName=null, array $arguments=null, string $languageKey=null, array $alternativeLanguageKeys=null)
Definition: LocalizationUtility.php:67
‪TYPO3\CMS\Workspaces\Service\IntegrityService\getStatus
‪string getStatus($identifier=null)
Definition: IntegrityService.php:148
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:75
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecord
‪static array null getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
Definition: BackendUtility.php:95
‪TYPO3\CMS\Core\Versioning\VersionState
Definition: VersionState.php:24
‪TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord\getLiveRecord
‪DatabaseRecord getLiveRecord()
Definition: CombinedRecord.php:106
‪TYPO3\CMS\Backend\Utility\BackendUtility\isTableLocalizable
‪static bool isTableLocalizable($table)
Definition: BackendUtility.php:578
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪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\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