‪TYPO3CMS  9.5
IntegrityService.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 
21 
26 {
32  const ‪STATUS_Succes = 100;
38  const ‪STATUS_Info = 101;
44  const ‪STATUS_Warning = 102;
50  const ‪STATUS_Error = 103;
54  protected ‪$statusRepresentation = [
55  self::STATUS_Succes => 'success',
56  self::STATUS_Info => 'info',
57  self::STATUS_Warning => 'warning',
58  self::STATUS_Error => 'error'
59  ];
60 
64  protected ‪$affectedElements;
65 
80  protected ‪$issues = [];
81 
87  public function ‪setAffectedElements(array ‪$affectedElements)
88  {
89  $this->affectedElements = ‪$affectedElements;
90  }
91 
95  public function ‪check()
96  {
97  foreach ($this->affectedElements as $affectedElement) {
98  $this->‪checkElement($affectedElement);
99  }
100  }
101 
107  public function ‪checkElement(CombinedRecord $element)
108  {
109  $this->‪checkLocalization($element);
110  }
111 
120  protected function ‪checkLocalization(CombinedRecord $element)
121  {
122  $table = $element->getTable();
124  $languageField = ‪$GLOBALS['TCA'][$table]['ctrl']['languageField'];
125  $languageParentField = ‪$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'];
126  $versionRow = $element->getVersionRecord()->getRow();
127  // If element is a localization:
128  if ($versionRow[$languageField] > 0) {
129  // Get localization parent from live workspace:
130  $languageParentRecord = ‪BackendUtility::getRecord($table, $versionRow[$languageParentField], 'uid,t3ver_state');
131  // If localization parent is a "new placeholder" record:
132  if (‪VersionState::cast($languageParentRecord['t3ver_state'])->equals(‪VersionState::NEW_PLACEHOLDER)) {
133  $title = ‪BackendUtility::getRecordTitle($table, $versionRow);
134  // Add warning for current versionized record:
135  $this->‪addIssue($element->getLiveRecord()->getIdentifier(), self::STATUS_Warning, sprintf(‪LocalizationUtility::translate('integrity.dependsOnDefaultLanguageRecord', 'workspaces'), $title));
136  // Add info for related localization parent record:
137  $this->‪addIssue($table . ':' . $languageParentRecord['uid'], self::STATUS_Info, sprintf(‪LocalizationUtility::translate('integrity.isDefaultLanguageRecord', 'workspaces'), $title));
138  }
139  }
140  }
141  }
142 
150  public function ‪getStatus($identifier = null)
151  {
152  $status = ‪self::STATUS_Succes;
153  if ($identifier === null) {
154  foreach ($this->issues as $idenfieriferIssues) {
155  foreach ($idenfieriferIssues as $issue) {
156  if ($status < $issue['status']) {
157  $status = $issue['status'];
158  }
159  }
160  }
161  } else {
162  foreach ($this->‪getIssues($identifier) as $issue) {
163  if ($status < $issue['status']) {
164  $status = $issue['status'];
165  }
166  }
167  }
168  return $status;
169  }
170 
178  public function ‪getStatusRepresentation($identifier = null)
179  {
180  return $this->statusRepresentation[$this->‪getStatus($identifier)];
181  }
182 
189  public function ‪getIssues($identifier = null)
190  {
191  if ($identifier === null) {
192  return ‪$this->issues;
193  }
194  if (isset($this->issues[$identifier])) {
195  return $this->issues[$identifier];
196  }
197  return [];
198  }
199 
207  public function ‪getIssueMessages($identifier = null, $asString = false)
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  if ($asString) {
222  $messages = implode('<br/>', $messages);
223  }
224  return $messages;
225  }
226 
234  protected function ‪addIssue($identifier, $status, $message)
235  {
236  if (!isset($this->issues[$identifier])) {
237  $this->issues[$identifier] = [];
238  }
239  $this->issues[$identifier][] = [
240  'status' => $status,
241  'message' => $message
242  ];
243  }
244 }
‪TYPO3\CMS\Workspaces\Service\IntegrityService\addIssue
‪addIssue($identifier, $status, $message)
Definition: IntegrityService.php:231
‪TYPO3\CMS\Workspaces\Service\IntegrityService\checkElement
‪checkElement(CombinedRecord $element)
Definition: IntegrityService.php:104
‪TYPO3\CMS\Core\Versioning\VersionState\NEW_PLACEHOLDER
‪const NEW_PLACEHOLDER
Definition: VersionState.php:46
‪TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord
Definition: CombinedRecord.php:23
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility
Definition: LocalizationUtility.php:29
‪TYPO3\CMS\Workspaces\Service\IntegrityService\STATUS_Warning
‪const STATUS_Warning
Definition: IntegrityService.php:44
‪TYPO3\CMS\Workspaces\Domain\Model\DatabaseRecord\getIdentifier
‪string getIdentifier()
Definition: DatabaseRecord.php:141
‪TYPO3\CMS\Workspaces\Service
Definition: AdditionalColumnService.php:2
‪TYPO3\CMS\Workspaces\Service\IntegrityService\STATUS_Succes
‪const STATUS_Succes
Definition: IntegrityService.php:32
‪TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord\getTable
‪string getTable()
Definition: CombinedRecord.php:85
‪TYPO3\CMS\Workspaces\Service\IntegrityService\STATUS_Error
‪const STATUS_Error
Definition: IntegrityService.php:50
‪TYPO3\CMS\Workspaces\Service\IntegrityService\getStatusRepresentation
‪string getStatusRepresentation($identifier=null)
Definition: IntegrityService.php:175
‪TYPO3\CMS\Workspaces\Service\IntegrityService\$statusRepresentation
‪array $statusRepresentation
Definition: IntegrityService.php:53
‪TYPO3\CMS\Workspaces\Service\IntegrityService\$affectedElements
‪CombinedRecord[] $affectedElements
Definition: IntegrityService.php:62
‪TYPO3\CMS\Workspaces\Service\IntegrityService\getIssueMessages
‪array string getIssueMessages($identifier=null, $asString=false)
Definition: IntegrityService.php:204
‪TYPO3\CMS\Core\Type\Enumeration\cast
‪static static cast($value)
Definition: Enumeration.php:182
‪TYPO3\CMS\Workspaces\Service\IntegrityService\STATUS_Info
‪const STATUS_Info
Definition: IntegrityService.php:38
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility\translate
‪static string null translate($key, $extensionName=null, $arguments=null, string $languageKey=null, array $alternativeLanguageKeys=null)
Definition: LocalizationUtility.php:63
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecordTitle
‪static string getRecordTitle($table, $row, $prep=false, $forceResult=true)
Definition: BackendUtility.php:1811
‪TYPO3\CMS\Workspaces\Service\IntegrityService\getIssues
‪array getIssues($identifier=null)
Definition: IntegrityService.php:186
‪TYPO3\CMS\Workspaces\Service\IntegrityService
Definition: IntegrityService.php:26
‪TYPO3\CMS\Workspaces\Service\IntegrityService\getStatus
‪string getStatus($identifier=null)
Definition: IntegrityService.php:147
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:72
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecord
‪static array null getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
Definition: BackendUtility.php:130
‪TYPO3\CMS\Core\Versioning\VersionState
Definition: VersionState.php:23
‪TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord\getLiveRecord
‪DatabaseRecord getLiveRecord()
Definition: CombinedRecord.php:105
‪TYPO3\CMS\Backend\Utility\BackendUtility\isTableLocalizable
‪static bool isTableLocalizable($table)
Definition: BackendUtility.php:616
‪$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:120
‪TYPO3\CMS\Workspaces\Service\IntegrityService\check
‪check()
Definition: IntegrityService.php:92
‪TYPO3\CMS\Workspaces\Service\IntegrityService\setAffectedElements
‪setAffectedElements(array $affectedElements)
Definition: IntegrityService.php:84
‪TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord\getVersionRecord
‪DatabaseRecord getVersionRecord()
Definition: CombinedRecord.php:125
‪TYPO3\CMS\Workspaces\Service\IntegrityService\checkLocalization
‪checkLocalization(CombinedRecord $element)
Definition: IntegrityService.php:117
‪TYPO3\CMS\Workspaces\Service\IntegrityService\$issues
‪array $issues
Definition: IntegrityService.php:77