protected function createAccount() { try { $backend = new DbUserBackend(ResourceFactory::createResource(new ConfigObject($this->data['adminAccountData']['resourceConfig']))); if ($backend->select()->where('user_name', $this->data['adminAccountData']['username'])->count() === 0) { $backend->insert('user', array('user_name' => $this->data['adminAccountData']['username'], 'password' => $this->data['adminAccountData']['password'], 'is_active' => true)); } } catch (Exception $e) { $this->dbError = $e; return false; } $this->dbError = false; return true; }
/** * Validate the configuration by creating a backend and requesting the user count * * @param Form $form The form to fetch the configuration values from * * @return bool Whether validation succeeded or not */ public static function isValidUserBackend(Form $form) { try { $dbUserBackend = new DbUserBackend(ResourceFactory::createResource($form->getResourceConfig())); if ($dbUserBackend->select()->where('is_active', true)->count() < 1) { $form->addError($form->translate('No active users found under the specified database backend')); return false; } } catch (Exception $e) { $form->addError(sprintf($form->translate('Using the specified backend failed: %s'), $e->getMessage())); return false; } return true; }