Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TASK] Integrity check for container parent #438

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions Classes/Integrity/Error/WrongParentError.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

declare(strict_types=1);

namespace B13\Container\Integrity\Error;

/*
* This file is part of TYPO3 CMS-based extension "container" by b13.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*/

use TYPO3\CMS\Core\Messaging\AbstractMessage;

class WrongParentError implements ErrorInterface
{
private const IDENTIFIER = 'WrongParentError';

/**
* @var array
*/
protected $containerRecord;

/**
* @var string
*/
protected $errorMessage;

/**
* @param array $containerRecord
*/
public function __construct(array $containerRecord)
{
$this->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;
}
}
25 changes: 18 additions & 7 deletions Classes/Integrity/Integrity.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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);
}
Expand All @@ -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']])) {
Expand Down
Loading