/** * Execute this command * @param array $arguments Array of commandline arguments */ public function execute(array $arguments) { if (!$this->interface->yesNo('Removing workbench requires re-installing workbench to use it again. Are you sure?')) { return; } // Remove component from Db and FileSystem $component = new \Cx\Core\Core\Model\Entity\ReflectionComponent('Workbench', 'core_module'); $component->remove(); // Remove additional files (config, command line script) foreach ($this->interface->getWorkbench()->getFileList() as $file) { if (is_dir($file)) { \Cx\Lib\FileSystem\FileSystem::delete_folder(ASCMS_DOCUMENT_ROOT . $file, true); } else { \Cx\Lib\FileSystem\FileSystem::delete_file(ASCMS_DOCUMENT_ROOT . $file); } } $this->interface->show('Done'); }
public function cleanTempPaths() { $dirs = array(); if ($dh = opendir(ASCMS_TEMP_PATH)) { while (($file = readdir($dh)) !== false) { if (is_dir(ASCMS_TEMP_PATH . '/' . $file)) { $dirs[] = $file; } } closedir($dh); } $sessionPaths = preg_grep('#^' . $this->sessionPathPrefix . '[0-9A-F]{32}$#i', $dirs); $sessions = array(); $query = 'SELECT `sessionid` FROM `' . DBPREFIX . 'sessions`'; $objResult = $this->_objDb->Execute($query); while (!$objResult->EOF) { $sessions[] = $objResult->fields['sessionid']; $objResult->MoveNext(); } foreach ($sessionPaths as $sessionPath) { if (!in_array(substr($sessionPath, strlen($this->sessionPathPrefix)), $sessions)) { \Cx\Lib\FileSystem\FileSystem::delete_folder(ASCMS_TEMP_WEB_PATH . '/' . $sessionPath, true); } } }
/** * Clear temp path's which are not in use */ public function cleanTempPaths() { $dirs = array(); if ($dh = opendir(ASCMS_TEMP_PATH)) { while (($file = readdir($dh)) !== false) { if (is_dir(ASCMS_TEMP_PATH . '/' . $file)) { $dirs[] = $file; } } closedir($dh); } // depending on the php setting session.hash_function and session.hash_bits_per_character // the length of the session-id varies between 22 and 40 characters. $sessionPaths = preg_grep('#^' . $this->sessionPathPrefix . '[0-9A-Z,-]{22,40}$#i', $dirs); $sessions = array(); $query = 'SELECT `sessionid` FROM `' . DBPREFIX . 'sessions`'; $objResult = \Env::get('db')->Execute($query); while (!$objResult->EOF) { $sessions[] = $objResult->fields['sessionid']; $objResult->MoveNext(); } foreach ($sessionPaths as $sessionPath) { if (!in_array(substr($sessionPath, strlen($this->sessionPathPrefix)), $sessions)) { \Cx\Lib\FileSystem\FileSystem::delete_folder(ASCMS_TEMP_WEB_PATH . '/' . $sessionPath, true); } } }
/** * {@inheritdoc} */ protected function doFlush() { foreach (new \DirectoryIterator($this->directory) as $file) { if ($file->isDir() && !$file->isDot()) { \Cx\Lib\FileSystem\FileSystem::delete_folder(str_replace('\\', '/', $file->getPath() . '/' . $file->getFilename()), true); } } return true; }
protected function cleanup() { \Cx\Lib\FileSystem\FileSystem::delete_folder($this->cx->getWebsiteTempPath() . '/workbench', true); \Cx\Lib\FileSystem\FileSystem::make_folder($this->cx->getWebsiteTempPath() . '/workbench'); }
/** * delete the file or directory * * @param array $params supplied arguments from JsonData-request * @return string */ public function delete($params) { global $_ARRAYLANG, $objInit; $operation = isset($params['post']['reset']) && !empty($params['post']['reset']) ? 'RESET' : 'DELETE'; $_ARRAYLANG = $objInit->loadLanguageData('ViewManager'); if (empty($params['post']['themes']) || empty($params['post']['themesPage'])) { return array('status' => 'error', 'message' => $_ARRAYLANG['TXT_THEME_OPERATION_FAILED_FOR_EMPTY_PARAMS']); } $filePath = $params['post']['themesPage']; $currentThemeFolder = \Env::get('cx')->getWebsiteThemesPath() . '/' . $params['post']['themes'] . '/'; $pathStripped = ltrim($params['post']['themesPage'], '/'); if (empty($pathStripped)) { return array('status' => 'error', 'message' => $_ARRAYLANG['TXT_THEME_OPERATION_FAILED_FOR_EMPTY_PARAMS']); } if (!\Cx\Lib\FileSystem\FileSystem::exists($currentThemeFolder . $filePath) && \Cx\Core\ViewManager\Controller\ViewManager::isFileTypeComponent($filePath)) { // resolve the component file $componentFilePath = \Cx\Core\ViewManager\Controller\ViewManager::getComponentFilePath($filePath, false); if ($componentFilePath && \Cx\Lib\FileSystem\FileSystem::exists($currentThemeFolder . $componentFilePath)) { // file exists $filePath = \Cx\Core\ViewManager\Controller\ViewManager::getComponentFilePath($filePath, false); } else { // file not exists may be a folder $filePath = \Cx\Core\ViewManager\Controller\ViewManager::replaceComponentFolderByItsType($filePath); } } if (\Cx\Lib\FileSystem\FileSystem::exists($currentThemeFolder . $filePath)) { if (is_dir($currentThemeFolder . $filePath)) { $status = \Cx\Lib\FileSystem\FileSystem::delete_folder($currentThemeFolder . $filePath, true); $succesMessage = sprintf($_ARRAYLANG['TXT_THEME_FOLDER_' . $operation . '_SUCCESS'], contrexx_input2xhtml($pathStripped)); } else { $status = \Cx\Lib\FileSystem\FileSystem::delete_file($currentThemeFolder . $filePath); $succesMessage = sprintf($_ARRAYLANG['TXT_THEME_FILE_' . $operation . '_SUCCESS'], contrexx_input2xhtml($pathStripped)); } if (!$status) { return array('status' => 'error', 'reload' => false, 'message' => $_ARRAYLANG['TXT_THEME_' . $operation . '_FAILED']); } return array('status' => 'success', 'reload' => true, 'message' => $succesMessage); } return array('status' => 'error', 'reload' => false, 'message' => sprintf($_ARRAYLANG['TXT_THEME_OPERATION_FAILED_FOR_FILE_NOT_EXITS'], contrexx_input2xhtml($filePath))); }
/** * Get the serialized Delta * * This loads the serialized Delta and calls applyNext() on it * until returns false. * * @return null */ public function applyDelta() { //Check if any of the update process is interrupt state, then rollback to old state $deltaRepository = new \Cx\Core_Modules\Update\Model\Repository\DeltaRepository(); $deltas = $deltaRepository->findAll(); if (empty($deltas)) { return; } asort($deltas); //set the website as Offline mode \Cx\Core\Setting\Controller\Setting::init('MultiSite', '', 'FileSystem'); \Cx\Core\Setting\Controller\Setting::set('websiteState', \Cx\Core_Modules\MultiSite\Model\Entity\Website::STATE_OFFLINE); \Cx\Core\Setting\Controller\Setting::update('websiteState'); $status = true; $yamlFile = null; foreach ($deltas as $delta) { $status = $delta->applyNext(); $delta->setRollback($delta->getRollback() ? false : true); $deltaRepository->flush(); if (!$status) { //Rollback to old state $this->rollBackDelta(); //Rollback the codebase changes(settings.php, configuration.php and website codebase in manager and service) $yamlFile = $this->cx->getWebsiteTempPath() . '/Update/' . $this->pendingCodeBaseChangesYml; if (file_exists($yamlFile)) { $pendingCodeBaseChanges = $this->getUpdateWebsiteDetailsFromYml($yamlFile); $oldCodeBase = $pendingCodeBaseChanges['PendingCodeBaseChanges']['oldCodeBaseId']; $latestCodeBase = $pendingCodeBaseChanges['PendingCodeBaseChanges']['latestCodeBaseId']; //Register YamlSettingEventListener \Cx\Core\Config\Controller\ComponentController::registerYamlSettingEventListener(); //Update codeBase in website $this->updateCodeBase($latestCodeBase, null, $oldCodeBase); //Update website codebase in manager and service \Cx\Core\Setting\Controller\Setting::init('MultiSite', '', 'FileSystem'); $websiteName = \Cx\Core\Setting\Controller\Setting::getValue('websiteName', 'MultiSite'); $params = array('websiteName' => $websiteName, 'codeBase' => $oldCodeBase); \Cx\Core_Modules\MultiSite\Controller\JsonMultiSiteController::executeCommandOnMyServiceServer('updateWebsiteCodeBase', $params); } break; } } //Remove the folder '/tmp/Update', After the completion of rollback or Non-rollback process $tmpUpdateFolderPath = \Cx\Core\Core\Controller\Cx::instanciate()->getWebsiteTempPath() . '/Update'; if (file_exists($tmpUpdateFolderPath)) { \Cx\Lib\FileSystem\FileSystem::delete_folder($tmpUpdateFolderPath, true); } //set the website back to Online mode \Cx\Core\Setting\Controller\Setting::set('websiteState', \Cx\Core_Modules\MultiSite\Model\Entity\Website::STATE_ONLINE); \Cx\Core\Setting\Controller\Setting::update('websiteState'); }
public function removeFile(File $file) { global $_ARRAYLANG; $filename = $file->getFullName(); $strPath = $file->getPath(); if (!empty($filename) && !empty($strPath)) { if (is_dir($this->getFullPath($file) . $filename)) { if (\Cx\Lib\FileSystem\FileSystem::delete_folder($this->getFullPath($file) . $filename, true)) { return sprintf($_ARRAYLANG['TXT_FILEBROWSER_DIRECTORY_SUCCESSFULLY_REMOVED'], $filename); } else { return sprintf($_ARRAYLANG['TXT_FILEBROWSER_DIRECTORY_UNSUCCESSFULLY_REMOVED'], $filename); } } else { if (\Cx\Lib\FileSystem\FileSystem::delete_file($this->getFullPath($file) . $filename)) { $this->removeThumbnails($file); return sprintf($_ARRAYLANG['TXT_FILEBROWSER_FILE_SUCCESSFULLY_REMOVED'], $filename); } else { return sprintf($_ARRAYLANG['TXT_FILEBROWSER_FILE_UNSUCCESSFULLY_REMOVED'], $filename); } } } return sprintf($_ARRAYLANG['TXT_FILEBROWSER_FILE_UNSUCCESSFULLY_REMOVED'], $filename); }
/** * Delete Selected Folder and its contents recursively upload form * * @global array $_ARRAYLANG * @param string $dirName * @return boolean true if directory and its contents deleted successfully and false if it failed */ private function deleteDirectory($dirName) { global $_ARRAYLANG; try { \Cx\Lib\FileSystem\FileSystem::delete_folder($dirName, true); \Message::ok($_ARRAYLANG['TXT_MEDIA_FOLDER_DELETED_SUCESSFULLY']); } catch (\Cx\Lib\FileSystem\FileSystemException $e) { \DBG::msg($e->getMessage()); return false; } return true; }
/** * Removes this component * * This might not work perfectly for legacy components, since there could * be files outside the component's directory! * Be sure there is no other component relying on this one! */ public function remove() { // remove from db $this->removeFromDb(); // if there are no files, quit if (!$this->exists()) { return; } // remove from fs \Cx\Lib\FileSystem\FileSystem::delete_folder($this->getDirectory(), true); }
/** * Notifies the callback. Invoked on upload completion. */ public function notifyCallback() { //temporary path where files were uploaded $tempDir = '/upload_' . $this->uploadId; $tempPath = $_SESSION->getTempPath() . $tempDir; $tempWebPath = $_SESSION->getWebTempPath() . $tempDir; //we're going to call the callbck, so the data is not needed anymore //well... not quite sure. need it again in contact form. //TODO: code session cleanup properly if time. //$this->cleanupCallbackData(); $classFile = $this->callbackData[0]; //call the callback, get return code if ($classFile != null) { if (!file_exists($classFile)) { throw new UploaderException("Class file '{$classFile}' specified for callback does not exist!"); } require_once $this->callbackData[0]; } $originalFileNames = array(); if (isset($_SESSION['upload']['handlers'][$this->uploadId]['originalFileNames'])) { $originalFileNames = $_SESSION['upload']['handlers'][$this->uploadId]['originalFileNames']; } //various file infos are passed via this array $fileInfos = array('originalFileNames' => $originalFileNames); $response = null; //the response data. if (isset($_SESSION['upload']['handlers'][$this->uploadId]['response_data'])) { $response = UploadResponse::fromSession($_SESSION['upload']['handlers'][$this->uploadId]['response_data']); } else { $response = new UploadResponse(); } $ret = call_user_func(array($this->callbackData[1], $this->callbackData[2]), $tempPath, $tempWebPath, $this->getData(), $this->uploadId, $fileInfos, $response); //clean up session: we do no longer need the array with the original file names unset($_SESSION['upload']['handlers'][$this->uploadId]['originalFileNames']); //same goes for the data //if(isset($_SESSION['upload']['handlers'][$this->uploadId]['data'])) // TODO: unset this when closing the uploader dialog, but not before // unset($_SESSION['upload']['handlers'][$this->uploadId]['data']); if (\Cx\Lib\FileSystem\FileSystem::exists($tempWebPath)) { //the callback could have returned a path where he wants the files moved to // check that $ret[1] is not empty is VERY important!!! if (!is_null($ret) && !empty($ret[1])) { //we need to move the files //gather target information $path = pathinfo($ret[0]); $pathWeb = pathinfo($ret[1]); //make sure the target directory is writable \Cx\Lib\FileSystem\FileSystem::makeWritable($pathWeb['dirname'] . '/' . $path['basename']); //revert $path and $pathWeb to whole path instead of pathinfo path for copying $path = $path['dirname'] . '/' . $path['basename'] . '/'; $pathWeb = $pathWeb['dirname'] . '/' . $pathWeb['basename'] . '/'; //trailing slash needed for File-class calls $tempPath .= '/'; $tempWebPath .= '/'; //move everything uploaded to target dir $h = opendir($tempPath); $im = new \ImageManager(); while (false != ($f = readdir($h))) { //skip . and .. if ($f == '.' || $f == '..') { continue; } //TODO: if return value = 'error' => react \Cx\Lib\FileSystem\FileSystem::move($tempWebPath . $f, $pathWeb . $f, true); if ($im->_isImage($path . $f)) { $im->_createThumb($path, $pathWeb, $f); } $response->increaseUploadedFilesCount(); } closedir($h); } else { // TODO: what now???? } //delete the folder \Cx\Lib\FileSystem\FileSystem::delete_folder($tempWebPath, true); } else { // TODO: output error message to user that no files had been uploaded!!! } $response->uploadFinished(); $_SESSION['upload']['handlers'][$this->uploadId]['response_data'] = $response->toSessionValue(); }
public function removeFile(File $file) { global $_ARRAYLANG; if ($file->getExtension() == '' && is_dir($this->rootPath . ltrim($file->getPath(), '.') . '/' . $file->getName())) { $filename = $file->getName(); } else { $filename = $file->getName() . '.' . $file->getExtension(); } $strPath = $file->getPath(); if (!empty($filename) && !empty($strPath)) { if (is_dir($this->rootPath . ltrim($file->getPath(), '.') . '/' . $file->getName())) { if (\Cx\Lib\FileSystem\FileSystem::delete_folder($this->rootPath . $strPath . $filename, true)) { return sprintf($_ARRAYLANG['TXT_FILEBROWSER_DIRECTORY_SUCCESSFULLY_REMOVED'], $filename); } else { return sprintf($_ARRAYLANG['TXT_FILEBROWSER_DIRECTORY_UNSUCCESSFULLY_REMOVED'], $filename); } } else { if (\Cx\Lib\FileSystem\FileSystem::delete_file($this->rootPath . '/' . $strPath . '/' . $filename)) { return sprintf($_ARRAYLANG['TXT_FILEBROWSER_FILE_SUCCESSFULLY_REMOVED'], $filename); } else { return sprintf($_ARRAYLANG['TXT_FILEBROWSER_FILE_UNSUCCESSFULLY_REMOVED'], $filename); } } } return sprintf($_ARRAYLANG['TXT_FILEBROWSER_FILE_UNSUCCESSFULLY_REMOVED'], $filename); }