Пример #1
0
 /**
  * Update custom images
  *
  * @return void
  */
 protected function updateCustomImages()
 {
     $dir = \XLite\Module\XC\ThemeTweaker\Main::getThemeDir() . 'images' . LC_DS;
     if ($_FILES && $_FILES['new_images'] && $_FILES['new_images']['name']) {
         if (!\Includes\Utils\FileManager::isExists($dir)) {
             \Includes\Utils\FileManager::mkdirRecursive($dir);
         }
         if (\Includes\Utils\FileManager::isDirWriteable($dir)) {
             foreach ($_FILES['new_images']['name'] as $i => $data) {
                 \Includes\Utils\FileManager::moveUploadedFileByMultiple('new_images', $i, $dir);
             }
         } else {
             \XLite\Core\TopMessage::addError('The directory {{dir}} does not exist or is not writable.', array('dir' => $dir));
         }
     }
     $delete = \XLite\Core\Request::getInstance()->delete;
     if ($delete && is_array($delete)) {
         foreach ($delete as $file => $del) {
             if ($del) {
                 \Includes\Utils\FileManager::deleteFile($dir . $file);
             }
         }
     }
 }
Пример #2
0
 /**
  * Uninstall module
  *
  * @param \XLite\Model\Module $module    Module object
  * @param array               &$messages Messages list
  *
  * @return boolean
  */
 public function uninstallModule(\XLite\Model\Module $module, &$messages)
 {
     $result = false;
     // Get module pack
     $pack = new \XLite\Core\Pack\Module($module);
     $dirs = $pack->getDirs();
     $nonWritableDirs = array();
     // Check module directories permissions
     foreach ($dirs as $dir) {
         if (\Includes\Utils\FileManager::isExists($dir) && !\Includes\Utils\FileManager::isDirWriteable($dir)) {
             $nonWritableDirs[] = \Includes\Utils\FileManager::getRelativePath($dir, LC_DIR_ROOT);
         }
     }
     $params = array('name' => sprintf('%s v%s (%s)', $module->getModuleName(), $module->getVersion(), $module->getAuthorName()));
     if (empty($nonWritableDirs)) {
         $yamlData = array();
         $yamlFiles = \Includes\Utils\ModulesManager::getModuleYAMLFiles($module->getAuthor(), $module->getName());
         foreach ($yamlFiles as $yamlFile) {
             $yamlData[] = \Includes\Utils\FileManager::read($yamlFile);
         }
         if (!$module->checkModuleMainClass()) {
             $classFile = LC_DIR_CLASSES . \Includes\Utils\Converter::getClassFile($module->getMainClass());
             if (\Includes\Utils\FileManager::isFileReadable($classFile)) {
                 require_once $classFile;
             }
         }
         // Call uninstall event method
         $r = $module->callModuleMethod('callUninstallEvent', 111);
         if (111 == $r) {
             \XLite\Logger::getInstance()->log($module->getActualName() . ': Method callUninstallEvent() was not called');
         }
         // Remove from FS
         foreach ($dirs as $dir) {
             \Includes\Utils\FileManager::unlinkRecursive($dir);
         }
         \Includes\Utils\ModulesManager::disableModule($module->getActualName());
         \Includes\Utils\ModulesManager::removeModuleFromDisabledStructure($module->getActualName());
         // Remove module from DB
         try {
             // Refresh module entity as it was changed by disableModule() method above
             $module = $this->find($module->getModuleID());
             $this->delete($module);
         } catch (\Exception $e) {
             $messages[] = $e->getMessage();
         }
         if ($module->getModuleID()) {
             $messages[] = \XLite\Core\Translation::getInstance()->translate('A DB error occured while uninstalling the module X', $params);
         } else {
             if (!empty($yamlData)) {
                 foreach ($yamlData as $yaml) {
                     \XLite\Core\Database::getInstance()->unloadFixturesFromYaml($yaml);
                 }
             }
             $messages[] = \XLite\Core\Translation::getInstance()->translate('The module X has been uninstalled successfully', $params);
             $result = true;
         }
     } else {
         $messages[] = \XLite\Core\Translation::getInstance()->translate('Unable to delete module X files: some dirs have no writable permissions: Y', $params + array('dirs' => implode(', ', $nonWritableDirs)));
     }
     return $result;
 }
Пример #3
0
 /**
  * Write data from request into a file
  *
  * @param \PEAR2\HTTP\Request\Response $response Response to get data
  *
  * @return string
  */
 protected function writeDataToFile(\PEAR2\HTTP\Request\Response $response)
 {
     if (!\Includes\Utils\FileManager::isDir(LC_DIR_TMP)) {
         \Includes\Utils\FileManager::mkdir(LC_DIR_TMP);
     }
     if (!\Includes\Utils\FileManager::isDirWriteable(LC_DIR_TMP)) {
         \Includes\ErrorHandler::fireError('Directory "' . LC_DIR_TMP . '" is not writeable');
     }
     $path = \Includes\Utils\FileManager::getUniquePath(LC_DIR_TMP, uniqid() . '.' . \Includes\Utils\PHARManager::getExtension() ?: 'tar');
     return isset($response->body) && \Includes\Utils\FileManager::write($path, $response->body) ? $path : null;
 }
Пример #4
0
 /**
  * Callback for a common operation for upgrade
  *
  * @param string  $path       File short path
  * @param boolean $isTestMode If in test mode
  *
  * @return void
  */
 protected function deleteFileCallback($path, $isTestMode)
 {
     if ($isTestMode) {
         if (!\Includes\Utils\FileManager::isDirWriteable($this->manageFile($path, 'getDir'))) {
             $this->addFileErrorMessage('File\'s directory is not writable', $path, false);
             $this->wrongPermissions[] = $this->manageFile($path, 'getDir');
         }
     } elseif ($this->manageFile($path, 'deleteFile')) {
         $this->addFileInfoMessage('File is deleted', $path, true);
         // Remove the parent directory if upgrade process removes all files in it
         $dir = dirname($path);
         if (\Includes\Utils\FileManager::isEmptyDir($dir)) {
             \Includes\Utils\FileManager::unlinkRecursive($dir);
             if (!\Includes\Utils\FileManager::isExists($dir)) {
                 $this->addFileInfoMessage('Directory is deleted', $dir, true);
             } else {
                 $this->addFileInfoMessage('Unable to delete directory', $dir, true);
             }
         }
     } else {
         $this->addFileErrorMessage('Unable to delete file', $path, true);
     }
 }
Пример #5
0
 /**
  * Import action
  *
  * @return void
  */
 protected function doActionImport()
 {
     foreach (\XLite\Logic\Import\Importer::getImportOptionsList() as $key) {
         \XLite\Core\Database::getRepo('XLite\\Model\\Config')->createOption(array('category' => 'Import', 'name' => $key, 'value' => isset(\XLite\Core\Request::getInstance()->options[$key]) ? \XLite\Core\Request::getInstance()->options[$key] : false));
     }
     \XLite\Core\Config::updateInstance();
     $dirTo = LC_DIR_VAR . \XLite\Logic\Import\Importer::getImportDir();
     if (!\Includes\Utils\FileManager::isExists($dirTo)) {
         \Includes\Utils\FileManager::mkdirRecursive($dirTo);
     }
     $filesToImport = array();
     if ($_FILES && isset($_FILES['files']) && $_FILES['files']['name'] && $_FILES['files']['name'][0] && \Includes\Utils\FileManager::isDirWriteable($dirTo)) {
         $list = glob($dirTo . LC_DS . '*');
         if ($list) {
             foreach ($list as $path) {
                 if (is_file($path)) {
                     \Includes\Utils\FileManager::deleteFile($path);
                 }
             }
         }
         $files = $_FILES['files'];
         foreach ($files['name'] as $key => $name) {
             $path = null;
             if ($name && UPLOAD_ERR_OK === $files['error'][$key]) {
                 $path = \Includes\Utils\FileManager::getUniquePath($dirTo, $name ?: $files['name'][$key]);
                 if (move_uploaded_file($files['tmp_name'][$key], $path)) {
                     if (\XLite\Core\Archive::getInstance()->isArchive($path) || 'csv' == substr(strrchr($path, '.'), 1)) {
                         $filesToImport[] = $path;
                     } else {
                         \XLite\Core\TopMessage::addError('The "{{file}}" is not CSV or archive', array('file' => $name));
                         \Includes\Utils\FileManager::deleteFile($path);
                     }
                 } else {
                     $path = null;
                 }
             }
             if (!$path) {
                 \XLite\Core\TopMessage::addError('The "{{file}}" file was not uploaded', array('file' => $name));
             }
         }
     }
     if ($filesToImport) {
         \XLite\Logic\Import\Importer::run(\XLite\Logic\Import\Importer::assembleImportOptions() + array('files' => $filesToImport));
     }
 }
Пример #6
0
 /**
  * Uninstall module
  *
  * @return void
  */
 protected function doActionUninstall()
 {
     $module = $this->getModule();
     if ($module) {
         $pack = new \XLite\Core\Pack\Module($module);
         $dirs = $pack->getDirs();
         $nonWritableDirs = array();
         // Check permissions
         foreach ($dirs as $dir) {
             if (!\Includes\Utils\FileManager::isDirWriteable($dir)) {
                 $nonWritableDirs[] = \Includes\Utils\FileManager::getRelativePath($dir, LC_DIR_ROOT);
             }
         }
         $params = array('name' => $module->getActualName());
         if (empty($nonWritableDirs)) {
             $yaml = \Includes\Utils\FileManager::read(\Includes\Utils\ModulesManager::getModuleYAMLFile($module->getAuthor(), $module->getName()));
             // Remove from FS
             foreach ($dirs as $dir) {
                 \Includes\Utils\FileManager::unlinkRecursive($dir);
             }
             // Disable this and depended modules
             \Includes\Utils\ModulesManager::disableModule($module->getActualName());
             \Includes\Utils\ModulesManager::removeModuleFromDisabledStructure($module->getActualName());
             // Remove from DB
             \XLite\Core\Database::getRepo('\\XLite\\Model\\Module')->delete($module);
             if ($module->getModuleID()) {
                 $message = 'A DB error occured while uninstalling the module "{{name}}"';
                 $this->showError(__FUNCTION__, $message, $params);
             } else {
                 if (!empty($yaml)) {
                     \XLite\Core\Database::getInstance()->unloadFixturesFromYaml($yaml);
                 }
                 $message = 'The module "{{name}}" has been uninstalled successfully';
                 $this->showInfo(__FUNCTION__, $message, $params);
             }
             // To restore previous state
             \XLite\Core\Marketplace::getInstance()->saveAddonsList(0);
             // Flag to rebuild cache
             \XLite::setCleanUpCacheFlag(true);
         } else {
             $message = 'Unable to delete module "{{name}}" files: some dirs have no writable permissions: {{dirs}}';
             $this->showError(__FUNCTION__, $message, $params + array('dirs' => implode(', ', $nonWritableDirs)));
         }
     }
 }
Пример #7
0
 /**
  * Check directory permissions and try to correct them
  *
  * @param string $dir Path to check
  *
  * @return void
  */
 protected static function checkPermissions($dir)
 {
     \Includes\Utils\FileManager::mkdirRecursive($dir);
     if (!\Includes\Utils\FileManager::isDirWriteable($dir)) {
         @\Includes\Utils\FileManager::chmod($dir, static::getDirDefaultPermissions($dir));
         if (!\Includes\Utils\FileManager::isDirWriteable($dir)) {
             static::fireDirPermissionsError($dir);
         }
     }
 }
Пример #8
0
 /**
  * Callback for a common operation for upgrade
  *
  * @param string  $path       File short path
  * @param boolean $isTestMode If in test mode
  *
  * @return void
  */
 protected function deleteFileCallback($path, $isTestMode)
 {
     if ($isTestMode) {
         if (!\Includes\Utils\FileManager::isDirWriteable($this->manageFile($path, 'getDir'))) {
             $this->addFileErrorMessage('File\'s directory is not writable', $path, false);
         }
     } elseif ($this->manageFile($path, 'deleteFile')) {
         $this->addFileInfoMessage('File is deleted', $path, true);
     } else {
         $this->addFileErrorMessage('Unable to delete file', $path, true);
     }
 }
Пример #9
0
 /**
  * Download pack
  *
  * @param \XLite\Core\Pack\APack $pack     Files to pack
  * @param boolean                $compress Flag OPTIONAL
  *  
  * @return void
  */
 protected static function download(\XLite\Core\Pack\APack $pack, $compress = true)
 {
     if (!\Includes\Utils\FileManager::isDir(LC_DIR_TMP)) {
         \Includes\Utils\FileManager::mkdir(LC_DIR_TMP);
     }
     if (!\Includes\Utils\FileManager::isDirWriteable(LC_DIR_TMP)) {
         \Includes\ErrorHandler::fireError('Directory "' . LC_DIR_TMP . '" is not writeable');
     }
     $path = LC_DIR_TMP . $pack->getName() . '.tar';
     $phar = static::pack($path, $pack->getDirectoryIterator(), $pack->getMetadata(), $compress);
     header('Content-Type: application/force-download');
     header('Content-Disposition: attachment; filename="' . basename($path) . '"');
     header('Content-Length: ' . filesize($path));
     echo \Includes\Utils\FileManager::read($path);
     \Includes\Utils\FileManager::deleteFile($path);
     exit(0);
 }
Пример #10
0
 /**
  * isDirExists
  *
  * @return boolean
  */
 public function isDirExists()
 {
     if (!is_dir(LC_DIR_BACKUP)) {
         \Includes\Utils\FileManager::mkdirRecursive(LC_DIR_BACKUP);
     }
     return \Includes\Utils\FileManager::isDirWriteable(LC_DIR_BACKUP);
 }