コード例 #1
0
 /**
  * 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;
 }
コード例 #2
0
 /**
  * Upload layout files
  *
  * @param string $layoutName
  * @param array $layoutConfig
  * @param string $tmpDirName
  * @param string $host
  * @param array $formData
  *      string login required
  *      string password required
  *      array layout required
  * @param boolean $checkInstallConfig
  * @throws Layout\Exception\LayoutException
  * return void
  */
 protected function uploadLayoutFiles($layoutName, array $layoutConfig, $tmpDirName, $host, array $formData, $checkInstallConfig = true)
 {
     $updated = false;
     // get the layout's path
     $layoutPath = !empty($layoutConfig['layout_path']) ? $tmpDirName . '/' . $layoutConfig['layout_path'] : null;
     // check the layout existing
     if ($layoutPath && (!file_exists($layoutPath) || !is_dir($layoutPath))) {
         throw new LayoutException('Cannot define the layout\'s path into the config file');
     }
     $globalLayoutPath = basename(APPLICATION_PUBLIC) . '/' . ApplicationService::getLayoutPath(false) . '/' . $layoutName;
     $localLayoutPath = dirname(APPLICATION_PUBLIC) . '/' . $globalLayoutPath;
     // check the layout install config
     if ($checkInstallConfig) {
         if (!file_exists($layoutPath . '/' . $this->layoutInstallConfig)) {
             throw new LayoutException('Layout not found');
         }
         if (file_exists($localLayoutPath)) {
             throw new LayoutException('Layout already uploaded');
         }
     }
     $ftp = new ApplicationFtpUtility($host, $formData['login'], $formData['password']);
     if ($layoutPath) {
         // upload the layout via FTP
         $ftp->createDirectory($globalLayoutPath, true);
         $ftp->copyDirectory($layoutPath, $globalLayoutPath);
         $updated = true;
     }
     // check modules templates
     if (!empty($layoutConfig['module_path']) && is_array($layoutConfig['module_path'])) {
         $globalModulePath = ApplicationService::getModulePath(false);
         $localModulePath = APPLICATION_ROOT . '/' . $globalModulePath;
         // upload modules templates
         foreach ($layoutConfig['module_path'] as $moduleName => $template) {
             // skip non existing modules
             if (!file_exists($localModulePath . '/' . $moduleName)) {
                 continue;
             }
             $templateDir = $tmpDirName . '/' . $template;
             // check the template existing
             if (!file_exists($templateDir) || !is_dir($templateDir)) {
                 throw new LayoutException('Cannot define the template\'s path into the config file');
             }
             $moduleTemplateDir = $globalModulePath . '/' . $moduleName . '/' . ApplicationService::getModuleViewDir() . '/' . $layoutName;
             $ftp->createDirectory($moduleTemplateDir, true);
             $ftp->copyDirectory($templateDir, $moduleTemplateDir);
             $updated = true;
         }
     }
     if (!$updated) {
         throw new LayoutException('Nothing to update the layout');
     }
 }