private function validateLanguageMainForPage($pageId)
{
$page = PageModel::findWithDetails($pageId);
// Moving a root page does not affect language assignments
if (null === $page || !$page->languageMain || 'root' === $page->type) {
return;
}
$duplicates = PageModel::countBy(['id IN (' . implode(',', Database::getInstance()->getChildRecords($page->rootId, 'tl_page')) . ')', 'languageMain=?', 'id!=?'], [$page->languageMain, $page->id]);
// Reset languageMain if another page in the new page tree has the same languageMain
if ($duplicates > 0) {
$this->resetPageAndChildren($page->id);
return;
}
$pageFinder = new PageFinder();
$masterRoot = $pageFinder->findMasterRootForPage($page);
// Reset languageMain if current tree has no master or if it's the master tree
if (null === $masterRoot || $masterRoot->id === $page->rootId) {
$this->resetPageAndChildren($page->id);
return;
}
// Reset languageMain if the current value is not a valid ID of the master tree
if (!in_array($page->id, Database::getInstance()->getChildRecords($masterRoot->id, 'tl_page'), false)) {
$this->resetPageAndChildren($page->id);
}
}