/** * 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; }
/** * Destroy this object, in DB and filesystem if needed * Destroy title label also * * @return boolean true on success, false on failure * @access public */ function destroy() { if ($this->_fieldID) { //delete all files of objects for this field $module = CMS_poly_object_catalog::getModuleCodenameForField($this->_fieldID); $filesDir = new CMS_file(PATH_MODULES_FILES_FS . '/' . $module, CMS_file::FILE_SYSTEM, CMS_file::TYPE_DIRECTORY); if ($filesDir->exists()) { //search all files of this field $filesList = $filesDir->getFileList(PATH_MODULES_FILES_FS . '/' . $module . '/*_f' . $this->_fieldID . '_*'); //then delete them foreach ($filesList as $aFile) { if (!CMS_file::deleteFile($aFile['name'])) { $this->raiseError("Can't delete file " . $aFile['name'] . " for field : " . $this->_fieldID); return false; } } } //delete all datas of objects for this field $tables = array('mod_subobject_date_deleted', 'mod_subobject_date_edited', 'mod_subobject_date_public', 'mod_subobject_integer_deleted', 'mod_subobject_integer_edited', 'mod_subobject_integer_public', 'mod_subobject_string_deleted', 'mod_subobject_string_edited', 'mod_subobject_string_public', 'mod_subobject_text_deleted', 'mod_subobject_text_edited', 'mod_subobject_text_public'); foreach ($tables as $aTable) { $sql = "\n\t\t\t\t\tdelete from\n\t\t\t\t\t\t" . $aTable . "\n\t\t\t\t\twhere\n\t\t\t\t\t\tobjectFieldID = '" . $this->_fieldID . "'\n\t\t\t\t"; $q = new CMS_query($sql); if ($q->hasError()) { $this->raiseError("Can't delete datas of table " . $aTable . " for field : " . $this->_fieldID); return false; } } //delete title label object if (sensitiveIO::IsPositiveInteger($this->_objectFieldValues["labelID"])) { $label = new CMS_object_i18nm($this->_objectFieldValues["labelID"]); $label->destroy(); } //delete field DB record $sql = "\n\t\t\t\tdelete from\n\t\t\t\t\tmod_object_field \n\t\t\t\twhere\n\t\t\t\t\tid_mof='" . $this->_fieldID . "'\n\t\t\t"; $q = new CMS_query($sql); if ($q->hasError()) { $this->raiseError("Can't delete datas of table mod_object_field for field : " . $this->_fieldID); return false; } //unset fields catalog in cache CMS_cache::clearTypeCache('atm-polymod-structure'); //Clear polymod cache //CMS_cache::clearTypeCacheByMetas('polymod', array('module' => CMS_poly_object_catalog::getModuleCodenameForField($this->_fieldID))); CMS_cache::clearTypeCache('polymod'); } //unset fields catalog in cache CMS_cache::clearTypeCacheByMetas('atm-polymod-structure', array('type' => 'fields')); //finally destroy object instance unset($this); return true; }
if (is_array($files)) { $content .= "Start update of Automne messages ...<br />"; foreach ($files as $file) { if (file_exists($file) && CMS_patch::executeSqlScript($file, true)) { CMS_patch::executeSqlScript($file); } else { $content .= 'Error during database update ! Script ' . $file . ' must be executed manualy<br/>'; } } $content .= "Automne messages updated.<br /><br />"; } //clear caches $content .= "Clean Automne cache.<br /><br />"; CMS_cache::clearTypeCache('polymod'); CMS_cache::clearTypeCache('atm-polymod-structure'); CMS_cache::clearTypeCache('text/javascript'); CMS_cache::clearTypeCache('text/css'); CMS_cache::clearTypeCache('atm-backtrace'); //compile polymod definitions CMS_polymod::compileDefinitions(); $content .= "Objects definitions recompilations is done.<br />"; //regenerate pages $content .= "<br />Launch pages regeneration."; CMS_tree::regenerateAllPages(true); $content .= '</pre>'; if (!$included) { $view->setContent($content); $view->show(); } else { echo $content; }
/** * Moves position of a category in list, with given offset * * @access public * @param CMS_moduleCategory $siblingCategory * @param integer $moveOffset values 1 or -1 expected * @return boolean true on succes, false on failure */ static function moveCategoryOrder(&$siblingCategory, $moveOffset) { // Checks : pages must be CMS_moduleCategory and offset in (1, -1) if (!$siblingCategory instanceof CMS_moduleCategory) { CMS_grandFather::raiseError("Category to move not valid."); return false; } if (!SensitiveIO::isInSet($moveOffset, array(1, -1))) { CMS_grandFather::raiseError("Offset must be 1 or -1"); return false; } // Find the siblings to switch order $parent = $siblingCategory->getParent(); // Use this function to compact of siblings order if (!$parent instanceof CMS_moduleCategory || !CMS_moduleCategories_catalog::compactSiblingsOrder($parent->getID())) { CMS_grandFather::raiseError("Reordering siblings failed for category " . $parent->getID()); return false; } $siblings = $parent->getSiblings(); $sibling_to_move_left = false; $sibling_to_move_right = false; $lastSibling = false; foreach ($siblings as $aSibling) { if ($moveOffset == 1 && $lastSibling && $lastSibling->getID() == $siblingCategory->getID()) { $sibling_to_move_left = $aSibling; $sibling_to_move_right = $siblingCategory; break; } if ($moveOffset == -1 && $lastSibling && $aSibling->getID() == $siblingCategory->getID()) { $sibling_to_move_left = $siblingCategory; $sibling_to_move_right = $lastSibling; break; } $lastSibling = $aSibling; } if ($sibling_to_move_left && $sibling_to_move_right) { //move the siblings order $sql = "\n\t\t\t\tupdate\n\t\t\t\t\tmodulesCategories\n\t\t\t\tset\n\t\t\t\t\torder_mca=order_mca - 1\n\t\t\t\twhere\n\t\t\t\t\tid_mca='" . $sibling_to_move_left->getID() . "'\n\t\t\t"; $q = new CMS_query($sql); $sql = "\n\t\t\t\tupdate\n\t\t\t\t\tmodulesCategories\n\t\t\t\tset\n\t\t\t\t\torder_mca=order_mca + 1\n\t\t\t\twhere\n\t\t\t\t\tid_mca='" . $sibling_to_move_right->getID() . "'\n\t\t\t"; $q = new CMS_query($sql); //Clear polymod cache //CMS_cache::clearTypeCacheByMetas('polymod', array('module' => $sibling_to_move_right->getAttribute('moduleCodename'))); CMS_cache::clearTypeCache('polymod'); return true; } else { CMS_grandFather::raiseError("Move impossible (first or last sibling to move, or parent and sibling not related"); return false; } }
/** * 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; } } }
/** * Completely destroy a list of objects and associated resources if any. After this, objects will no longer exists at all. * /!\ if objects are primary resources, no validation will be queried to validators, objects will be directly destroyed from all locations. /!\ * * @param integer $objectID the object type ID to destroy * @param array $itemIDs array of object ids to completely destroy * @access public * @static */ static function hardDeleteObjects($objectID, $itemIDs) { if (!sensitiveIO::isPositiveInteger($objectID)) { CMS_grandFather::raiseError("objectID is not a positive integer : " . $objectID); return false; } if (!is_array($itemIDs)) { CMS_grandFather::raiseError("itemIDs is not an array : " . print_r($itemIDs, true)); return false; } //get object definition $objectDef = CMS_poly_object_catalog::getObjectDefinition($objectID); //if object is a primary resource, destroy all resources associated to objects if ($objectDef->isPrimaryResource()) { //get resources Ids $sql = "select \n\t\t\t\t\t\tvalue \n\t\t\t\t\tfrom \n\t\t\t\t\t\tmod_subobject_integer_edited \n\t\t\t\t\twhere \n\t\t\t\t\t\tobjectID in (" . implode(',', $itemIDs) . ")\n\t\t\t\t\t\tand objectFieldID = 0"; $q = new CMS_query($sql); $resourceIDs = array(); if ($q->getNumRows()) { while ($r = $q->getArray()) { $resourceIDs[] = $r['value']; } } //get resources statuses Ids $sql = "select \n\t\t\t\t\t\tstatus_res \n\t\t\t\t\tfrom \n\t\t\t\t\t\tresources \n\t\t\t\t\twhere \n\t\t\t\t\t\tid_res in (" . implode(',', $resourceIDs) . ")"; $q = new CMS_query($sql); $resourceStatusesIDs = array(); if ($q->getNumRows()) { while ($r = $q->getArray()) { $resourceStatusesIDs[] = $r['status_res']; } } //then delete both of them $sql = "delete\n\t\t\t\t\tfrom \n\t\t\t\t\t\tresources \n\t\t\t\t\twhere \n\t\t\t\t\t\tid_res in (" . implode(',', $resourceIDs) . ")"; $q = new CMS_query($sql); $sql = "delete\n\t\t\t\t\tfrom \n\t\t\t\t\t\tresourceStatuses \n\t\t\t\t\twhere \n\t\t\t\t\t\tid_rs in (" . implode(',', $resourceStatusesIDs) . ")"; $q = new CMS_query($sql); } //delete objects datas from poly_object table $sql = "delete\n\t\t\t\tfrom \n\t\t\t\t\tmod_object_polyobjects \n\t\t\t\twhere \n\t\t\t\t\tid_moo in (" . implode(',', $itemIDs) . ")"; $q = new CMS_query($sql); //delete from data tables $dataTables = array('mod_subobject_date_deleted', 'mod_subobject_date_edited', 'mod_subobject_date_public', 'mod_subobject_integer_deleted', 'mod_subobject_integer_edited', 'mod_subobject_integer_public', 'mod_subobject_string_deleted', 'mod_subobject_string_edited', 'mod_subobject_string_public', 'mod_subobject_text_deleted', 'mod_subobject_text_edited', 'mod_subobject_text_public'); foreach ($dataTables as $datasTable) { $sql = "delete\n\t\t\t\t\tfrom \n\t\t\t\t\t\t" . $datasTable . "\n\t\t\t\t\twhere \n\t\t\t\t\t\tobjectID in (" . implode(',', $itemIDs) . ")"; $q = new CMS_query($sql); } //delete associated objects module files if any foreach ($itemIDs as $itemID) { $files = glob(PATH_MODULES_FILES_FS . '/' . $objectDef->getValue('module') . '/*/r' . $itemID . '_*'); if (is_array($files) && $files) { foreach ($files as $file) { if (is_file($file)) { @unlink($file); } } } } //Clear polymod cache //CMS_cache::clearTypeCacheByMetas('polymod', array('module' => $objectDef->getValue('module'))); CMS_cache::clearTypeCache('polymod'); return true; }
/** * Destroy the module * * @return void * @access public */ function destroy() { global $cms_user; // Check module exists and is polymod if (!$this->isDestroyable()) { return false; } // CHECK USED ROWS $rowsIds = CMS_rowsCatalog::getByModules(array($this->_codename), false, false); //delete all module rows foreach ($rowsIds as $rowId) { $row = CMS_rowsCatalog::getByID($rowId); if (is_object($row)) { $row->destroy(); } } // TREAT CATEGORIES $attrs = array("module" => $this->_codename, "language" => CMS_languagesCatalog::getDefaultLanguage(), "level" => -1, "root" => -1, "cms_user" => $cms_user, "clearanceLevel" => CLEARANCE_MODULE_EDIT, "strict" => false); $cats = CMS_moduleCategories_catalog::getAll($attrs); if ($cats) { foreach ($cats as $cat) { // Destroy category $cat->destroy(); } } // TREAT MODULE & VALIDATIONS RIGHTS $sql = "\n\t\t\tselect \n\t\t\t\t*\n\t\t\tfrom\n\t\t\t\tprofiles\n\t\t\twhere\n\t\t\t\tmoduleClearancesStack_pr like '" . io::sanitizeSQLString($this->_codename) . ",%'\n\t\t\t\t or moduleClearancesStack_pr like '%;" . io::sanitizeSQLString($this->_codename) . ",%'\n\t\t "; $q = new CMS_query($sql); if ($q->getNumRows()) { while ($r = $q->getArray()) { $stack = new CMS_stack(); $stack->setTextDefinition($r['moduleClearancesStack_pr']); $stack->delAllWithOneKey($this->_codename); $qInsert = new CMS_query("update profiles set moduleClearancesStack_pr='" . io::sanitizeSQLString($stack->getTextDefinition()) . "' where id_pr='" . $r['id_pr'] . "'"); } } $sql = "\n\t\t\tselect \n\t\t\t\t*\n\t\t\tfrom\n\t\t\t\tprofiles\n\t\t\twhere\n\t\t\t\tvalidationClearancesStack_pr like '" . io::sanitizeSQLString($this->_codename) . ";%'\n\t\t\t\t or validationClearancesStack_pr like '%;" . io::sanitizeSQLString($this->_codename) . ";%'\n\t\t\t\t or validationClearancesStack_pr = '" . io::sanitizeSQLString($this->_codename) . "'\n\t\t\t"; $q = new CMS_query($sql); if ($q->getNumRows()) { while ($r = $q->getArray()) { $stack = new CMS_stack(); $stack->setTextDefinition($r['validationClearancesStack_pr']); $stack->delAllWithOneKey($this->_codename); $qInsert = new CMS_query("update profiles set validationClearancesStack_pr='" . io::sanitizeSQLString($stack->getTextDefinition()) . "' where id_pr='" . $r['id_pr'] . "'"); } } //remove module files if (CMS_file::deltreeSimulation(PATH_MODULES_FILES_FS . '/' . $this->_codename, true)) { CMS_file::deltree(PATH_MODULES_FILES_FS . '/' . $this->_codename, true); } //remove JS and CSS if (is_dir(PATH_JS_FS . '/modules/' . $this->_codename) && CMS_file::deltreeSimulation(PATH_JS_FS . '/modules/' . $this->_codename, true)) { CMS_file::deltree(PATH_JS_FS . '/modules/' . $this->_codename, true); } if (is_dir(PATH_CSS_FS . '/modules/' . $this->_codename) && CMS_file::deltreeSimulation(PATH_CSS_FS . '/modules/' . $this->_codename, true)) { CMS_file::deltree(PATH_CSS_FS . '/modules/' . $this->_codename, true); } $cssFiles = $this->getCSSFiles('', true); foreach ($cssFiles as $mediaCssFiles) { foreach ($mediaCssFiles as $cssFile) { CMS_file::deleteFile(PATH_REALROOT_FS . '/' . $cssFile); } } //Clear polymod cache //CMS_cache::clearTypeCacheByMetas('polymod', array('module' => $this->_codename)); CMS_cache::clearTypeCache('polymod'); // Destroy module return parent::destroy(); }
/** * Deletes a category from persistence * Must be called from static method * @see CMS_moduleCategories_catalog * * @access public * @return boolean */ function destroy() { if ($this->_categoryID > 0) { $err = 0; $sql = "\n\t\t\t\tdelete\n\t\t\t\tfrom\n\t\t\t\t\tmodulesCategories\n\t\t\t\twhere\n\t\t\t\t\tid_mca='" . $this->_categoryID . "'\n\t\t\t"; $q = new CMS_query($sql); if ($q->hasError()) { $err++; $this->raiseError("Error deleting category."); } $sql = "\n\t\t\t\tdelete\n\t\t\t\tfrom\n\t\t\t\t\tmodulesCategories_i18nm\n\t\t\t\twhere\n\t\t\t\t\tcategory_mcl='" . $this->_categoryID . "'\n\t\t\t"; $q = new CMS_query($sql); if ($q->hasError()) { $err++; $this->raiseError("Error deleting category labels."); } $sql = "\n\t\t\t\tdelete\n\t\t\t\tfrom\n\t\t\t\t\tmodulesCategories_clearances\n\t\t\t\twhere\n\t\t\t\t\tcategory_mcc='" . $this->_categoryID . "'\n\t\t\t"; $q = new CMS_query($sql); if ($q->hasError()) { $err++; $this->raiseError("Error deleting category clearances."); } //Clear polymod cache //CMS_cache::clearTypeCacheByMetas('polymod', array('module' => $this->_moduleCodename)); CMS_cache::clearTypeCache('polymod'); unset($this); return $err <= 0; } return false; }
/** * Writes the group data into persistence (MySQL for now). * * @return boolean true on success, false on failure * @access public */ function writeToPersistence() { parent::writeToPersistence(); $sql_fields = "\n\t\t\tlabel_prg='" . SensitiveIO::sanitizeSQLString($this->_label) . "',\n\t\t\tdescription_prg='" . SensitiveIO::sanitizeSQLString($this->_description) . "',\n\t\t\tprofile_prg='" . SensitiveIO::sanitizeSQLString(parent::getId()) . "'\n\t\t"; if ($this->_groupId) { $sql = "\n\t\t\t\tupdate\n\t\t\t\t\tprofilesUsersGroups\n\t\t\t\tset\n\t\t\t\t\t" . $sql_fields . "\n\t\t\t\twhere\n\t\t\t\t\tid_prg='" . $this->_groupId . "'\n\t\t\t"; } else { $sql = "\n\t\t\t\tinsert into\n\t\t\t\t\tprofilesUsersGroups\n\t\t\t\tset\n\t\t\t\t\t" . $sql_fields; } $q = new CMS_query($sql); if ($q->hasError()) { return false; } elseif (!$this->_groupId) { $this->_groupId = $q->getLastInsertedID(); } /* Delete all records and re-insert the good ones */ $sql = "\n\t\t\tdelete from\n\t\t\t\tprofileUsersByGroup\n\t\t\twhere\n\t\t\t\tgroupId_gu='" . $this->_groupId . "'\n\t\t"; $q = new CMS_query($sql); if (is_array($this->_users) && $this->_users) { $sql = ''; foreach ($this->_users as $user) { $sql .= $sql ? ', ' : ''; $sql .= "('" . $this->_groupId . "' ,'" . $user . "') "; } $sql = "\n\t\t\t\tinsert into\n\t\t\t\t\tprofileUsersByGroup (groupId_gu, userId_gu)\n\t\t\t\tvalues \n\t\t\t\t\t" . $sql; $q = new CMS_query($sql); } //Clear polymod cache //CMS_cache::clearTypeCacheByMetas('polymod', array('resource' => 'users')); CMS_cache::clearTypeCache('polymod'); return true; }
/** * Destroy this object in DB * * @return boolean true on success, false on failure * @access public */ function destroy() { if ($this->_ID) { //first delete old polyobject references $sql = "\n\t\t\t\tdelete from\n\t\t\t\t\tmod_object_polyobjects\n\t\t\t\twhere\n\t\t\t\t\tobject_type_id_moo = '" . $this->_ID . "'\n\t\t\t"; $q = new CMS_query($sql); if ($q->hasError()) { $this->raiseError("Can't delete datas of table mod_object_polyobjects for object : " . $this->_ID); return false; } //second delete object label and description if (sensitiveIO::IsPositiveInteger($this->getValue("labelID"))) { $label = new CMS_object_i18nm($this->getValue("labelID")); $label->destroy(); } if (sensitiveIO::IsPositiveInteger($this->getValue("descriptionID"))) { $description = new CMS_object_i18nm($this->getValue("labelID")); $description->destroy(); } //third, delete object definition datas $sql = "\n\t\t\t\tdelete from\n\t\t\t\t\tmod_object_definition\n\t\t\t\twhere\n\t\t\t\t\tid_mod = '" . $this->_ID . "'\n\t\t\t"; $q = new CMS_query($sql); if ($q->hasError()) { $this->raiseError("Can't delete datas of table mod_object_definition for object : " . $this->_ID); return false; } //unset objects catalog in cache CMS_cache::clearTypeCacheByMetas('atm-polymod-structure', array('type' => 'object')); //Clear polymod cache //CMS_cache::clearTypeCacheByMetas('polymod', array('module' => $this->_objectValues["module"])); CMS_cache::clearTypeCache('polymod'); } unset($this); return true; }
} else { if (@file_put_contents(PATH_MAIN_FS . "/SUBVERSION", time()) !== false) { CMS_file::chmodFile(FILES_CHMOD, PATH_MAIN_FS . "/SUBVERSION"); $cms_message = $cms_language->getMessage(MESSAGE_OPERATION_DONE); } else { $cms_message = $cms_language->getMessage(MESSAGE_CREATION_ERROR); } } //remove JS and CSS cache if (!CMS_cache::clearTypeCache('text/javascript') || !CMS_cache::clearTypeCache('text/css')) { $cms_message = $cms_language->getMessage(MESSAGE_CREATION_ERROR); } break; case 'polymod-cache-reset': //remove polymod cache if (CMS_cache::clearTypeCache('polymod') && CMS_cache::clearTypeCache('atm-polymod-structure')) { $cms_message = $cms_language->getMessage(MESSAGE_OPERATION_DONE); } else { $cms_message = $cms_language->getMessage(MESSAGE_CREATION_ERROR); } break; case 'cache-reset': //remove polymod cache if (CMS_file::deltree(PATH_CACHE_FS, false)) { $cms_message = $cms_language->getMessage(MESSAGE_OPERATION_DONE); } else { $cms_message = $cms_language->getMessage(MESSAGE_CREATION_ERROR); } break; case 'update-db': ob_start();
/** * Writes the user Data into persistence (MySQL for now). * * @return boolean true on success, false on failure * @access public */ function writeToPersistence() { $this->writeProfileToPersistence(); $this->_contactData->writeToPersistence(); //if deleted, must set the login to nothing, so this login could be reused in the future if ($this->_deleted) { $this->_login = ''; } $sql_fields = "\n\t\t\tactive_pru='" . $this->_active . "',\n\t\t\tdeleted_pru='" . $this->_deleted . "',\n\t\t\tlogin_pru='" . SensitiveIO::sanitizeSQLString($this->_login) . "',\n\t\t\tpassword_pru='" . SensitiveIO::sanitizeSQLString($this->_password) . "',\n\t\t\tfirstName_pru='" . SensitiveIO::sanitizeSQLString($this->_firstName) . "',\n\t\t\tlastName_pru='" . SensitiveIO::sanitizeSQLString($this->_lastName) . "',\n\t\t\tcontactData_pru='" . SensitiveIO::sanitizeSQLString($this->_contactData->getId()) . "',\n\t\t\tlanguage_pru='" . SensitiveIO::sanitizeSQLString($this->_language->getCode()) . "',\n\t\t\tprofile_pru='" . SensitiveIO::sanitizeSQLString(parent::getId()) . "',\n\t\t\talerts_pru='" . SensitiveIO::sanitizeSQLString($this->_alerts->getTextDefinition()) . "',\n\t\t\tfavorites_pru='" . SensitiveIO::sanitizeSQLString(implode(',', $this->_favorites)) . "'\n\t\t"; if ($this->_userId) { $sql = "\n\t\t\t\tupdate\n\t\t\t\t\tprofilesUsers\n\t\t\t\tset\n\t\t\t\t\t" . $sql_fields . "\n\t\t\t\twhere\n\t\t\t\t\tid_pru='" . $this->_userId . "'\n\t\t\t"; } else { $sql = "\n\t\t\t\tinsert into\n\t\t\t\t\tprofilesUsers\n\t\t\t\tset\n\t\t\t\t\t" . $sql_fields; } $q = new CMS_query($sql); if ($q->hasError()) { return false; } elseif (!$this->_userId) { $this->_userId = $q->getLastInsertedID(); } // Update validation catalog if ($this->_validationChange || $this->_deleted) { $sql = "\n\t\t\t\tdelete\n\t\t\t\tfrom\n\t\t\t\t\tprofilesUsers_validators\n\t\t\t\twhere\n\t\t\t\t\tuserId_puv='" . $this->_userId . "'\n\t\t\t\t"; $q = new CMS_query($sql); if ($this->_active) { //loop through validationClearances $validationClearances = parent::getValidationClearances(); $elements = $validationClearances->getElements(); $sql = ''; foreach ($elements as $value) { $sql .= $sql ? ', ' : ''; $sql .= "('" . $this->_userId . "' ,'" . $value[0] . "') "; } if ($sql) { $sql = "\n\t\t\t\t\t\t\tinsert into\n\t\t\t\t\t\t\t\tprofilesUsers_validators (userId_puv, module_puv)\n\t\t\t\t\t\t\tvalues\n\t\t\t\t\t\t\t\t" . $sql; $q = new CMS_query($sql); } } $this->_validationChange = false; } //if deleted, must remove user from group list if ($this->_deleted) { $sql = "\n\t\t\t\tdelete\n\t\t\t\tfrom\n\t\t\t\t\tprofileUsersByGroup\n\t\t\t\twhere\n\t\t\t\t\tuserId_gu='" . $this->_userId . "'\n\t\t\t"; $q = new CMS_query($sql); } //Clear polymod cache //CMS_cache::clearTypeCacheByMetas('polymod', array('resource' => 'users')); CMS_cache::clearTypeCache('polymod'); return true; }
/** * Destroy this object in DB * * @return boolean true on success, false on failure * @access public */ function destroy() { if ($this->_ID) { //first delete definition $sql = "\n\t\t\t\tdelete from\n\t\t\t\t\tmod_object_plugin_definition\n\t\t\t\twhere\n\t\t\t\t\tid_mowd = '" . $this->_ID . "'\n\t\t\t"; $q = new CMS_query($sql); if ($q->hasError()) { $this->raiseError("Can't delete datas of table mod_object_polyobjects for object : " . $this->_ID); return false; } //second delete object label and description if (sensitiveIO::IsPositiveInteger($this->getValue("labelID"))) { $label = new CMS_object_i18nm($this->getValue("labelID")); $label->destroy(); } if (sensitiveIO::IsPositiveInteger($this->getValue("descriptionID"))) { $description = new CMS_object_i18nm($this->getValue("labelID")); $description->destroy(); } //Clear polymod cache //CMS_cache::clearTypeCacheByMetas('polymod', array('module' => CMS_poly_object_catalog::getModuleCodenameForObjectType($this->getValue('objectID')))); CMS_cache::clearTypeCache('polymod'); //unset polymod structure in cache CMS_cache::clearTypeCache('atm-polymod-structure'); } unset($this); return true; }
/** * 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; }