/** * Changes The item data (in the DB) from one location to another. * * @param CMS_resource $resource The resource concerned by the data location change * @param string $locationFrom The starting location among "edited", "edition", "public", "archived", "deleted" * @param string $locationTo The ending location among "edited", "edition", "public", "archived", "deleted" * @param boolean $copyOnly If true, data is not deleted from the original location * @return void * @access private */ protected function _changeDataLocation($resource, $locationFrom, $locationTo, $copyOnly = false) { //check queried data location change if (!parent::_changeDataLocation($resource, $locationFrom, $locationTo, $copyOnly)) { return false; } //get all secondary resources concerned by this validation $secondaryResourceIds = $resource->getAllSecondaryResourcesForPrimaryResource(); if (is_array($secondaryResourceIds) && $secondaryResourceIds) { foreach ($secondaryResourceIds as $secondaryResourceId) { if ($locationTo != RESOURCE_DATA_LOCATION_DELETED && $locationTo != RESOURCE_DATA_LOCATION_DEVNULL) { //move the data CMS_modulePolymodValidation::moveResourceData($this->getCodename(), $secondaryResourceId, $locationFrom, $locationTo, $copyOnly); } } } //then move resource data for concerned resource CMS_modulePolymodValidation::moveResourceData($this->getCodename(), $resource->getID(), $locationFrom, $locationTo, $copyOnly); }
/** * Delete object and values. * If object is a primary resource, this deletion is submitted to validation and an email is sent to validators. * * @param boolean $hardDelete : completely destroy object and associated resource if any. After this, this object will no longer exists at all. Default : false. * /!\ if object is a primary resource, no validation will be queried to validators, object will be directly destroyed from all locations. /!\ * @return boolean true on success, false on failure * @access public */ function delete($hardDelete = false) { global $cms_user; //get Object definition $objectDef = $this->getObjectDefinition(); //get module codename $polyModuleCodename = $objectDef->getValue('module'); //if object is not a primary resource if ($this->_objectResourceStatus != 1 || $hardDelete) { $forceSecondaryRessourcePublication = false; if ($this->_objectResourceStatus == 2 && !$hardDelete) { //if this object is a secondary resource, primary items which uses this object must be updated //get all primary resource associated $primaryItems = CMS_poly_object_catalog::getPrimaryItemsWhichUsesSecondaryItem($this->_ID, true, false); if ($primaryItems) { foreach ($primaryItems as $primaryItem) { $primaryItem->writeToPersistence(); } } else { $forceSecondaryRessourcePublication = true; } } //if object is not a secondary resource, delete public datas, else preserve it : it will be deleted on primary resource validation if ($this->_objectResourceStatus != 2 || $this->_objectResourceStatus == 2 && $forceSecondaryRessourcePublication || $hardDelete) { //delete datas from public locations CMS_modulePolymodValidation::moveResourceData($polyModuleCodename, $this->getID(), RESOURCE_DATA_LOCATION_PUBLIC, RESOURCE_DATA_LOCATION_DEVNULL); if (!$hardDelete) { //mark item as deleted CMS_modulePolymodValidation::markDeletedItem($this->getID()); } else { //destroy poly_object reference $sql = "delete from mod_object_polyobjects where id_moo = '" . $this->getID() . "'"; new CMS_query($sql); } } if ($this->_objectResourceStatus != 1 && $this->_objectResourceStatus != 2 || $this->_objectResourceStatus == 2 && $forceSecondaryRessourcePublication) { $modulesCodes = new CMS_modulesCodes(); //add a call to all modules for before validation specific treatment $modulesCodes->getModulesCodes(MODULE_TREATMENT_BEFORE_VALIDATION_TREATMENT, '', $this, array('result' => VALIDATION_OPTION_ACCEPT, 'lastvalidation' => true, 'module' => $polyModuleCodename, 'action' => 'delete')); } if (!$hardDelete) { //move resource datas from edited to deleted location CMS_modulePolymodValidation::moveResourceData($polyModuleCodename, $this->getID(), RESOURCE_DATA_LOCATION_EDITED, RESOURCE_DATA_LOCATION_DELETED); } else { //delete datas from edited locations CMS_modulePolymodValidation::moveResourceData($polyModuleCodename, $this->getID(), RESOURCE_DATA_LOCATION_EDITED, RESOURCE_DATA_LOCATION_DEVNULL); } if ($this->_objectResourceStatus != 1 && $this->_objectResourceStatus != 2 || $this->_objectResourceStatus == 2 && $forceSecondaryRessourcePublication) { //add a call to all modules for after validation specific treatment $modulesCodes->getModulesCodes(MODULE_TREATMENT_AFTER_VALIDATION_TREATMENT, '', $this, array('result' => VALIDATION_OPTION_ACCEPT, 'lastvalidation' => true, 'module' => $polyModuleCodename, 'action' => 'delete')); } if ($this->_objectResourceStatus == 1 && $hardDelete) { //delete associated resource parent::destroy(); } //Log action $log = new CMS_log(); $language = $cms_user->getLanguage(); $log->logMiscAction(CMS_log::LOG_ACTION_RESOURCE_DELETE, $cms_user, 'Item \'' . $this->getLabel() . '\' (' . $objectDef->getLabel($language) . ')', $polyModuleCodename); if ($hardDelete) { unset($this); } //Clear polymod cache //CMS_cache::clearTypeCacheByMetas('polymod', array('module' => $polyModuleCodename)); CMS_cache::clearTypeCache('polymod'); return true; } else { //change the article proposed location and send emails to all the validators if ($this->setProposedLocation(RESOURCE_LOCATION_DELETED, $cms_user)) { parent::writeToPersistence(); if (APPLICATION_ENFORCES_WORKFLOW) { if (!NO_APPLICATION_MAIL) { //get editors $editors = $this->getEditors(); $editorsIds = array(); foreach ($editors as $editor) { $editorsIds[] = $editor->getUserId(); } $validators = CMS_profile_usersCatalog::getValidators($polyModuleCodename); foreach ($validators as $validator) { //add script to send email for validator if needed CMS_scriptsManager::addScript($polyModuleCodename, array('task' => 'emailNotification', 'object' => $this->getID(), 'validator' => $validator->getUserId(), 'type' => 'delete', 'editors' => $editorsIds)); } //then launch scripts execution CMS_scriptsManager::startScript(); } } else { $validation = new CMS_resourceValidation($polyModuleCodename, RESOURCE_EDITION_LOCATION, $this); $mod = CMS_modulesCatalog::getByCodename($polyModuleCodename); $mod->processValidation($validation, VALIDATION_OPTION_ACCEPT); } //Log action $log = new CMS_log(); $language = $cms_user->getLanguage(); $log->logResourceAction(CMS_log::LOG_ACTION_RESOURCE_DELETE, $cms_user, $polyModuleCodename, $this->getStatus(), 'Item \'' . $this->getLabel() . '\' (' . $objectDef->getLabel($language) . ')', $this); //Clear polymod cache //CMS_cache::clearTypeCacheByMetas('polymod', array('module' => $polyModuleCodename)); CMS_cache::clearTypeCache('polymod'); return true; } else { return false; } } }