public function deleteRow(RM_Unit_Row $unit) { $folderName = implode(DIRECTORY_SEPARATOR, array(RM_Environment::getConnector()->getCorePath(), 'userdata', 'images', 'units', $unit->id)); $fileSystem = new RM_Filesystem(); $fileSystem->deleteFolder($folderName); return $unit->delete(); }
public function deleteLanguage($iso) { $languageFolder = implode(DIRECTORY_SEPARATOR, array(RM_Environment::getConnector()->getRootPath(), 'RM', 'userdata', 'plugins', $this->name, 'languages', $iso)); RM_Filesystem::deleteFolder($languageFolder); }
/** * 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; }
/** * 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; }
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); }
/** * 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)); }
/** * Upload zip srchive with all language files and config.ini * * @return array array($iso, $name) ISO code of uploaded language and language name on this language */ function upload() { //0. Create temp folder $folderName = self::_createTempFolderName(); //We create a name in a timestamp $rmConfig = new RM_Config(); $chmodOctal = intval($rmConfig->getValue('rm_config_chmod_value'), 8); $tempFolderPath = RM_Environment::getConnector()->getTempFolderPath() . DIRECTORY_SEPARATOR . $folderName; if (mkdir($tempFolderPath, $chmodOctal) == false) { throw new RM_Exception($this->_translate->_('Admin.System.Language', 'CantCreateTempFolder')); } //1. Upload zip file $validators = array(); $validators[] = new Zend_Validate_File_Extension('zip'); $adapter = new Zend_File_Transfer_Adapter_Http(); $adapter->setValidators($validators); try { $adapter->setDestination($tempFolderPath); } catch (Zend_File_Transfer_Exception $exception) { throw new RM_Exception($exception->getMessage()); } if (!$adapter->receive()) { $message = $this->_translate->_('Admin.System.Language', 'UploadFailed'); $message .= '. ' . implode("; ", $adapter->getMessages()); throw new RM_Exception($message); } //2. Unpack it $files = $adapter->getFileInfo(); $tempFileName = $files[self::$_formName]['name']; $tempFilePath = $tempFolderPath . DIRECTORY_SEPARATOR . $tempFileName; if (!extension_loaded('zlib')) { unlink($tempFilePath); RM_Filesystem::deleteFolder($tempFolderPath); throw new RM_Exception($this->_translate->_('Admin.System.Language', 'ZlibNotSupported')); } $zip = new PclZip($tempFilePath); $userDataFolder = RM_Environment::getConnector()->getCorePath() . DIRECTORY_SEPARATOR . 'userdata'; $result = $zip->extract(PCLZIP_OPT_PATH, $userDataFolder, PCLZIP_OPT_SET_CHMOD, $chmodOctal); unlink($tempFilePath); RM_Filesystem::deleteFolder($tempFolderPath); if (!$result) { throw new RM_Exception($this->_translate->_('Admin.System.Language', 'UnzipFailed')); } //3. Parse config.ini file $iniFilePath = $userDataFolder . DIRECTORY_SEPARATOR . self::$_configFilename; if (is_file($iniFilePath) == false) { RM_Filesystem::deleteFolder($tempFolderPath); throw new RM_Exception($this->_translate->_('Admin.System.Language', 'NoConfigIniFile')); } $parser = new RM_Language_Config_Parser(); try { $config = $parser->getConfig($iniFilePath); } catch (RM_Exception $e) { RM_Filesystem::deleteFolder($tempFolderPath); throw new RM_Exception($e->getMessage()); } //4. Get iso $iso = $config->iso; $name = $config->name; unlink($iniFilePath); return array($iso, $name); }