/** * Constructor. * Initializes the process manager and lauches the action if all went well, then delete the PIDFile * NOTE : SCRIPT_CODENAME is a constant that must be defined, and unique accross all usage of the background scripts * (i.e. One background script for one application should have the same, but two applications having the same script shouldn't collate) * * @param boolean $debug Set to true if you want a debug of what the script does * @return void * @access public */ function backgroundScript($debug = false, $scriptID = 'Master') { $this->_debug = $debug; $this->_processManager = new processManager(SCRIPT_CODENAME . '_' . $scriptID); // Cleans previous PIDs if (isset($_SERVER['argv']['3']) && $_SERVER['argv']['3'] == '-F') { if (!APPLICATION_IS_WINDOWS) { $tmpDir = dir($this->_processManager->getTempPath()); while (false !== ($file = $tmpDir->read())) { if (io::strpos($file, SCRIPT_CODENAME) !== false) { @unlink($this->_processManager->getTempPath() . '/' . $file); } } } else { $files = glob(realpath($this->_processManager->getTempPath()) . '/' . SCRIPT_CODENAME . '*.*', GLOB_NOSORT); if (is_array($files)) { foreach ($files as $file) { if (!CMS_file::deleteFile($file)) { $this->raiseError("Can't delete file " . $file); } } } } } //write script process PID File if ($this->_processManager->writePIDFile()) { if ($this->_debug) { $this->raiseError("PID file successfully written (" . $this->_processManager->getPIDFileName() . ")."); } //start script process $this->activate($this->_debug); //delete script process PID File if ($this->_processManager->deletePIDFile()) { if ($this->_debug) { $this->raiseError("PID file successfully deleted (" . $this->_processManager->getPIDFileName() . ")."); } } else { $this->raiseError("Can not delete PID file (" . $this->_processManager->getPIDFileName() . ")."); } exit; } else { if ($this->_debug) { $this->raiseError("PID file already exists or impossible to write (" . $this->_processManager->getPIDFileName() . ")."); } exit; } }
/** * Move the data of a resource from one data location to another. * May be used by every module, provided it respects the naming rules described in the modules HOWTO * * @param string $module, The module codename * @param integer $resourceID The DB ID of the resource whose data we want to move * @param string $locationFrom The starting location, among the available RESOURCE_DATA_LOCATION * @param string $locationTo The ending location, among the available RESOURCE_DATA_LOCATION * @param boolean $copyOnly If set to true, the deletion from the originating tables and dirs won't occur * @return boolean true on success, false on failure * @access public * @static */ function moveResourceData($module, $resourceID, $locationFrom, $locationTo, $copyOnly = false) { //get all datas locations $locations = CMS_resource::getAllDataLocations(); if (!in_array($locationFrom, $locations)) { CMS_grandFather::raiseError("LocationFrom is not a valid location : " . $locationFrom); return false; } if (!in_array($locationTo, $locations)) { CMS_grandFather::raiseError("LocationTo is not a valid location : " . $locationTo); return false; } if (!sensitiveIO::IsPositiveInteger($resourceID)) { CMS_grandFather::raiseError("ResourceID must be a positive integer : " . $resourceID); return false; } //first move DB datas $tables_prefixes = array('mod_subobject_date_', 'mod_subobject_integer_', 'mod_subobject_string_', 'mod_subobject_text_'); foreach ($tables_prefixes as $table_prefix) { //delete all in the destination table and insert new ones if ($locationTo != RESOURCE_DATA_LOCATION_DEVNULL) { $sql = "\n\t\t\t\t\tdelete from\n\t\t\t\t\t\t" . $table_prefix . $locationTo . "\n\t\t\t\t\twhere\n\t\t\t\t\t\tobjectID='" . $resourceID . "'\n\t\t\t\t"; $q = new CMS_query($sql); $sql = "\n\t\t\t\t\treplace into\n\t\t\t\t\t\t" . $table_prefix . $locationTo . "\n\t\t\t\t\t\tselect\n\t\t\t\t\t\t\t*\n\t\t\t\t\t\tfrom\n\t\t\t\t\t\t\t" . $table_prefix . $locationFrom . "\n\t\t\t\t\t\twhere\n\t\t\t\t\t\t\tobjectID='" . $resourceID . "'\n\t\t\t\t"; $q = new CMS_query($sql); } if (!$copyOnly) { //delete from the starting table $sql = "\n\t\t\t\t\tdelete from\n\t\t\t\t\t\t" . $table_prefix . $locationFrom . "\n\t\t\t\t\twhere\n\t\t\t\t\t\tobjectID='" . $resourceID . "'\n\t\t\t\t"; $q = new CMS_query($sql); } } //second, move the files $locationFromDir = new CMS_file(PATH_MODULES_FILES_FS . "/" . $module . "/" . $locationFrom, CMS_file::FILE_SYSTEM, CMS_file::TYPE_DIRECTORY); //cut here if the locationFromDir doesn't exists. That means the module doesn't have files if (!$locationFromDir->exists()) { return true; } if ($locationTo != RESOURCE_DATA_LOCATION_DEVNULL) { $locationToDir = new CMS_file(PATH_MODULES_FILES_FS . "/" . $module . "/" . $locationTo, CMS_file::FILE_SYSTEM, CMS_file::TYPE_DIRECTORY); //cut here if the locationToDir doesn't exists. if (!$locationToDir->exists()) { CMS_grandFather::raiseError("LocationToDir does not exists : " . PATH_MODULES_FILES_FS . "/" . $module . "/" . $locationTo); return false; } //delete all files of the locationToDir $files = glob(PATH_MODULES_FILES_FS . "/" . $module . "/" . $locationTo . '/r' . $resourceID . '_*', GLOB_NOSORT); if (is_array($files)) { foreach ($files as $file) { if (!CMS_file::deleteFile($file)) { $this->raiseError("Can't delete file " . $file); return false; } } } //then copy or move them to the locationToDir $files = glob(PATH_MODULES_FILES_FS . "/" . $module . "/" . $locationFrom . '/r' . $resourceID . '_*', GLOB_NOSORT); if (is_array($files)) { foreach ($files as $file) { $to = str_replace('/' . $locationFrom . '/', '/' . $locationTo . '/', $file); if ($copyOnly) { if (!CMS_file::copyTo($file, $to)) { $this->raiseError("Can't copy file " . $file . " to " . $to); return false; } } else { if (!CMS_file::moveTo($file, $to)) { $this->raiseError("Can't move file " . $file . " to " . $to); return false; } } //then chmod new file CMS_file::chmodFile(FILES_CHMOD, $to); } } } else { //then get all files of the locationFromDir $files = glob(PATH_MODULES_FILES_FS . "/" . $module . "/" . $locationFrom . '/r' . $resourceID . '_*', GLOB_NOSORT); if (is_array($files)) { foreach ($files as $file) { if (!CMS_file::deleteFile($file)) { $this->raiseError("Can't delete file " . $file); return false; } } } } return true; }
/** * activates the script function. * * @return void * @access public */ function activate() { parent::activate(); if ($_SERVER['argv']['1'] == '-s' && SensitiveIO::isPositiveInteger($_SERVER['argv']['2'])) { // SUB-SCRIPT : Processes one script task @ini_set('max_execution_time', SUB_SCRIPT_TIME_OUT); //set max execution time for sub script @set_time_limit(SUB_SCRIPT_TIME_OUT); //set the PHP timeout for sub script $sql = "\n\t\t\t\tselect\n\t\t\t\t\t*\n\t\t\t\tfrom\n\t\t\t\t\tregenerator\n\t\t\t\twhere\n\t\t\t\t\tid_reg = '" . $_SERVER['argv']['2'] . "'\n\t\t\t"; $q = new CMS_query($sql); if ($q->getNumRows()) { $data = $q->getArray(); //send script informations to process manager $this->_processManager->setParameters($data['module_reg'], $data['parameters_reg']); //instanciate script module $module = CMS_modulesCatalog::getByCodename($data['module_reg']); //then send script task to module (return task title by reference) $task = $module->scriptTask(unserialize($data['parameters_reg'])); //delete the current script task $sql_delete = "\n\t\t\t\t\tdelete\n\t\t\t\t\tfrom\n\t\t\t\t\t\tregenerator\n\t\t\t\t\twhere\n\t\t\t\t\t\tid_reg='" . $data['id_reg'] . "'"; $q = new CMS_query($sql_delete); if ($this->_debug) { $this->raiseError($this->_processManager->getPIDFilePath() . " : task " . $_SERVER['argv']['2'] . " seems " . (!$task ? 'NOT ' : '') . "done !"); $this->raiseError($this->_processManager->getPIDFilePath() . " : PID file exists ? " . @file_exists($this->_processManager->getPIDFilePath())); } $fpath = $this->_processManager->getPIDFilePath() . '.ok'; if (@touch($fpath) && @chmod($fpath, octdec(FILES_CHMOD))) { $f = @fopen($fpath, 'a'); if (!@fwrite($f, 'Script OK')) { $this->raiseError($this->_processManager->getPIDFilePath() . " : Can't write into file: " . $fpath); } @fclose($f); } else { $this->raiseError($this->_processManager->getPIDFilePath() . " : Can't create file: " . $fpath); } } } else { // MASTER SCRIPT : Processes all sub-scripts @ini_set('max_execution_time', MASTER_SCRIPT_TIME_OUT); //set max execution time for master script @set_time_limit(MASTER_SCRIPT_TIME_OUT); //set the PHP timeout for master script //max simultaneous scripts $maxScripts = $_SERVER['argv']['2']; $scriptsArray = array(); //send script informations to process manager $this->_processManager->setParameters(processManager::MASTER_SCRIPT_NAME, ''); //the sql script which selects one script task at a time $sql_select = "\n\t\t\t\tselect\n\t\t\t\t\t*\n\t\t\t\tfrom\n\t\t\t\t\tregenerator\n\t\t\t\tlimit\n\t\t\t\t\t" . $maxScripts . "\n\t\t\t"; //and now, launch all sub-scripts until table is empty. while (true) { //get scripts $q = new CMS_query($sql_select); if ($q->getNumRows()) { while (count($scriptsArray) < $maxScripts && ($data = $q->getArray())) { // Launch sub-process if (!APPLICATION_IS_WINDOWS) { // On unix system $sub_system = PATH_PACKAGES_FS . "/scripts/script.php -s " . $data["id_reg"] . " > /dev/null 2>&1 &"; if (!defined('PATH_PHP_CLI_UNIX') || !PATH_PHP_CLI_UNIX) { CMS_patch::executeCommand("cd " . PATH_REALROOT_FS . "; php " . $sub_system, $error); if ($error) { CMS_grandFather::raiseError('Error during execution of sub script command (cd ' . PATH_REALROOT_FS . '; php ' . $sub_system . '), please check your configuration : ' . $error); return false; } } else { CMS_patch::executeCommand("cd " . PATH_REALROOT_FS . "; " . PATH_PHP_CLI_UNIX . " " . $sub_system, $error); if ($error) { CMS_grandFather::raiseError('Error during execution of sub script command (cd ' . PATH_REALROOT_FS . '; ' . PATH_PHP_CLI_UNIX . ' ' . $sub_system . '), please check your configuration : ' . $error); return false; } } $PIDfile = $this->_processManager->getTempPath() . "/" . SCRIPT_CODENAME . "_" . $data["id_reg"]; if ($this->_debug) { $this->raiseError(processManager::MASTER_SCRIPT_NAME . " : Executes system(" . $sub_system . ")"); } //sleep a little @sleep(SLEEP_TIME); } else { // On windows system //Create the BAT file $command = '@echo off' . "\r\n" . '@start /B /BELOWNORMAL ' . realpath(PATH_PHP_CLI_WINDOWS) . ' ' . realpath(PATH_PACKAGES_FS . '\\scripts\\script.php') . ' -s ' . $data["id_reg"]; if (!@touch(realpath(PATH_WINDOWS_BIN_FS) . DIRECTORY_SEPARATOR . "sub_script.bat")) { $this->raiseError(processManager::MASTER_SCRIPT_NAME . " : Create file error : sub_script.bat"); } $replace = array('program files (x86)' => 'progra~2', 'program files' => 'progra~1', 'documents and settings' => 'docume~1'); $command = str_ireplace(array_keys($replace), $replace, $command); $fh = fopen(realpath(PATH_WINDOWS_BIN_FS . DIRECTORY_SEPARATOR . "sub_script.bat"), "wb"); if (is_resource($fh)) { if (!fwrite($fh, $command, io::strlen($command))) { CMS_grandFather::raiseError(processManager::MASTER_SCRIPT_NAME . " : Save file error : sub_script.bat"); } fclose($fh); } $WshShell = new COM("WScript.Shell"); $oExec = $WshShell->Run(str_ireplace(array_keys($replace), $replace, realpath(PATH_WINDOWS_BIN_FS . '\\sub_script.bat')), 0, false); $PIDfile = $this->_processManager->getTempPath() . DIRECTORY_SEPARATOR . SCRIPT_CODENAME . "_" . $data["id_reg"]; //sleep a little @sleep(SLEEP_TIME); } if ($this->_debug) { $this->raiseError(processManager::MASTER_SCRIPT_NAME . " : script : " . $data["id_reg"] . " - sub_system : " . $sub_system); } $scriptsArray[] = array("PID" => $PIDfile, "startTime" => CMS_stats::getmicrotime(), "scriptID" => $data["id_reg"], "scriptDatas" => $data); } } else { // no more scripts to process // > delete all temporary files // > end script if (APPLICATION_IS_WINDOWS) { $files = glob(realpath($this->_processManager->getTempPath()) . DIRECTORY_SEPARATOR . SCRIPT_CODENAME . '*.ok', GLOB_NOSORT); if (is_array($files)) { foreach ($files as $file) { if (!CMS_file::deleteFile($file)) { $this->raiseError("Can't delete file " . $file); return false; } } } } else { $tmpDir = dir($this->_processManager->getTempPath()); while (false !== ($file = $tmpDir->read())) { if (io::strpos($file, SCRIPT_CODENAME) !== false) { @unlink($this->_processManager->getTempPath() . '/' . $file); } } } break; } while (true) { @sleep(SLEEP_TIME); //wait a little to check sub_scripts $break = false; $timeStop = CMS_stats::getmicrotime(); if ($this->_debug) { $this->raiseError(processManager::MASTER_SCRIPT_NAME . " Scripts in progress : " . sizeof($scriptsArray)); } foreach ($scriptsArray as $nb => $aScript) { if ($this->_debug) { $this->raiseError(processManager::MASTER_SCRIPT_NAME . " PID : " . $aScript["PID"] . " - time : " . ($timeStop - $aScript["startTime"])); } $ok = ''; $ok = is_file($aScript["PID"] . '.ok'); if ($ok) { //$break = true; if ($this->_debug) { $this->raiseError(processManager::MASTER_SCRIPT_NAME . " Script : " . $aScript["PID"] . " OK !"); } unset($scriptsArray[$nb]); } elseif ($timeStop - $aScript["startTime"] >= SUB_SCRIPT_TIME_OUT) { if ($this->_debug) { $this->raiseError(processManager::MASTER_SCRIPT_NAME . " : Script : " . $aScript["PID"] . " NOT OK !"); } $this->raiseError(processManager::MASTER_SCRIPT_NAME . ' : Error on task : ' . $aScript["scriptID"] . ' ... skip it. Task parameters : ' . print_r($aScript['scriptDatas'], true)); //$break = true; unset($scriptsArray[$nb]); //delete the script in error from task list $q_del = "\n\t\t\t\t\t\t\t\tdelete\n\t\t\t\t\t\t\t\tfrom\n\t\t\t\t\t\t\t\t\tregenerator\n\t\t\t\t\t\t\t\twhere\n\t\t\t\t\t\t\t\t\tid_reg='" . $aScript["scriptID"] . "'"; $q_del = new CMS_query($q_del); } } if (!$scriptsArray) { break; } } } } }
/** * 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; }
/** * Remove a file located in the edited, public, archived and edition directory of the module * * @param string $filename name of the file to remove */ private function removeFilesFromModuleDirectory($filename) { $moduleDirectories = array(RESOURCE_DATA_LOCATION_EDITED, RESOURCE_DATA_LOCATION_PUBLIC, RESOURCE_DATA_LOCATION_ARCHIVED, RESOURCE_DATA_LOCATION_EDITION); foreach ($moduleDirectories as $directory) { if (file_exists(PATH_MODULES_FILES_FS . '/' . $this->_codename . '/' . $directory . '/' . $filename)) { CMS_file::deleteFile(PATH_MODULES_FILES_FS . '/' . $this->_codename . '/' . $directory . '/' . $filename); } } }
/** * Move the data of a resource from one data location to another. * May be used by every module, provided it respects the naming rules described in the modules HOWTO * * @param CMS_module $module The module who want its data moved * @param string $tablesPrefix The prefix of the tables containing the data * @param string $resourceIDFieldName The name of the field containing the resource ID * @param integer $resourceID The DB ID of the resource whose data we want to move * @param string $locationFrom The starting location, among the available RESOURCE_DATA_LOCATION * @param string $locationTo The ending location, among the available RESOURCE_DATA_LOCATION * @param boolean $copyOnly If set to true, the deletion from the originating tables and dirs won't occur * @return boolean true on success, false on failure * @access public */ static function moveResourceData(&$module, $tablesPrefix, $resourceIDFieldName, $resourceID, $locationFrom, $locationTo, $copyOnly = false) { if (!is_a($module, "CMS_module")) { CMS_grandFather::raiseError("Module is not a CMS_module"); return false; } if (!SensitiveIO::isInSet($locationFrom, CMS_resource::getAllDataLocations()) || !SensitiveIO::isInSet($locationTo, CMS_resource::getAllDataLocations())) { CMS_grandFather::raiseError("Locations are not in the set"); return false; } //get the tables : named PREFIXXXXX_public $sql = "show tables"; $q = new CMS_query($sql); $tables_prefixes = array(); while ($data = $q->getArray()) { if (preg_match("#" . $tablesPrefix . "(.*)_public#", $data[0])) { $tables_prefixes[] = io::substr($data[0], 0, strrpos($data[0], "_") + 1); } } foreach ($tables_prefixes as $table_prefix) { //delete all in the destination table just incase and insert if ($locationTo != RESOURCE_DATA_LOCATION_DEVNULL) { $sql = "\n\t\t\t\t\tdelete from\n\t\t\t\t\t\t" . $table_prefix . $locationTo . "\n\t\t\t\t\twhere\n\t\t\t\t\t\t" . $resourceIDFieldName . "='" . $resourceID . "'\n\t\t\t\t"; $q = new CMS_query($sql); $sql = "\n\t\t\t\t\tinsert into\n\t\t\t\t\t\t" . $table_prefix . $locationTo . "\n\t\t\t\t\t\tselect\n\t\t\t\t\t\t\t*\n\t\t\t\t\t\tfrom\n\t\t\t\t\t\t\t" . $table_prefix . $locationFrom . "\n\t\t\t\t\t\twhere\n\t\t\t\t\t\t\t" . $resourceIDFieldName . "='" . $resourceID . "'\n\t\t\t\t"; $q = new CMS_query($sql); } if (!$copyOnly) { //delete from the starting table $sql = "\n\t\t\t\t\tdelete from\n\t\t\t\t\t\t" . $table_prefix . $locationFrom . "\n\t\t\t\t\twhere\n\t\t\t\t\t\t" . $resourceIDFieldName . "='" . $resourceID . "'\n\t\t\t\t"; $q = new CMS_query($sql); } } //second, move the files $locationFromDir = new CMS_file(PATH_MODULES_FILES_FS . "/" . $module->getCodename() . "/" . $locationFrom, CMS_file::FILE_SYSTEM, CMS_file::TYPE_DIRECTORY); //cut here if the locationFromDir doesn't exists. That means the module doesn't have files if (!$locationFromDir->exists()) { return true; } if ($locationTo != RESOURCE_DATA_LOCATION_DEVNULL) { $locationToDir = new CMS_file(PATH_MODULES_FILES_FS . "/" . $module->getCodename() . "/" . $locationTo, CMS_file::FILE_SYSTEM, CMS_file::TYPE_DIRECTORY); //cut here if the locationToDir doesn't exists. if (!$locationToDir->exists()) { CMS_grandFather::raiseError("LocationToDir does not exists : " . PATH_MODULES_FILES_FS . "/" . $module->getCodename() . "/" . $locationTo); return false; } //delete all files of the locationToDir $files = glob(PATH_MODULES_FILES_FS . "/" . $module->getCodename() . "/" . $locationTo . '/r' . $resourceID . '_*', GLOB_NOSORT); if (is_array($files)) { foreach ($files as $file) { if (!CMS_file::deleteFile($file)) { CMS_grandFather::raiseError("Can't delete file " . $file); return false; } } } //then copy or move them to the locationToDir $files = glob(PATH_MODULES_FILES_FS . "/" . $module->getCodename() . "/" . $locationFrom . '/r' . $resourceID . '_*', GLOB_NOSORT); if (is_array($files)) { foreach ($files as $file) { $to = str_replace('/' . $locationFrom . '/', '/' . $locationTo . '/', $file); if ($copyOnly) { if (!CMS_file::copyTo($file, $to)) { CMS_grandFather::raiseError("Can't copy file " . $file . " to " . $to); return false; } } else { if (!CMS_file::moveTo($file, $to)) { CMS_grandFather::raiseError("Can't move file " . $file . " to " . $to); return false; } } //then chmod new file CMS_file::chmodFile(FILES_CHMOD, $to); } } } //cleans the initial dir if not a copy if (!$copyOnly) { //then get all files of the locationFromDir $files = glob(PATH_MODULES_FILES_FS . "/" . $module->getCodename() . "/" . $locationFrom . '/r' . $resourceID . '_*', GLOB_NOSORT); if (is_array($files)) { foreach ($files as $file) { if (!CMS_file::deleteFile($file)) { CMS_grandFather::raiseError("Can't delete file " . $file); return false; } } } } 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(); }
/** * Check presence of a file and delete it * * @param string $key, which path ? * @return boolean true if deletion succeeded, false otherwise * @access private */ protected function _deletePathFile($key) { if (!$this->_isValidPathKey($key)) { return false; } elseif (@is_file($this->_pathes[$key])) { if (!CMS_file::deleteFile($this->_pathes[$key])) { $this->raiseError("File exists (" . $this->_pathes[$key] . ") but cannot be deleted"); return false; } else { $this->_pathes[$key] = false; return true; } } else { $this->raiseError("File does not exists (" . $this->_pathes[$key] . ")"); return false; } }