/** * Delete file * * @return afResponse */ protected function processDelete() { $file_path = $this->getParameter('file'); $file = afStudioFileCommandHelper::getPath($file_path); $permissions = new Permissions(); $is_writable = $permissions->isWritable(dirname($file)); if ($is_writable !== true) { return $is_writable; } if (!Util::removeResource($file)) { $message = afStudioFileCommandHelper::checkFolder($file_path); $message = is_string($message) ? $message : 'Cannot delete ' . (is_file($file) ? 'file' : 'directory') . ' ' . $file_path; return afResponseHelper::create()->success(false)->message($message); } return afResponseHelper::create()->success(true); }
/** * Rename module functionality * * @return afResponse * @author Sergey Startsev */ protected function processRename() { $type = $this->getParameter('type'); $place = $this->getParameter('place'); $name = $this->getParameter('name'); $renamed = $this->getParameter('renamed'); $permissions = new Permissions(); $is_writable = $permissions->isWritable(sfConfig::get('sf_apps_dir') . '/' . $place . '/modules/'); if ($is_writable !== true) { return $is_writable; } $response = afResponseHelper::create(); $root = afStudioUtil::getRootDir(); if (!afStudioModuleCommandHelper::isValidName($renamed)) { return afResponseHelper::create()->success(false)->message("Module name not valid, should contains only upper and lower case alphabet characters"); } $oldDir = "{$root}/{$type}s/{$place}/modules/{$name}/"; $newDir = "{$root}/{$type}s/{$place}/modules/{$renamed}/"; if (file_exists($newDir)) { return $response->success(false)->message("Module <b>{$renamed}</b> already exists inside <b>{$place}</b> {$type}!"); } afsFileSystem::create()->rename($oldDir, $newDir); // Rename in actions class afStudioModuleCommandHelper::renameAction($name, $renamed, $place, $type); if (!file_exists($oldDir) && file_exists($newDir)) { $console = afStudioConsole::getInstance()->execute(array('afs fix-perms', 'sf cc')); return $response->success(true)->message("Renamed module from <b>{$name}</b> to <b>{$renamed}</b> inside <b>{$place}</b> {$type}!")->console($console); } return $response->success(false)->message("Can't rename module from <b>{$name}</b> to <b>{$renamed}</b> inside <b>{$place}</b> {$type}!"); }
/** * Execute project functionality * * @param sfWebRequest $request * @return string - json * @author Sergey Startsev */ public function executeProject(sfWebRequest $request) { $permissions = new Permissions(); $is_writable = $permissions->isWritable(sfConfig::get('sf_root_dir') . '/cache/'); if ($is_writable !== true) { echo $is_writable; die; } $command = $request->getParameter('cmd'); if (!sfConfig::get('app_afs_projects_management_enabled') && in_array($command, array('saveWizard', 'CheckConfig'))) { //If projects management is disabled we allow only run and export, and helper processing commands throw new Exception('Projects management is disabled!'); } $response = afStudioCommand::process('project', $command, $request->getParameterHolder()->getAll()); if ($command == 'run') { afsNotificationPeer::log('[run] Run was executed on the project'); $response->query(sfContext::getInstance()->getController()->genUrl('@homepage')); } if ($command == 'get') { if ($response->getParameter(afResponseSuccessDecorator::IDENTIFICATOR)) { return $this->renderJson($response->getParameter(afResponseDataDecorator::IDENTIFICATOR_DATA)); } } if ($command == 'uploadWallpaper') { return $this->renderText($response->asJson()); } return $this->renderJson($response->asArray()); }
/** * Rename page processing * * @return afResponse * @author Sergey Startsev */ protected function processDelete() { $application = $this->getParameter('app'); $page_name = pathinfo($this->getParameter('page'), PATHINFO_FILENAME); $permissions = new Permissions(); $is_writable = $permissions->isWritable(sfConfig::get('sf_apps_dir') . '/' . $application . '/config/pages/'); if ($is_writable !== true) { return $is_writable; } $page = afsPageModelHelper::retrieve($page_name, $application); if ($page->isNew()) { return afResponseHelper::create()->success(false)->message("Page <b>{$page_name}</b> doesn't exists"); } $response = $page->delete(); if ($response->getParameter(afResponseSuccessDecorator::IDENTIFICATOR)) { $response->console(afStudioConsole::getInstance()->execute('sf cc')); } return $response; }
/** * Set wallpaper action * * @return afResponse * @author Sergey Startsev */ protected function processSetWallpaper() { $response = afResponseHelper::create(); $place = $this->getParameter('place', 'frontend'); $place_type = $this->getParameter('place_type', 'app'); $path = $this->getParameter('path'); $color = $this->getParameter('color'); $permissions = new Permissions(); $is_writable = $permissions->isWritable(sfConfig::get('sf_apps_dir') . '/' . $place . '/config/app.yml'); if ($is_writable !== true) { return $is_writable; } if (empty($path) && empty($color)) { return $response->success(false)->message("You should provide path for background wallpaper or background color"); } $app_path = sfConfig::get("sf_{$place_type}s_dir") . "/{$place}/config/app.yml"; $app_config = array(); if (file_exists($app_path)) { $app_config = sfYaml::load($app_path); } if (!empty($path)) { $app_config['all'][afStudioProjectCommandHelper::CONFIG_APP_APPFLOWER][afStudioProjectCommandHelper::CONFIG_DESKTOP_BACKGROUND_IMAGE] = $path; } if (!empty($color)) { $app_config['all'][afStudioProjectCommandHelper::CONFIG_APP_APPFLOWER][afStudioProjectCommandHelper::CONFIG_DESKTOP_BACKGROUND_COLOR] = $color; } $is_saved = file_put_contents($app_path, sfYaml::dump($app_config, 4)); return $response->success($is_saved)->message($is_saved ? "Wallpaper has been successfully saved" : "Some problems occured while save processing"); }