/**
  * 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);
 }
 /**
  * Delete xml functionality
  * 
  * @return afResponse
  * @author Sergey Startsev
  */
 protected function processDelete()
 {
     // init params
     $name = pathinfo($this->getParameter('name'), PATHINFO_FILENAME);
     $module = $this->getParameter('module');
     $model = $this->getParameter('model');
     $place = $this->getParameter('place');
     $place_type = $this->getParameter('type', 'app');
     if ($place_type == 'app') {
         $dir = 'apps';
     } elseif ($place_type == 'plugin') {
         $dir = 'plugins';
     }
     $permissions = new Permissions();
     $are_writable = $permissions->areWritable(array(sfConfig::get('sf_root_dir') . '/' . $dir . '/' . $place . '/modules/', sfConfig::get('sf_root_dir') . '/' . $dir . '/' . $place . '/modules/' . $module, sfConfig::get('sf_root_dir') . '/' . $dir . '/' . $place . '/modules/' . $module . '/actions/', sfConfig::get('sf_root_dir') . '/' . $dir . '/' . $place . '/modules/' . $module . '/templates/'));
     if ($are_writable !== true) {
         return $are_writable;
     }
     // retrieve widget
     $widget = afsWidgetModelHelper::retrieve($name, $module, $place, $place_type, $model);
     if (!$widget->isNew()) {
         $response = $widget->delete();
         if ($response->getParameter(afResponseSuccessDecorator::IDENTIFICATOR)) {
             $response->console(afStudioConsole::getInstance()->execute('sf cc'));
         }
         return $response;
     }
     return afResponseHelper::create()->success(false)->message("Widget <b>{$name}</b> doesn't exists");
 }
 /**
  * Set wdiget as homepage functionality
  * 
  * @return afResponse
  * @author Lukasz Wojciechowski
  */
 protected function processSetAsHomepage()
 {
     $widgetUri = $this->getParameter('widgetUri');
     $permissions = new Permissions();
     $is_readable_and_writable = $permissions->isReadableAndWritable(sfConfig::get('sf_apps_dir') . '/frontend/config/routing.yml');
     if ($is_readable_and_writable !== true) {
         return $is_readable_and_writable;
     }
     $response = afResponseHelper::create();
     $rm = new RoutingConfigurationManager();
     if ($rm->setHomepageUrlFromWidgetUri($widgetUri)) {
         return $response->success(true)->message("Homepage for your project is now set to <b>{$widgetUri}</b>");
     }
     return $response->success(false)->message("Can't set <b>{$widgetUri}</b> as homepage. An error occured.");
 }
 /**
  * Checking if model is writable
  *
  * @return true or afResponseHelper
  * @author Michal Piotrowski
  */
 public function isModelWritable()
 {
     $permissions = new Permissions();
     $are_writable = $permissions->areWritable(array(sfConfig::get('sf_config_dir') . '/schema.yml', sfConfig::get('sf_lib_dir') . '/filter', sfConfig::get('sf_lib_dir') . '/filter/base', sfConfig::get('sf_lib_dir') . '/form', sfConfig::get('sf_lib_dir') . '/form/base', sfConfig::get('sf_lib_dir') . '/model', sfConfig::get('sf_lib_dir') . '/model/map', sfConfig::get('sf_lib_dir') . '/model/migration', sfConfig::get('sf_lib_dir') . '/model/om'), true);
     return $are_writable;
 }
 /**
  * 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;
 }
 /**
  * Add plugin functionality
  * 
  * @return afResponse
  * @author Sergey Startsev
  */
 protected function processAdd()
 {
     $name = $this->getParameter('name');
     $root = sfConfig::get('sf_root_dir');
     $console = afStudioConsole::getInstance();
     $response = afResponseHelper::create();
     $filesystem = afsFileSystem::create();
     $permissions = new Permissions();
     $are_writable = $permissions->areWritable(array($root . "/plugins/"));
     if ($are_writable !== true) {
         return $are_writable;
     }
     $dir = "{$root}/plugins/{$name}";
     if (empty($name)) {
         return $response->success(false)->message('Please enter plugin name');
     }
     if (substr($name, -6) != 'Plugin') {
         return $response->success(false)->message("Plugin '{$name}' should Contains 'Plugin' in the end");
     }
     if (file_exists($dir)) {
         return $response->success(false)->message("Plugin '{$name}' already exists");
     }
     $dirs = array($dir, "{$dir}/config", "{$dir}/modules");
     foreach ($dirs as $dir) {
         $filesystem->mkdirs($dir);
     }
     if (file_exists($dir)) {
         // create config file with auto enable all modules in current plugin
         $created = afStudioUtil::writeFile("{$dir}/config/config.php", afStudioPluginCommandTemplate::config($name));
         $console_result = $console->execute(array('afs fix-perms', 'sf cc'));
         return $response->success(true)->message("Plugin '{$name}' successfully created")->console($console_result);
     }
     return $response->success(false)->message("Some problems to create dirs, please check permissions, and run fix-perms task");
 }
 /**
  * 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());
 }
 /**
  * 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");
 }