TYPO3 CMS  TYPO3_6-2
IntegrityService.php
Go to the documentation of this file.
1 <?php
3 
19 
26 
32  const STATUS_Succes = 100;
38  const STATUS_Info = 101;
44  const STATUS_Warning = 102;
50  const STATUS_Error = 103;
54  protected $statusRepresentation = array(
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 = array();
81 
88  public function setAffectedElements(array $affectedElements) {
89  $this->affectedElements = $affectedElements;
90  }
91 
97  public function check() {
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  $this->checkLocalization($element);
111  }
112 
122  protected function checkLocalization(\TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord $element) {
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(\TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('integrity.dependsOnDefaultLanguageRecord', 'workspaces'), $title));
137  // Add info for related localization parent record:
138  $this->addIssue($table . ':' . $languageParentRecord['uid'], self::STATUS_Info, sprintf(\TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('integrity.isDefaultLanguageRecord', 'workspaces'), $title));
139  }
140  }
141  }
142  }
143 
151  public function getStatus($identifier = NULL) {
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  return $this->statusRepresentation[$this->getStatus($identifier)];
180  }
181 
188  public function getIssues($identifier = NULL) {
189  if ($identifier === NULL) {
190  return $this->issues;
191  } elseif (isset($this->issues[$identifier])) {
192  return $this->issues[$identifier];
193  }
194  return array();
195  }
196 
204  public function getIssueMessages($identifier = NULL, $asString = FALSE) {
205  $messages = array();
206  if ($identifier === NULL) {
207  foreach ($this->issues as $idenfieriferIssues) {
208  foreach ($idenfieriferIssues as $issue) {
209  $messages[] = $issue['message'];
210  }
211  }
212  } else {
213  foreach ($this->getIssues($identifier) as $issue) {
214  $messages[] = $issue['message'];
215  }
216  }
217  if ($asString) {
218  $messages = implode('<br/>', $messages);
219  }
220  return $messages;
221  }
222 
231  protected function addIssue($identifier, $status, $message) {
232  if (!isset($this->issues[$identifier])) {
233  $this->issues[$identifier] = array();
234  }
235  $this->issues[$identifier][] = array(
236  'status' => $status,
237  'message' => $message
238  );
239  }
240 
241 }
checkLocalization(\TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord $element)
getIssueMessages($identifier=NULL, $asString=FALSE)
addIssue($identifier, $status, $message)
static getRecordTitle($table, $row, $prep=FALSE, $forceResult=TRUE)
checkElement(\TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord $element)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]