Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
concrete5 5.7系で、更新されたスタックとグローバルエリアが利用されているページのcID一覧を取得するJobのサンプルコード
<?php
namespace Application\Job;
use Concrete\Core\Cache\Cache;
use Config;
use Job as AbstractJob;
use Core;
use Database;
use PermissionKey;
use Group;
use DateTime;
use CollectionAttributeKey;
use Concrete\Core\Permission\Access\Entity\GroupEntity as GroupPermissionAccessEntity;
use Concrete\Core\Multilingual\Page\Section\Section as MultilingualSection;
use Page;
use PageList;
use Events;
use StackList;
use Stack;
use Loader;
class GetUpdatedStackPages extends AbstractJob
{
/** Returns the job name.
* @return string
*/
public function getJobName()
{
return t('Get updated pages include Stack and Global Area');
}
/** Returns the job description.
* @return string
*/
public function getJobDescription()
{
return t('Get updated pages include Stack and Global Area.');
}
/** 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();
$date = "2016-03-23 00:00:00";//更新基準日時
try {
//変更されたスタックの一覧を取得
$sl = new StackList();
$sl->filter('cvDateCreated', $date, ">");
$rs = $sl->get();
$stacks = array();
$globals = array();
foreach($rs as $s){//スタックとグローバルエリアを分ける
if($s->getStackType() == Stack::ST_TYPE_GLOBAL_AREA){
$globals[] = $s->getStackName();// Stack name = Global area name
}else{
$stacks[] = $s->getCollectionID();
}
}
$db = Loader::db();
//スタックが利用されているページを取得
$sql = "
SELECT cvb.cID
FROM CollectionVersionBlocks as cvb
INNER JOIN CollectionVersions as cv ON cv.cvID = cvb.cvID AND cvb.cID = cv.cID
WHERE cvb.bID IN (
SELECT sd.bID FROM btCoreStackDisplay as sd WHERE sd.stID IN ( ".implode(",",$stacks)." )
)
AND cv.cvIsApproved = 1
AND cv.pTemplateID > 5
GROUP BY cvb.cID";
$rs = $db->query($sql);
$results = array();
foreach($rs as $r){
$results[] = $r["cID"];
}
//グローバルエリアが利用されているページを取得
//AreasからarHandleで検索
$sql = "SELECT cID From Areas WHERE arHandle IN ( '".implode("','",$globals)."' )";
$rs = $db->query($sql);
foreach($rs as $r){
$results[] = $r["cID"];
}
$results = array_unique($results);
return implode(",", $results);
} catch (\Exception $x) {
throw $x;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.