/** * Installs this component from a zip file (if available) * @todo DB stuff (structure and data) * @todo check dependency versions * @todo activate templates */ public function install() { // Check (not already installed (different version), all dependencies installed) if (!$this->packageFile) { throw new SystemComponentException('Package file not available'); } if (!file_exists(ASCMS_APP_CACHE_FOLDER . '/meta.yml')) { throw new ReflectionComponentException('Invalid package file'); } if ($this->exists()) { throw new SystemComponentException('Component is already installed'); } $websitePath = \Env::get('cx')->getWebsiteDocumentRootPath(); // Read meta file $yaml = new \Symfony\Component\Yaml\Yaml(); $content = file_get_contents(ASCMS_APP_CACHE_FOLDER . '/meta.yml'); $meta = $yaml->load($content); // Check dependencies echo "Checking dependencies ... "; foreach ($meta['DlcInfo']['dependencies'] as $dependencyInfo) { $dependency = new static($dependencyInfo['name'], $dependencyInfo['type']); if (!$dependency->exists()) { throw new SystemComponentException('Dependency "' . $dependency->getName() . '" not met'); } } echo "Done \n"; // Copy ZIP contents echo "Copying files to installation ... "; $filesystem = new \Cx\Lib\FileSystem\FileSystem(); $filesystem->copyDir(ASCMS_APP_CACHE_FOLDER . '/DLC_FILES', ASCMS_APP_CACHE_FOLDER_WEB_PATH . '/DLC_FILES', '', $websitePath, '', '', true); echo "Done \n"; // Activate (if type is system or application) // TODO: templates need to be activated too! if ($this->componentType != 'core' && $this->componentType != 'core_module' && $this->componentType != 'module') { return; } // Copy ZIP contents (also copy meta.yml into component folder if type is system or application) try { $objFile = new \Cx\Lib\FileSystem\File(ASCMS_APP_CACHE_FOLDER . '/meta.yml'); $objFile->copy($this->getDirectory(false) . '/meta.yml'); } catch (\Cx\Lib\FileSystem\FileSystemException $e) { \DBG::msg($e->getMessage()); } echo "Importing component data (structure & data) ... "; if (!file_exists($this->getDirectory(false) . "/Model/Yaml")) { $this->importStructureFromSql(); } else { $this->createTablesFromYaml(); } $this->importDataFromSql(); echo "Done \n"; // Activate this component echo "Activating component ... "; $this->activate(); echo "Done \n"; }
function copyCxFilesToRoot($src, $dst) { static $copiedCxFilesIndex = 0; $src = str_replace('\\', '/', $src); $dst = str_replace('\\', '/', $dst); $dir = opendir($src); $arrCurrentFolderStructure = array(); while ($file = readdir($dir)) { if (!in_array($file, array('.', '..'))) { $arrCurrentFolderStructure[] = $file; } } sort($arrCurrentFolderStructure); if (!isset($_SESSION['contrexx_update']['copiedCxFilesTotal'])) { $_SESSION['contrexx_update']['copiedCxFilesTotal'] = 0; } foreach ($arrCurrentFolderStructure as $file) { if (!checkMemoryLimit() || !checkTimeoutLimit()) { $_SESSION['contrexx_update']['copiedCxFilesIndex'] = $copiedCxFilesIndex; return 'timeout'; } $srcPath = $src . '/' . $file; $dstPath = $dst . '/' . $file; if (is_dir($srcPath)) { \Cx\Lib\FileSystem\FileSystem::make_folder($dstPath); $status = copyCxFilesToRoot($srcPath, $dstPath); if ($status !== true) { return $status; } } else { $copiedCxFilesIndex++; if (isset($_SESSION['contrexx_update']['copiedCxFilesIndex']) && $copiedCxFilesIndex <= $_SESSION['contrexx_update']['copiedCxFilesIndex']) { continue; } $_SESSION['contrexx_update']['copiedCxFilesTotal'] = $_SESSION['contrexx_update']['copiedCxFilesTotal'] + 1; try { // rename the file if its exists on customizing if (!renameCustomizingFile($dstPath)) { return false; } if (!verifyMd5SumOfFile($dstPath, $srcPath)) { if (!backupModifiedFile($dstPath)) { return false; } } $objFile = new \Cx\Lib\FileSystem\File($srcPath); $objFile->copy($dstPath, true); } catch (\Exception $e) { $copiedCxFilesIndex--; $_SESSION['contrexx_update']['copiedCxFilesIndex'] = $copiedCxFilesIndex; $_SESSION['contrexx_update']['copiedCxFilesTotal'] = $_SESSION['contrexx_update']['copiedCxFilesTotal'] - 1; setUpdateMsg('Folgende Datei konnte nicht installiert werden:<br />' . $dstPath); setUpdateMsg('Fehler: ' . $e->getMessage()); setUpdateMsg('<br />Häufigste Ursache dieses Problems ist, dass zur Ausführung dieses Vorgangs die benötigten Schreibrechte nicht vorhanden sind. Prüfen Sie daher, ob die FTP-Konfiguration in der Datei <strong>config/configuration.php</strong> korrekt eingerichtet ist.'); return false; } } } closedir($dir); return true; }
/** * Copies a file from the source to the target path * * If $force is true, any destination file will be overwritten. * @param string $source_path The path of the source file * @param string $target_path The path of the target file * @param string $force Overwrite if true * @return boolean True on success, false otherwise */ static function copy_file($source_path, $target_path, $force = false) { if (self::exists($target_path) && !$force) { return false; } try { $objFile = new \Cx\Lib\FileSystem\File($source_path); $objFile->copy($target_path, $force); } catch (\Cx\Lib\FileSystem\FileSystemException $e) { \DBG::msg($e->getMessage()); } }
/** * the upload is finished * rewrite the names * write the uploaded files to the database * * @param string $tempPath the temporary file path * @param string $tempWebPath the temporary file path which is accessable by web browser * @param array $data the data which are attached by uploader init method * @param integer $uploadId the upload id * @param array $fileInfos the file infos * * @return array the target paths */ public static function notesUploadFinished($tempPath, $tempWebPath, $data, $uploadId, $fileInfos, $response) { global $objDatabase, $objFWUser; $cx = \Cx\Core\Core\Controller\Cx::instanciate(); $depositionTarget = $cx->getWebsiteImagesCrmPath() . '/'; //target folder $h = opendir($tempPath); if ($h) { while (false != ($file = readdir($h))) { $info = pathinfo($file); //skip . and .. if ($file == '.' || $file == '..') { continue; } if ($file != '..' && $file != '.') { //do not overwrite existing files. $prefix = ''; while (file_exists($depositionTarget . $prefix . $file)) { if (empty($prefix)) { $prefix = 0; } $prefix++; } // move file try { $objFile = new \Cx\Lib\FileSystem\File($tempPath . '/' . $file); $objFile->copy($depositionTarget . $prefix . $file, false); // create thumbnail if (empty($objImage)) { $objImage = new \ImageManager(); } $imageName = trim($prefix . $file); $objImage->_createThumbWhq($cx->getWebsiteImagesCrmPath() . '/', $cx->getWebsiteImagesCrmWebPath() . '/', $imageName, 16, 16, 90, '_16X16.thumb'); $_SESSION['importFilename'] = $imageName; } catch (\Cx\Lib\FileSystem\FileSystemException $e) { \DBG::msg($e->getMessage()); } } $arrFiles[] = $file; } closedir($h); } // return web- and filesystem path. files will be moved there. return array($tempPath, $tempWebPath); }
/** * Create default theme files * * \Cx\Core\View\Model\Entity\Theme $theme */ private function createDefaultFiles(\Cx\Core\View\Model\Entity\Theme $theme) { global $_ARRAYLANG; foreach ($this->directories as $dir) { if (!\Cx\Lib\FileSystem\FileSystem::make_folder($this->path . $theme->getFoldername() . '/' . $dir)) { \Message::add(sprintf($_ARRAYLANG['TXT_UNABLE_TO_CREATE_FILE'], contrexx_raw2xhtml($theme->getFoldername() . '/' . $dir)), \Message::CLASS_ERROR); return false; } } //copy "not available" preview.gif as default preview image $previewImage = $this->path . $theme->getFoldername() . \Cx\Core\View\Model\Entity\Theme::THEME_PREVIEW_FILE; if (!file_exists($previewImage)) { try { $objFile = new \Cx\Lib\FileSystem\File(\Env::get('cx')->getCodeBaseDocumentRootPath() . \Cx\Core\View\Model\Entity\Theme::THEME_DEFAULT_PREVIEW_FILE); $objFile->copy($previewImage); } catch (\Cx\Lib\FileSystem\FileSystemException $e) { \DBG::msg($e->getMessage()); \Message::add(sprintf($_ARRAYLANG['TXT_UNABLE_TO_CREATE_FILE'], contrexx_raw2xhtml($theme->getFoldername() . \Cx\Core\View\Model\Entity\Theme::THEME_PREVIEW_FILE)), \Message::CLASS_ERROR); return false; } } foreach ($this->filenames as $file) { // skip component.yml, will be created later if ($file == 'component.yml') { continue; } $filePath = $this->path . $theme->getFoldername() . '/' . $file; if (!file_exists($filePath)) { try { $objFile = new \Cx\Lib\FileSystem\File($filePath); $objFile->touch(); } catch (\Cx\Lib\FileSystem\FileSystemException $e) { \DBG::msg($e->getMessage()); \Message::add(sprintf($_ARRAYLANG['TXT_UNABLE_TO_CREATE_FILE'], contrexx_raw2xhtml($theme->getFoldername() . '/' . $file)), \Message::CLASS_ERROR); return false; } } } // write component.yml file // this line will create a default component.yml file try { $this->themeRepository->loadComponentData($theme); $this->themeRepository->convertThemeToComponent($theme); } catch (\Exception $e) { \DBG::msg($e->getMessage()); \Message::add($_ARRAYLANG['TXT_UNABLE_TO_CONVERT_THEME_TO_COMPONENT'], \Message::CLASS_ERROR); } return true; }