More work on web installer
This commit is contained in:
parent
9fed113f74
commit
f5b4928538
23 changed files with 728 additions and 186 deletions
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
require_once dirname(dirname( __DIR__)) . '/library/php-amqplib/amqp.inc';
|
||||
|
||||
/**
|
||||
* User: sourcefabric
|
||||
* Date: 02/12/14
|
||||
|
@ -9,13 +12,25 @@
|
|||
*/
|
||||
class RabbitMQSetup extends Setup {
|
||||
|
||||
// airtime.conf section header
|
||||
const SECTION = "[rabbitmq]";
|
||||
|
||||
// Constant form field names for passing errors back to the front-end
|
||||
const RMQ_USER = "rmqUser",
|
||||
RMQ_PASS = "rmqPass",
|
||||
RMQ_PORT = "rmqPort",
|
||||
RMQ_HOST = "rmqHost",
|
||||
RMQ_VHOST = "rmqVHost";
|
||||
|
||||
static $user, $pass, $name, $host, $port, $vhost;
|
||||
// Form field values
|
||||
static $user, $pass, $host, $port, $vhost;
|
||||
|
||||
// Array of key->value pairs for airtime.conf
|
||||
static $properties;
|
||||
|
||||
// Message and error fields to return to the front-end
|
||||
static $message = null;
|
||||
static $errors = array();
|
||||
|
||||
function __construct($settings) {
|
||||
self::$user = $settings[self::RMQ_USER];
|
||||
|
@ -23,19 +38,63 @@ class RabbitMQSetup extends Setup {
|
|||
self::$port = $settings[self::RMQ_PORT];
|
||||
self::$host = $settings[self::RMQ_HOST];
|
||||
self::$vhost = $settings[self::RMQ_VHOST];
|
||||
|
||||
self::$properties = array(
|
||||
"host" => self::$host,
|
||||
"port" => self::$port,
|
||||
"user" => self::$user,
|
||||
"password" => self::$pass,
|
||||
"vhost" => self::$vhost,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array associative array containing a display message and fields with errors
|
||||
*/
|
||||
function runSetup() {
|
||||
$message = "";
|
||||
$errors = array();
|
||||
try {
|
||||
if ($this->checkRMQConnection()) {
|
||||
self::$message = "Connection successful!";
|
||||
} else {
|
||||
$this->identifyRMQConnectionError();
|
||||
}
|
||||
} catch(Exception $e) {
|
||||
$this->identifyRMQConnectionError();
|
||||
}
|
||||
|
||||
if (count(self::$errors) <= 0) {
|
||||
$this->writeToTemp();
|
||||
}
|
||||
|
||||
return array(
|
||||
"message" => $message,
|
||||
"errors" => $errors
|
||||
"message" => self::$message,
|
||||
"errors" => self::$errors
|
||||
);
|
||||
}
|
||||
|
||||
function writeToTemp() {
|
||||
parent::writeToTemp(self::SECTION, self::$properties);
|
||||
}
|
||||
|
||||
function checkRMQConnection() {
|
||||
$conn = new AMQPConnection(self::$host,
|
||||
self::$port,
|
||||
self::$user,
|
||||
self::$pass,
|
||||
self::$vhost);
|
||||
return isset($conn);
|
||||
}
|
||||
|
||||
function identifyRMQConnectionError() {
|
||||
// It's impossible to identify errors coming out of amqp.inc without a major
|
||||
// rewrite, so for now just tell the user ALL THE THINGS went wrong
|
||||
self::$message = "Couldn't connect to RabbitMQ server! Please check if the server "
|
||||
. "is running and your credentials are correct.";
|
||||
self::$errors[] = self::RMQ_USER;
|
||||
self::$errors[] = self::RMQ_PASS;
|
||||
self::$errors[] = self::RMQ_HOST;
|
||||
self::$errors[] = self::RMQ_PORT;
|
||||
self::$errors[] = self::RMQ_VHOST;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue