Пример #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 plugin is installed
     $pluginClassName = 'RM_Plugin_' . $this->_getName();
     if (class_exists($pluginClassName) == false) {
         return false;
     }
     //2. check if plugin is enabled
     $pluginModel = new RM_Plugins();
     $pluginRow = $pluginModel->fetchByName($this->_getName());
     if ($pluginModel->isEnabled($pluginRow) == false) {
         return false;
     }
     //3. check it's min version
     $minPluginVersion = $this->_getVersion();
     $pluginVersion = $pluginRow->version;
     if (version_compare($pluginVersion, $minPluginVersion, '<')) {
         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
 public function getDatabaseRow()
 {
     $pluginModel = new RM_Plugins();
     return $pluginModel->fetchByName($this->name);
 }
Пример #5
0
 /**
  * Full installation process of plugin
  *
  * @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);
     $rootPath = RM_Environment::getConnector()->getRootPath();
     $chunks = explode('.', $tempFileName);
     $pluginName = $chunks[0];
     //Plugin name will be always the first chunk, example: price.0.1.1.zip
     $pluginModel = new RM_Plugins();
     $existingPlugin = $pluginModel->fetchByName($pluginName);
     if ($existingPlugin !== null) {
         unlink($tempFilePath);
         throw new RM_Exception($this->_translate->_('Admin.Plugins.InstallMsg', 'PluginAlreadyInstalled'));
     }
     $pluginFolderPath = $rootPath . DIRECTORY_SEPARATOR . 'RM' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . $pluginName;
     if (is_dir($pluginFolderPath)) {
         $result = RM_Filesystem::deleteFolder($pluginFolderPath);
         if ($result == false) {
             unlink($tempFilePath);
             throw new RM_Exception($this->_translate->_('Admin.Plugins.InstallMsg', 'PluginFolderAlreadyExists') . ': ' . $pluginFolderPath);
         }
     }
     $result = mkdir($pluginFolderPath, $chmodOctal);
     if ($result == false) {
         unlink($tempFilePath);
         throw new RM_Exception($this->_translate->_('Admin.Plugins.InstallMsg', 'CreatePluginFolderFailer'));
     } else {
         $json = $this->_addMessageToJson($json, $this->_translate->_('Admin.Plugins.InstallMsg', 'PluginFolderCreatedSuccessfully'));
     }
     //4. unzip plugin into new directory
     if (!extension_loaded('zlib')) {
         unlink($tempFilePath);
         RM_Filesystem::deleteFolder($pluginFolderPath);
         throw new RM_Exception($this->_translate->_('Admin.Plugins.InstallMsg', 'ZlibNotSupported'));
     }
     $zip = new PclZip($tempFilePath);
     $result = $zip->extract(PCLZIP_OPT_PATH, $pluginFolderPath);
     if (!$result) {
         unlink($tempFilePath);
         RM_Filesystem::deleteFolder($pluginFolderPath);
         throw new RM_Exception($this->_translate->_('Admin.Plugins.InstallMsg', 'UnzipFailed'));
     } else {
         $json = $this->_addMessageToJson($json, $this->_translate->_('Admin.Plugins.InstallMsg', 'UnzipSuccessfully'));
     }
     unlink($tempFilePath);
     chmod($pluginFolderPath, $chmodOctal);
     //4.0. create separate folder in 'userdata/plugins' for a new plugin
     $userdataFolderPath = $rootPath . DIRECTORY_SEPARATOR . 'RM' . DIRECTORY_SEPARATOR . 'userdata' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . $pluginName;
     if (is_dir($userdataFolderPath)) {
         $result = RM_Filesystem::deleteFolder($userdataFolderPath);
         if ($result == false) {
             throw new RM_Exception($this->_translate->_('Admin.Plugins.InstallMsg', 'PluginFolderAlreadyExists') . ': ' . $userdataFolderPath);
         }
     }
     $result = mkdir($userdataFolderPath . DIRECTORY_SEPARATOR, $chmodOctal);
     if ($result == false) {
         RM_Filesystem::deleteFolder($pluginFolderPath);
         throw new RM_Exception($this->_translate->_('Admin.Plugins.InstallMsg', 'CreatePluginUserdataFolderFailer'));
     } else {
         $json = $this->_addMessageToJson($json, $this->_translate->_('Admin.Plugins.InstallMsg', 'PluginFolderCreatedSuccessfully'));
     }
     @rename($pluginFolderPath . DIRECTORY_SEPARATOR . 'views', $userdataFolderPath . DIRECTORY_SEPARATOR . 'views');
     @chmod($pluginFolderPath . DIRECTORY_SEPARATOR . 'views', $chmodOctal);
     @rename($pluginFolderPath . DIRECTORY_SEPARATOR . 'languages', $userdataFolderPath . DIRECTORY_SEPARATOR . 'languages');
     @chmod($pluginFolderPath . DIRECTORY_SEPARATOR . 'languages', $chmodOctal);
     @rename($pluginFolderPath . DIRECTORY_SEPARATOR . 'css', $userdataFolderPath . DIRECTORY_SEPARATOR . 'css');
     @chmod($pluginFolderPath . DIRECTORY_SEPARATOR . 'css', $chmodOctal);
     @rename($pluginFolderPath . DIRECTORY_SEPARATOR . 'images', $userdataFolderPath . DIRECTORY_SEPARATOR . 'images');
     @chmod($pluginFolderPath . DIRECTORY_SEPARATOR . 'images', $chmodOctal);
     @chmod($userdataFolderPath, $chmodOctal);
     //5. get INI file
     $iniFilePath = $pluginFolderPath . DIRECTORY_SEPARATOR . self::$_iniFilename;
     if (is_file($iniFilePath) == false) {
         RM_Filesystem::deleteFolder($pluginFolderPath);
         throw new RM_Exception($this->_translate->_('Admin.Plugins.InstallMsg', 'NoIniFile'));
     }
     //6. parse INI file
     $parser = new RM_Plugin_Config_Parser();
     try {
         $config = $parser->getConfig($iniFilePath);
     } catch (RM_Exception $e) {
         //Error in ini file parsing
         RM_Filesystem::deleteFolder($pluginFolderPath);
         throw new RM_Exception($e->getMessage());
     }
     //Check: could be a module if no 'module' value is in config
     if ($config->information['module'] == "") {
         RM_Filesystem::deleteFolder($pluginFolderPath);
         throw new RM_Exception($this->_translate->_('Admin.Plugins.InstallMsg', 'WrongTryToInstallModule'));
     }
     $json = $this->_addMessageToJson($json, $this->_translate->_('Admin.Plugins.InstallMsg', 'UnzipSuccess'));
     //7. invoke SQL install file
     try {
         $result = self::installDatabase($pluginFolderPath);
     } catch (Exception $e) {
         self::uninstallDatabase($pluginFolderPath);
         RM_Filesystem::deleteFolder($pluginFolderPath);
         throw new RM_Exception($e->getMessage());
     }
     if ($result == false) {
         self::uninstallDatabase($pluginFolderPath);
         RM_Filesystem::deleteFolder($pluginFolderPath);
         throw new RM_Exception($this->_translate->_('Admin.Plugins.InstallMsg', 'WrongInstallSQLQueries'));
     } else {
         $json = $this->_addMessageToJson($json, $this->_translate->_('Admin.Plugins.InstallMsg', 'InstallSQLSuccess'));
     }
     //8. create a new record in Plugin database
     $pluginRow = array();
     $pluginRow = $config->information;
     $pluginRow['module_name'] = $pluginRow['module'];
     unset($pluginRow['module']);
     //convert creation date into MySQL format
     $rmConfig = new RM_Config();
     $pluginRow['creation_date'] = $rmConfig->convertDates(strtotime($pluginRow['creation_date']), RM_Config::TIMESTAMP_DATEFORMAT, RM_Config::MYSQL_DATEFORMAT);
     //TODO:
     //1.check the insertions
     $pkey = $pluginModel->insert($pluginRow);
     //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 plugin
     $pluginClassFilepath = $pluginFolderPath . DIRECTORY_SEPARATOR . RM_Plugin_Config::CLASSES . DIRECTORY_SEPARATOR . 'RM' . DIRECTORY_SEPARATOR . 'Plugin' . DIRECTORY_SEPARATOR . $config->information['name'] . '.php';
     if (is_file($pluginClassFilepath) == false) {
         self::uninstallDatabase($pluginFolderPath);
         RM_Filesystem::deleteFolder($pluginFolderPath);
         throw new RM_Exception($this->_translate->_('Admin.Plugins.InstallMsg', 'DoesntExists'));
     }
     require_once $pluginClassFilepath;
     $pluginClassName = 'RM_Plugin_' . $config->information['name'];
     if (class_exists($pluginClassName) == false) {
         self::uninstallDatabase($pluginFolderPath);
         RM_Filesystem::deleteFolder($pluginFolderPath);
         throw new RM_Exception($pluginClassName . $this->_translate->_('Admin.Plugins.InstallMsg', 'DoesntExists'));
     }
     $pluginObject = new $pluginClassName();
     if (!$pluginObject instanceof RM_Plugin_Interface) {
         self::uninstallDatabase($pluginFolderPath);
         RM_Filesystem::deleteFolder($pluginFolderPath);
         throw new RM_Exception($pluginClassName . $this->_translate->_('Admin.Plugins.InstallMsg', 'WrongInterface'));
     }
     //10. invoke install method of that class (if we need something extra)
     $result = $pluginObject->install();
     $json = $this->_addMessageToJson($json, $this->_translate->_('Admin.Plugins.InstallMsg', 'InstallSuccess'));
     //Check dependencies and if some of them is validate==false disable plugin
     $dependencyManager = new RM_Dependency_Manager();
     $plugin = $pluginModel->find($pkey)->current();
     $dependencies = $dependencyManager->getDependencies($plugin);
     foreach ($dependencies as $dependency) {
         if ($dependency->validate() == false) {
             try {
                 $pluginModel->disable($plugin);
                 break;
             } catch (Exception $e) {
                 //TODO: add log message that we could not disable this module.
             }
         }
     }
     return $json;
 }