Esempio n. 1
0
 public function saveForm(Page $c)
 {
     $controls = Control::getList($this->type);
     $outputControls = array();
     foreach ($controls as $cn) {
         $data = $cn->getRequestValue();
         $cn->publishToPage($c, $data, $controls);
         $outputControls[] = $cn;
     }
     // set page name from controls
     // now we see if there's a page name field in there
     $containsPageNameControl = false;
     foreach ($outputControls as $cn) {
         if ($cn instanceof NameCorePageProperty) {
             $containsPageNameControl = true;
             break;
         }
     }
     if (!$containsPageNameControl) {
         foreach ($outputControls as $cn) {
             if ($cn->canPageTypeComposerControlSetPageName()) {
                 $pageName = $cn->getPageTypeComposerControlPageNameValue($c);
                 $c->updateCollectionName($pageName);
             }
         }
     }
     // remove all but the most recent X drafts.
     if ($c->isPageDraft()) {
         $vl = new VersionList($c);
         $vl->setItemsPerPage(-1);
         // this will ensure that we only ever keep X versions.
         $vArray = $vl->getPage();
         if (count($vArray) > $this->ptDraftVersionsToSave) {
             for ($i = $this->ptDraftVersionsToSave; $i < count($vArray); ++$i) {
                 $v = $vArray[$i];
                 @$v->delete();
             }
         }
     }
     $c = Page::getByID($c->getCollectionID(), 'RECENT');
     $controls = array();
     foreach ($outputControls as $oc) {
         $oc->setPageObject($c);
         $controls[] = $oc;
     }
     $ev = new Event($c);
     $ev->setPageType($this->type);
     $ev->setArgument('controls', $controls);
     \Events::dispatch('on_page_type_save_composer_form', $ev);
     return $controls;
 }
 public function run()
 {
     $pNum = (int) Config::get('concrete.maintenance.version_job_page_num');
     $pNum = $pNum < 0 ? 1 : $pNum + 1;
     $pl = new PageList();
     $pl->ignorePermissions();
     $pl->setItemsPerPage(3);
     $pl->filter('p.cID', $pNum, '>=');
     $pl->sortByCollectionIDAscending();
     $pagination = $pl->getPagination();
     $pages = $pagination->getCurrentPageResults();
     /* probably want to keep a record of pages that have been gone through
      * so you don't start from the beginning each time..
      */
     if (!count($pages)) {
         Config::save('concrete.maintenance.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) {
         $pvl = new VersionList($page);
         $pagesAffected[] = $page->getCollectionID();
         foreach (array_slice($pvl->get(), 10) as $v) {
             if ($v instanceof Version && !$v->isApproved() && !$v->isMostRecent()) {
                 @$v->delete();
                 ++$versionCount;
             }
         }
         $pNum = $page->getCollectionID();
     }
     $pageCount = count($pagesAffected);
     Config::save('concrete.maintenance.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$s)', '%1$d versions deleted from %2$d pages (%3$s)', $pageCount, $versionCount, $pageCount, implode(',', $pagesAffected));
 }
Esempio n. 3
0
 public function new_page()
 {
     if ($this->validateAction()) {
         $c = $this->page;
         $e = Core::make('helper/validation/error');
         $pt = $c->getPageTypeObject();
         if (is_object($pt)) {
             $ptp = new \Permissions($pt);
             if (!$ptp->canAddPageType()) {
                 $e->add(t('You do not have permission to create new pages of this type.'));
             }
         }
         $r = new PageEditVersionResponse();
         $r->setError($e);
         if (!$e->has()) {
             $c->loadVersionObject($_REQUEST['cvID']);
             $nc = $c->cloneVersion(t('New Page Created From Version'));
             $v = $nc->getVersionObject();
             $drafts = Page::getByPath(\Config::get('concrete.paths.drafts'));
             $nc = $c->duplicate($drafts);
             $nc->deactivate();
             $nc->move($drafts);
             // now we delete all but the new version
             $vls = new VersionList($nc);
             $vls->setItemsPerPage(-1);
             $vArray = $vls->getPage();
             for ($i = 1; $i < count($vArray); $i++) {
                 $cv = $vArray[$i];
                 $cv->delete();
             }
             // now, we delete the version we duped on the current page, since we don't need it anymore.
             $v->delete();
             // finally, we redirect the user to the new drafts page in composer mode.
             $r->setPage($nc);
             $r->setRedirectURL(BASE_URL . DIR_REL . '/' . DISPATCHER_FILENAME . '?cID=' . $nc->getCollectionID() . '&ctask=check-out-first&' . Loader::helper('validation/token')->getParameter());
         }
         $r->outputJSON();
     }
 }
Esempio n. 4
0
 public function delete()
 {
     if ($this->cID > 0) {
         $db = Loader::db();
         // First we delete all versions
         $vl = new VersionList($this);
         $vl->setItemsPerPage(-1);
         $vlArray = $vl->getPage();
         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);
         try {
             $q = "delete from CollectionSearchIndexAttributes where cID = {$cID}";
             $db->query($q);
         } catch (\Exception $e) {
         }
     }
 }