2 namespace TYPO3\CMS\Workspaces\Service
;
5 * This file is part of the TYPO3 CMS project.
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.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use TYPO3\CMS\Backend\Utility\BackendUtility
;
18 use TYPO3\CMS\Core\Versioning\VersionState
;
19 use TYPO3\CMS\Extbase\Utility\LocalizationUtility
;
20 use TYPO3\CMS\Workspaces\Domain\Model\CombinedRecord
;
23 * Service for integrity
25 class IntegrityService
28 * Success status - everything is fine
32 const STATUS_Succes
= 100;
34 * Info status - nothing is wrong, but a notice is shown
38 const STATUS_Info
= 101;
40 * Warning status - user interaction might be required
44 const STATUS_Warning
= 102;
46 * Error status - user interaction is required
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'
62 * @var CombinedRecord[]
64 protected $affectedElements;
67 * Array storing all issues that have been checked and
68 * found during runtime in this object. The array keys
69 * are identifiers of table and the version-id.
71 * 'tx_table:123' => array(
73 * 'status' => 'warning',
74 * 'message' => 'Element cannot be...',
80 protected $issues = [];
83 * Sets the affected elements.
85 * @param CombinedRecord[] $affectedElements
87 public function setAffectedElements(array $affectedElements)
89 $this->affectedElements
= $affectedElements;
93 * Checks integrity of affected records.
95 public function check()
97 foreach ($this->affectedElements
as $affectedElement) {
98 $this->checkElement($affectedElement);
103 * Checks a single element.
105 * @param CombinedRecord $element
107 public function checkElement(CombinedRecord
$element)
109 $this->checkLocalization($element);
113 * Checks workspace localization integrity of a single elements.
114 * If current record is a localization and its localization parent
115 * is new in this workspace (has only a placeholder record in live),
116 * then both (localization and localization parent) should be published.
118 * @param CombinedRecord $element
120 protected function checkLocalization(CombinedRecord
$element)
122 $table = $element->getTable();
123 if (BackendUtility
::isTableLocalizable($table)) {
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));
144 * Gets the status of the most important severity.
145 * (low << success, info, warning, error >> high)
147 * @param string $identifier Record identifier (table:id) for look-ups
150 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'];
162 foreach ($this->getIssues($identifier) as $issue) {
163 if ($status < $issue['status']) {
164 $status = $issue['status'];
172 * Gets the (human readable) representation of the status with the most
173 * important severity (wraps $this->getStatus() and translates the result).
175 * @param string $identifier Record identifier (table:id) for look-ups
176 * @return string One out of success, info, warning, error
178 public function getStatusRepresentation($identifier = null
)
180 return $this->statusRepresentation
[$this->getStatus($identifier)];
184 * Gets issues, all or specific for one identifier.
186 * @param string $identifier Record identifier (table:id) for look-ups
189 public function getIssues($identifier = null
)
191 if ($identifier === null
) {
192 return $this->issues
;
194 if (isset($this->issues
[$identifier])) {
195 return $this->issues
[$identifier];
201 * Gets the message of all issues.
203 * @param string $identifier Record identifier (table:id) for look-ups
204 * @param bool $asString Return results as string instead of array
205 * @return array|string
207 public function getIssueMessages($identifier = null
, $asString = false
)
210 if ($identifier === null
) {
211 foreach ($this->issues
as $idenfieriferIssues) {
212 foreach ($idenfieriferIssues as $issue) {
213 $messages[] = $issue['message'];
217 foreach ($this->getIssues($identifier) as $issue) {
218 $messages[] = $issue['message'];
222 $messages = implode('<br/>', $messages);
230 * @param string $identifier Record identifier (table:id)
231 * @param int $status Status code (see constants)
232 * @param string $message Message/description of the issue
234 protected function addIssue($identifier, $status, $message)
236 if (!isset($this->issues
[$identifier])) {
237 $this->issues
[$identifier] = [];
239 $this->issues
[$identifier][] = [
241 'message' => $message