TYPO3 CMS  TYPO3_7-6
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 
86  public function setAffectedElements(array $affectedElements)
87  {
88  $this->affectedElements = $affectedElements;
89  }
90 
96  public function check()
97  {
98  foreach ($this->affectedElements as $affectedElement) {
99  $this->checkElement($affectedElement);
100  }
101  }
102 
109  public function checkElement(\TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord $element)
110  {
111  $this->checkLocalization($element);
112  }
113 
123  protected function checkLocalization(\TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord $element)
124  {
125  $table = $element->getTable();
127  $languageField = $GLOBALS['TCA'][$table]['ctrl']['languageField'];
128  $languageParentField = $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'];
129  $versionRow = $element->getVersionRecord()->getRow();
130  // If element is a localization:
131  if ($versionRow[$languageField] > 0) {
132  // Get localization parent from live workspace:
133  $languageParentRecord = BackendUtility::getRecord($table, $versionRow[$languageParentField], 'uid,t3ver_state');
134  // If localization parent is a "new placeholder" record:
135  if (VersionState::cast($languageParentRecord['t3ver_state'])->equals(VersionState::NEW_PLACEHOLDER)) {
136  $title = BackendUtility::getRecordTitle($table, $versionRow);
137  // Add warning for current versionized record:
138  $this->addIssue($element->getLiveRecord()->getIdentifier(), self::STATUS_Warning, sprintf(\TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('integrity.dependsOnDefaultLanguageRecord', 'workspaces'), $title));
139  // Add info for related localization parent record:
140  $this->addIssue($table . ':' . $languageParentRecord['uid'], self::STATUS_Info, sprintf(\TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('integrity.isDefaultLanguageRecord', 'workspaces'), $title));
141  }
142  }
143  }
144  }
145 
153  public function getStatus($identifier = null)
154  {
155  $status = self::STATUS_Succes;
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($identifier = null)
182  {
183  return $this->statusRepresentation[$this->getStatus($identifier)];
184  }
185 
192  public function getIssues($identifier = null)
193  {
194  if ($identifier === null) {
195  return $this->issues;
196  } elseif (isset($this->issues[$identifier])) {
197  return $this->issues[$identifier];
198  }
199  return [];
200  }
201 
209  public function getIssueMessages($identifier = null, $asString = false)
210  {
211  $messages = [];
212  if ($identifier === null) {
213  foreach ($this->issues as $idenfieriferIssues) {
214  foreach ($idenfieriferIssues as $issue) {
215  $messages[] = $issue['message'];
216  }
217  }
218  } else {
219  foreach ($this->getIssues($identifier) as $issue) {
220  $messages[] = $issue['message'];
221  }
222  }
223  if ($asString) {
224  $messages = implode('<br/>', $messages);
225  }
226  return $messages;
227  }
228 
237  protected function addIssue($identifier, $status, $message)
238  {
239  if (!isset($this->issues[$identifier])) {
240  $this->issues[$identifier] = [];
241  }
242  $this->issues[$identifier][] = [
243  'status' => $status,
244  'message' => $message
245  ];
246  }
247 }
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']