Skip to content

Instantly share code, notes, and snippets.

@hissy
Created February 29, 2016 07:09
Show Gist options
  • Save hissy/167611b142457c378342 to your computer and use it in GitHub Desktop.
Save hissy/167611b142457c378342 to your computer and use it in GitHub Desktop.
#concrete5 A job for bulk update permission inheritance of pages
<?php
// application/jobs/update_page_permissions.php
namespace Application\Job;
use Concrete\Core\Cache\Cache;
use Job as AbstractJob;
use Page;
use PageList;
class UpdatePagePermissions extends AbstractJob
{
/** Returns the job name.
* @return string
*/
public function getJobName()
{
return t('Update Page Permissions');
}
/** Returns the job description.
* @return string
*/
public function getJobDescription()
{
return t('This is a maintenance job.');
}
/** Executes the job.
* @throws \Exception Throws an exception in case of errors.
*
* @return string Returns a string describing the job result in case of success.
*/
public function run()
{
Cache::disableAll();
try {
// PageList インスタンス化
$list = new PageList();
// ページタイプで絞り込み
$list->filterByPageTypeHandle('blog_entry');
// ページパスで絞り込み
$list->filterByPath('/blog');
// 全件取得
$pages = $list->getResults();
foreach ($pages as $page) {
// ページタイプのデフォルトの継承に変更
$page->inheritPermissionsFromDefaults();
// 親ページ継承
// $page->inheritPermissionsFromParent();
// 手動
// $page->setPermissionsToManualOverride();
}
} catch (\Exception $x) {
throw $x;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment