/** * Add a new admin to the system * * @param array $args * @return void */ public function add(array $args = array()) { $ini = Garp_Auth::getInstance()->getConfigValues(); if (empty($ini['adapters']['db'])) { Garp_Cli::errorOut('Error: DB adapter is not configured in application.ini.'); } elseif (empty($ini['adapters']['db']['identityColumn']) || empty($ini['adapters']['db']['credentialColumn'])) { Garp_Cli::errorOut('Error: identityColumn or credentialColumn not configured in application.ini'); } else { $newUserData = array('role' => 'admin'); $promptData = array(); // Pull required fields from Spawner config $modelSet = Garp_Spawn_Model_Set::getInstance(); $userModelConfig = $modelSet['User']; $requiredFields = $userModelConfig->fields->getFields('required', true); foreach ($requiredFields as $field) { if ($field->origin == 'config' && $field->name !== 'id') { $promptData[] = $field->name; } elseif ($field->origin == 'relation') { Garp_Cli::errorOut('Field ' . $field->name . ' is required but must be filled by way of relation. ' . 'This makes it impossible to create an admin from the commandline.'); } } if (!in_array($ini['adapters']['db']['identityColumn'], $promptData)) { $promptData[] = $ini['adapters']['db']['identityColumn']; } // prompt for the new data Garp_Cli::lineOut('Please fill the following columns:'); foreach ($promptData as $key) { $newUserData[$key] = trim(Garp_Cli::prompt($key . ':')); } $newAuthLocalData = array('password' => trim(Garp_Cli::prompt('Choose a password:'******'s entirely possible to circumvent these * conventions and come up with project-specific standards. * In that case however, this CLI command is not for you. */ $user = new Model_User(); try { $id = $user->insert($newUserData); $authLocal = new Model_AuthLocal(); $newAuthLocalData['user_id'] = $id; if ($authLocal->insert($newAuthLocalData)) { Garp_Cli::lineOut('Successfully created the administrator. (id: ' . $id . ')'); } else { Garp_Cli::errorOut('Error: could not create administrator.'); } } catch (Zend_Db_Statement_Exception $e) { if (strpos($e->getMessage(), 'Duplicate entry') !== false && strpos($e->getMessage(), 'email_unique') !== false) { Garp_Cli::errorOut('Error: this email address is already in use. ' . 'Maybe you meant to use Garp Admin make?'); } else { throw $e; } } } }
public static function getInstance(Garp_Spawn_Config_Model_Set $config = null) { if (!self::$_instance) { self::$_instance = self::_createInstance($config); self::_addMirroredRelations(); } return self::$_instance; }
/** * Pushes all appropriate existing database content to the indexer. * * @return bool */ public function index() { Garp_Cli::lineOut('Building up index. Hang on to your knickers...'); $modelSet = Garp_Spawn_Model_Set::getInstance(); foreach ($modelSet as $model) { $this->_indexModel($model); } return true; }
protected function _getVisibleModels() { return array_filter((array) Garp_Spawn_Model_Set::getInstance(), getProperty('visible')); }
/** * Show datamodel * * @todo: refactor naar nieuwe Spawn opbouw. * @return Void */ public function datamodelAction() { $this->view->models = Garp_Spawn_Model_Set::getInstance(); $request = $this->getRequest(); $params = $request->getParams(); if (array_key_exists('text', $params)) { $this->view->textMode = true; $this->_helper->layout->setLayout('blank'); } else { $this->_helper->layout->setLayout('datamodel-layout'); } }
protected function _throwErrorIfRelatedModelDoesNotExist(Garp_Spawn_Relation $relation) { $model = $this->getModel(); $modelSet = Garp_Spawn_Model_Set::getInstance(); if (array_key_exists($relation->model, $modelSet)) { return; } $error = sprintf(self::ERROR_RELATION_TO_NON_EXISTING_MODEL, $model->id, $relation->type, $relation->model); throw new Exception($error); }
protected function _getInternationalizedModels() { $modelSet = (array) Garp_Spawn_Model_Set::getInstance(); $modelsWithI18nFields = array_filter($modelSet, function ($model) { return array_reduce($model->fields->toArray(), function ($hasMultilingualField, $field) { return $hasMultilingualField || $field->multilingual; }, false); }); return array_values(array_map(function ($model) { return $model->id; }, $modelsWithI18nFields)); }
protected function _constructMockModelSet() { return Garp_Spawn_Model_Set::getInstance(new Garp_Spawn_Config_Model_Set(new Garp_Spawn_Config_Storage_File($this->_mocks['directory'], $this->_mocks['extension']), new Garp_Spawn_Config_Format_Json())); }
/** * @param String $modelName * @return Garp_Spawn_Model_Abstract $model */ protected function _getModelFromModelName($modelName) { $modelSet = Garp_Spawn_Model_Set::getInstance(); return $modelSet[$modelName]; }
protected function _initModelSet() { $modelSet = Garp_Spawn_Model_Set::getInstance(); return $modelSet; }