TYPO3 CMS  TYPO3_8-7
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 
19 
24 {
30  const STATUS_Succes = 100;
36  const STATUS_Info = 101;
42  const STATUS_Warning = 102;
48  const STATUS_Error = 103;
52  protected $statusRepresentation = [
53  self::STATUS_Succes => 'success',
54  self::STATUS_Info => 'info',
55  self::STATUS_Warning => 'warning',
56  self::STATUS_Error => 'error'
57  ];
58 
62  protected $affectedElements;
63 
78  protected $issues = [];
79 
85  public function setAffectedElements(array $affectedElements)
86  {
87  $this->affectedElements = $affectedElements;
88  }
89 
93  public function check()
94  {
95  foreach ($this->affectedElements as $affectedElement) {
96  $this->checkElement($affectedElement);
97  }
98  }
99 
105  public function checkElement(\TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord $element)
106  {
107  $this->checkLocalization($element);
108  }
109 
118  protected function checkLocalization(\TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord $element)
119  {
120  $table = $element->getTable();
122  $languageField = $GLOBALS['TCA'][$table]['ctrl']['languageField'];
123  $languageParentField = $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'];
124  $versionRow = $element->getVersionRecord()->getRow();
125  // If element is a localization:
126  if ($versionRow[$languageField] > 0) {
127  // Get localization parent from live workspace:
128  $languageParentRecord = BackendUtility::getRecord($table, $versionRow[$languageParentField], 'uid,t3ver_state');
129  // If localization parent is a "new placeholder" record:
130  if (VersionState::cast($languageParentRecord['t3ver_state'])->equals(VersionState::NEW_PLACEHOLDER)) {
131  $title = BackendUtility::getRecordTitle($table, $versionRow);
132  // Add warning for current versionized record:
133  $this->addIssue($element->getLiveRecord()->getIdentifier(), self::STATUS_Warning, sprintf(\TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('integrity.dependsOnDefaultLanguageRecord', 'workspaces'), $title));
134  // Add info for related localization parent record:
135  $this->addIssue($table . ':' . $languageParentRecord['uid'], self::STATUS_Info, sprintf(\TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('integrity.isDefaultLanguageRecord', 'workspaces'), $title));
136  }
137  }
138  }
139  }
140 
148  public function getStatus($identifier = null)
149  {
150  $status = self::STATUS_Succes;
151  if ($identifier === null) {
152  foreach ($this->issues as $idenfieriferIssues) {
153  foreach ($idenfieriferIssues as $issue) {
154  if ($status < $issue['status']) {
155  $status = $issue['status'];
156  }
157  }
158  }
159  } else {
160  foreach ($this->getIssues($identifier) as $issue) {
161  if ($status < $issue['status']) {
162  $status = $issue['status'];
163  }
164  }
165  }
166  return $status;
167  }
168 
176  public function getStatusRepresentation($identifier = null)
177  {
178  return $this->statusRepresentation[$this->getStatus($identifier)];
179  }
180 
187  public function getIssues($identifier = null)
188  {
189  if ($identifier === null) {
190  return $this->issues;
191  }
192  if (isset($this->issues[$identifier])) {
193  return $this->issues[$identifier];
194  }
195  return [];
196  }
197 
205  public function getIssueMessages($identifier = null, $asString = false)
206  {
207  $messages = [];
208  if ($identifier === null) {
209  foreach ($this->issues as $idenfieriferIssues) {
210  foreach ($idenfieriferIssues as $issue) {
211  $messages[] = $issue['message'];
212  }
213  }
214  } else {
215  foreach ($this->getIssues($identifier) as $issue) {
216  $messages[] = $issue['message'];
217  }
218  }
219  if ($asString) {
220  $messages = implode('<br/>', $messages);
221  }
222  return $messages;
223  }
224 
232  protected function addIssue($identifier, $status, $message)
233  {
234  if (!isset($this->issues[$identifier])) {
235  $this->issues[$identifier] = [];
236  }
237  $this->issues[$identifier][] = [
238  'status' => $status,
239  'message' => $message
240  ];
241  }
242 }
checkLocalization(\TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord $element)
addIssue($identifier, $status, $message)
static getRecordTitle($table, $row, $prep=false, $forceResult=true)
getIssueMessages($identifier=null, $asString=false)
checkElement(\TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord $element)
static getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']