public function run() { $cfg = new Config(); $pNum = (int) $cfg->get('OLD_VERSION_JOB_PAGE_NUM'); $pNum = $pNum < 0 ? 1 : $pNum + 1; $pl = new PageList(); $pl->setItemsPerPage(3); /* probably want to keep a record of pages that have been gone through * so you don't start from the beginning each time.. */ $pages = $pl->getPage($pNum); if (!count($pages)) { $cfg->save('OLD_VERSION_JOB_PAGE_NUM', 0); return t("All pages have been processed, starting from beginning on next run."); } $versionCount = 0; $pagesAffected = array(); foreach ($pages as $page) { if ($page instanceof Page) { $pvl = new VersionList($page); $pagesAffected[] = $page->getCollectionID(); foreach (array_slice(array_reverse($pvl->getVersionListArray()), 10) as $v) { if ($v instanceof CollectionVersion && !$v->isApproved() && !$v->isMostRecent()) { @$v->delete(); $versionCount++; } } } } $pageCount = count($pagesAffected); $cfg->save('OLD_VERSION_JOB_PAGE_NUM', $pNum); //i18n: %1$d is the number of versions deleted, %2$d is the number of affected pages, %3$d is the number of times that the Remove Old Page Versions job has been executed. return t2('%1$d versions deleted from %2$d page (%3$d)', '%1$d versions deleted from %2$d pages (%3$s)', $pageCount, $versionCount, $pageCount, implode(',', $pagesAffected)); }
public function run() { //$u = new User(); //if(!$u->isSuperUser()) { die(t("Access Denied."));} // cheap security check... $cfg = new Config(); Loader::model('page_list'); $pl = new PageList(); //$pl->ignorePermissions(); $pNum = $cfg->get('OLD_VERSION_JOB_PAGE_NUM'); if ($pNum <= 0) { $cfg->save('OLD_VERSION_JOB_PAGE_NUM', 0); } $pl->setItemsPerPage(3); /* probably want to keep a record of pages that have been gone through * so you don't start from the beginning each time.. */ $pNum = $pNum + 1; $pages = $pl->getPage($pNum); $cfg->save('OLD_VERSION_JOB_PAGE_NUM', $pNum); $pageCount = 0; $versionCount = 0; if (count($pages) == 0) { $cfg->save('OLD_VERSION_JOB_PAGE_NUM', 0); return t("All pages have been processes, starting from beginning on next run."); } foreach ($pages as $page) { if ($page instanceof Page) { $pvl = new VersionList($page); $versions = $pvl->getVersionListArray(); $versions = array_reverse($versions); $vCount = count($versions); if ($vCount <= 10) { continue; } $pageCount++; $stopAt = $vCount - 10; $i = 0; foreach ($versions as $v) { if ($v instanceof CollectionVersion) { if ($v->isApproved() || $v->isMostRecent()) { // may want to add a date check here too continue; } else { @$v->delete(); $versionCount++; } } $i++; if ($i >= $stopAt) { break; } } } } $pages = $pageCount == 1 ? t("Page") : t("Pages"); return $versionCount . " " . t("versions deleted from") . " " . $pageCount . " " . $pages . " (" . $pNum . ")"; }
header("Location: " . REL_DIR_FILES_TOOLS_REQUIRED . "/versions.php?forcereload=1&deferred=true&cID=" . $cID . "&cvID=" . $_GET['cvID']); exit; } else { // we only get this response if we have skipped workflows and jumped straight in to an approve() step. header("Location: " . REL_DIR_FILES_TOOLS_REQUIRED . "/versions.php?forcereload=1&cID=" . $cID . "&cvID=" . $_GET['cvID']); exit; } } break; } } $page = $_REQUEST[PAGING_STRING]; if (!$page) { $page = 1; } $vl = new VersionList($c, 20, $page); $total = $vl->getVersionListCount(); $vArray = $vl->getVersionListArray(); $ph = Loader::helper('pagination'); $ph->init($page, $total, '', 20, 'ccm_goToVersionPage'); } if (!$_GET['versions_reloaded']) { ?> <div id="ccm-versions-container"> <?php if ($_REQUEST['deferred']) { ?> <div class="alert alert-info"> <?php echo t('<strong>Request Saved.</strong> You must complete the workflow before this change is active.'); ?>
public function delete() { if ($this->cID > 0) { $db = Loader::db(); // First we delete all versions $vl = new VersionList($this); $vlArray = $vl->getVersionListArray(); foreach($vlArray as $v) { $v->delete(); } $cID = $this->getCollectionID(); $q = "delete from CollectionAttributeValues where cID = {$cID}"; $db->query($q); $q = "delete from Collections where cID = '{$cID}'"; $r = $db->query($q); } }