/**
  * Process the module validations. Note that the EMails sent to either the transferred validator or the editors were sent before.
  *
  * @param CMS_resourceValidation $resourceValidation The resource validation to process
  * @param integer $result The result of the validation process. See VALIDATION_OPTION constants
  * @return boolean true on success, false on failure to process
  * @access public
  */
 function processValidation($resourceValidation, $result, $lastValidation = true)
 {
     if (!CMS_poly_object_catalog::hasPrimaryResource($this->getCodename())) {
         $this->raiseError("Module have not any primary resource !");
         return false;
     }
     if (!$resourceValidation instanceof CMS_resourceValidation) {
         $this->raiseError("ResourceValidation is not a valid CMS_resourceValidation object");
         return false;
     }
     if (!SensitiveIO::isInSet($result, CMS_resourceValidation::getAllValidationOptions())) {
         $this->raiseError("ProcessValidation : result is not a valid validation option");
         return false;
     }
     //Tell the resource of the changes
     $resource = $resourceValidation->getResource();
     $editions = $resourceValidation->getEditions();
     //add a call to all modules for validation specific treatment
     $modulesCodes = new CMS_modulesCodes();
     //add a call to modules after validation
     $modulesCodes->getModulesCodes(MODULE_TREATMENT_BEFORE_VALIDATION_TREATMENT, '', $resource, array('result' => $result, 'lastvalidation' => $lastValidation, 'module' => $this->_codename));
     switch ($result) {
         case VALIDATION_OPTION_REFUSE:
             //validation was refused, adjust the array of validations refused
             $all_editions = CMS_resourceStatus::getAllEditions();
             foreach ($all_editions as $aEdition) {
                 if ($aEdition & $editions) {
                     if (RESOURCE_EDITION_LOCATION & $aEdition && $resource->getProposedLocation() == RESOURCE_LOCATION_DELETED) {
                         $resource->removeProposedLocation();
                     } else {
                         $resource->addValidationRefused($aEdition);
                     }
                 }
             }
             break;
         case VALIDATION_OPTION_ACCEPT:
             //if one of the edition was the location, only treat this one. Move the data.
             if ($editions & RESOURCE_EDITION_LOCATION) {
                 if ($resource->getLocation() == RESOURCE_LOCATION_USERSPACE) {
                     //pulling resource out of USERSPACE
                     switch ($resource->getProposedLocation()) {
                         case RESOURCE_LOCATION_DELETED:
                             $locationTo = RESOURCE_DATA_LOCATION_DELETED;
                             break;
                     }
                     //first, move edited
                     $this->_changeDataLocation($resource, RESOURCE_DATA_LOCATION_EDITED, $locationTo);
                     //then delete public
                     $this->_changeDataLocation($resource, RESOURCE_DATA_LOCATION_PUBLIC, RESOURCE_DATA_LOCATION_DEVNULL);
                     //mark item as deleted
                     CMS_modulePolymodValidation::markDeletedItem($resource->getID());
                 } else {
                     if ($resource->getProposedLocation() == RESOURCE_LOCATION_USERSPACE) {
                         //Pushing resource to USERSPACE
                         switch ($resource->getLocation()) {
                             case RESOURCE_LOCATION_DELETED:
                                 $locationFrom = RESOURCE_DATA_LOCATION_DELETED;
                                 break;
                         }
                         //if resource was published, copy data to public table
                         if ($resource->getPublication() != RESOURCE_PUBLICATION_NEVERVALIDATED) {
                             $this->_changeDataLocation($resource, $locationFrom, RESOURCE_DATA_LOCATION_PUBLIC, true);
                         }
                         //move data from its location to edited
                         $this->_changeDataLocation($resource, $locationFrom, RESOURCE_DATA_LOCATION_EDITED);
                     } else {
                         //the move entirely takes place outside of USERSPACE (archived to deleted hopefully)
                         switch ($resource->getLocation()) {
                             case RESOURCE_LOCATION_DELETED:
                                 $locationFrom = RESOURCE_DATA_LOCATION_DELETED;
                                 break;
                         }
                         switch ($resource->getProposedLocation()) {
                             case RESOURCE_LOCATION_DELETED:
                                 $locationTo = RESOURCE_DATA_LOCATION_DELETED;
                                 break;
                         }
                         $this->_changeDataLocation($resource, $locationFrom, $locationTo);
                         if ($locationTo == RESOURCE_DATA_LOCATION_DELETED) {
                             //mark item as deleted
                             CMS_modulePolymodValidation::markDeletedItem($resource->getID());
                         }
                     }
                 }
                 $resource->validateProposedLocation();
             } else {
                 $all_editions = CMS_resourceStatus::getAllEditions();
                 $this->_changeDataLocation($resource, RESOURCE_DATA_LOCATION_EDITED, RESOURCE_DATA_LOCATION_PUBLIC, true);
                 foreach ($all_editions as $aEdition) {
                     if ($aEdition & $editions) {
                         $resource->validateEdition($aEdition);
                     }
                 }
             }
             break;
     }
     //if resource is a polyobject, we need to save only it resource (parent) status
     if (!$resource instanceof CMS_poly_object) {
         $resource->writeToPersistence();
     } else {
         $resource->writeToPersistence(false);
         //Clear polymod cache
         //CMS_cache::clearTypeCacheByMetas('polymod', array('module' => $this->_codename));
         CMS_cache::clearTypeCache('polymod');
     }
     $modulesCodes->getModulesCodes(MODULE_TREATMENT_AFTER_VALIDATION_TREATMENT, '', $resource, array('result' => $result, 'lastvalidation' => $lastValidation, 'module' => $this->_codename));
     return true;
 }
Exemple #2
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;
 }