diff --git a/src/PortlandLabs/Concrete5/MigrationTool/Publisher/Command/Handler/CreatePageStructureCommandHandler.php b/src/PortlandLabs/Concrete5/MigrationTool/Publisher/Command/Handler/CreatePageStructureCommandHandler.php index 535be1c..5cdfe32 100644 --- a/src/PortlandLabs/Concrete5/MigrationTool/Publisher/Command/Handler/CreatePageStructureCommandHandler.php +++ b/src/PortlandLabs/Concrete5/MigrationTool/Publisher/Command/Handler/CreatePageStructureCommandHandler.php @@ -62,9 +62,9 @@ private function publishPage(Batch $batch, LoggerInterface $logger, MTPage $mtPa $ccmPage = $this->createRegularPage($batch, $ccmParentPage, $mtPage); break; } + $this->setAdditionalPaths($mtPage, $ccmPage); $logger->logPublishComplete($mtPage, $ccmPage); } - $this->setAdditionalPaths($mtPage, $ccmPage); return $ccmPage; } @@ -107,7 +107,7 @@ private function createRegularPage(Batch $batch, ?CCMPage $ccmParentPage, MTPage $page = $service->addHomePage($locale, $pageTemplate, $data['name'] ?? 'Home', $data['cHandle']); $page->update([ 'cDescription' => $data['cDescription'], - 'cDatePublic' => $data['$cDatePublic'], + 'cDatePublic' => $data['cDatePublic'], 'ptID' => $data['ptID'], 'uID' => $data['uID'], 'pkgID' => $data['pkgID'], @@ -297,6 +297,7 @@ protected function getBatchParentPage(Batch $batch): CCMPage private function updateExistingPage(Batch $batch, MTPage $mtPage, CCMPage $ccmPage): void { + $this->setAdditionalPaths($mtPage, $ccmPage); switch ($mtPage->getKind()) { case MTPage::KIND_ALIAS: break; diff --git a/src/PortlandLabs/Concrete5/MigrationTool/Publisher/Command/Handler/PublishPageContentCommandHandler.php b/src/PortlandLabs/Concrete5/MigrationTool/Publisher/Command/Handler/PublishPageContentCommandHandler.php index 5ae847f..c46250e 100644 --- a/src/PortlandLabs/Concrete5/MigrationTool/Publisher/Command/Handler/PublishPageContentCommandHandler.php +++ b/src/PortlandLabs/Concrete5/MigrationTool/Publisher/Command/Handler/PublishPageContentCommandHandler.php @@ -1,10 +1,14 @@ getPage($this->command->getPageId()); + switch ($mtPage->getKind()) { + case MTPage::KIND_ALIAS: + case MTPage::KIND_EXTERNAL_LINK: + return; + } $ccmPage = $this->getPageByPath($batch, $mtPage->getBatchPath()); + $this->publishHRefLangs($batch, $mtPage, $ccmPage); foreach ($mtPage->getAttributes() as $mtAttribute) { $ak = $this->getTargetItem($batch, 'page_attribute', $mtAttribute->getAttribute()->getHandle()); if (is_object($ak)) { @@ -116,4 +126,32 @@ public function execute(BatchInterface $batch, LoggerInterface $logger) $ccmBlock->deleteBlock(); } } + + private function publishHRefLangs(Batch $batch, MTPage $mtPage, CCMPage $ccmPage): void + { + if ($batch->isPublishToSitemap() !== true) { + return; + } + foreach ($mtPage->getHRefLangs() as $hrefLang) { + /** @var \PortlandLabs\Concrete5\MigrationTool\Entity\Import\Page\HRefLang $hrefLang */ + $destinationPage = $this->getPageByPath($batch, $hrefLang->getPathForLocale()); + if ($destinationPage === null || $destinationPage->getCollectionID() == $ccmPage->getCollectionID()) { + continue; + } + $destinationSection = Section::getByID($destinationPage->getCollectionID()); + if (!$destinationSection || $destinationSection->isError()) { + $destinationSection = Section::getBySectionOfSite($destinationPage); + if (!$destinationSection || $destinationSection->isError()) { + continue; + } + } + if ($destinationSection->getLocale() !== $hrefLang->getLocaleID()) { + continue; + } + if (!Section::isAssigned($ccmPage)) { + Section::registerPage($ccmPage); + } + Section::relatePage($ccmPage, $destinationPage, $destinationSection->getLocale()); + } + } }