Exemplo n.º 1
0
 public function move($nc)
 {
     $db = Database::get();
     $newCParentID = $nc->getCollectionID();
     $dh = Core::make('helper/date');
     $cID = $this->getCollectionPointerOriginalID() > 0 ? $this->getCollectionPointerOriginalID() : $this->cID;
     PageStatistics::decrementParents($cID);
     $cDateModified = $dh->getOverridableNow();
     //      if ($this->getPermissionsCollectionID() != $this->getCollectionID() && $this->getPermissionsCollectionID() != $this->getMasterCollectionID()) {
     if ($this->getPermissionsCollectionID() != $this->getCollectionID()) {
         // implicitly, we're set to inherit the permissions of wherever we are in the site.
         // as such, we'll change to inherit whatever permissions our new parent has
         $npID = $nc->getPermissionsCollectionID();
         if ($npID != $this->getPermissionsCollectionID()) {
             //we have to update the existing collection with the info for the new
             //as well as all collections beneath it that are set to inherit from this parent
             // first we do this one
             $q = 'update Pages set cInheritPermissionsFromCID = ? where cID = ?';
             $r = $db->query($q, array($npID, $this->cID));
             $this->updatePermissionsCollectionID($this->getCollectionID(), $npID);
         }
     }
     $oldParent = Page::getByID($this->getCollectionParentID(), 'RECENT');
     $db->query('update Collections set cDateModified = ? where cID = ?', array($cDateModified, $cID));
     $v = array($newCParentID, $cID);
     $q = 'update Pages set cParentID = ? where cID = ?';
     $r = $db->prepare($q);
     $db->execute($r, $v);
     PageStatistics::incrementParents($cID);
     if (!$this->isActive()) {
         $this->activate();
         // if we're moving from the trash, we have to activate recursively
         if ($this->isInTrash()) {
             $pages = array();
             $pages = $this->populateRecursivePages($pages, array('cID' => $this->getCollectionID()), $this->getCollectionParentID(), 0, false);
             foreach ($pages as $page) {
                 $db->Execute('update Pages set cIsActive = 1 where cID = ?', array($page['cID']));
             }
         }
     }
     $this->cParentID = $newCParentID;
     $this->movePageDisplayOrderToBottom();
     // run any event we have for page move. Arguments are
     // 1. current page being moved
     // 2. former parent
     // 3. new parent
     $newParent = Page::getByID($newCParentID, 'RECENT');
     $pe = new MovePageEvent($this);
     $pe->setOldParentPageObject($oldParent);
     $pe->setNewParentPageObject($newParent);
     Events::dispatch('on_page_move', $pe);
     Section::registerMove($this, $oldParent, $newParent);
     // now that we've moved the collection, we rescan its path
     $this->rescanCollectionPath();
 }