Skip to content

Instantly share code, notes, and snippets.

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 katzueno/02a0d08b78e7b0b06aec225d25ebf54a to your computer and use it in GitHub Desktop.
Save katzueno/02a0d08b78e7b0b06aec225d25ebf54a to your computer and use it in GitHub Desktop.
#concrete5 c5:exec command to bulk change page type & template
<?php
/**
* Usage:
* concrete/bin/concrete5 c5:exec bulk_change_page_template.php old_page_template_handle /parent-page-path new_page_template_handle
*/
$filterPageTemplateHandle = $args[0];
$filterPagePath = $args[1];
$changePageTemplateHandle = $args[2];
$filterPageTemplate = \Concrete\Core\Page\Template::getByHandle($filterPageTemplateHandle);
if (!is_object($filterPageTemplate)) {
echo sprintf('Page Template %s not found.', $filterPageTemplateHandle);
die();
}
/** @var \Concrete\Core\Entity\Page\Template $changePageTemplate */
$changePageTemplate = \Concrete\Core\Page\Template::getByHandle($changePageTemplateHandle);
if (!is_object($changePageTemplate)) {
echo sprintf('Page Template %s not found.', $changePageTemplateHandle);
die();
}
$list = new \Concrete\Core\Page\PageList();
$list->ignorePermissions();
$list->filterByPageTemplate($filterPageTemplate);
$list->filterByPath($filterPagePath);
$pages = $list->getResults();
$count = 0;
/** @var \Concrete\Core\Page\Page|\Concrete\Core\Page\Collection\Version\Version $page */
foreach ($pages as $page) {
$page->update(['pTemplateID' => $changePageTemplate->getPageTemplateID()]);
++$count;
}
echo sprintf('%d pages changed to %s', $count, $changePageTemplate->getPageTemplateDisplayName());
<?php
/**
* Usage:
* concrete/bin/concrete5 c5:exec bulk_change_page_type.php old_page_type_handle /parent-page-path new_page_type_handle
*/
$filterPageTypeHandle = $args[0];
$filterPagePath = $args[1];
$changePageTypeHandle = $args[2];
$filterPageType = \Concrete\Core\Page\Type\Type::getByHandle($filterPageTypeHandle);
if (!is_object($filterPageType)) {
echo sprintf('Page Type %s not found.', $filterPageTypeHandle);
die();
}
$changePageType = \Concrete\Core\Page\Type\Type::getByHandle($changePageTypeHandle);
if (!is_object($changePageType)) {
echo sprintf('Page Type %s not found.', $changePageTypeHandle);
die();
}
$list = new \Concrete\Core\Page\PageList();
$list->ignorePermissions();
$list->filterByPageTypeHandle($filterPageTypeHandle);
$list->filterByPath($filterPagePath);
$pages = $list->getResults();
$count = 0;
/** @var \Concrete\Core\Page\Page $page */
foreach ($pages as $page) {
$page->setPageType($changePageType);
++$count;
}
echo sprintf('%d pages changed to %s', $count, $changePageType->getPageTypeDisplayName());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment