/** * 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; }
/** * Gets a validation for a given item * * @param integer $itemID The item we want the validations for * @param CMS_user $user The user we want the validations for * @param integer $getEditionType The validation type we want. * by default function return RESOURCE_EDITION_LOCATION then RESOURCE_EDITION_CONTENT then RESOURCE_EDITION_SIBLINGSORDER * @return array(CMS_resourceValidation) The resourceValidations objects, false if none found for the given user. * @access public */ function getValidationByID($itemID, &$user, $getEditionType = false) { if (!is_a($user, "CMS_profile_user")) { $this->raiseError("User is not a valid CMS_profile_user object"); return false; } if (!$user->hasValidationClearance($this->_codename)) { return false; } if (is_array($this->_resourceInfo) && $this->_resourceInfo) { $primaryResource = $this->getPrimaryResourceInfo(); if (!$getEditionType) { $getEditionType = RESOURCE_EDITION_LOCATION + RESOURCE_EDITION_CONTENT; } $sql = "\n\t\t\t\t\tselect\n\t\t\t\t\t\t" . $primaryResource['key'] . " as id,\n\t\t\t\t\t\tlocation_rs as location,\n\t\t\t\t\t\tproposedFor_rs as proposedFor,\n\t\t\t\t\t\tvalidationsRefused_rs as validationsRefused,\n\t\t\t\t\t\teditions_rs as editions\n\t\t\t\t\tfrom\n\t\t\t\t\t\t" . $primaryResource['tableName'] . "_edited,\n\t\t\t\t\t\tresources,\n\t\t\t\t\t\tresourceStatuses\n\t\t\t\t\twhere\n\t\t\t\t\t\t" . $primaryResource['key'] . " = '" . $itemID . "'\n\t\t\t\t\t\tand " . $primaryResource['resource'] . " = id_res\n\t\t\t\t\t\tand status_res = id_rs\n\t\t\t\t"; $q = new CMS_query($sql); if ($q->getNumRows() == 1) { $r = $q->getArray(); $id = $r["id"]; //search the type of edition //RESOURCE_EDITION_LOCATION if ($r["location"] == RESOURCE_LOCATION_USERSPACE && $r["proposedFor"] != 0 && !($r["validationsRefused"] & RESOURCE_EDITION_LOCATION) && $getEditionType & RESOURCE_EDITION_LOCATION) { $language = $user->getLanguage(); $item = $this->getResourceByID($id); $validation = new CMS_resourceValidation($this->_codename, RESOURCE_EDITION_LOCATION, $item); if (!$validation->hasError()) { $validation->setValidationTypeLabel($language->getMessage($this->getModuleValidationLabel("locationChange"), false, $this->_codename)); $validation->setValidationLabel($language->getMessage($this->getModuleValidationLabel("locationChangeOfResource"), false, $this->_codename) . " " . $item->{$this->_resourceNameMethod}()); $validation->setValidationShortLabel($item->{$this->_resourceNameMethod}()); if ($this->_resourcePrevizFile) { $validation->addHelpUrl($language->getMessage($this->getModuleValidationLabel("URLPreviz"), false, $this->_codename), PATH_ADMIN_MODULES_WR . "/" . $this->_codename . "/" . $this->_resourcePrevizFile . ".php?item=" . $id); } $validation->setEditorsStack($item->getEditorsStack()); return $validation; } else { return false; } //RESOURCE_EDITION_CONTENT } elseif ($r["location"] == RESOURCE_LOCATION_USERSPACE && $r["proposedFor"] == 0 && ($r["editions"] & RESOURCE_EDITION_CONTENT && !($r["validationsRefused"] & RESOURCE_EDITION_CONTENT)) && $getEditionType & RESOURCE_EDITION_CONTENT) { $language = $user->getLanguage(); $editions = $r["editions"]; //RESOURCE_EDITION_CONTENT $item = $this->getResourceByID($id); $validation = new CMS_resourceValidation($this->_codename, $editions, $item); if (!$validation->hasError()) { $validation->setValidationTypeLabel($language->getMessage($this->getModuleValidationLabel("edition"), false, $this->_codename)); $validation->setValidationLabel($language->getMessage($this->getModuleValidationLabel("editionOfResource"), false, $this->_codename) . " " . $item->{$this->_resourceNameMethod}()); $validation->setValidationShortLabel($item->{$this->_resourceNameMethod}()); if ($this->_resourcePrevizFile) { $validation->addHelpUrl($language->getMessage($this->getModuleValidationLabel("URLPreviz"), false, $this->_codename), PATH_ADMIN_MODULES_WR . "/" . $this->_codename . "/" . $this->_resourcePrevizFile . "?item=" . $id); } $validation->setEditorsStack($item->getEditorsStack()); return $validation; } else { return false; } } } elseif ($q->getNumRows() == 0) { return false; } else { $this->raiseError("Can't have more than one item for a given ID"); return false; } } else { return false; } }
if (!$module) { CMS_grandFather::raiseError('Module not set ...'); $view->show(); } if (!$editions && !$resource) { CMS_grandFather::raiseError('Module editions not set ...'); $view->show(); } elseif ($resource) { //get current edition for given resource //load module $mod = CMS_modulesCatalog::getByCodename($module); //load module resource by ID $resource = $mod->getResourceByID($resource); $validation = false; //Clean old validations CMS_resourceValidation::cleanOldValidations(); if (is_object($resource) && !$resource->hasError()) { if (method_exists($mod, "getValidationByID")) { $validation = $mod->getValidationByID($resource->getID(), $cms_user); if (!is_a($validation, "CMS_resourceValidation") || $validation->hasError()) { $validation = false; } } else { $validations = $mod->getValidations($cms_user); if (is_array($validations)) { foreach ($validations as $aValidation) { if ($aValidation->getResourceID() == $resource->getID() && !$aValidation->hasError()) { $validation = $aValidation; } } }
/** * 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; }