diff --git a/Classes/Integrity/Error/WrongParentError.php b/Classes/Integrity/Error/WrongParentError.php new file mode 100644 index 00000000..5ed66272 --- /dev/null +++ b/Classes/Integrity/Error/WrongParentError.php @@ -0,0 +1,65 @@ +containerRecord = $containerRecord; + $this->errorMessage = self::IDENTIFIER . ': container uid ' . $containerRecord['uid'] . + ' (page: ' . $containerRecord['pid'] . ' language: ' . $containerRecord['sys_language_uid'] . ')' . + ' has tx_container_parent ' . $containerRecord['tx_container_parent']; + } + + /** + * @return string + */ + public function getErrorMessage(): string + { + return $this->errorMessage; + } + + /** + * @return int + */ + public function getSeverity(): int + { + return AbstractMessage::ERROR; + } + + /** + * @return array + */ + public function getContainerRecord(): array + { + return $this->containerRecord; + } +} diff --git a/Classes/Integrity/Integrity.php b/Classes/Integrity/Integrity.php index 7da30076..b8dd60ce 100644 --- a/Classes/Integrity/Integrity.php +++ b/Classes/Integrity/Integrity.php @@ -17,6 +17,7 @@ use B13\Container\Integrity\Error\UnusedColPosWarning; use B13\Container\Integrity\Error\WrongL18nParentError; use B13\Container\Integrity\Error\WrongLanguageWarning; +use B13\Container\Integrity\Error\WrongParentError; use B13\Container\Integrity\Error\WrongPidError; use B13\Container\Tca\Registry; use TYPO3\CMS\Core\SingletonInterface; @@ -66,15 +67,20 @@ public function run(): array private function nonDefaultLanguageRecords(array $cTypes, array $colPosByCType): void { $nonDefaultLanguageChildRecords = $this->database->getNonDefaultLanguageContainerChildRecords(); - $nonDefaultLangaugeContainerRecords = $this->database->getNonDefaultLanguageContainerRecords($cTypes); + $nonDefaultLanguageContainerRecords = $this->database->getNonDefaultLanguageContainerRecords($cTypes); + foreach ($nonDefaultLanguageContainerRecords as $containerRecord) { + if ($containerRecord['uid'] === $containerRecord['tx_container_parent']) { + $this->res['errors'][] = new WrongParentError($containerRecord); + } + } $defaultLanguageContainerRecords = $this->database->getContainerRecords($cTypes); foreach ($nonDefaultLanguageChildRecords as $nonDefaultLanguageChildRecord) { if ($nonDefaultLanguageChildRecord['l18n_parent'] > 0) { // connected mode // tx_container_parent should be default container record uid if (!isset($defaultLanguageContainerRecords[$nonDefaultLanguageChildRecord['tx_container_parent']])) { - if (isset($nonDefaultLangaugeContainerRecords[$nonDefaultLanguageChildRecord['tx_container_parent']])) { - $containerRecord = $nonDefaultLangaugeContainerRecords[$nonDefaultLanguageChildRecord['tx_container_parent']]; + if (isset($nonDefaultLanguageContainerRecords[$nonDefaultLanguageChildRecord['tx_container_parent']])) { + $containerRecord = $nonDefaultLanguageContainerRecords[$nonDefaultLanguageChildRecord['tx_container_parent']]; if ($containerRecord['sys_language_uid'] === $nonDefaultLanguageChildRecord['sys_language_uid'] && $containerRecord['l18n_parent'] > 0) { $this->res['errors'][] = new ChildInTranslatedContainerError($nonDefaultLanguageChildRecord, $containerRecord); } else { @@ -83,8 +89,8 @@ private function nonDefaultLanguageRecords(array $cTypes, array $colPosByCType): } else { $this->res['warnings'][] = new NonExistingParentWarning($nonDefaultLanguageChildRecord); } - } elseif (isset($nonDefaultLangaugeContainerRecords[$nonDefaultLanguageChildRecord['tx_container_parent']])) { - $containerRecord = $nonDefaultLangaugeContainerRecords[$nonDefaultLanguageChildRecord['tx_container_parent']]; + } elseif (isset($nonDefaultLanguageContainerRecords[$nonDefaultLanguageChildRecord['tx_container_parent']])) { + $containerRecord = $nonDefaultLanguageContainerRecords[$nonDefaultLanguageChildRecord['tx_container_parent']]; $this->res['errors'][] = new WrongL18nParentError($nonDefaultLanguageChildRecord, $containerRecord); } } else { @@ -96,10 +102,10 @@ private function nonDefaultLanguageRecords(array $cTypes, array $colPosByCType): $this->res['errors'][] = new WrongPidError($nonDefaultLanguageChildRecord, $containerRecord); } $this->res['warnings'][] = new WrongLanguageWarning($nonDefaultLanguageChildRecord, $containerRecord); - } elseif (!isset($nonDefaultLangaugeContainerRecords[$nonDefaultLanguageChildRecord['tx_container_parent']])) { + } elseif (!isset($nonDefaultLanguageContainerRecords[$nonDefaultLanguageChildRecord['tx_container_parent']])) { $this->res['warnings'][] = new NonExistingParentWarning($nonDefaultLanguageChildRecord); } else { - $containerRecord = $nonDefaultLangaugeContainerRecords[$nonDefaultLanguageChildRecord['tx_container_parent']]; + $containerRecord = $nonDefaultLanguageContainerRecords[$nonDefaultLanguageChildRecord['tx_container_parent']]; if ($containerRecord['pid'] !== $nonDefaultLanguageChildRecord['pid']) { $this->res['errors'][] = new WrongPidError($nonDefaultLanguageChildRecord, $containerRecord); } @@ -120,6 +126,11 @@ private function nonDefaultLanguageRecords(array $cTypes, array $colPosByCType): private function defaultLanguageRecords(array $cTypes, array $colPosByCType): void { $containerRecords = $this->database->getContainerRecords($cTypes); + foreach ($containerRecords as $containerRecord) { + if ($containerRecord['uid'] === $containerRecord['tx_container_parent']) { + $this->res['errors'][] = new WrongParentError($containerRecord); + } + } $containerChildRecords = $this->database->getContainerChildRecords(); foreach ($containerChildRecords as $containerChildRecord) { if (!isset($containerRecords[$containerChildRecord['tx_container_parent']])) {