示例#1
0
 function renewJsonAction()
 {
     $extensions = RM_Environment::getInstance()->getOutOfDateExtensions();
     $pluginModel = new RM_Plugins();
     $pluginManager = new RM_Plugin_Manager($this->_translate);
     $failedPlugins = array();
     foreach ($extensions['plugins'] as $pluginName) {
         $plugin = $pluginModel->fetchByName($pluginName);
         try {
             $pluginManager->autoUpgrade($plugin);
         } catch (Exception $e) {
             $failedPlugins[] = $pluginName;
             continue;
         }
     }
     $moduleModel = new RM_Modules();
     $moduleManager = new RM_Module_Manager($this->_translate);
     $failedModules = array();
     foreach ($extensions['modules'] as $moduleName) {
         $module = $moduleModel->fetchByName($moduleName);
         try {
             $moduleManager->autoUpgrade($module);
         } catch (Exception $e) {
             $failedModules[] = $moduleName;
             continue;
         }
     }
     return array('data' => array('success' => true));
 }
示例#2
0
 /**
  * @see RM_Dependency_Abstract::validate method
  * @return bool
  */
 public function validate()
 {
     //1. check if module is installed
     $moduleClassName = 'RM_Module_' . $this->_getName();
     if (class_exists($moduleClassName) == false) {
         return false;
     }
     //2. check if module is enabled
     $moduleModel = new RM_Modules();
     $moduleRow = $moduleModel->fetchByName($this->_getName());
     if ($moduleModel->isEnabled($moduleRow) == false) {
         return false;
     }
     //3. check it's min version
     $minModuleVersion = $this->_getVersion();
     $moduleVersion = $moduleRow->version;
     if (version_compare($moduleVersion, $minModuleVersion, '<')) {
         return false;
     }
     return true;
 }
示例#3
0
 /**
  * Returns extension names that are out of date and there are new versions of them on the resmania site
  *
  * @return array - array in format
  * [ modules => array() , plugins => array() ]
  */
 public function getOutOfDateExtensions()
 {
     $pluginsModel = new RM_Plugins();
     $result = array('modules' => array(), 'plugins' => array());
     $versions = $this->getExtensionVersions();
     foreach ($versions['plugins'] as $pluginInfo) {
         $plugin = $pluginsModel->fetchByName($pluginInfo['name']);
         if ($plugin == null) {
             continue;
         }
         if (version_compare($plugin->version, $pluginInfo['version'], '<')) {
             $result['plugins'][] = $pluginInfo['name'];
         }
     }
     $modulesModel = new RM_Modules();
     foreach ($versions['modules'] as $moduleInfo) {
         $module = $modulesModel->fetchByName($moduleInfo['name']);
         if ($module == null) {
             continue;
         }
         if (version_compare($module->version, $moduleInfo['version'], '<')) {
             $result['modules'][] = $moduleInfo['name'];
         }
     }
     return $result;
 }
示例#4
0
 /**
  * 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;
 }
示例#5
0
文件: Row.php 项目: laiello/resmania
 /**
  * Returns RM_Module_Row or a string with module_name if this module
  * is not installed in application
  *
  * @return RM_Module_Row|string
  */
 function getParentModule()
 {
     $model = new RM_Modules();
     $module = $model->fetchByName($this->module_name)->current();
     return $module;
 }