Esempio n. 1
0
 function approve($doReindexImmediately = true)
 {
     $db = Loader::db();
     $u = new User();
     $uID = $u->getUserID();
     $cvID = $this->cvID;
     $cID = $this->cID;
     $c = Page::getByID($cID, $this->cvID);
     $ov = Page::getByID($cID, 'ACTIVE');
     $oldHandle = $ov->getCollectionHandle();
     $newHandle = $this->cvHandle;
     // update a collection updated record
     $dh = Loader::helper('date');
     $db->query('update Collections set cDateModified = ? where cID = ?', array($dh->getOverridableNow(), $cID));
     // first we remove approval for the other version of this collection
     $v = array($cID);
     $q = "update CollectionVersions set cvIsApproved = 0 where cID = ?";
     $r = $db->query($q, $v);
     $ov->refreshCache();
     // now we approve our version
     $v2 = array($uID, $cID, $cvID);
     $q2 = "update CollectionVersions set cvIsNew = 0, cvIsApproved = 1, cvApproverUID = ? where cID = ? and cvID = ?";
     $r = $db->query($q2, $v2);
     // next, we rescan our collection paths for the particular collection, but only if this isn't a generated collection
     // I don't know why but this just isn't reliable. It might be a race condition with the cached page objects?
     /*
      * if ((($oldHandle != $newHandle) || $oldHandle == '') && (!$c->isGeneratedCollection())) {
      */
     $c->rescanCollectionPath();
     // }
     // check for related version edits. This only gets applied when we edit global areas.
     $r = $db->Execute('select cRelationID, cvRelationID from CollectionVersionRelatedEdits where cID = ? and cvID = ?', array($cID, $cvID));
     while ($row = $r->FetchRow()) {
         $cn = Page::getByID($row['cRelationID'], $row['cvRelationID']);
         $cnp = new Permissions($cn);
         if ($cnp->canApprovePageVersions()) {
             $v = $cn->getVersionObject();
             $v->approve();
             $db->Execute('delete from CollectionVersionRelatedEdits where cID = ? and cvID = ? and cRelationID = ? and cvRelationID = ?', array($cID, $cvID, $row['cRelationID'], $row['cvRelationID']));
         }
     }
     if ($c->getCollectionInheritance() == 'TEMPLATE') {
         // we make sure to update the cInheritPermissionsFromCID value
         $pType = PageType::getByID($c->getPageTypeID());
         $pTemplate = PageTemplate::getByID($c->getPageTemplateID());
         $masterC = $pType->getPageTypePageTemplateDefaultPageObject($pTemplate);
         $db->Execute('update Pages set cInheritPermissionsFromCID = ? where cID = ?', array($masterC->getCollectionID(), $c->getCollectioniD()));
     }
     $ev = new Event($c);
     $ev->setCollectionVersionObject($this);
     Events::dispatch('on_page_version_approve', $ev);
     $c->reindex(false, $doReindexImmediately);
     $c->writePageThemeCustomizations();
     $this->refreshCache();
 }
Esempio n. 2
0
 public function approve($doReindexImmediately = true, $scheduleDatetime = null)
 {
     $app = Facade::getFacadeApplication();
     $db = $app->make('database')->connection();
     $u = new User();
     $uID = $u->getUserID();
     $cvID = $this->cvID;
     $cID = $this->cID;
     $c = Page::getByID($cID, $this->cvID);
     // Current active
     $ov = Page::getByID($cID, 'ACTIVE');
     $oldHandle = $ov->getCollectionHandle();
     $newHandle = $this->cvHandle;
     // update a collection updated record
     $dh = $app->make('helper/date');
     $db->executeQuery('update Collections set cDateModified = ? where cID = ?', array($dh->getOverridableNow(), $cID));
     // Remove all publish dates before setting the new ones, if any
     $this->clearPublishDates();
     if ($scheduleDatetime) {
         // remove approval for all versions except the current one because a scheduled version is being processed
         $oldVersion = $ov->getVersionObject();
         $v = array($cID, $oldVersion->cvID);
         $q = "update CollectionVersions set cvIsApproved = 0 where cID = ? and cvID != ?";
         $this->setPublishDate($scheduleDatetime);
     } else {
         // remove approval for the other version of this collection
         $v = array($cID);
         $q = "update CollectionVersions set cvIsApproved = 0 where cID = ?";
     }
     $r = $db->executeQuery($q, $v);
     $ov->refreshCache();
     // now we approve our version
     $v2 = array($uID, $cID, $cvID);
     $q2 = "update CollectionVersions set cvIsNew = 0, cvIsApproved = 1, cvApproverUID = ? where cID = ? and cvID = ?";
     $db->executeQuery($q2, $v2);
     // next, we rescan our collection paths for the particular collection, but only if this isn't a generated collection
     // I don't know why but this just isn't reliable. It might be a race condition with the cached page objects?
     /*
      * if ((($oldHandle != $newHandle) || $oldHandle == '') && (!$c->isGeneratedCollection())) {
      */
     $c->rescanCollectionPath();
     // }
     // check for related version edits. This only gets applied when we edit global areas.
     $r = $db->executeQuery('select cRelationID, cvRelationID from CollectionVersionRelatedEdits where cID = ? and cvID = ?', array($cID, $cvID));
     while ($row = $r->fetch()) {
         $cn = Page::getByID($row['cRelationID'], $row['cvRelationID']);
         $cnp = new Permissions($cn);
         if ($cnp->canApprovePageVersions()) {
             $v = $cn->getVersionObject();
             $v->approve();
             $db->executeQuery('delete from CollectionVersionRelatedEdits where cID = ? and cvID = ? and cRelationID = ? and cvRelationID = ?', array($cID, $cvID, $row['cRelationID'], $row['cvRelationID']));
         }
     }
     if ($c->getCollectionInheritance() == 'TEMPLATE') {
         // we make sure to update the cInheritPermissionsFromCID value
         $pType = PageType::getByID($c->getPageTypeID());
         $masterC = $pType->getPageTypePageTemplateDefaultPageObject();
         $db->executeQuery('update Pages set cInheritPermissionsFromCID = ? where cID = ?', array($masterC->getCollectionID(), $c->getCollectioniD()));
     }
     $ev = new Event($c);
     $ev->setCollectionVersionObject($this);
     $app->make('director')->dispatch('on_page_version_approve', $ev);
     $c->reindex(false, $doReindexImmediately);
     $c->writePageThemeCustomizations();
     $this->refreshCache();
 }