public function uninstall() { $moduleModel = new RM_Modules(); $module = $moduleModel->find($this->name)->current(); if ($module !== null) { $dependenciesModel = new RM_Dependencies(); $dependencies = $dependenciesModel->getDependencies($module); foreach ($dependencies as $dependency) { $dependency->delete(); } } }
/** * Full installation process of module * * @param string $tempFileName * @param string $tempFilePath * @param stdclass $json * @return stdclass */ function install($tempFileName, $tempFilePath, $json) { // get config values $rmConfig = new RM_Config(); $chmodOctal = intval($rmConfig->getValue('rm_config_chmod_value'), 8); $chunks = explode('.', $tempFileName); $moduleName = $chunks[0]; //Module name will be always the first chunk, example: price.0.1.1.zip $moduleModel = new RM_Modules(); $existingModule = $moduleModel->fetchByName($moduleName); if ($existingModule !== null) { unlink($tempFilePath); throw new RM_Exception($this->_translate->_('Admin.Modules.InstallMsg', 'ModuleAlreadyInstalled')); } $moduleFolderPath = self::getModuleFolderpath($moduleName); if (is_dir($moduleFolderPath)) { $result = RM_Filesystem::deleteFolder($moduleFolderPath); if ($result == false) { unlink($tempFilePath); throw new RM_Exception($this->_translate->_('Admin.Modules.InstallMsg', 'ModuleFolderAlreadyExists') . ': ' . $moduleFolderPath); } } $result = mkdir($moduleFolderPath, $chmodOctal); if ($result == false) { unlink($tempFilePath); throw new RM_Exception($this->_translate->_('Admin.Modules.InstallMsg', 'CreateModuleFolderFailer')); } else { $json = $this->_addMessageToJson($json, $this->_translate->_('Admin.Modules.InstallMsg', 'ModuleFolderCreatedSuccessfully')); } //4. unzip module into new directory if (!extension_loaded('zlib')) { unlink($tempFilePath); RM_Filesystem::deleteFolder($moduleFolderPath); throw new RM_Exception($this->_translate->_('Admin.Modules.InstallMsg', 'ZlibNotSupported')); } $zip = new PclZip($tempFilePath); $result = $zip->extract(PCLZIP_OPT_PATH, $moduleFolderPath); if (!$result) { unlink($tempFilePath); RM_Filesystem::deleteFolder($moduleFolderPath); throw new RM_Exception($this->_translate->_('Admin.Modules.InstallMsg', 'UnzipFailed')); } else { $json = $this->_addMessageToJson($json, $this->_translate->_('Admin.Modules.InstallMsg', 'UnzipSuccessfully')); } unlink($tempFilePath); chmod($moduleFolderPath, $chmodOctal); //4.0. create separate folder in 'userdata/modules' for a new module, if it's don't exists $userdataFolderPath = self::getModuleUserFolderpath($moduleName) . DIRECTORY_SEPARATOR; if (is_dir($userdataFolderPath)) { $result = RM_Filesystem::deleteFolder($userdataFolderPath); if ($result == false) { throw new RM_Exception($this->_translate->_('Admin.Modules.InstallMsg', 'ModuleFolderAlreadyExists') . ': ' . $userdataFolderPath); } } if (is_dir($userdataFolderPath) == false) { $result = mkdir($userdataFolderPath, $chmodOctal); if ($result == false) { RM_Filesystem::deleteFolder($moduleFolderPath); throw new RM_Exception($this->_translate->_('Admin.Modules.InstallMsg', 'CreateModuleUserdataFolderFailer')); } else { $json = $this->_addMessageToJson($json, $this->_translate->_('Admin.Modules.InstallMsg', 'ModuleFolderCreatedSuccessfully')); } @rename($moduleFolderPath . DIRECTORY_SEPARATOR . 'views', $userdataFolderPath . 'views'); @chmod($userdataFolderPath . 'views', $chmodOctal); @rename($moduleFolderPath . DIRECTORY_SEPARATOR . 'languages', $userdataFolderPath . 'languages'); @chmod($userdataFolderPath . 'languages', $chmodOctal); @rename($moduleFolderPath . DIRECTORY_SEPARATOR . 'css', $userdataFolderPath . 'css'); @chmod($userdataFolderPath . 'css', $chmodOctal); @rename($moduleFolderPath . DIRECTORY_SEPARATOR . 'images', $userdataFolderPath . 'images'); @chmod($userdataFolderPath . 'images', $chmodOctal); @chmod($moduleFolderPath, $chmodOctal); } //5. get INI file $iniFilePath = $moduleFolderPath . DIRECTORY_SEPARATOR . self::$_iniFilename; if (is_file($iniFilePath) == false) { RM_Filesystem::deleteFolder($moduleFolderPath); throw new RM_Exception($this->_translate->_('Admin.Modules.InstallMsg', 'NoIniFile')); } //6. parse INI file $parser = new RM_Module_Config_Parser(); try { $config = $parser->getConfig($iniFilePath); } catch (RM_Exception $e) { //Error in ini file parsing RM_Filesystem::deleteFolder($moduleFolderPath); throw new RM_Exception($e->getMessage()); } if (isset($config->information['module'])) { RM_Filesystem::deleteFolder($moduleFolderPath); throw new RM_Exception($this->_translate->_('Admin.Modules.InstallMsg', 'WrongTryToInstallPlugin')); } $json = $this->_addMessageToJson($json, $this->_translate->_('Admin.Modules.InstallMsg', 'UnzipSuccess')); //7. invoke SQL install file try { $result = self::installDatabase($moduleFolderPath); } catch (Exception $e) { self::uninstallDatabase($moduleFolderPath); RM_Filesystem::deleteFolder($moduleFolderPath); RM_Filesystem::deleteFolder($userdataFolderPath); throw new RM_Exception($e->getMessage()); } if ($result == false) { self::uninstallDatabase($moduleFolderPath); RM_Filesystem::deleteFolder($moduleFolderPath); RM_Filesystem::deleteFolder($userdataFolderPath); throw new RM_Exception($this->_translate->_('Admin.Modules.InstallMsg', 'WrongInstallSQLQueries')); } else { $json = $this->_addMessageToJson($json, $this->_translate->_('Admin.Modules.InstallMsg', 'InstallSQLSuccess')); } //8. create a new record in Module database $moduleRow = array(); $moduleRow = $config->information; //TODO: //1.check the insertions $pkey = $moduleModel->insert($moduleRow); //Create a new records in dependencies database table $model = new RM_Dependencies(); if (is_array($config->dependencies)) { foreach ($config->dependencies as $dependency) { $model->insert($dependency); } } //9. get the main class of the module $moduleClassFilepath = $moduleFolderPath . DIRECTORY_SEPARATOR . RM_Module_Config::CLASSES . DIRECTORY_SEPARATOR . 'RM' . DIRECTORY_SEPARATOR . 'Module' . DIRECTORY_SEPARATOR . $config->information['name'] . '.php'; if (is_file($moduleClassFilepath) == false) { self::uninstallDatabase($moduleFolderPath); RM_Filesystem::deleteFolder($moduleFolderPath); RM_Filesystem::deleteFolder($userdataFolderPath); throw new RM_Exception($this->_translate->_('Admin.Modules.InstallMsg', 'DoesntExists')); } require_once $moduleClassFilepath; $moduleClassName = 'RM_Module_' . $config->information['name']; if (class_exists($moduleClassName) == false) { self::uninstallDatabase($moduleFolderPath); RM_Filesystem::deleteFolder($moduleFolderPath); RM_Filesystem::deleteFolder($userdataFolderPath); throw new RM_Exception($moduleClassName . $this->_translate->_('Admin.Modules.InstallMsg', 'DoesntExists')); } $moduleObject = new $moduleClassName(); if (!$moduleObject instanceof RM_Module_Interface) { self::uninstallDatabase($moduleFolderPath); RM_Filesystem::deleteFolder($moduleFolderPath); RM_Filesystem::deleteFolder($userdataFolderPath); throw new RM_Exception($moduleClassName . $this->_translate->_('Admin.Modules.InstallMsg', 'WrongInterface')); } //10. invoke install method of that class (if we need something extra) $result = $moduleObject->install(); $json = $this->_addMessageToJson($json, $this->_translate->_('Admin.Modules.InstallMsg', 'InstallSuccess')); //Check dependencies and if some of them is validate==false disable module $moduleManager = new RM_Module_Manager(RM_Environment::getInstance()->getTranslation()); $dependencyManager = new RM_Dependency_Manager(); $module = $moduleModel->find($pkey)->current(); $dependencies = $dependencyManager->getDependencies($module); foreach ($dependencies as $dependency) { if ($dependency->validate() == false) { try { $moduleModel->disable($module); break; } catch (Exception $e) { //TODO: add log message that we could not disable this module. } } } return $json; }
public function disableJsonAction() { $json = new stdClass(); $json->success = 1; $json->msg = array(); $ids = $this->_getParam('ids', array()); $manager = new RM_Module_Manager($this->_translate); $model = new RM_Modules(); foreach ($ids as $id) { $row = $model->find($id)->current(); try { $manager->disable($row); } catch (Exception $e) { $json->success = 0; $json->msg[] = $e->getMessage(); } } return array('data' => $json); }