Example #1
0
 function delete()
 {
     $model = new RM_Dependencies();
     $dependencies = $model->getDependencies($this);
     foreach ($dependencies as $row) {
         $row->delete();
     }
     parent::delete();
 }
Example #2
0
 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();
         }
     }
 }
Example #3
0
 public function ajaxAction()
 {
     parent::ajaxAction();
     $data = (object) array_merge($this->getRequest()->getPost(), $_GET);
     $this->_ajaxResponse = new stdClass();
     switch ($data->type) {
         case 'userLogin':
             $this->_ajaxResponse->login = 0;
             /* @var Application_Model_User_Profile $profileClass */
             $profileClass = RM_Dependencies::getInstance()->userProfile;
             $profile = $profileClass::getByEmail($data->mail);
             /* @var RM_User_Profile_Interface $profile */
             if ($profile instanceof $profileClass && $profile->checkPassword($data->passwd)) {
                 if ($profile->getUser()->getRole()->isAdmin()) {
                     $this->_session->create($profile->getUser());
                     if (intval($data->remember) == 1) {
                         $this->_session->remember();
                     }
                     $this->_ajaxResponse->login = 2;
                 } else {
                     $this->_ajaxResponse->login = 1;
                 }
             }
             break;
     }
 }
Example #4
0
 protected function _initDependencies()
 {
     $dependencies = RM_Dependencies::getInstance();
     $dependencies->userClass = 'RM_User_Base';
     $dependencies->userProfile = 'Application_Model_User_Profile';
     $dependencies->pageClass = 'Application_Model_TextPage';
 }
Example #5
0
 public function uninstall()
 {
     $pluginsModel = new RM_Plugins();
     $plugin = $pluginsModel->find($this->name)->current();
     if ($plugin !== null) {
         $dependenciesModel = new RM_Dependencies();
         $dependencies = $dependenciesModel->getDependencies($plugin);
         foreach ($dependencies as $dependency) {
             $dependency->delete();
         }
     }
 }
Example #6
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;
 }
Example #7
0
 /**
  * Returns all dependency child dependencies
  *
  * @param RM_Dependency_Child_Interface $child
  * @return array
  */
 function getDependencies($child)
 {
     $model = new RM_Dependencies();
     $rows = $model->getDependencies($child);
     return $this->_getDependencies($rows);
 }