Merge branch 'saas-dev' into saas-dev-schedule-widget-angular
This commit is contained in:
commit
5f925f2f1f
103 changed files with 9339 additions and 2988 deletions
|
@ -1250,7 +1250,7 @@ input[type="checkbox"] {
|
|||
}
|
||||
|
||||
.dataTables_scrolling {
|
||||
min-height: 150px;
|
||||
/*min-height: 150px;*/
|
||||
}
|
||||
|
||||
.ui-dialog #schedule_playlist_dialog.ui-dialog-content {
|
||||
|
|
|
@ -10,7 +10,8 @@ var AIRTIME = (function(AIRTIME) {
|
|||
mod.checkAddButton = function() {
|
||||
var selected = mod.getChosenItemsLength(), $cursor = $('tr.sb-selected'), check = false,
|
||||
shows = $('tr.sb-header'), current = $('tr.sb-current-show'),
|
||||
cursorText = $.i18n._('Add to next show');
|
||||
// TODO: this is an ugly way of doing this... we should find a more robust way of checking which view we're in.
|
||||
cursorText = (window.location.href.toLowerCase().indexOf("schedule") > -1) ? $.i18n._('Add to show') : $.i18n._('Add to next show');
|
||||
|
||||
// make sure library items are selected and a cursor is selected.
|
||||
if (selected !== 0) {
|
||||
|
|
|
@ -614,17 +614,6 @@ var AIRTIME = (function(AIRTIME) {
|
|||
},
|
||||
"fnRowCallback": AIRTIME.library.fnRowCallback,
|
||||
"fnCreatedRow": function( nRow, aData, iDataIndex ) {
|
||||
//add soundcloud icon
|
||||
if (aData.soundcloud_id !== undefined) {
|
||||
if (aData.soundcloud_id === "-2") {
|
||||
$(nRow).find("td.library_title").append('<span class="small-icon progress"/>');
|
||||
} else if (aData.soundcloud_id === "-3") {
|
||||
$(nRow).find("td.library_title").append('<span class="small-icon sc-error"/>');
|
||||
} else if (aData.soundcloud_id !== null) {
|
||||
$(nRow).find("td.library_title").append('<span class="small-icon soundcloud"/>');
|
||||
}
|
||||
}
|
||||
|
||||
// add checkbox
|
||||
$(nRow).find('td.library_checkbox').html("<input type='checkbox' name='cb_"+aData.id+"'>");
|
||||
|
||||
|
@ -903,10 +892,6 @@ var AIRTIME = (function(AIRTIME) {
|
|||
|
||||
});
|
||||
|
||||
checkLibrarySCUploadStatus();
|
||||
|
||||
addQtipToSCIcons();
|
||||
|
||||
// begin context menu initialization.
|
||||
$.contextMenu({
|
||||
selector: '#library_display td:not(.library_checkbox)',
|
||||
|
@ -1037,21 +1022,31 @@ var AIRTIME = (function(AIRTIME) {
|
|||
// add callbacks for Soundcloud menu items.
|
||||
if (oItems.soundcloud !== undefined) {
|
||||
var soundcloud = oItems.soundcloud.items;
|
||||
|
||||
|
||||
// define an upload to soundcloud callback.
|
||||
if (soundcloud.upload !== undefined) {
|
||||
|
||||
|
||||
callback = function() {
|
||||
$.post(soundcloud.upload.url, function(){
|
||||
addProgressIcon(data.id);
|
||||
});
|
||||
alert($.i18n._("Your track is being uploaded and will " +
|
||||
"appear on SoundCloud in a couple of minutes"));
|
||||
$.post(soundcloud.upload.url, function(){});
|
||||
};
|
||||
soundcloud.upload.callback = callback;
|
||||
}
|
||||
|
||||
|
||||
// define an upload to soundcloud callback.
|
||||
if (soundcloud.remove !== undefined) {
|
||||
|
||||
callback = function() {
|
||||
alert($.i18n._("Your track is being deleted from SoundCloud"));
|
||||
$.post(soundcloud.remove.url, function(){});
|
||||
};
|
||||
soundcloud.remove.callback = callback;
|
||||
}
|
||||
|
||||
// define a view on soundcloud callback
|
||||
if (soundcloud.view !== undefined) {
|
||||
|
||||
|
||||
callback = function() {
|
||||
window.open(soundcloud.view.url);
|
||||
};
|
||||
|
@ -1151,122 +1146,6 @@ function addProgressIcon(id) {
|
|||
}
|
||||
}
|
||||
|
||||
function checkLibrarySCUploadStatus(){
|
||||
var url = baseUrl+'Library/get-upload-to-soundcloud-status',
|
||||
span,
|
||||
id;
|
||||
|
||||
function checkSCUploadStatusCallback(json) {
|
||||
|
||||
if (json.sc_id > 0) {
|
||||
span.removeClass("progress").addClass("soundcloud");
|
||||
|
||||
}
|
||||
else if (json.sc_id == "-3") {
|
||||
span.removeClass("progress").addClass("sc-error");
|
||||
}
|
||||
}
|
||||
|
||||
function checkSCUploadStatusRequest() {
|
||||
|
||||
span = $(this);
|
||||
id = span.parents("tr").data("aData").id;
|
||||
|
||||
$.post(url, {format: "json", id: id, type:"file"}, checkSCUploadStatusCallback);
|
||||
}
|
||||
|
||||
$("#library_display span.progress").each(checkSCUploadStatusRequest);
|
||||
setTimeout(checkLibrarySCUploadStatus, 5000);
|
||||
}
|
||||
|
||||
function addQtipToSCIcons() {
|
||||
$("#content")
|
||||
.on('mouseover', ".progress, .soundcloud, .sc-error", function() {
|
||||
|
||||
var aData = $(this).parents("tr").data("aData"),
|
||||
id = aData.id,
|
||||
sc_id = aData.soundcloud_id;
|
||||
|
||||
if ($(this).hasClass("progress")){
|
||||
$(this).qtip({
|
||||
content: {
|
||||
text: $.i18n._("Uploading in progress...")
|
||||
},
|
||||
position:{
|
||||
adjust: {
|
||||
resize: true,
|
||||
method: "flip flip"
|
||||
},
|
||||
at: "right center",
|
||||
my: "left top",
|
||||
viewport: $(window)
|
||||
},
|
||||
style: {
|
||||
classes: "ui-tooltip-dark file-md-long"
|
||||
},
|
||||
show: {
|
||||
ready: true // Needed to make it show on first mouseover event
|
||||
}
|
||||
});
|
||||
}
|
||||
else if ($(this).hasClass("soundcloud")){
|
||||
|
||||
$(this).qtip({
|
||||
content: {
|
||||
text: $.i18n._("The soundcloud id for this file is: ") + sc_id
|
||||
},
|
||||
position:{
|
||||
adjust: {
|
||||
resize: true,
|
||||
method: "flip flip"
|
||||
},
|
||||
at: "right center",
|
||||
my: "left top",
|
||||
viewport: $(window)
|
||||
},
|
||||
style: {
|
||||
classes: "ui-tooltip-dark file-md-long"
|
||||
},
|
||||
show: {
|
||||
ready: true // Needed to make it show on first mouseover event
|
||||
}
|
||||
});
|
||||
}
|
||||
else if ($(this).hasClass("sc-error")) {
|
||||
$(this).qtip({
|
||||
content: {
|
||||
text: $.i18n._("Retreiving data from the server..."),
|
||||
ajax: {
|
||||
url: baseUrl+"Library/get-upload-to-soundcloud-status",
|
||||
type: "post",
|
||||
data: ({format: "json", id : id, type: "file"}),
|
||||
success: function(json, status){
|
||||
this.set('content.text', $.i18n._("There was an error while uploading to soundcloud.")+"<br>"+
|
||||
$.i18n._("Error code: ")+json.error_code+
|
||||
"<br>"+$.i18n._("Error msg: ")+json.error_msg+"<br>");
|
||||
}
|
||||
}
|
||||
},
|
||||
position:{
|
||||
adjust: {
|
||||
resize: true,
|
||||
method: "flip flip"
|
||||
},
|
||||
at: "right center",
|
||||
my: "left top",
|
||||
viewport: $(window)
|
||||
},
|
||||
style: {
|
||||
classes: "ui-tooltip-dark file-md-long"
|
||||
},
|
||||
show: {
|
||||
ready: true // Needed to make it show on first mouseover event
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* This function is called from dataTables.columnFilter.js
|
||||
*/
|
||||
|
|
|
@ -82,6 +82,20 @@ function setTuneInSettingsReadonly() {
|
|||
}
|
||||
}
|
||||
|
||||
function setSoundCloudSettingsListener() {
|
||||
var connect = $("#SoundCloudConnect"),
|
||||
disconnect = $("#SoundCloudDisconnect");
|
||||
connect.click(function(e){
|
||||
e.preventDefault();
|
||||
window.location.replace(baseUrl + "soundcloud/authorize");
|
||||
});
|
||||
|
||||
disconnect.click(function(e){
|
||||
e.preventDefault();
|
||||
window.location.replace(baseUrl + "soundcloud/deauthorize");
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* Enable/disable mail server authentication fields
|
||||
*/
|
||||
|
@ -147,4 +161,5 @@ $(document).ready(function() {
|
|||
setEnableSystemEmailsListener();
|
||||
setTuneInSettingsReadonly();
|
||||
setTuneInSettingsListener();
|
||||
setSoundCloudSettingsListener();
|
||||
});
|
||||
|
|
|
@ -194,31 +194,6 @@ function eventRender(event, element, view) {
|
|||
|
||||
$(element).find(".fc-event-content").append(div);
|
||||
}
|
||||
|
||||
//add the record/rebroadcast/soundcloud icons if needed
|
||||
if (event.record === 1) {
|
||||
if (view.name === 'agendaDay' || view.name === 'agendaWeek') {
|
||||
if (event.soundcloud_id === -1) {
|
||||
$(element).find(".fc-event-time").before('<span class="small-icon recording"></span>');
|
||||
} else if ( event.soundcloud_id > 0) {
|
||||
$(element).find(".fc-event-time").before('<span class="small-icon recording"></span><span class="small-icon soundcloud"></span>');
|
||||
} else if (event.soundcloud_id === -2) {
|
||||
$(element).find(".fc-event-time").before('<span class="small-icon recording"></span><span class="small-icon progress"></span>');
|
||||
} else if (event.soundcloud_id === -3) {
|
||||
$(element).find(".fc-event-time").before('<span class="small-icon recording"></span><span class="small-icon sc-error"></span>');
|
||||
}
|
||||
} else if (view.name === 'month') {
|
||||
if(event.soundcloud_id === -1) {
|
||||
$(element).find(".fc-event-title").after('<span class="small-icon recording"></span>');
|
||||
} else if (event.soundcloud_id > 0) {
|
||||
$(element).find(".fc-event-title").after('<span class="small-icon recording"></span><span class="small-icon soundcloud"></span>');
|
||||
} else if (event.soundcloud_id === -2) {
|
||||
$(element).find(".fc-event-title").after('<span class="small-icon recording"></span><span class="small-icon progress"></span>');
|
||||
} else if (event.soundcloud_id === -3) {
|
||||
$(element).find(".fc-event-title").after('<span class="small-icon recording"></span><span class="small-icon sc-error"></span>');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (event.record === 0 && event.rebroadcast === 0) {
|
||||
if (view.name === 'agendaDay' || view.name === 'agendaWeek') {
|
||||
|
|
|
@ -63,25 +63,6 @@ function confirmCancelRecordedShow(show_instance_id){
|
|||
}
|
||||
}
|
||||
|
||||
function uploadToSoundCloud(show_instance_id, el){
|
||||
|
||||
var url = baseUrl+"Schedule/upload-to-sound-cloud",
|
||||
$el = $(el),
|
||||
$span = $el.find(".soundcloud");
|
||||
|
||||
$.post(url, {id: show_instance_id, format: "json"});
|
||||
|
||||
//first upload to soundcloud.
|
||||
if ($span.length === 0){
|
||||
$span = $("<span/>", {"class": "progress"});
|
||||
|
||||
$el.find(".fc-event-title").after($span);
|
||||
}
|
||||
else {
|
||||
$span.removeClass("soundcloud").addClass("progress");
|
||||
}
|
||||
}
|
||||
|
||||
function checkCalendarSCUploadStatus(){
|
||||
var url = baseUrl+'Library/get-upload-to-soundcloud-status',
|
||||
span,
|
||||
|
@ -421,24 +402,6 @@ $(document).ready(function() {
|
|||
oItems.content.callback = callback;
|
||||
}
|
||||
|
||||
//define a soundcloud upload callback.
|
||||
if (oItems.soundcloud_upload !== undefined) {
|
||||
|
||||
callback = function() {
|
||||
uploadToSoundCloud(data.id, this.context);
|
||||
};
|
||||
oItems.soundcloud_upload.callback = callback;
|
||||
}
|
||||
|
||||
//define a view on soundcloud callback.
|
||||
if (oItems.soundcloud_view !== undefined) {
|
||||
|
||||
callback = function() {
|
||||
window.open(oItems.soundcloud_view.url);
|
||||
};
|
||||
oItems.soundcloud_view.callback = callback;
|
||||
}
|
||||
|
||||
//define a cancel recorded show callback.
|
||||
if (oItems.cancel_recorded !== undefined) {
|
||||
|
||||
|
|
|
@ -12,7 +12,8 @@ var AIRTIME = (function(AIRTIME){
|
|||
cursors = [],
|
||||
cursorIds = [],
|
||||
showInstanceIds = [],
|
||||
headerFooter = [];
|
||||
headerFooter = [],
|
||||
DISABLED_CLASS = 'ui-state-disabled';
|
||||
|
||||
if (AIRTIME.showbuilder === undefined) {
|
||||
AIRTIME.showbuilder = {};
|
||||
|
@ -135,8 +136,7 @@ var AIRTIME = (function(AIRTIME){
|
|||
mod.checkDeleteButton = function() {
|
||||
var $selected = $sbTable.find("tbody").find("input:checkbox").filter(":checked");
|
||||
|
||||
var button = $("#show_builder").find(".icon-trash").parent(),
|
||||
DISABLED_CLASS = 'ui-state-disabled';
|
||||
var button = $("#show_builder").find(".icon-trash").parent();
|
||||
if ($selected.length !== 0) {
|
||||
button.removeClass(DISABLED_CLASS);
|
||||
button.removeAttr('disabled');
|
||||
|
@ -535,9 +535,6 @@ var AIRTIME = (function(AIRTIME){
|
|||
cl = 'sb-header';
|
||||
|
||||
if (aData.record === true) {
|
||||
|
||||
headerIcon = (aData.soundcloud_id > 0) ? "soundcloud" : "recording";
|
||||
|
||||
$div = $("<div/>", {
|
||||
"class": "small-icon " + headerIcon
|
||||
});
|
||||
|
@ -1191,8 +1188,10 @@ var AIRTIME = (function(AIRTIME){
|
|||
//delete selected tracks
|
||||
$toolbar.find('.icon-trash').parent()
|
||||
.click(function() {
|
||||
|
||||
if (AIRTIME.button.isDisabled('icon-trash', true) === true) {
|
||||
|
||||
var button = $("#show_builder").find(".icon-trash").parent();
|
||||
|
||||
if (button.hasClass(DISABLED_CLASS)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
class DatabaseSetup extends Setup {
|
||||
|
||||
// airtime.conf section header
|
||||
const SECTION = "[database]";
|
||||
protected static $_settings = "[database]";
|
||||
|
||||
// Constant form field names for passing errors back to the front-end
|
||||
const DB_USER = "dbUser",
|
||||
|
@ -17,31 +17,26 @@ class DatabaseSetup extends Setup {
|
|||
DB_NAME = "dbName",
|
||||
DB_HOST = "dbHost";
|
||||
|
||||
// Form field values
|
||||
private $user, $pass, $name, $host;
|
||||
|
||||
// Array of key->value pairs for airtime.conf
|
||||
static $properties;
|
||||
protected static $_properties;
|
||||
|
||||
/**
|
||||
* @var PDO
|
||||
*/
|
||||
static $dbh = null;
|
||||
|
||||
public function __construct($settings) {
|
||||
$this->user = $settings[self::DB_USER];
|
||||
$this->pass = $settings[self::DB_PASS];
|
||||
$this->name = $settings[self::DB_NAME];
|
||||
$this->host = $settings[self::DB_HOST];
|
||||
|
||||
self::$properties = array(
|
||||
"host" => $this->host,
|
||||
"dbname" => $this->name,
|
||||
"dbuser" => $this->user,
|
||||
"dbpass" => $this->pass,
|
||||
static::$_properties = array(
|
||||
"host" => $settings[self::DB_HOST],
|
||||
"dbname" => $settings[self::DB_NAME],
|
||||
"dbuser" => $settings[self::DB_USER],
|
||||
"dbpass" => $settings[self::DB_PASS],
|
||||
);
|
||||
}
|
||||
|
||||
private function setNewDatabaseConnection($dbName) {
|
||||
self::$dbh = new PDO("pgsql:host=" . $this->host . ";dbname=" . $dbName . ";port=5432"
|
||||
. ";user=" . $this->user . ";password=" . $this->pass);
|
||||
self::$dbh = new PDO("pgsql:host=" . self::$_properties["host"] . ";dbname=" . $dbName . ";port=5432"
|
||||
. ";user=" . self::$_properties["dbuser"] . ";password=" . self::$_properties["dbpass"]);
|
||||
$err = self::$dbh->errorInfo();
|
||||
if ($err[1] != null) {
|
||||
throw new PDOException();
|
||||
|
@ -69,11 +64,7 @@ class DatabaseSetup extends Setup {
|
|||
throw new AirtimeDatabaseException("Couldn't establish a connection to the database! "
|
||||
. "Please check your credentials and try again. "
|
||||
. "PDO Exception: " . $e->getMessage(),
|
||||
array(
|
||||
self::DB_NAME,
|
||||
self::DB_USER,
|
||||
self::DB_PASS,
|
||||
));
|
||||
array(self::DB_NAME, self::DB_USER, self::DB_PASS));
|
||||
}
|
||||
|
||||
$this->writeToTemp();
|
||||
|
@ -85,13 +76,9 @@ class DatabaseSetup extends Setup {
|
|||
);
|
||||
}
|
||||
|
||||
protected function writeToTemp() {
|
||||
parent::writeToTemp(self::SECTION, self::$properties);
|
||||
}
|
||||
|
||||
private function installDatabaseTables() {
|
||||
$this->checkDatabaseEncoding();
|
||||
$this->setNewDatabaseConnection($this->name);
|
||||
$this->setNewDatabaseConnection(self::$_properties["dbname"]);
|
||||
$this->checkSchemaExists();
|
||||
$this->createDatabaseTables();
|
||||
}
|
||||
|
@ -102,7 +89,7 @@ class DatabaseSetup extends Setup {
|
|||
*/
|
||||
private function checkDatabaseExists() {
|
||||
$statement = self::$dbh->prepare("SELECT datname FROM pg_database WHERE datname = :dbname");
|
||||
$statement->execute(array(":dbname" => $this->name));
|
||||
$statement->execute(array(":dbname" => self::$_properties["dbname"]));
|
||||
$result = $statement->fetch();
|
||||
return isset($result[0]);
|
||||
}
|
||||
|
@ -126,16 +113,13 @@ class DatabaseSetup extends Setup {
|
|||
*/
|
||||
private function checkUserCanCreateDb() {
|
||||
$statement = self::$dbh->prepare("SELECT 1 FROM pg_roles WHERE rolname=:dbuser AND rolcreatedb='t'");
|
||||
$statement->execute(array(":dbuser" => $this->user));
|
||||
$statement->execute(array(":dbuser" => self::$_properties["dbuser"]));
|
||||
$result = $statement->fetch();
|
||||
if (!isset($result[0])) {
|
||||
throw new AirtimeDatabaseException("No database " . $this->name . " exists; user '" . $this->user
|
||||
. "' does not have permission to create databases on " . $this->host,
|
||||
array(
|
||||
self::DB_NAME,
|
||||
self::DB_USER,
|
||||
self::DB_PASS,
|
||||
));
|
||||
throw new AirtimeDatabaseException("No database " . self::$_properties["dbname"] . " exists; user '"
|
||||
. self::$_properties["dbuser"] . "' does not have permission to "
|
||||
. "create databases on " . self::$_properties["host"],
|
||||
array(self::DB_NAME, self::DB_USER, self::DB_PASS));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -144,9 +128,9 @@ class DatabaseSetup extends Setup {
|
|||
* @throws AirtimeDatabaseException
|
||||
*/
|
||||
private function createDatabase() {
|
||||
$statement = self::$dbh->prepare("CREATE DATABASE " . pg_escape_string($this->name)
|
||||
$statement = self::$dbh->prepare("CREATE DATABASE " . pg_escape_string(self::$_properties["dbname"])
|
||||
. " WITH ENCODING 'UTF8' TEMPLATE template0"
|
||||
. " OWNER " . pg_escape_string($this->user));
|
||||
. " OWNER " . pg_escape_string(self::$_properties["dbuser"]));
|
||||
if (!$statement->execute()) {
|
||||
throw new AirtimeDatabaseException("There was an error creating the database!",
|
||||
array(self::DB_NAME,));
|
||||
|
@ -169,8 +153,9 @@ class DatabaseSetup extends Setup {
|
|||
* have multiple issues; they similarly die on any SQL errors, fail to read in multi-line
|
||||
* commands, and fail on any unescaped ? or $ characters.
|
||||
*/
|
||||
exec("export PGPASSWORD=" . $this->pass . " && psql -U " . $this->user . " --dbname "
|
||||
. $this->name . " -h " . $this->host . " -f $sqlDir$f 2>/dev/null", $out, $status);
|
||||
exec("export PGPASSWORD=" . self::$_properties["dbpass"] . " && psql -U " . self::$_properties["dbuser"]
|
||||
. " --dbname " . self::$_properties["dbname"] . " -h " . self::$_properties["host"]
|
||||
. " -f $sqlDir$f 2>/dev/null", $out, $status);
|
||||
} catch (Exception $e) {
|
||||
throw new AirtimeDatabaseException("There was an error setting up the Airtime schema!",
|
||||
array(self::DB_NAME,));
|
||||
|
@ -185,7 +170,7 @@ class DatabaseSetup extends Setup {
|
|||
private function checkDatabaseEncoding() {
|
||||
$statement = self::$dbh->prepare("SELECT pg_encoding_to_char(encoding) "
|
||||
. "FROM pg_database WHERE datname = :dbname");
|
||||
$statement->execute(array(":dbname" => $this->name));
|
||||
$statement->execute(array(":dbname" => self::$_properties["dbname"]));
|
||||
$encoding = $statement->fetch();
|
||||
if (!($encoding && $encoding[0] == "UTF8")) {
|
||||
throw new AirtimeDatabaseException("The database was installed with an incorrect encoding type!",
|
||||
|
|
|
@ -11,37 +11,28 @@
|
|||
class GeneralSetup extends Setup {
|
||||
|
||||
// airtime.conf section header
|
||||
const SECTION = "[general]";
|
||||
protected static $_section = "[general]";
|
||||
|
||||
// Constant form field names for passing errors back to the front-end
|
||||
const GENERAL_PORT = "generalPort",
|
||||
GENERAL_HOST = "generalHost";
|
||||
|
||||
// Form field values
|
||||
static $user, $host, $port, $root;
|
||||
|
||||
// Array of key->value pairs for airtime.conf
|
||||
static $properties;
|
||||
protected static $_properties;
|
||||
|
||||
// Message and error fields to return to the front-end
|
||||
static $message = null;
|
||||
static $errors = array();
|
||||
|
||||
function __construct($settings) {
|
||||
self::$host = $settings[self::GENERAL_HOST];
|
||||
self::$port = $settings[self::GENERAL_PORT];
|
||||
|
||||
self::$properties = array(
|
||||
self::$_properties = array(
|
||||
"api_key" => $this->generateRandomString(),
|
||||
"base_url" => self::$host,
|
||||
"base_port" => self::$port,
|
||||
"base_url" => $settings[self::GENERAL_HOST],
|
||||
"base_port" => $settings[self::GENERAL_PORT],
|
||||
);
|
||||
}
|
||||
|
||||
function writeToTemp() {
|
||||
parent::writeToTemp(self::SECTION, self::$properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array associative array containing a display message and fields with errors
|
||||
*/
|
||||
|
|
|
@ -26,7 +26,9 @@ class MediaSetup extends Setup {
|
|||
|
||||
const MEDIA_FOLDER = "mediaFolder";
|
||||
const AIRTIME_CONF_PATH = "/etc/airtime/airtime.conf";
|
||||
|
||||
const RMQ_INI_BASE_PATH = "/etc/airtime-saas/";
|
||||
const RMQ_INI_FILE_NAME = "rabbitmq-analyzer.ini";
|
||||
|
||||
static $path;
|
||||
static $message = null;
|
||||
static $errors = array();
|
||||
|
@ -62,10 +64,14 @@ class MediaSetup extends Setup {
|
|||
// Finalize and move airtime.conf.temp
|
||||
if (file_exists("/etc/airtime/")) {
|
||||
if (!$this->moveAirtimeConfig()) {
|
||||
$message = "Error moving airtime.conf or deleting /tmp/airtime.conf.temp!";
|
||||
$errors[] = "ERR";
|
||||
self::$message = "Error moving airtime.conf or deleting /tmp/airtime.conf.temp!";
|
||||
self::$errors[] = "ERR";
|
||||
}
|
||||
|
||||
if (!$this->moveRmqConfig()) {
|
||||
self::$message = "Error moving rabbitmq-analyzer.ini or deleting /tmp/rabbitmq.ini.tmp!";
|
||||
self::$errors[] = "ERR";
|
||||
}
|
||||
|
||||
/*
|
||||
* If we're upgrading from an old Airtime instance (pre-2.5.2) we rename their old
|
||||
* airtime.conf to airtime.conf.tmp during the setup process. Now that we're done,
|
||||
|
@ -75,8 +81,8 @@ class MediaSetup extends Setup {
|
|||
rename(self::AIRTIME_CONF_PATH . ".tmp", self::AIRTIME_CONF_PATH . ".bak");
|
||||
}
|
||||
} else {
|
||||
$message = "Failed to move airtime.conf; /etc/airtime doesn't exist!";
|
||||
$errors[] = "ERR";
|
||||
self::$message = "Failed to move airtime.conf; /etc/airtime doesn't exist!";
|
||||
self::$errors[] = "ERR";
|
||||
}
|
||||
|
||||
return array(
|
||||
|
@ -84,7 +90,7 @@ class MediaSetup extends Setup {
|
|||
"errors" => self::$errors
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Moves /tmp/airtime.conf.temp to /etc/airtime.conf and then removes it to complete setup
|
||||
* @return boolean false if either of the copy or removal operations fail
|
||||
|
@ -94,6 +100,16 @@ class MediaSetup extends Setup {
|
|||
&& unlink(AIRTIME_CONF_TEMP_PATH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves /tmp/airtime.conf.temp to /etc/airtime.conf and then removes it to complete setup
|
||||
* @return boolean false if either of the copy or removal operations fail
|
||||
*/
|
||||
function moveRmqConfig() {
|
||||
return copy(RMQ_INI_TEMP_PATH, self::RMQ_INI_BASE_PATH . self::RMQ_INI_FILE_NAME)
|
||||
&& copy(RMQ_INI_TEMP_PATH, self::RMQ_INI_BASE_PATH . "production/" . self::RMQ_INI_FILE_NAME)
|
||||
&& unlink(RMQ_INI_TEMP_PATH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the given directory to cc_music_dirs
|
||||
* TODO Should we check for an existing entry in cc_music_dirs?
|
||||
|
|
|
@ -13,7 +13,10 @@ require_once dirname(dirname( __DIR__)) . '/library/php-amqplib/amqp.inc';
|
|||
class RabbitMQSetup extends Setup {
|
||||
|
||||
// airtime.conf section header
|
||||
const SECTION = "[rabbitmq]";
|
||||
protected static $_section = "[rabbitmq]";
|
||||
|
||||
// Array of key->value pairs for airtime.conf
|
||||
protected static $_properties;
|
||||
|
||||
// Constant form field names for passing errors back to the front-end
|
||||
const RMQ_USER = "rmqUser",
|
||||
|
@ -22,29 +25,17 @@ class RabbitMQSetup extends Setup {
|
|||
RMQ_HOST = "rmqHost",
|
||||
RMQ_VHOST = "rmqVHost";
|
||||
|
||||
// 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];
|
||||
self::$pass = $settings[self::RMQ_PASS];
|
||||
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,
|
||||
static::$_properties = array(
|
||||
"host" => $settings[self::RMQ_HOST],
|
||||
"port" => $settings[self::RMQ_PORT],
|
||||
"user" => $settings[self::RMQ_USER],
|
||||
"password" => $settings[self::RMQ_PASS],
|
||||
"vhost" => $settings[self::RMQ_VHOST],
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -72,24 +63,20 @@ class RabbitMQSetup extends Setup {
|
|||
);
|
||||
}
|
||||
|
||||
function writeToTemp() {
|
||||
parent::writeToTemp(self::SECTION, self::$properties);
|
||||
}
|
||||
|
||||
function checkRMQConnection() {
|
||||
$conn = new AMQPConnection(self::$host,
|
||||
self::$port,
|
||||
self::$user,
|
||||
self::$pass,
|
||||
self::$vhost);
|
||||
$conn = new AMQPConnection(self::$_properties["host"],
|
||||
self::$_properties["port"],
|
||||
self::$_properties["user"],
|
||||
self::$_properties["password"],
|
||||
self::$_properties["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::$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;
|
||||
|
@ -97,4 +84,12 @@ class RabbitMQSetup extends Setup {
|
|||
self::$errors[] = self::RMQ_VHOST;
|
||||
}
|
||||
|
||||
protected function writeToTemp() {
|
||||
if (!file_exists(RMQ_INI_TEMP_PATH)) {
|
||||
copy(BUILD_PATH . "rabbitmq-analyzer.ini", RMQ_INI_TEMP_PATH);
|
||||
}
|
||||
$this->_write(RMQ_INI_TEMP_PATH);
|
||||
parent::writeToTemp();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
define("BUILD_PATH", dirname(dirname(__DIR__)) . "/build/");
|
||||
define("AIRTIME_CONF_TEMP_PATH", "/tmp/airtime.conf.temp");
|
||||
define("RMQ_INI_TEMP_PATH", "/tmp/rabbitmq.ini.tmp");
|
||||
|
||||
/**
|
||||
* Class Setup
|
||||
|
@ -11,50 +12,59 @@ define("AIRTIME_CONF_TEMP_PATH", "/tmp/airtime.conf.temp");
|
|||
*/
|
||||
abstract class Setup {
|
||||
|
||||
protected static $_section;
|
||||
|
||||
/**
|
||||
* Array of key->value pairs for airtime.conf
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $_properties;
|
||||
|
||||
abstract function __construct($settings);
|
||||
|
||||
abstract function runSetup();
|
||||
|
||||
/**
|
||||
* Write new property values to a given section in airtime.conf.temp
|
||||
*
|
||||
* @param string $section
|
||||
* the configuration section to write to
|
||||
* @param array $properties
|
||||
* the configuration properties and values to overwrite
|
||||
*/
|
||||
protected function writeToTemp($section, $properties) {
|
||||
protected function writeToTemp() {
|
||||
if (!file_exists(AIRTIME_CONF_TEMP_PATH)) {
|
||||
copy(BUILD_PATH . "airtime.example.conf", AIRTIME_CONF_TEMP_PATH);
|
||||
}
|
||||
|
||||
$file = file(AIRTIME_CONF_TEMP_PATH);
|
||||
|
||||
$this->_write(AIRTIME_CONF_TEMP_PATH);
|
||||
}
|
||||
|
||||
protected function _write($filePath) {
|
||||
$file = file($filePath);
|
||||
$fileOutput = "";
|
||||
|
||||
|
||||
$inSection = false;
|
||||
|
||||
|
||||
foreach ($file as $line) {
|
||||
if (strpos($line, $section) !== false) {
|
||||
if (strpos($line, static::$_section) !== false) {
|
||||
$inSection = true;
|
||||
} else if (strpos($line, "[") !== false) {
|
||||
$inSection = false;
|
||||
}
|
||||
|
||||
|
||||
if (substr(trim($line), 0, 1) == "#") {
|
||||
/* Workaround to strip comments from airtime.conf.
|
||||
* We need to do this because python's ConfigObj and PHP
|
||||
* have different (and equally strict) rules about comment
|
||||
* have different (and equally strict) rules about comment
|
||||
* characters in configuration files.
|
||||
*/
|
||||
} else if ($inSection) {
|
||||
$key = trim(@substr($line, 0, strpos($line, "=")));
|
||||
$fileOutput .= $key && isset($properties[$key]) ? $key . " = " . $properties[$key] . "\n" : $line;
|
||||
$fileOutput .= $key && isset(static::$_properties[$key]) ?
|
||||
$key . " = " . static::$_properties[$key] . "\n" : $line;
|
||||
} else {
|
||||
$fileOutput .= $line;
|
||||
}
|
||||
}
|
||||
|
||||
file_put_contents(AIRTIME_CONF_TEMP_PATH, $fileOutput);
|
||||
|
||||
file_put_contents($filePath, $fileOutput);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue