Exemple #1
0
 protected function _moveUserDataFolders($source, $destination, $chmodOctal)
 {
     $system = new RM_Filesystem();
     if (!is_dir($destination)) {
         mkdir($destination);
         chmod($destination, $chmodOctal);
     }
     $system->recursivecopy($source, $destination);
     rmdir($source);
     chmod($destination, $chmodOctal);
 }
Exemple #2
0
 public function uninstall()
 {
     parent::uninstall();
     //1. remove template for advanced search panel
     $rootPath = RM_Environment::getConnector()->getRootPath();
     $file = implode(DIRECTORY_SEPARATOR, array($rootPath, 'RM', 'userdata', 'views', 'user', 'scripts', 'Search', 'advanced', 'category_advancedsearch.phtml'));
     RM_Filesystem::deleteFile($file);
     //2. remove information about this panel from database in form->state field
     $formModel = new RM_Forms();
     $form = $formModel->find('advancedsearch')->current();
     $deleted = $form->deletePanel('category_advancedsearch');
     if ($deleted) {
         $form->save();
     }
 }
Exemple #3
0
 public static function getControllersJavaScript()
 {
     $frontController = Zend_Controller_Front::getInstance();
     $directories = $frontController->getControllerDirectory();
     $moduleDirectories = $directories[RM_Environment::getConnector()->getModule()];
     $jsResult = "";
     foreach ($moduleDirectories as $directoryName) {
         $moduleDirectory = $directoryName . DIRECTORY_SEPARATOR . 'RM' . DIRECTORY_SEPARATOR . ucfirst(RM_Environment::getConnector()->getModule());
         $files = RM_Filesystem::getFilesRecursively($moduleDirectory);
         foreach ($files as $file) {
             Zend_Loader::loadFile($file, null, true);
             $className = self::_getClassName($moduleDirectory, $file);
             $jsMethodNames = self::_getJsMethodList($className);
             if (count($jsMethodNames) == 0) {
                 continue;
             }
             $controller = new $className($frontController->getRequest(), $frontController->getResponse());
             foreach ($jsMethodNames as $jsMethodName) {
                 $jsResult .= $controller->{$jsMethodName}();
             }
         }
     }
     return $jsResult;
 }
Exemple #4
0
 /**
  * this method will clear the module css cache
  */
 public function clearCSSCache()
 {
     // clear the module CSS Cache
     $cacheDir = RM_Environment::getConnector()->getRootPath() . DIRECTORY_SEPARATOR . 'RM' . DIRECTORY_SEPARATOR . 'userdata' . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'css';
     if (file_exists($cacheDir)) {
         RM_Filesystem::emptyFolder($cacheDir);
     }
 }
Exemple #5
0
 /**
  * Clear all cache files.
  *
  * @return void
  */
 public function clearCache()
 {
     $cacheDir = self::getConnector()->getRootPath() . DIRECTORY_SEPARATOR . 'RM' . DIRECTORY_SEPARATOR . 'userdata' . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR;
     RM_Filesystem::emptyFolder($cacheDir . DIRECTORY_SEPARATOR . 'cache');
     RM_Filesystem::emptyFolder($cacheDir . DIRECTORY_SEPARATOR . 'css');
     RM_Filesystem::emptyFolder($cacheDir . DIRECTORY_SEPARATOR . 'classes');
     RM_Filesystem::emptyFolder($cacheDir . DIRECTORY_SEPARATOR . 'extensions');
     RM_Filesystem::emptyFolder($cacheDir . DIRECTORY_SEPARATOR . 'language');
     RM_Filesystem::emptyFolder($cacheDir . DIRECTORY_SEPARATOR . 'models');
 }
Exemple #6
0
 public function deleteLanguage($iso)
 {
     $languageFolder = implode(DIRECTORY_SEPARATOR, array(RM_Environment::getConnector()->getRootPath(), 'RM', 'userdata', 'plugins', $this->name, 'languages', $iso));
     RM_Filesystem::deleteFolder($languageFolder);
 }
Exemple #7
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;
 }
Exemple #8
0
 /**
  * Delete recursivly folder/file in the system
  *
  * @param string $foldername - full folder/file path
  * @return bool
  */
 public static function deleteFolder($foldername)
 {
     if (is_file($foldername)) {
         return RM_Filesystem::deleteFile($foldername);
     }
     if (is_dir($foldername)) {
         if ($handle = opendir($foldername)) {
             while (false !== ($file = readdir($handle))) {
                 if ($file != "." && $file != "..") {
                     RM_Filesystem::deleteFolder($foldername . DIRECTORY_SEPARATOR . $file);
                 }
             }
         }
         closedir($handle);
         rmdir($foldername);
     }
     return true;
 }
Exemple #9
0
 public function deleteLanguage($locale)
 {
     $languageFolderPath = implode(DIRECTORY_SEPARATOR, array(RM_Environment::getConnector()->getRootPath(), 'RM', 'userdata', 'modules', $this->name, 'languages', $locale));
     $fileSystem = new RM_Filesystem();
     return $fileSystem->deleteFolder($languageFolderPath);
 }
Exemple #10
0
 /**
  * Delete unit image
  *     
  * @param string $filename
  * @return boolean
  */
 public function deleteImageFiles($filename)
 {
     $extensionMediaFolder = $this->getFolder();
     $files = array();
     $files[] = $unitFolder . DIRECTORY_SEPARATOR . $filename;
     $files[] = $unitFolder . DIRECTORY_SEPARATOR . RM_Media_Image::get(RM_Media_Image::THUMB)->createFilename($filename);
     return RM_Filesystem::deleteFiles($files);
 }
Exemple #11
0
 /**
  * clear up
  * remove old upgrade files
  */
 public function cleanupJsonAction()
 {
     // upgrade temp file path
     $filePath = implode(DIRECTORY_SEPARATOR, array(RM_Environment::getConnector()->getRootPath(), 'RM', 'userdata', 'temp', 'upgrade'));
     $deleteArray = array($filePath . DIRECTORY_SEPARATOR . "core.zip", $filePath . DIRECTORY_SEPARATOR . "modules", $filePath . DIRECTORY_SEPARATOR . "plugins", $filePath . DIRECTORY_SEPARATOR . "system", $filePath . DIRECTORY_SEPARATOR . "tests", $filePath . DIRECTORY_SEPARATOR . "userdata", $filePath . DIRECTORY_SEPARATOR . "license", $filePath . DIRECTORY_SEPARATOR . "postupgrade.php");
     foreach ($deleteArray as $item) {
         RM_Log::toLog('Upgrade - temp file/folder deleted: ' . $item, RM_Log::INFO);
         RM_Filesystem::deleteFolder($item);
     }
     return array('data' => array('success' => true));
 }
Exemple #12
0
 protected function _copyMediaFiles(RM_Unit_Row $original, RM_Unit_Row $copy)
 {
     $rmConfig = new RM_Config();
     $chmodOctal = intval($rmConfig->getValue('rm_config_chmod_value'), 8);
     $destination = implode(DIRECTORY_SEPARATOR, array(RM_Environment::getConnector()->getCorePath(), 'userdata', 'images', 'units', $copy->getId()));
     $result = mkdir($destination, $chmodOctal, true);
     if (!$result) {
         throw new RM_Exception(RM_Environment::getInstance()->getTranslation()->_('Admin.Units.List', 'CopyErrorMediaFolderCreation') . ' ' . $destination);
     }
     $fileSystem = new RM_Filesystem();
     $source = implode(DIRECTORY_SEPARATOR, array(RM_Environment::getConnector()->getCorePath(), 'userdata', 'images', 'units', $original->getId()));
     $result = $fileSystem->recursivecopy($source, $destination);
     if ($result == false) {
         throw new RM_Exception(sprintf(RM_Environment::getInstance()->getTranslation()->_('Admin.Units.List', 'CopyErrorMediaFilesCopy'), $source, $destination));
     }
 }
Exemple #13
0
 /**
  * Clears the language cache files
  * @todo we need to use Zend cache methods to made this code more clear.
  */
 public function clearCache()
 {
     return RM_Filesystem::emptyFolder($this->_cacheFolderPath);
 }
Exemple #14
0
 /**
  * Resize all thumbnails
  */
 public function resize()
 {
     RM_Media_Image::initialize();
     $files = RM_Filesystem::getFiles($this->_imageFolder, $this->_extensions);
     foreach ($files as $filename) {
         if (RM_Media_Image::isOriginal($filename)) {
             $this->createThumbnail($filename);
         }
     }
 }