/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { $types = $options['type']; $refresh = $options['refresh']; $models = afStudioCommand::process('model', 'get')->getParameter(afResponseDataDecorator::IDENTIFICATOR_DATA); foreach ($models as $model) { $this->logSection('model', $model['text']); $this->createTask('afs:generate-widget')->run(array(), array('model' => $model['text'], 'type' => $types, 'refresh' => $refresh)); } }
/** * Add new plugin action * * @param sfWebRequest $request * @author Sergey Startsev */ public function executeAdd(sfWebRequest $request) { $parameters = array('name' => $request->getParameter('name')); return $this->renderJson(afStudioCommand::process('plugin', 'add', $parameters)->asArray()); }
/** * Test not existed command, catch expected exception via pseudo-annotation * * @expectedException afStudioCommandException * * @author Sergey Startsev */ public function testNotExistedCommand() { $response = afStudioCommand::process('notExistedCommand', 'notExistedMethod'); }
/** * Checking database functionality * * @param sfWebRequest $request * @author Sergey Startsev */ public function executeSaveWizard(sfWebRequest $request) { $parameters = array('userForm' => $request->getParameter('userForm'), 'name' => $request->getParameter('name'), 'template' => $request->getParameter('template'), 'path' => $request->getParameter('path')); $response = afStudioCommand::process('project', 'saveWizard', $parameters); return $this->renderJson($response); }
/** * Set as homepage module action * * @param sfWebRequest $request * @author Radu Topala */ public function executeSetAsHomepage(sfWebRequest $request) { $parameters = array('widgetUri' => $request->getParameter('widgetUri')); return $this->renderJson(afStudioCommand::process('layout', 'setAsHomepage', $parameters)->asArray()); }
/** * Testing delete non existen model * * @depends testDeleteModel * * @author Sergey Startsev */ public function testDeleteNonExistenModel() { $response = afStudioCommand::process('model', 'delete', $this->getParameters()); $this->assertTrue($response instanceof afResponse, 'response should be afResponse instance'); $this->assertTrue($response->hasParameter(afResponseSuccessDecorator::IDENTIFICATOR), "response from command delete should contains 'success'"); $this->assertFalse($response->getParameter(afResponseSuccessDecorator::IDENTIFICATOR), "response should be false - model should be already deleted"); }
/** * Delete module view action * * @param sfWebRequest $request * @author Sergey Startsev */ public function executeDeleteView(sfWebRequest $request) { $parameters = array('type' => $request->getParameter('type', 'app'), 'place' => $request->getParameter('place'), 'module' => $request->getParameter('moduleName'), 'name' => $request->getParameter('name')); return $this->renderJson(afStudioCommand::process('widget', 'delete', $parameters)->asArray()); }
/** * Execute validate schema command * * @return boolean * @author Sergey Startsev */ private function validateSchema() { $response = afStudioCommand::process('model', 'validateSchema'); if (!$response->getParameter(afResponseSuccessDecorator::IDENTIFICATOR)) { throw new sfCommandException(implode("\n", $response->getParameter(afResponseMessageDecorator::IDENTIFICATOR))); } return true; }
/** * @see sfTask */ protected function execute($arguments = array(), $options = array()) { // XmlParser uses sfContext that not defined by default - so we create instance here sfContext::createInstance(ProjectConfiguration::getApplicationConfiguration($this->getFirstApplication(), 'dev', true)); // pushed params $model = $options['model']; $module = !empty($options['module']) ? $options['module'] : lcfirst(sfInflector::camelize($model)); $types = $options['type']; $fields = $options['fields']; $placeType = $options['place-type']; $place = $options['place']; $refresh = $options['refresh'] == 'true' || $options['refresh'] === true ? true : false; // required params if (empty($model)) { throw new sfCommandException("Option 'model' should be defined"); } // place params validation if (!in_array($placeType, $this->place_types)) { throw new sfCommandException("Place type '{$placeType}' doesn't allowed"); } if (!in_array($place, $this->getPlaces($placeType))) { throw new sfCommandException("Place '{$place}' wasn't found in {$placeType}s area"); } if (!afStudioCommand::process('model', 'has', array('model' => $model))->getParameter(afResponseSuccessDecorator::IDENTIFICATOR)) { throw new sfCommandException("Model '{$model}' doesn't exists"); } $response = afStudioCommand::process('model', 'read', array('model' => $model)); $widget_fields = $model_fields = $response->getParameter(afResponseDataDecorator::IDENTIFICATOR_DATA); if (!empty($fields)) { $widget_model_fields = array(); foreach ($model_fields as $field) { $widget_model_fields[$field['name']] = $field; } $widget_fields = array(); $requested_fields = explode(',', $fields); // validate fields - if commented next 3 lines - will be used optimistic checking // foreach ($requested_fields as $field) { // if (!array_key_exists($field, $widget_model_fields)) throw new sfCommandException("Field '{$field}' wasn't found in model fields"); // } foreach ($model_fields as $field) { if (in_array($field['name'], $requested_fields)) { $widget_fields[] = $field; } } if (empty($widget_fields)) { $widget_fields = $model_fields; } } foreach (explode(',', $types) as $type) { if (!in_array($type, $this->types)) { throw new sfCommandException("Type '{$type}' doesn't exists or not allowed"); } $widget_name = lcfirst(sfInflector::camelize($model)) . ucfirst(strtolower($type)); $widget_path = "{$placeType}s/{$place}/modules/{$module}/config/{$widget_name}.xml"; if (file_exists(sfConfig::get('sf_root_dir') . "/{$widget_path}")) { if (!$refresh) { $this->logSection('exists', $widget_path, null, 'ERROR'); continue; } else { afStudioCommand::process('widget', 'delete', array('type' => $placeType, 'place' => $place, 'module' => $module, 'name' => $widget_name)); } } $create_response = afStudioCommand::process('widget', 'save', array('uri' => "{$module}/{$widget_name}", 'data' => $this->getDefinition($type, array('title' => ucfirst(strtolower($type)) . ' ' . sfInflector::humanize($model), 'fields' => $widget_fields, 'model' => $model, 'module' => $module, 'widget_name' => $widget_name, 'types' => $types)), 'widgetType' => $type, 'createNewWidget' => 'true', 'placeType' => $placeType, 'place' => $place, 'model' => $model)); $is_created = $create_response->getParameter(afResponseSuccessDecorator::IDENTIFICATOR); if (!$is_created) { $this->log_it($create_response->getParameter(afResponseMessageDecorator::IDENTIFICATOR)); } $this->logSection($is_created ? 'created' : 'not created', $widget_path, null, $is_created ? 'INFO' : 'ERROR'); $this->log_it(($is_created ? 'created' : 'not created') . ' - ' . $widget_path); } // execute fix permissions task, ran in background $task = new afsPermissionsTask(sfContext::getInstance()->getEventDispatcher(), new sfFormatter()); $task->run(); }
/** * Process query struct type * * @param string $query * @param int $offset * @param int $limit * @return afResponse * @author Sergey Startsev */ protected function processQueryStruct($query, $offset, $limit) { $stm = $this->dbh->prepare($query); $bExecuted = $stm->execute(); $response = afResponseHelper::create(); if ($bExecuted) { afStudioCommand::process('model', 'updateSchemas'); if (preg_match('/(?:alter\\s{1,}table)\\s{1,}(.*?)(?:\\s|$)/si', $query, $matched)) { return $this->processQuerySelect("SELECT * FROM {$matched[1]}", 0, 50); } return $response->success(true)->data(array(), array(), 0)->message('Query successfully executed. Models regenerated')->query($query); } return $response->success(false)->message($stm->errorInfo())->query($query); }
/** * Export project call * * @param sfWebRequest $request * @return mixed * @author Sergey Startsev */ public function executeExport(sfWebRequest $request) { $response = afStudioCommand::process('project', 'export', $request->getParameterHolder()->getAll()); if (!$response->getParameter(afResponseSuccessDecorator::IDENTIFICATOR)) { return $this->renderText($response->getParameter(afResponseMessageDecorator::IDENTIFICATOR)); } $data = $response->getParameter(afResponseDataDecorator::IDENTIFICATOR_DATA); $file_name = $data['file']; $file_path = $data['path']; $response = $this->getContext()->getResponse(); $response->clearHttpHeaders(); $response->addCacheControlHttpHeader('Cache-control', 'must-revalidate, post-check=0, pre-check=0'); $response->setContentType('application/octet-stream', true); $response->setHttpHeader('Content-Transfer-Encoding', 'binary', true); $response->setHttpHeader('Content-Disposition', "attachment; filename={$file_name}", true); $response->sendHttpHeaders(); readfile("{$file_path}{$file_name}"); return sfView::NONE; }
/** * Generate all widgets action * * @param sfWebRequest $request * @return string - json * @author Sergey Startsev */ public function executeGenerateAll(sfWebRequest $request) { return $this->renderJson(afStudioCommand::process('widget', 'generateAll', $request->getParameterHolder()->getAll())->asArray()); }