예제 #1
0
 /**
  * Clear css cache
  *
  * @return boolean
  */
 public static function clearCssCache()
 {
     try {
         return ApplicationFileSystem::deleteFiles(LayoutService::getLayoutCachePath());
     } catch (Exception $e) {
         ApplicationErrorLogger::log($e);
     }
     return false;
 }
예제 #2
0
 /**
  * Upload layout updates
  *
  * @param array $formData
  *      string login required
  *      string password required
  *      array layout required
  * @param string $host
  * @return array|string
  */
 public function uploadLayoutUpdates(array $formData, $host)
 {
     $uploadResult = true;
     try {
         // create a tmp dir
         $tmpDirName = $this->generateTmpDir();
         ApplicationFileSystemUtility::createDir($tmpDirName);
         // unzip a layout updates into the tmp dir
         $this->unzipFiles($formData['layout']['tmp_name'], $tmpDirName);
         // check the layout's config
         if (!file_exists($tmpDirName . '/update_layout_config.php')) {
             throw new LayoutException('Cannot define the layout\'s config file');
         }
         // get the layout's config
         $updateLayoutConfig = (include $tmpDirName . '/update_layout_config.php');
         // get updates params
         $layoutCompatable = !empty($updateLayoutConfig['compatable']) ? $updateLayoutConfig['compatable'] : null;
         $layoutName = !empty($updateLayoutConfig['layout_name']) ? $updateLayoutConfig['layout_name'] : null;
         $layoutVersion = !empty($updateLayoutConfig['version']) ? $updateLayoutConfig['version'] : null;
         $layoutVendor = !empty($updateLayoutConfig['vendor']) ? $updateLayoutConfig['vendor'] : null;
         $layoutVendorEmail = !empty($updateLayoutConfig['vendor_email']) ? $updateLayoutConfig['vendor_email'] : null;
         // check the layout existing
         if (!$layoutName) {
             throw new LayoutException('Layout not found');
         }
         $layoutInstalled = true;
         // get layout info from db
         if (null == ($layoutInfo = $this->getLayoutInfo($layoutName))) {
             // get info from config
             if (false === ($layoutInfo = $this->getCustomLayoutInstallConfig($layoutName))) {
                 // nothing to update
                 throw new LayoutException('Layout not found');
             }
             $layoutInstalled = false;
         }
         // compare the layout options
         if (!$layoutVendor || !$layoutVendorEmail || empty($layoutInfo['vendor']) || empty($layoutInfo['vendor_email']) || strcasecmp($layoutVendor, $layoutInfo['vendor']) != 0 || strcasecmp($layoutVendorEmail, $layoutInfo['vendor_email']) != 0) {
             throw new LayoutException('Layout not found');
         }
         if (!$layoutCompatable || true !== ($result = version_compare(SettingService::getSetting('application_generator_version'), $layoutCompatable, '>='))) {
             throw new LayoutException('These updates are not compatible with current CMS version');
         }
         // compare the layout versions
         if (!$layoutVersion || empty($layoutInfo['version']) || version_compare($layoutVersion, $layoutInfo['version']) <= 0) {
             throw new LayoutException('This layout updates are not necessary or not defined');
         }
         // clear caches
         $this->clearLayoutCaches();
         // upload layout's updates
         $this->uploadLayoutFiles($layoutName, $updateLayoutConfig, $tmpDirName, $host, $formData, false);
         // update version
         if ($layoutInstalled) {
             $update = $this->update()->table('layout_list')->set(['version' => $layoutVersion])->where(['name' => $layoutName]);
             $statement = $this->prepareStatementForSqlObject($update);
             $statement->execute();
         }
     } catch (Exception $e) {
         ApplicationErrorLogger::log($e);
         $uploadResult = $e->getMessage();
     }
     // remove the tmp dir
     if (file_exists($tmpDirName)) {
         ApplicationFileSystemUtility::deleteFiles($tmpDirName, [], false, true);
     }
     // fire the upload layout updates event
     if (true === $uploadResult) {
         LayoutEvent::fireUploadLayoutUpdatesEvent($layoutName);
     }
     // return an error description
     return $uploadResult;
 }
 /**
  * Upload custom module
  *
  * @param array $formData
  *      string login required
  *      string password required
  *      array module required
  * @param string $host
  * @return boolean|string
  */
 public function uploadCustomModule(array $formData, $host)
 {
     $uploadResult = true;
     try {
         // create a tmp dir
         $tmpDirName = $this->generateTmpDir();
         ApplicationFileSystemUtility::createDir($tmpDirName);
         // unzip a custom module into the tmp dir
         $this->unzipFiles($formData['module']['tmp_name'], $tmpDirName);
         // check the module's config
         if (!file_exists($tmpDirName . '/config.php')) {
             throw new ApplicationException('Cannot define the module\'s config file');
         }
         // get the module's config
         $moduleConfig = (include $tmpDirName . '/config.php');
         // get the module's path
         $modulePath = !empty($moduleConfig['module_path']) ? $tmpDirName . '/' . $moduleConfig['module_path'] : null;
         // check the module existing
         if (!$modulePath || !file_exists($modulePath) || !is_dir($modulePath)) {
             throw new ApplicationException('Cannot define the module\'s path into the config file');
         }
         if (!file_exists($modulePath . '/' . $this->moduleInstallConfig) || !file_exists($modulePath . '/' . $this->moduleConfig)) {
             throw new ApplicationException('Module not found');
         }
         // check the module layout existing
         $moduleLayoutPath = null;
         if (!empty($moduleConfig['layout_path'])) {
             $moduleLayoutPath = $tmpDirName . '/' . $moduleConfig['layout_path'];
             if (!file_exists($moduleLayoutPath) || !is_dir($moduleLayoutPath)) {
                 throw new ApplicationException('Cannot define the module\'s layout path into the config file');
             }
         }
         // check the module existing into modules and layouts dirs
         $moduleName = basename($modulePath);
         $globalModulePath = ApplicationService::getModulePath(false) . '/' . $moduleName;
         $moduleLayoutName = $moduleLayoutPath ? basename($moduleLayoutPath) : null;
         $localModulePath = APPLICATION_ROOT . '/' . $globalModulePath;
         $localModuleLayout = $moduleLayoutName ? ApplicationService::getBaseLayoutPath() . '/' . $moduleLayoutName : null;
         if (file_exists($localModulePath) || $localModuleLayout && file_exists($localModuleLayout)) {
             throw new ApplicationException('Module already uploaded');
         }
         // upload the module via FTP
         $ftp = new ApplicationFtpUtility($host, $formData['login'], $formData['password']);
         $ftp->createDirectory($globalModulePath);
         $ftp->copyDirectory($modulePath, $globalModulePath);
         // upload the module's layout
         if ($moduleLayoutPath) {
             $globalModuleLayoutPath = basename(APPLICATION_PUBLIC) . '/' . ApplicationService::getBaseLayoutPath(false) . '/' . $moduleLayoutName;
             $ftp->createDirectory($globalModuleLayoutPath);
             $ftp->copyDirectory($moduleLayoutPath, $globalModuleLayoutPath);
         }
     } catch (Exception $e) {
         ApplicationErrorLogger::log($e);
         $uploadResult = $e->getMessage();
     }
     // remove the tmp dir
     if (file_exists($tmpDirName)) {
         ApplicationFileSystemUtility::deleteFiles($tmpDirName, [], false, true);
     }
     // fire the upload custom module event
     if (true === $uploadResult) {
         ApplicationEvent::fireUploadCustomModuleEvent($moduleName);
     }
     return $uploadResult;
 }
예제 #4
0
 /**
  * Delete user's file or directory
  *
  * @param string $fileName
  * @param string $path
  * @return boolean
  */
 public function deleteUserFile($fileName, $path)
 {
     // process the directory path
     if (null == ($path = self::processDirectoryPath($path))) {
         return false;
     }
     $fullPath = self::getUserBaseFilesDir() . '/' . $path . '/' . $fileName;
     $isDirectory = is_dir($fullPath);
     $result = FileSystemUtility::deleteFiles($fullPath, [], false, true);
     // fire the event
     if ($result) {
         $isDirectory ? FileManagerEvent::fireDeleteDirectoryEvent($fullPath) : FileManagerEvent::fireDeleteFileEvent($fullPath);
     }
     return $result;
 }