mirror of
https://github.com/Yetangitu/ampache
synced 2025-10-06 03:49:56 +02:00
Add Server-Sent Events on catalog actions
This commit is contained in:
parent
a9d74c58ad
commit
c763103bee
11 changed files with 314 additions and 179 deletions
|
@ -30,72 +30,42 @@ if (!Access::check('interface','100')) {
|
|||
|
||||
UI::show_header();
|
||||
|
||||
$sse_catalogs = urlencode(serialize($_REQUEST['catalogs']));
|
||||
|
||||
/* Big switch statement to handle various actions */
|
||||
switch ($_REQUEST['action']) {
|
||||
case 'add_to_all_catalogs':
|
||||
$_REQUEST['catalogs'] = Catalog::get_catalogs();
|
||||
$sse_url = AmpConfig::get('web_path') . "/server/sse.server.php?worker=catalog&action=add_to_all_catalogs";
|
||||
sse_worker($sse_url);
|
||||
show_confirmation(T_('Catalog Update started...'), '', AmpConfig::get('web_path') . '/admin/catalog.php', 0, 'confirmation', false);
|
||||
break;
|
||||
case 'add_to_catalog':
|
||||
toggle_visible('ajax-loading');
|
||||
ob_end_flush();
|
||||
if (AmpConfig::get('demo_mode')) { break; }
|
||||
if ($_REQUEST['catalogs']) {
|
||||
foreach ($_REQUEST['catalogs'] as $catalog_id) {
|
||||
$catalog = Catalog::create_from_id($catalog_id);
|
||||
$catalog->add_to_catalog($_POST);
|
||||
}
|
||||
}
|
||||
$url = AmpConfig::get('web_path') . '/admin/catalog.php';
|
||||
$title = T_('Catalog Updated');
|
||||
$body = '';
|
||||
show_confirmation($title, $body, $url);
|
||||
toggle_visible('ajax-loading');
|
||||
|
||||
$sse_url = AmpConfig::get('web_path') . "/server/sse.server.php?worker=catalog&action=add_to_catalog&catalogs=" . $sse_catalogs;
|
||||
sse_worker($sse_url);
|
||||
show_confirmation(T_('Catalog Update started...'), '', AmpConfig::get('web_path') . '/admin/catalog.php', 0, 'confirmation', false);
|
||||
break;
|
||||
case 'update_all_catalogs':
|
||||
$_REQUEST['catalogs'] = Catalog::get_catalogs();
|
||||
$sse_url = AmpConfig::get('web_path') . "/server/sse.server.php?worker=catalog&action=update_all_catalogs";
|
||||
sse_worker($sse_url);
|
||||
show_confirmation(T_('Catalog Update started...'), '', AmpConfig::get('web_path') . '/admin/catalog.php', 0, 'confirmation', false);
|
||||
break;
|
||||
case 'update_catalog':
|
||||
toggle_visible('ajax-loading');
|
||||
ob_end_flush();
|
||||
/* If they are in demo mode stop here */
|
||||
if (AmpConfig::get('demo_mode')) { break; }
|
||||
|
||||
if (isset($_REQUEST['catalogs'])) {
|
||||
foreach ($_REQUEST['catalogs'] as $catalog_id) {
|
||||
$catalog = Catalog::create_from_id($catalog_id);
|
||||
$catalog->verify_catalog();
|
||||
}
|
||||
}
|
||||
$url = AmpConfig::get('web_path') . '/admin/catalog.php';
|
||||
$title = T_('Catalog Updated');
|
||||
$body = '';
|
||||
show_confirmation($title,$body,$url);
|
||||
toggle_visible('ajax-loading');
|
||||
$sse_url = AmpConfig::get('web_path') . "/server/sse.server.php?worker=catalog&action=update_catalog&catalogs=" . $sse_catalogs;
|
||||
sse_worker($sse_url);
|
||||
show_confirmation(T_('Catalog Update started...'), '', AmpConfig::get('web_path') . '/admin/catalog.php', 0, 'confirmation', false);
|
||||
break;
|
||||
case 'full_service':
|
||||
toggle_visible('ajax-loading');
|
||||
ob_end_flush();
|
||||
/* Make sure they aren't in demo mode */
|
||||
if (AmpConfig::get('demo_mode')) { UI::access_denied(); break; }
|
||||
|
||||
if (!$_REQUEST['catalogs']) {
|
||||
$_REQUEST['catalogs'] = Catalog::get_catalogs();
|
||||
}
|
||||
|
||||
/* This runs the clean/verify/add in that order */
|
||||
foreach ($_REQUEST['catalogs'] as $catalog_id) {
|
||||
$catalog = Catalog::create_from_id($catalog_id);
|
||||
$catalog->clean_catalog();
|
||||
$catalog->verify_catalog();
|
||||
$catalog->add_to_catalog();
|
||||
}
|
||||
Dba::optimize_tables();
|
||||
$url = AmpConfig::get('web_path') . '/admin/catalog.php';
|
||||
$title = T_('Catalog Updated');
|
||||
$body = '';
|
||||
show_confirmation($title,$body,$url);
|
||||
toggle_visible('ajax-loading');
|
||||
$sse_url = AmpConfig::get('web_path') . "/server/sse.server.php?worker=catalog&action=full_service&catalogs=" . $sse_catalogs;
|
||||
sse_worker($sse_url);
|
||||
show_confirmation(T_('Catalog Update started...'), '', AmpConfig::get('web_path') . '/admin/catalog.php', 0, 'confirmation', false);
|
||||
break;
|
||||
case 'delete_catalog':
|
||||
/* Make sure they aren't in demo mode */
|
||||
if (AmpConfig::get('demo_mode')) { break; }
|
||||
|
||||
if (!Core::form_verify('delete_catalog')) {
|
||||
|
@ -132,27 +102,14 @@ switch ($_REQUEST['action']) {
|
|||
show_confirmation($title,$body,$url);
|
||||
break;
|
||||
case 'clean_all_catalogs':
|
||||
$_REQUEST['catalogs'] = Catalog::get_catalogs();
|
||||
$sse_url = AmpConfig::get('web_path') . "/server/sse.server.php?worker=catalog&action=clean_all_catalogs";
|
||||
sse_worker($sse_url);
|
||||
show_confirmation(T_('Catalog Clean sStarted...'), '', AmpConfig::get('web_path') . '/admin/catalog.php', 0, 'confirmation', false);
|
||||
break;
|
||||
case 'clean_catalog':
|
||||
toggle_visible('ajax-loading');
|
||||
ob_end_flush();
|
||||
/* If they are in demo mode stop them here */
|
||||
if (AmpConfig::get('demo_mode')) { break; }
|
||||
|
||||
// Make sure they checked something
|
||||
if (isset($_REQUEST['catalogs'])) {
|
||||
foreach ($_REQUEST['catalogs'] as $catalog_id) {
|
||||
$catalog = Catalog::create_from_id($catalog_id);
|
||||
$catalog->clean_catalog();
|
||||
} // end foreach catalogs
|
||||
Dba::optimize_tables();
|
||||
}
|
||||
|
||||
$url = AmpConfig::get('web_path') . '/admin/catalog.php';
|
||||
$title = T_('Catalog Cleaned');
|
||||
$body = '';
|
||||
show_confirmation($title,$body,$url);
|
||||
toggle_visible('ajax-loading');
|
||||
$sse_url = AmpConfig::get('web_path') . "/server/sse.server.php?worker=catalog&action=clean_catalog&catalogs" . $sse_catalogs;
|
||||
sse_worker($sse_url);
|
||||
show_confirmation(T_('Catalog Clean started...'), '', AmpConfig::get('web_path') . '/admin/catalog.php', 0, 'confirmation', false);
|
||||
break;
|
||||
case 'update_catalog_settings':
|
||||
/* No Demo Here! */
|
||||
|
@ -169,29 +126,9 @@ switch ($_REQUEST['action']) {
|
|||
case 'update_from':
|
||||
if (AmpConfig::get('demo_mode')) { break; }
|
||||
|
||||
$catalog_id = 0;
|
||||
// First see if we need to do an add
|
||||
if ($_POST['add_path'] != '/' AND strlen($_POST['add_path'])) {
|
||||
if ($catalog_id = Catalog_local::get_from_path($_POST['add_path'])) {
|
||||
$catalog = Catalog::create_from_id($catalog_id);
|
||||
$catalog->add_to_catalog(array('subdirectory'=>$_POST['add_path']));
|
||||
}
|
||||
} // end if add
|
||||
|
||||
// Now check for an update
|
||||
if ($_POST['update_path'] != '/' AND strlen($_POST['update_path'])) {
|
||||
if ($catalog_id = Catalog_local::get_from_path($_POST['update_path'])) {
|
||||
$songs = Song::get_from_path($_POST['update_path']);
|
||||
foreach ($songs as $song_id) { Catalog::update_single_item('song',$song_id); }
|
||||
}
|
||||
} // end if update
|
||||
|
||||
if ($catalog_id > 0) {
|
||||
echo T_("Subdirectory update completed.");
|
||||
} else {
|
||||
echo T_("This subdirectory is not part of an existing catalog. Update cannot be processed.");
|
||||
}
|
||||
show_confirmation('','', AmpConfig::get('web_path').'/admin/catalog.php');
|
||||
$sse_url = AmpConfig::get('web_path') . "/server/sse.server.php?worker=catalog&action=update_from&add_path" . scrub_in($_POST['add_path']) . "&update_path=" . $_POST['update_path'];
|
||||
sse_worker($sse_url);
|
||||
show_confirmation(T_('Subdirectory update started...'), '', AmpConfig::get('web_path') . '/admin/catalog.php', 0, 'confirmation', false);
|
||||
break;
|
||||
case 'add_catalog':
|
||||
/* Wah Demo! */
|
||||
|
@ -222,19 +159,10 @@ switch ($_REQUEST['action']) {
|
|||
break;
|
||||
}
|
||||
|
||||
$catalog = Catalog::create_from_id($catalog_id);
|
||||
|
||||
// Run our initial add
|
||||
$catalog->add_to_catalog($_POST);
|
||||
|
||||
UI::show_box_top(T_('Catalog Created'), 'box box_catalog_created');
|
||||
echo "<h2>" . T_('Catalog Created') . "</h2>";
|
||||
Error::display('general');
|
||||
Error::display('catalog_add');
|
||||
UI::show_box_bottom();
|
||||
|
||||
show_confirmation('','', AmpConfig::get('web_path').'/admin/catalog.php');
|
||||
$sse_url = AmpConfig::get('web_path') . "/server/sse.server.php?worker=catalog&action=add_catalog&catalog_id=" . $catalog_id . "&options=" . urlencode(serialize($_POST));
|
||||
sse_worker($sse_url);
|
||||
|
||||
show_confirmation(T_('Catalog Creation started...'), '', AmpConfig::get('web_path') . '/admin/catalog.php', 0, 'confirmation', false);
|
||||
} else {
|
||||
require AmpConfig::get('prefix') . '/templates/show_add_catalog.inc.php';
|
||||
}
|
||||
|
@ -280,22 +208,9 @@ switch ($_REQUEST['action']) {
|
|||
require_once AmpConfig::get('prefix') . '/templates/show_edit_catalog.inc.php';
|
||||
break;
|
||||
case 'gather_media_art':
|
||||
toggle_visible('ajax-loading');
|
||||
ob_end_flush();
|
||||
|
||||
$catalogs = $_REQUEST['catalogs'] ? $_REQUEST['catalogs'] : Catalog::get_catalogs();
|
||||
|
||||
// Iterate throught the catalogs and gather as needed
|
||||
foreach ($catalogs as $catalog_id) {
|
||||
$catalog = Catalog::create_from_id($catalog_id);
|
||||
require AmpConfig::get('prefix') . '/templates/show_gather_art.inc.php';
|
||||
flush();
|
||||
$catalog->gather_art();
|
||||
}
|
||||
$url = AmpConfig::get('web_path') . '/admin/catalog.php';
|
||||
$title = T_('Media Art Search Finished');
|
||||
$body = '';
|
||||
show_confirmation($title,$body,$url);
|
||||
$sse_url = AmpConfig::get('web_path') . "/server/sse.server.php?worker=catalog&action=gather_media_art&catalogs=" . $sse_catalogs;
|
||||
sse_worker($sse_url);
|
||||
show_confirmation(T_('Media Art Search started...'), '', AmpConfig::get('web_path') . '/admin/catalog.php', 0, 'confirmation', false);
|
||||
break;
|
||||
case 'show_catalogs':
|
||||
default:
|
||||
|
|
|
@ -80,6 +80,13 @@ class Error
|
|||
$_SESSION['errors'][$name] .= "<br />\n" . $message;
|
||||
}
|
||||
|
||||
// If on SSE worker, output the error directly.
|
||||
if (defined('SSE_OUTPUT')) {
|
||||
echo "data: display_sse_error('" . addslashes($message) . "')\n\n";
|
||||
ob_flush();
|
||||
flush();
|
||||
}
|
||||
|
||||
} // add
|
||||
|
||||
/**
|
||||
|
|
|
@ -326,11 +326,22 @@ END;
|
|||
return;
|
||||
}
|
||||
|
||||
echo '<script type="text/javascript">';
|
||||
echo "updateText('$field', '$value');";
|
||||
echo "</script>\n";
|
||||
static $id = 1;
|
||||
|
||||
if (defined('SSE_OUTPUT')) {
|
||||
echo "id: " . $id . "\n";
|
||||
echo "data: displayNotification('" . addslashes($value) . "', 5000)\n\n";
|
||||
} else {
|
||||
if (!empty($field)) {
|
||||
echo "<script>updateText('" . $field . "', '" . addslashes($value) ."');</script>\n";
|
||||
} else {
|
||||
echo "<br />" . $value . "<br /><br />\n";
|
||||
}
|
||||
}
|
||||
|
||||
ob_flush();
|
||||
flush();
|
||||
$id++;
|
||||
}
|
||||
|
||||
public static function get_logo_url()
|
||||
|
|
|
@ -33,6 +33,38 @@ function loadContentPage(url)
|
|||
});
|
||||
}
|
||||
|
||||
var sseSource = null;
|
||||
function sse_worker(url) {
|
||||
if(typeof(EventSource) !== "undefined") {
|
||||
sseSource = new EventSource(url);
|
||||
sseSource.onmessage = function(event) {
|
||||
eval(event.data);
|
||||
};
|
||||
sseSource.onopen = function() {
|
||||
displayNotification('Connected through Server-Sent Events, processing...', 5000);
|
||||
};
|
||||
sseSource.onerror = function() {
|
||||
displayNotification('Server-Sent Events connection error. Re-connection...', 5000);
|
||||
};
|
||||
} else {
|
||||
// Server-Sent Events not supported, call the update in ajax and the output result
|
||||
$.get(url + '&html=1', function (data) {
|
||||
$("#guts").append(data);
|
||||
}, 'html')
|
||||
}
|
||||
}
|
||||
|
||||
function stop_sse_worker() {
|
||||
if (sseSource !== null) {
|
||||
sseSource.close();
|
||||
sseSource = null;
|
||||
}
|
||||
}
|
||||
|
||||
function display_sse_error(error) {
|
||||
displayNotification('ERROR: ' + error, 10000);
|
||||
}
|
||||
|
||||
$(function() {
|
||||
|
||||
var newHash = "";
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
* @param integer $cancel T/F show a cancel button that uses return_referrer()
|
||||
* @return void
|
||||
*/
|
||||
function show_confirmation($title,$text,$next_url,$cancel=0,$form_name='confirmation')
|
||||
function show_confirmation($title,$text,$next_url,$cancel=0,$form_name='confirmation',$visible=true)
|
||||
{
|
||||
if (substr_count($next_url,AmpConfig::get('web_path'))) {
|
||||
$path = $next_url;
|
||||
|
@ -46,6 +46,13 @@ function show_confirmation($title,$text,$next_url,$cancel=0,$form_name='confirma
|
|||
require AmpConfig::get('prefix') . '/templates/show_confirmation.inc.php';
|
||||
} // show_confirmation
|
||||
|
||||
function sse_worker($url)
|
||||
{
|
||||
echo '<script type="text/javascript">';
|
||||
echo "sse_worker('$url');";
|
||||
echo "</script>\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* return_referer
|
||||
* returns the script part of the referer address passed by the web browser
|
||||
|
|
|
@ -240,9 +240,13 @@ class Catalog_dropbox extends Catalog
|
|||
$this->authcode = $options['authcode'];
|
||||
}
|
||||
|
||||
if (!defined('SSE_OUTPUT')) {
|
||||
UI::show_box_top(T_('Running Dropbox Remote Update') . '. . .');
|
||||
}
|
||||
$this->update_remote_catalog();
|
||||
if (!defined('SSE_OUTPUT')) {
|
||||
UI::show_box_bottom();
|
||||
}
|
||||
|
||||
return true;
|
||||
} // add_to_catalog
|
||||
|
@ -279,16 +283,12 @@ class Catalog_dropbox extends Catalog
|
|||
$this->count = 0;
|
||||
$this->add_files($client, $this->path);
|
||||
|
||||
echo "\n<br />" .
|
||||
printf(T_('Catalog Update Finished. Total Media: [%s]'), $this->count);
|
||||
echo '<br />';
|
||||
UI::update_text('', sprintf(T_('Catalog Update Finished. Total Media: [%s]'), $this->count));
|
||||
if ($this->count == 0) {
|
||||
echo T_('No media updated, do you respect the patterns?') . '<br />';
|
||||
Error::add('general', T_('No media updated, do you respect the patterns?'));
|
||||
}
|
||||
echo '<br />';
|
||||
} else {
|
||||
echo "<p>" . T_('API Error: cannot connect to Dropbox.') . "</p><hr />\n";
|
||||
flush();
|
||||
Error::add('general', T_('API Error: cannot connect to Dropbox.'));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -321,8 +321,7 @@ class Catalog_dropbox extends Catalog
|
|||
$this->add_file($client, $metadata);
|
||||
}
|
||||
} else {
|
||||
echo "<p>" . T_('API Error: Cannot access file/folder at ' . $this->path . '.') . "</p><hr />\n";
|
||||
flush();
|
||||
Error::add('general', T_('API Error: Cannot access file/folder at ' . $this->path . '.'));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -432,8 +431,7 @@ class Catalog_dropbox extends Catalog
|
|||
}
|
||||
}
|
||||
} else {
|
||||
echo "<p>" . T_('API Error: cannot connect to Dropbox.') . "</p><hr />\n";
|
||||
flush();
|
||||
Error::add('general', T_('API Error: cannot connect to Dropbox.'));
|
||||
}
|
||||
|
||||
return $dead;
|
||||
|
|
|
@ -426,8 +426,10 @@ class Catalog_local extends Catalog
|
|||
$this->added_songs_to_gather = array();
|
||||
$this->added_videos_to_gather = array();
|
||||
|
||||
if (!defined('SSE_OUTPUT')) {
|
||||
require AmpConfig::get('prefix') . '/templates/show_adds_catalog.inc.php';
|
||||
flush();
|
||||
}
|
||||
|
||||
/* Set the Start time */
|
||||
$start_time = time();
|
||||
|
@ -457,8 +459,10 @@ class Catalog_local extends Catalog
|
|||
|
||||
if ($options['gather_art']) {
|
||||
$catalog_id = $this->id;
|
||||
if (!defined('SSE_OUTPUT')) {
|
||||
require AmpConfig::get('prefix') . '/templates/show_gather_art.inc.php';
|
||||
flush();
|
||||
}
|
||||
$this->gather_art($this->added_songs_to_gather, $this->added_videos_to_gather);
|
||||
}
|
||||
|
||||
|
@ -468,12 +472,13 @@ class Catalog_local extends Catalog
|
|||
$time_diff = ($current_time - $start_time) ?: 0;
|
||||
$rate = intval(($time_diff > 0) ? $this->count / $time_diff : false) ?: T_('N/A');
|
||||
|
||||
if (!defined('SSE_OUTPUT')) {
|
||||
UI::show_box_top();
|
||||
echo "\n<br />" .
|
||||
printf(T_('Catalog Update Finished. Total Time: [%s] Total Media: [%s] Media Per Second: [%s]'),
|
||||
date('i:s', $time_diff), $this->count, $rate);
|
||||
echo '<br /><br />';
|
||||
}
|
||||
UI::update_text('', sprintf(T_('Catalog Update Finished. Total Time: [%s] Total Media: [%s] Media Per Second: [%s]'), date('i:s', $time_diff), $this->count, $rate));
|
||||
if (!defined('SSE_OUTPUT')) {
|
||||
UI::show_box_bottom();
|
||||
}
|
||||
|
||||
} // add_to_catalog
|
||||
|
||||
|
@ -491,7 +496,10 @@ class Catalog_local extends Catalog
|
|||
$total_updated = 0;
|
||||
$this->count = 0;
|
||||
|
||||
if (!defined('SSE_OUTPUT')) {
|
||||
require_once AmpConfig::get('prefix') . '/templates/show_verify_catalog.inc.php';
|
||||
flush();
|
||||
}
|
||||
|
||||
foreach (array('video', 'song') as $media_type) {
|
||||
$total = $stats[$media_type . 's']; // UGLY
|
||||
|
|
|
@ -181,9 +181,13 @@ class Catalog_remote extends Catalog
|
|||
*/
|
||||
public function add_to_catalog($options = null)
|
||||
{
|
||||
if (!defined('SSE_OUTPUT')) {
|
||||
UI::show_box_top(T_('Running Remote Update') . '. . .');
|
||||
}
|
||||
$this->update_remote_catalog();
|
||||
if (!defined('SSE_OUTPUT')) {
|
||||
UI::show_box_bottom();
|
||||
}
|
||||
|
||||
return true;
|
||||
} // add_to_catalog
|
||||
|
@ -239,8 +243,7 @@ class Catalog_remote extends Catalog
|
|||
$remote_catalog_info = $remote_handle->info();
|
||||
|
||||
// Tell 'em what we've found, Johnny!
|
||||
printf(T_('%u remote catalog(s) found (%u songs)'), $remote_catalog_info['catalogs'], $remote_catalog_info['songs']);
|
||||
flush();
|
||||
UI::update_text('', sprintf(T_('%u remote catalog(s) found (%u songs)'), $remote_catalog_info['catalogs'], $remote_catalog_info['songs']));
|
||||
|
||||
// Hardcoded for now
|
||||
$step = 500;
|
||||
|
@ -275,8 +278,7 @@ class Catalog_remote extends Catalog
|
|||
}
|
||||
} // end while
|
||||
|
||||
echo "<p>" . T_('Completed updating remote catalog(s).') . "</p><hr />\n";
|
||||
flush();
|
||||
UI::update_text('', T_('Completed updating remote catalog(s).'));
|
||||
|
||||
// Update the last update value
|
||||
$this->update_last_update();
|
||||
|
|
|
@ -219,9 +219,13 @@ class Catalog_soundcloud extends Catalog
|
|||
$this->authcode = $options['authcode'];
|
||||
}
|
||||
|
||||
if (!defined('SSE_OUTPUT')) {
|
||||
UI::show_box_top(T_('Running SoundCloud Remote Update') . '. . .');
|
||||
}
|
||||
$this->update_remote_catalog();
|
||||
if (!defined('SSE_OUTPUT')) {
|
||||
UI::show_box_bottom();
|
||||
}
|
||||
|
||||
return true;
|
||||
} // add_to_catalog
|
||||
|
@ -278,8 +282,6 @@ class Catalog_soundcloud extends Catalog
|
|||
if (!Song::insert($data)) {
|
||||
debug_event('soundcloud_catalog', 'Insert failed for ' . $data['file'], 1);
|
||||
Error::add('general', T_('Unable to Insert Song - %s'), $data['file']);
|
||||
Error::display('general');
|
||||
flush();
|
||||
} else {
|
||||
$songsadded++;
|
||||
}
|
||||
|
@ -287,21 +289,18 @@ class Catalog_soundcloud extends Catalog
|
|||
}
|
||||
}
|
||||
|
||||
echo "<p>" . T_('Completed updating SoundCloud catalog(s).') . " " . $songsadded . " " . T_('Songs added.') . "</p><hr />\n";
|
||||
flush();
|
||||
UI::update_text('', T_('Completed updating SoundCloud catalog(s).') . " " . $songsadded . " " . T_('Songs added.'));
|
||||
|
||||
// Update the last update value
|
||||
$this->update_last_update();
|
||||
} else {
|
||||
echo "<p>" . T_('API Error: cannot get song list.') . "</p><hr />\n";
|
||||
flush();
|
||||
Error::add('general', T_('API Error: cannot get song list.'));
|
||||
}
|
||||
} else {
|
||||
echo "<p>" . T_('API Error: cannot connect to SoundCloud.') . "</p><hr />\n";
|
||||
flush();
|
||||
Error::add('general', T_('API Error: cannot connect to SoundCloud.'));
|
||||
}
|
||||
} catch (Exception $ex) {
|
||||
echo "<p>" . T_('SoundCloud exception: ') . $ex->getMessage() . "</p><hr />\n";
|
||||
Error::add('general', T_('SoundCloud exception: ') . $ex->getMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -185,9 +185,13 @@ class Catalog_subsonic extends Catalog
|
|||
// Prevent the script from timing out
|
||||
set_time_limit(0);
|
||||
|
||||
if (!defined('SSE_OUTPUT')) {
|
||||
UI::show_box_top(T_('Running Subsonic Remote Update') . '. . .');
|
||||
}
|
||||
$this->update_remote_catalog();
|
||||
if (!defined('SSE_OUTPUT')) {
|
||||
UI::show_box_bottom();
|
||||
}
|
||||
|
||||
return true;
|
||||
} // add_to_catalog
|
||||
|
@ -243,8 +247,6 @@ class Catalog_subsonic extends Catalog
|
|||
if (!Song::insert($data)) {
|
||||
debug_event('subsonic_catalog', 'Insert failed for ' . $song['path'], 1);
|
||||
Error::add('general', T_('Unable to Insert Song - %s'), $song['path']);
|
||||
Error::display('general');
|
||||
flush();
|
||||
} else {
|
||||
$songsadded++;
|
||||
}
|
||||
|
@ -252,26 +254,22 @@ class Catalog_subsonic extends Catalog
|
|||
}
|
||||
}
|
||||
} else {
|
||||
echo "<p>" . T_('Song Error.') . ": " . $songs['error'] . "</p><hr />\n";
|
||||
flush();
|
||||
Error::add('general', T_('Song Error.') . ": " . $songs['error']);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
echo "<p>" . T_('Album Error.') . ": " . $albums['error'] . "</p><hr />\n";
|
||||
flush();
|
||||
Error::add('general', T_('Album Error.') . ": " . $albums['error']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo "<p>" . T_('Completed updating Subsonic catalog(s).') . " " . $songsadded . " " . T_('Songs added.') . "</p><hr />\n";
|
||||
flush();
|
||||
UI::update_text('', T_('Completed updating Subsonic catalog(s).') . " " . $songsadded . " " . T_('Songs added.'));
|
||||
|
||||
// Update the last update value
|
||||
$this->update_last_update();
|
||||
} else {
|
||||
echo "<p>" . T_('Artist Error.') . ": " . $artists['error'] . "</p><hr />\n";
|
||||
flush();
|
||||
Error::add('general', T_('Artist Error.') . ": " . $artists['error']);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
158
server/sse.server.php
Normal file
158
server/sse.server.php
Normal file
|
@ -0,0 +1,158 @@
|
|||
<?php
|
||||
/* vim:set softtabstop=4 shiftwidth=4 expandtab: */
|
||||
/**
|
||||
*
|
||||
* LICENSE: GNU General Public License, version 2 (GPLv2)
|
||||
* Copyright 2001 - 2015 Ampache.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License v2
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once '../lib/init.php';
|
||||
|
||||
if (!Access::check('interface','100')) {
|
||||
UI::access_denied();
|
||||
exit;
|
||||
}
|
||||
if (AmpConfig::get('demo_mode')) { exit; }
|
||||
|
||||
ob_end_clean();
|
||||
set_time_limit(0);
|
||||
|
||||
if (!$_REQUEST['html']) {
|
||||
define('SSE_OUTPUT', true);
|
||||
header('Content-Type: text/event-stream');
|
||||
header('Cache-Control: no-cache');
|
||||
}
|
||||
|
||||
$worker = isset($_REQUEST['worker']) ? $_REQUEST['worker'] : null;
|
||||
$options = unserialize(urldecode(scrub_in($_REQUEST['options'])));
|
||||
|
||||
$_REQUEST['catalogs'] = scrub_in(unserialize(urldecode($_REQUEST['catalogs'])));
|
||||
|
||||
switch ($worker) {
|
||||
case 'catalog':
|
||||
if (defined('SSE_OUTPUT')) {
|
||||
echo "data: toggleVisible('ajax-loading')\n\n";
|
||||
ob_flush();
|
||||
flush();
|
||||
}
|
||||
|
||||
switch ($_REQUEST['action']) {
|
||||
case 'add_to_all_catalogs':
|
||||
$_REQUEST['catalogs'] = Catalog::get_catalogs();
|
||||
case 'add_to_catalog':
|
||||
if ($_REQUEST['catalogs']) {
|
||||
foreach ($_REQUEST['catalogs'] as $catalog_id) {
|
||||
$catalog = Catalog::create_from_id($catalog_id);
|
||||
$catalog->add_to_catalog($_POST);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'update_all_catalogs':
|
||||
$_REQUEST['catalogs'] = Catalog::get_catalogs();
|
||||
case 'update_catalog':
|
||||
if (isset($_REQUEST['catalogs'])) {
|
||||
foreach ($_REQUEST['catalogs'] as $catalog_id) {
|
||||
$catalog = Catalog::create_from_id($catalog_id);
|
||||
$catalog->verify_catalog();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'full_service':
|
||||
if (!$_REQUEST['catalogs']) {
|
||||
$_REQUEST['catalogs'] = Catalog::get_catalogs();
|
||||
}
|
||||
|
||||
/* This runs the clean/verify/add in that order */
|
||||
foreach ($_REQUEST['catalogs'] as $catalog_id) {
|
||||
$catalog = Catalog::create_from_id($catalog_id);
|
||||
$catalog->clean_catalog();
|
||||
$catalog->verify_catalog();
|
||||
$catalog->add_to_catalog();
|
||||
}
|
||||
Dba::optimize_tables();
|
||||
break;
|
||||
case 'clean_all_catalogs':
|
||||
$_REQUEST['catalogs'] = Catalog::get_catalogs();
|
||||
case 'clean_catalog':
|
||||
// Make sure they checked something
|
||||
if (isset($_REQUEST['catalogs'])) {
|
||||
foreach ($_REQUEST['catalogs'] as $catalog_id) {
|
||||
$catalog = Catalog::create_from_id($catalog_id);
|
||||
$catalog->clean_catalog();
|
||||
} // end foreach catalogs
|
||||
Dba::optimize_tables();
|
||||
}
|
||||
break;
|
||||
case 'update_from':
|
||||
$catalog_id = 0;
|
||||
// First see if we need to do an add
|
||||
if ($_REQUEST['add_path'] != '/' AND strlen($_REQUEST['add_path'])) {
|
||||
if ($catalog_id = Catalog_local::get_from_path($_REQUEST['add_path'])) {
|
||||
$catalog = Catalog::create_from_id($catalog_id);
|
||||
$catalog->add_to_catalog(array('subdirectory'=>$_REQUEST['add_path']));
|
||||
}
|
||||
} // end if add
|
||||
|
||||
// Now check for an update
|
||||
if ($_REQUEST['update_path'] != '/' AND strlen($_REQUEST['update_path'])) {
|
||||
if ($catalog_id = Catalog_local::get_from_path($_REQUEST['update_path'])) {
|
||||
$songs = Song::get_from_path($_REQUEST['update_path']);
|
||||
foreach ($songs as $song_id) { Catalog::update_single_item('song',$song_id); }
|
||||
}
|
||||
} // end if update
|
||||
|
||||
if ($catalog_id <= 0) {
|
||||
Error::add('general', T_("This subdirectory is not part of an existing catalog. Update cannot be processed."));
|
||||
}
|
||||
break;
|
||||
case 'add_catalog':
|
||||
$catalog_id = intval($_REQUEST['catalog_id']);
|
||||
$catalog = Catalog::create_from_id($catalog_id);
|
||||
// Run our initial add
|
||||
$catalog->add_to_catalog($options);
|
||||
|
||||
if (!defined('SSE_OUTPUT')) {
|
||||
Error::display('catalog_add');
|
||||
}
|
||||
break;
|
||||
case 'gather_media_art':
|
||||
$catalogs = $_REQUEST['catalogs'] ? $_REQUEST['catalogs'] : Catalog::get_catalogs();
|
||||
|
||||
// Iterate throught the catalogs and gather as needed
|
||||
foreach ($catalogs as $catalog_id) {
|
||||
$catalog = Catalog::create_from_id($catalog_id);
|
||||
require AmpConfig::get('prefix') . '/templates/show_gather_art.inc.php';
|
||||
flush();
|
||||
$catalog->gather_art();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (defined('SSE_OUTPUT')) {
|
||||
echo "data: toggleVisible('ajax-loading')\n\n";
|
||||
ob_flush();
|
||||
flush();
|
||||
|
||||
echo "data: stop_sse_worker()\n\n";
|
||||
ob_flush();
|
||||
flush();
|
||||
} else {
|
||||
Error::display('general');
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue