Skip to content

Instantly share code, notes, and snippets.

@hissy
Last active March 17, 2023 03:57
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/efed3efc2def5420158432f185eccc47 to your computer and use it in GitHub Desktop.
Save hissy/efed3efc2def5420158432f185eccc47 to your computer and use it in GitHub Desktop.
Automated job to move all pages under old parent to new parent
<?php
namespace Application\Job;
use Concrete\Core\Job\QueueableJob;
use Concrete\Core\Page\Page;
use Concrete\Core\Page\PageList;
use ZendQueue\Message as ZendQueueMessage;
use ZendQueue\Queue as ZendQueue;
class BulkMovePages extends QueueableJob
{
public $jQueueBatchSize = 20;
public $jSupportsQueue = true;
protected $fromPath = '/blog';
protected $toPath = '/portfolio';
/**
* {@inheritdoc}
*/
public function getJobName()
{
return t('Bulk Move Pages');
}
/**
* {@inheritdoc}
*/
public function getJobDescription()
{
return t('A custom job.');
}
/**
* {@inheritdoc}
*/
public function start(ZendQueue $q)
{
$list = new PageList();
$list->ignorePermissions();
$list->includeInactivePages();
$list->filterByPath($this->fromPath);
$pages = $list->getResults();
/** @var Page $page */
foreach ($pages as $page) {
$q->send($page->getCollectionID());
}
}
/**
* {@inheritdoc}
*/
public function finish(ZendQueue $q)
{
return t('Done.');
}
/**
* {@inheritdoc}
*/
public function processQueueItem(ZendQueueMessage $msg)
{
$nc = Page::getByPath($this->toPath);
$p = Page::getByID($msg->body);
if (is_object($p) && !$p->isError()) {
$p->move($nc);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment