/**
  * 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;
 }