Last active
March 17, 2023 03:57
-
-
Save hissy/efed3efc2def5420158432f185eccc47 to your computer and use it in GitHub Desktop.
Automated job to move all pages under old parent to new parent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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