/** * Validate the given form data and check whether the defined user has sufficient access rights * * @param array $data The data to validate * * @return bool */ public function isValid($data) { if (false === parent::isValid($data)) { return false; } if (isset($data['skip_validation']) && $data['skip_validation']) { return true; } $config = $this->config; $config['username'] = $this->getValue('username'); $config['password'] = $this->getValue('password'); $db = new DbTool($config); try { $db->connectToDb(); // Are we able to login on the database? } catch (PDOException $_) { try { $db->connectToHost(); // Are we able to login on the server? } catch (PDOException $e) { // We are NOT able to login on the server.. $this->error($e->getMessage()); $this->addSkipValidationCheckbox(); return false; } } // In case we are connected the credentials filled into this // form need to be granted to create databases, users... if (false === $db->checkPrivileges($this->databaseSetupPrivileges)) { $this->error($this->translate('The provided credentials cannot be used to create the database and/or the user.')); $this->addSkipValidationCheckbox(); return false; } // ...and to grant all required usage privileges to others if (false === $db->isGrantable($this->databaseUsagePrivileges)) { $this->error(sprintf($this->translate('The provided credentials cannot be used to grant all required privileges to the login "%s".'), $this->config['username'])); $this->addSkipValidationCheckbox(); return false; } return true; }