fix(legacy): update setup with new db config schema (#1567)
This commit is contained in:
parent
3245216869
commit
c80f520d76
|
@ -15,34 +15,30 @@ if (file_exists($tempConfigPath)) {
|
||||||
</p>
|
</p>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="control-label" for="dbUser">Username</label>
|
<label class="control-label" for="dbUser">Username</label>
|
||||||
<input required class="form-control" type="text" name="dbUser" id="dbUser" placeholder="Username"
|
<input required class="form-control" type="text" name="dbUser" id="dbUser" placeholder="Username" value="<?php echo isset($db) ? $db['user'] : 'airtime'; ?>" />
|
||||||
value="<?php echo isset($db) ? $db['dbuser'] : 'airtime'; ?>" />
|
|
||||||
<span class="glyphicon glyphicon-remove form-control-feedback"></span>
|
<span class="glyphicon glyphicon-remove form-control-feedback"></span>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="control-label" for="dbPass">Password</label>
|
<label class="control-label" for="dbPass">Password</label>
|
||||||
<input required class="form-control" type="password" name="dbPass" id="dbPass" placeholder="Password"
|
<input required class="form-control" type="password" name="dbPass" id="dbPass" placeholder="Password" value="<?php echo isset($db) ? $db['password'] : 'airtime'; ?>" />
|
||||||
value="<?php echo isset($db) ? $db['dbpass'] : 'airtime'; ?>" />
|
|
||||||
<span class="glyphicon glyphicon-remove form-control-feedback"></span>
|
<span class="glyphicon glyphicon-remove form-control-feedback"></span>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="control-label" for="dbName">Name</label>
|
<label class="control-label" for="dbName">Name</label>
|
||||||
<input required class="form-control" type="text" name="dbName" id="dbName" placeholder="Name"
|
<input required class="form-control" type="text" name="dbName" id="dbName" placeholder="Name" value="<?php echo isset($db) ? $db['name'] : 'airtime'; ?>" />
|
||||||
value="<?php echo isset($db) ? $db['dbname'] : 'airtime'; ?>" />
|
|
||||||
<span class="glyphicon glyphicon-remove form-control-feedback"></span>
|
<span class="glyphicon glyphicon-remove form-control-feedback"></span>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="control-label" for="dbHost">Host</label>
|
<label class="control-label" for="dbHost">Host</label>
|
||||||
<input required class="form-control" type="text" name="dbHost" id="dbHost" placeholder="Host"
|
<input required class="form-control" type="text" name="dbHost" id="dbHost" placeholder="Host" value="<?php echo isset($db) ? $db['host'] : 'localhost'; ?>" />
|
||||||
value="<?php echo isset($db) ? $db['host'] : 'localhost'; ?>" />
|
|
||||||
<span class="glyphicon glyphicon-remove form-control-feedback"></span>
|
<span class="glyphicon glyphicon-remove form-control-feedback"></span>
|
||||||
</div>
|
</div>
|
||||||
<input class="form-control" type="hidden" name="dbErr" id="dbErr" aria-describedby="helpBlock"/>
|
<input class="form-control" type="hidden" name="dbErr" id="dbErr" aria-describedby="helpBlock" />
|
||||||
<div>
|
<div>
|
||||||
<p style="text-align:right">
|
<p style="text-align:right">
|
||||||
This may take up to 30 seconds to complete!
|
This may take up to 30 seconds to complete!
|
||||||
</p>
|
</p>
|
||||||
<input type="submit" formtarget="dbSettingsForm" class="btn btn-primary btn-next" value="Next ❱"/>
|
<input type="submit" formtarget="dbSettingsForm" class="btn btn-primary btn-next" value="Next ❱" />
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|
|
@ -29,16 +29,16 @@ class DatabaseSetup extends Setup
|
||||||
{
|
{
|
||||||
static::$_properties = [
|
static::$_properties = [
|
||||||
'host' => $settings[self::DB_HOST],
|
'host' => $settings[self::DB_HOST],
|
||||||
'dbname' => $settings[self::DB_NAME],
|
'name' => $settings[self::DB_NAME],
|
||||||
'dbuser' => $settings[self::DB_USER],
|
'user' => $settings[self::DB_USER],
|
||||||
'dbpass' => $settings[self::DB_PASS],
|
'password' => $settings[self::DB_PASS],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function setNewDatabaseConnection($dbName)
|
private function setNewDatabaseConnection($dbName)
|
||||||
{
|
{
|
||||||
self::$dbh = new PDO('pgsql:host=' . self::$_properties['host'] . ';dbname=' . $dbName . ';port=5432'
|
self::$dbh = new PDO('pgsql:host=' . self::$_properties['host'] . ';dbname=' . $dbName . ';port=5432'
|
||||||
. ';user=' . self::$_properties['dbuser'] . ';password=' . self::$_properties['dbpass']);
|
. ';user=' . self::$_properties['user'] . ';password=' . self::$_properties['password']);
|
||||||
$err = self::$dbh->errorInfo();
|
$err = self::$dbh->errorInfo();
|
||||||
if ($err[1] != null) {
|
if ($err[1] != null) {
|
||||||
throw new PDOException();
|
throw new PDOException();
|
||||||
|
@ -70,8 +70,8 @@ class DatabaseSetup extends Setup
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
throw new AirtimeDatabaseException(
|
throw new AirtimeDatabaseException(
|
||||||
"Couldn't establish a connection to the database! " .
|
"Couldn't establish a connection to the database! " .
|
||||||
'Please check your credentials and try again. '
|
'Please check your credentials and try again. '
|
||||||
. 'PDO Exception: ' . $e->getMessage(),
|
. 'PDO Exception: ' . $e->getMessage(),
|
||||||
[self::DB_NAME, self::DB_USER, self::DB_PASS]
|
[self::DB_NAME, self::DB_USER, self::DB_PASS]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ class DatabaseSetup extends Setup
|
||||||
private function installDatabaseTables()
|
private function installDatabaseTables()
|
||||||
{
|
{
|
||||||
$this->checkDatabaseEncoding();
|
$this->checkDatabaseEncoding();
|
||||||
$this->setNewDatabaseConnection(self::$_properties['dbname']);
|
$this->setNewDatabaseConnection(self::$_properties['name']);
|
||||||
$this->checkSchemaExists();
|
$this->checkSchemaExists();
|
||||||
$this->createDatabaseTables();
|
$this->createDatabaseTables();
|
||||||
$this->updateIcecastPassword();
|
$this->updateIcecastPassword();
|
||||||
|
@ -101,7 +101,7 @@ class DatabaseSetup extends Setup
|
||||||
private function checkDatabaseExists()
|
private function checkDatabaseExists()
|
||||||
{
|
{
|
||||||
$statement = self::$dbh->prepare('SELECT datname FROM pg_database WHERE datname = :dbname');
|
$statement = self::$dbh->prepare('SELECT datname FROM pg_database WHERE datname = :dbname');
|
||||||
$statement->execute([':dbname' => self::$_properties['dbname']]);
|
$statement->execute([':dbname' => self::$_properties['name']]);
|
||||||
$result = $statement->fetch();
|
$result = $statement->fetch();
|
||||||
|
|
||||||
return isset($result[0]);
|
return isset($result[0]);
|
||||||
|
@ -130,13 +130,13 @@ class DatabaseSetup extends Setup
|
||||||
private function checkUserCanCreateDb()
|
private function checkUserCanCreateDb()
|
||||||
{
|
{
|
||||||
$statement = self::$dbh->prepare("SELECT 1 FROM pg_roles WHERE rolname=:dbuser AND rolcreatedb='t'");
|
$statement = self::$dbh->prepare("SELECT 1 FROM pg_roles WHERE rolname=:dbuser AND rolcreatedb='t'");
|
||||||
$statement->execute([':dbuser' => self::$_properties['dbuser']]);
|
$statement->execute([':dbuser' => self::$_properties['user']]);
|
||||||
$result = $statement->fetch();
|
$result = $statement->fetch();
|
||||||
if (!isset($result[0])) {
|
if (!isset($result[0])) {
|
||||||
throw new AirtimeDatabaseException(
|
throw new AirtimeDatabaseException(
|
||||||
'No database ' . self::$_properties['dbname'] . " exists; user '"
|
'No database ' . self::$_properties['name'] . " exists; user '"
|
||||||
. self::$_properties['dbuser'] . "' does not have permission to "
|
. self::$_properties['user'] . "' does not have permission to "
|
||||||
. 'create databases on ' . self::$_properties['host'],
|
. 'create databases on ' . self::$_properties['host'],
|
||||||
[self::DB_NAME, self::DB_USER, self::DB_PASS]
|
[self::DB_NAME, self::DB_USER, self::DB_PASS]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -149,9 +149,9 @@ class DatabaseSetup extends Setup
|
||||||
*/
|
*/
|
||||||
private function createDatabase()
|
private function createDatabase()
|
||||||
{
|
{
|
||||||
$statement = self::$dbh->prepare('CREATE DATABASE ' . pg_escape_string(self::$_properties['dbname'])
|
$statement = self::$dbh->prepare('CREATE DATABASE ' . pg_escape_string(self::$_properties['name'])
|
||||||
. " WITH ENCODING 'UNICODE' TEMPLATE template0"
|
. " WITH ENCODING 'UNICODE' TEMPLATE template0"
|
||||||
. ' OWNER ' . pg_escape_string(self::$_properties['dbuser']));
|
. ' OWNER ' . pg_escape_string(self::$_properties['user']));
|
||||||
if (!$statement->execute()) {
|
if (!$statement->execute()) {
|
||||||
throw new AirtimeDatabaseException(
|
throw new AirtimeDatabaseException(
|
||||||
'There was an error creating the database!',
|
'There was an error creating the database!',
|
||||||
|
@ -178,9 +178,9 @@ class DatabaseSetup extends Setup
|
||||||
* have multiple issues; they similarly die on any SQL errors, fail to read in multi-line
|
* have multiple issues; they similarly die on any SQL errors, fail to read in multi-line
|
||||||
* commands, and fail on any unescaped ? or $ characters.
|
* commands, and fail on any unescaped ? or $ characters.
|
||||||
*/
|
*/
|
||||||
exec('export PGPASSWORD=' . self::$_properties['dbpass'] . ' && /usr/bin/psql -U ' . self::$_properties['dbuser']
|
exec('export PGPASSWORD=' . self::$_properties['password'] . ' && /usr/bin/psql -U ' . self::$_properties['user']
|
||||||
. ' --dbname ' . self::$_properties['dbname'] . ' -h ' . self::$_properties['host']
|
. ' --dbname ' . self::$_properties['name'] . ' -h ' . self::$_properties['host']
|
||||||
. " -f {$sqlDir}{$f} 2>/dev/null", $out, $status);
|
. " -f {$sqlDir}{$f} 2>/dev/null", $out, $status);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
throw new AirtimeDatabaseException(
|
throw new AirtimeDatabaseException(
|
||||||
'There was an error setting up the Airtime schema!',
|
'There was an error setting up the Airtime schema!',
|
||||||
|
@ -198,8 +198,8 @@ class DatabaseSetup extends Setup
|
||||||
private function checkDatabaseEncoding()
|
private function checkDatabaseEncoding()
|
||||||
{
|
{
|
||||||
$statement = self::$dbh->prepare('SELECT pg_encoding_to_char(encoding) '
|
$statement = self::$dbh->prepare('SELECT pg_encoding_to_char(encoding) '
|
||||||
. 'FROM pg_database WHERE datname = :dbname');
|
. 'FROM pg_database WHERE datname = :dbname');
|
||||||
$statement->execute([':dbname' => self::$_properties['dbname']]);
|
$statement->execute([':dbname' => self::$_properties['name']]);
|
||||||
$encoding = $statement->fetch();
|
$encoding = $statement->fetch();
|
||||||
if (!($encoding && $encoding[0] == 'UTF8')) {
|
if (!($encoding && $encoding[0] == 'UTF8')) {
|
||||||
throw new AirtimeDatabaseException(
|
throw new AirtimeDatabaseException(
|
||||||
|
|
Loading…
Reference in New Issue