Skip to content

Instantly share code, notes, and snippets.

@hissy
Last active December 19, 2018 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hissy/61652c564d2abd0a893c434a76572e1f to your computer and use it in GitHub Desktop.
Save hissy/61652c564d2abd0a893c434a76572e1f to your computer and use it in GitHub Desktop.
[concrete5] [v8] Bulk mapping pages between multilingual sitemaps from command line

What this script does?

  1. Get all pages in original multilingual section
  2. Get a page in destination multilingual section that has same collection path
  3. Make a relation
  4. Go to next page

How to use

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();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment