Merge branch 'saas' into saas-media-refactor
This commit is contained in:
commit
76141b38b8
|
@ -36,19 +36,33 @@ class ProvisioningHelper
|
|||
$this->parsePostParams();
|
||||
|
||||
//For security, the Airtime Pro provisioning system creates the database for the user.
|
||||
// $this->setNewDatabaseConnection();
|
||||
$this->setNewDatabaseConnection();
|
||||
|
||||
//if ($this->checkDatabaseExists()) {
|
||||
// throw new Exception("ERROR: Airtime database already exists");
|
||||
//}
|
||||
|
||||
if (!$this->checkDatabaseExists()) {
|
||||
throw new Exception("ERROR: $this->dbname database does not exist.");
|
||||
}
|
||||
|
||||
//We really want to do this check because all the Propel-generated SQL starts with "DROP TABLE IF EXISTS".
|
||||
//If we don't check, then a second call to this API endpoint would wipe all the tables!
|
||||
if ($this->checkTablesExist()) {
|
||||
throw new Exception("ERROR: airtime tables already exists");
|
||||
}
|
||||
|
||||
//$this->createDatabase();
|
||||
|
||||
//All we need to do is create the database tables.
|
||||
|
||||
$this->createDatabaseTables();
|
||||
$this->initializeMusicDirsTable($this->instanceId);
|
||||
} catch (Exception $e) {
|
||||
http_response_code(400);
|
||||
Logging::error($e->getMessage());
|
||||
echo $e->getMessage();
|
||||
Logging::error($e->getMessage()
|
||||
);
|
||||
echo $e->getMessage() . PHP_EOL;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -67,6 +81,19 @@ class ProvisioningHelper
|
|||
return isset($result[0]);
|
||||
}
|
||||
|
||||
private function checkTablesExist()
|
||||
{
|
||||
try {
|
||||
$result = self::$dbh->query("SELECT 1 FROM cc_files LIMIT 1");
|
||||
} catch (Exception $e) {
|
||||
// We got an exception == table not found
|
||||
echo($e . PHP_EOL);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Result is either boolean FALSE (no table found) or PDOStatement Object (table found)
|
||||
return $result !== FALSE;
|
||||
}
|
||||
private function parsePostParams()
|
||||
{
|
||||
$this->dbuser = $_POST['dbuser'];
|
||||
|
@ -84,9 +111,11 @@ class ProvisioningHelper
|
|||
private function setNewDatabaseConnection()
|
||||
{
|
||||
self::$dbh = new PDO("pgsql:host=" . $this->dbhost
|
||||
. ";dbname=postgres"
|
||||
. ";dbname=" . $this->dbname
|
||||
. ";port=5432" . ";user=" . $this->dbuser
|
||||
. ";password=" . $this->dbpass);
|
||||
//Turn on PDO exceptions because they're off by default.
|
||||
//self::$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$err = self::$dbh->errorInfo();
|
||||
if ($err[1] != null) {
|
||||
throw new PDOException("ERROR: Could not connect to database");
|
||||
|
|
Loading…
Reference in New Issue