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 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) { } } }
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(\Core::getApplicationURL() . '/' . DISPATCHER_FILENAME . '?cID=' . $nc->getCollectionID() . '&ctask=check-out-first&' . Loader::helper('validation/token')->getParameter()); } $r->outputJSON(); } }