Esempio n. 1
0
 /**
  * Process the module validations : here, calls the parent function but before :
  * - Pass all the editors to remindedEditors
  * - computes all the pages that got to be regenerated.
  *
  * @param CMS_resourceValidation $resourceValidation The resource validation to process
  * @param integer $result The result of the validation process. See VALIDATION_OPTION constants
  * @param boolean $lastValidation Is this the last validation done in a load of multiple validations (or the only one) ?
  *        if true, launch the regeneration script.
  * @return boolean true on success, false on failure to process
  * @access public
  */
 function processValidation($resourceValidation, $result, $lastValidation = true)
 {
     if (!$resourceValidation instanceof CMS_resourceValidation) {
         $this->raiseError("ResourceValidation is not a valid CMS_resourceValidation object");
         return false;
     }
     $editions = $resourceValidation->getEditions();
     $page = $resourceValidation->getResource();
     $publication_before = $page->getPublication();
     $location_before = $page->getLocation();
     //Clear polymod cache
     //CMS_cache::clearTypeCacheByMetas('polymod', array('module' => MOD_STANDARD_CODENAME));
     CMS_cache::clearTypeCache('polymod');
     //Get the linked pages (it will be too late after parent processing if pages move outside USERSPACE
     //first add the page to regen
     $regen_pages = array();
     if ($result == VALIDATION_OPTION_ACCEPT) {
         //2.1. If editions contains SIBLINGSORDER, all pages monitoring this one for father changes should regen
         if ($editions & RESOURCE_EDITION_SIBLINGSORDER || $editions & RESOURCE_EDITION_MOVE) {
             $temp_regen = CMS_linxesCatalog::getWatchers($page);
             if ($temp_regen) {
                 $regen_pages = array_merge($regen_pages, $temp_regen);
             }
         }
         //2.2. If editions contains BASEDATA, all pages linked with this one should regen, and all monitoring its father
         if ($editions & RESOURCE_EDITION_BASEDATA || $editions & RESOURCE_EDITION_LOCATION) {
             $temp_regen = CMS_linxesCatalog::getLinkers($page);
             if ($temp_regen) {
                 $regen_pages = array_merge($regen_pages, $temp_regen);
             }
             $father = CMS_tree::getFather($page);
             if ($father) {
                 $temp_regen = CMS_linxesCatalog::getWatchers($father);
                 if ($temp_regen) {
                     $regen_pages = array_merge($regen_pages, $temp_regen);
                 }
             }
         }
         //2.3. If editions contains CONTENT, only the page should be regen
         if ($editions & RESOURCE_EDITION_CONTENT) {
             //do nothing, the page is already in the array
         }
         $regen_pages = array_unique($regen_pages);
     }
     //call the parent function, but empty the reminded editors stack before
     if ($result == VALIDATION_OPTION_ACCEPT) {
         $stack = $page->getRemindedEditorsStack();
         $stack->emptyStack();
         $page->setRemindedEditorsStack($stack);
         $page->writeToPersistence();
     }
     if (!parent::processValidation($resourceValidation, $result)) {
         return false;
     }
     if ($result == VALIDATION_OPTION_REFUSE && ($editions & RESOURCE_EDITION_SIBLINGSORDER || $editions & RESOURCE_EDITION_MOVE)) {
         //validation was refused, move the page to it's original position
         if ($editions & RESOURCE_EDITION_SIBLINGSORDER) {
             //revert page order to the old one
             CMS_tree::revertSiblingsOrder($page);
         } elseif ($editions & RESOURCE_EDITION_MOVE) {
             //revert page move to the old position
             CMS_tree::revertPageMove($page);
         }
     }
     //if validation was not accepted, nothing more to do
     if ($result != VALIDATION_OPTION_ACCEPT) {
         return true;
     }
     //re-instanciate the page object that have changed
     $page = CMS_tree::getPageByID($resourceValidation->getResourceID());
     //page was moved out of userspace
     if ($editions & RESOURCE_EDITION_LOCATION) {
         if ($page->getLocation() != RESOURCE_LOCATION_USERSPACE && $location_before == RESOURCE_LOCATION_USERSPACE) {
             $page->deleteFiles();
             CMS_linxesCatalog::deleteLinxes($page, true);
             if ($publication_before != RESOURCE_PUBLICATION_NEVERVALIDATED) {
                 CMS_tree::detachPageFromTree($page, true);
             }
             CMS_tree::detachPageFromTree($page, false);
             //can't regenerate the page now
             if ($key = array_search($page->getID(), $regen_pages)) {
                 unset($regen_pages[$key]);
             }
         }
     } elseif ($editions & RESOURCE_EDITION_BASEDATA && $publication_before != RESOURCE_PUBLICATION_NEVERVALIDATED && $page->getPublication() != RESOURCE_PUBLICATION_PUBLIC && CMS_tree::isInPublicTree($page)) {
         //detach page if publication dates changed and page no longer published
         $page->deleteFiles();
         CMS_linxesCatalog::deleteLinxes($page, true);
         CMS_tree::detachPageFromTree($page, true);
         //can't regenerate the page now
         if ($key = array_search($page->getID(), $regen_pages)) {
             unset($regen_pages[$key]);
         }
     } else {
         //LINX_TREE RECORDS GENERATION
         //1. If the page has never been validated
         if ($publication_before == RESOURCE_PUBLICATION_NEVERVALIDATED) {
             //test the father's editions. If SIBLINGSORDER, only attach the page, else validate all of siblings orders
             $father = CMS_tree::getFather($page, true);
             $father_status = $father->getStatus();
             if ($father_status->getEditions() & RESOURCE_EDITION_SIBLINGSORDER || $editions & RESOURCE_EDITION_MOVE) {
                 CMS_tree::attachPageToTree($page, $father, true);
             } else {
                 CMS_tree::publishSiblingsOrder($father);
             }
         }
         //2. If the page has been validated, attach it to the public tree
         $grand_root = CMS_tree::getRoot();
         if ($page->getPublication() == RESOURCE_PUBLICATION_PUBLIC && $page->getID() != $grand_root->getID()) {
             $father = CMS_tree::getFather($page);
             if ($editions & RESOURCE_EDITION_MOVE) {
                 //publish page move
                 CMS_tree::publishPageMove($page);
                 //regenerate all pages which link moved page
                 $temp_regen = CMS_linxesCatalog::getLinkers($page);
                 if ($temp_regen) {
                     $regen_pages = array_merge($regen_pages, $temp_regen);
                 }
                 //and regenerate all page who watch new father page
                 $temp_regen = CMS_linxesCatalog::getWatchers($father);
                 if ($temp_regen) {
                     $regen_pages = array_merge($regen_pages, $temp_regen);
                 }
             } else {
                 CMS_tree::attachPageToTree($page, $father, true);
             }
         }
         //PAGE REGENERATION
         //3. the page itself (fromscratch needed).
         $launchRegnerator = $lastValidation && !$regen_pages ? true : false;
         CMS_tree::submitToRegenerator($page->getID(), true, $launchRegnerator);
     }
     $regen_pages = array_unique($regen_pages);
     //2. the linked pages
     CMS_tree::submitToRegenerator($regen_pages, false, !$lastValidation);
     return true;
 }