- Get all pages in original multilingual section
- Get a page in destination multilingual section that has same collection path
- Make a relation
- Go to next page
concrete/bin/concrete5 c5:exec bulk_mapping_multilingual_sitemap.php
| <?php | |
| use Concrete\Core\Page\Page; | |
| use Concrete\Core\Multilingual\Page\Section\Section; | |
| use Concrete\Core\Multilingual\Page\PageList as MultilingualPageList; | |
| $originSection = Section::getByLocale('ja_JP'); | |
| $destSection = Section::getByLocale('en_US'); | |
| $pl = new MultilingualPageList(); | |
| $pl->setSiteTreeObject($originSection->getSiteTreeObject()); | |
| $results = $pl->getResults(); | |
| $mapped = 0; | |
| $skipped = 0; | |
| foreach ($results as $result) { | |
| $path = $result->getCollectionPath(); | |
| $destPage = Page::getByPath($destSection->getCollectionPath() . $path, 'RECENT', $destSection->getSiteTreeObject()); | |
| if (is_object($destPage) && !$destPage->isError()) { | |
| if (!Section::isAssigned($result)) { | |
| Section::registerPage($result); | |
| } | |
| Section::relatePage($result, $destPage, $destSection->getLocale()); | |
| ++$mapped; | |
| } else { | |
| ++$skipped; | |
| } | |
| } | |
| echo sprintf('%d pages mapped. %d pages skipped.', $mapped, $skipped); | |
| echo "\n"; | |
| die(); |