1
0
Fork 0
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:
Afterster 2015-02-02 22:45:57 +01:00
parent a9d74c58ad
commit c763103bee
11 changed files with 314 additions and 179 deletions

View file

@ -30,72 +30,42 @@ if (!Access::check('interface','100')) {
UI::show_header(); UI::show_header();
$sse_catalogs = urlencode(serialize($_REQUEST['catalogs']));
/* Big switch statement to handle various actions */ /* Big switch statement to handle various actions */
switch ($_REQUEST['action']) { switch ($_REQUEST['action']) {
case 'add_to_all_catalogs': 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': case 'add_to_catalog':
toggle_visible('ajax-loading');
ob_end_flush();
if (AmpConfig::get('demo_mode')) { break; } if (AmpConfig::get('demo_mode')) { break; }
if ($_REQUEST['catalogs']) {
foreach ($_REQUEST['catalogs'] as $catalog_id) { $sse_url = AmpConfig::get('web_path') . "/server/sse.server.php?worker=catalog&action=add_to_catalog&catalogs=" . $sse_catalogs;
$catalog = Catalog::create_from_id($catalog_id); sse_worker($sse_url);
$catalog->add_to_catalog($_POST); show_confirmation(T_('Catalog Update started...'), '', AmpConfig::get('web_path') . '/admin/catalog.php', 0, 'confirmation', false);
}
}
$url = AmpConfig::get('web_path') . '/admin/catalog.php';
$title = T_('Catalog Updated');
$body = '';
show_confirmation($title, $body, $url);
toggle_visible('ajax-loading');
break; break;
case 'update_all_catalogs': 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': 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 (AmpConfig::get('demo_mode')) { break; }
if (isset($_REQUEST['catalogs'])) { $sse_url = AmpConfig::get('web_path') . "/server/sse.server.php?worker=catalog&action=update_catalog&catalogs=" . $sse_catalogs;
foreach ($_REQUEST['catalogs'] as $catalog_id) { sse_worker($sse_url);
$catalog = Catalog::create_from_id($catalog_id); show_confirmation(T_('Catalog Update started...'), '', AmpConfig::get('web_path') . '/admin/catalog.php', 0, 'confirmation', false);
$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');
break; break;
case 'full_service': 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 (AmpConfig::get('demo_mode')) { UI::access_denied(); break; }
if (!$_REQUEST['catalogs']) { $sse_url = AmpConfig::get('web_path') . "/server/sse.server.php?worker=catalog&action=full_service&catalogs=" . $sse_catalogs;
$_REQUEST['catalogs'] = Catalog::get_catalogs(); sse_worker($sse_url);
} show_confirmation(T_('Catalog Update started...'), '', AmpConfig::get('web_path') . '/admin/catalog.php', 0, 'confirmation', false);
/* 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');
break; break;
case 'delete_catalog': case 'delete_catalog':
/* Make sure they aren't in demo mode */
if (AmpConfig::get('demo_mode')) { break; } if (AmpConfig::get('demo_mode')) { break; }
if (!Core::form_verify('delete_catalog')) { if (!Core::form_verify('delete_catalog')) {
@ -132,27 +102,14 @@ switch ($_REQUEST['action']) {
show_confirmation($title,$body,$url); show_confirmation($title,$body,$url);
break; break;
case 'clean_all_catalogs': 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': case 'clean_catalog':
toggle_visible('ajax-loading'); $sse_url = AmpConfig::get('web_path') . "/server/sse.server.php?worker=catalog&action=clean_catalog&catalogs" . $sse_catalogs;
ob_end_flush(); sse_worker($sse_url);
/* If they are in demo mode stop them here */ show_confirmation(T_('Catalog Clean started...'), '', AmpConfig::get('web_path') . '/admin/catalog.php', 0, 'confirmation', false);
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');
break; break;
case 'update_catalog_settings': case 'update_catalog_settings':
/* No Demo Here! */ /* No Demo Here! */
@ -169,29 +126,9 @@ switch ($_REQUEST['action']) {
case 'update_from': case 'update_from':
if (AmpConfig::get('demo_mode')) { break; } if (AmpConfig::get('demo_mode')) { break; }
$catalog_id = 0; $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'];
// First see if we need to do an add sse_worker($sse_url);
if ($_POST['add_path'] != '/' AND strlen($_POST['add_path'])) { show_confirmation(T_('Subdirectory update started...'), '', AmpConfig::get('web_path') . '/admin/catalog.php', 0, 'confirmation', false);
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');
break; break;
case 'add_catalog': case 'add_catalog':
/* Wah Demo! */ /* Wah Demo! */
@ -222,19 +159,10 @@ switch ($_REQUEST['action']) {
break; break;
} }
$catalog = Catalog::create_from_id($catalog_id); $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);
// 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');
show_confirmation(T_('Catalog Creation started...'), '', AmpConfig::get('web_path') . '/admin/catalog.php', 0, 'confirmation', false);
} else { } else {
require AmpConfig::get('prefix') . '/templates/show_add_catalog.inc.php'; 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'; require_once AmpConfig::get('prefix') . '/templates/show_edit_catalog.inc.php';
break; break;
case 'gather_media_art': case 'gather_media_art':
toggle_visible('ajax-loading'); $sse_url = AmpConfig::get('web_path') . "/server/sse.server.php?worker=catalog&action=gather_media_art&catalogs=" . $sse_catalogs;
ob_end_flush(); sse_worker($sse_url);
show_confirmation(T_('Media Art Search started...'), '', AmpConfig::get('web_path') . '/admin/catalog.php', 0, 'confirmation', false);
$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);
break; break;
case 'show_catalogs': case 'show_catalogs':
default: default:

View file

@ -80,6 +80,13 @@ class Error
$_SESSION['errors'][$name] .= "<br />\n" . $message; $_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 } // add
/** /**

View file

@ -326,11 +326,22 @@ END;
return; return;
} }
echo '<script type="text/javascript">'; static $id = 1;
echo "updateText('$field', '$value');";
echo "</script>\n"; 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(); ob_flush();
flush(); flush();
$id++;
} }
public static function get_logo_url() public static function get_logo_url()

View file

@ -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() { $(function() {
var newHash = ""; var newHash = "";

View file

@ -35,7 +35,7 @@
* @param integer $cancel T/F show a cancel button that uses return_referrer() * @param integer $cancel T/F show a cancel button that uses return_referrer()
* @return void * @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'))) { if (substr_count($next_url,AmpConfig::get('web_path'))) {
$path = $next_url; $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'; require AmpConfig::get('prefix') . '/templates/show_confirmation.inc.php';
} // show_confirmation } // show_confirmation
function sse_worker($url)
{
echo '<script type="text/javascript">';
echo "sse_worker('$url');";
echo "</script>\n";
}
/** /**
* return_referer * return_referer
* returns the script part of the referer address passed by the web browser * returns the script part of the referer address passed by the web browser

View file

@ -240,9 +240,13 @@ class Catalog_dropbox extends Catalog
$this->authcode = $options['authcode']; $this->authcode = $options['authcode'];
} }
if (!defined('SSE_OUTPUT')) {
UI::show_box_top(T_('Running Dropbox Remote Update') . '. . .'); UI::show_box_top(T_('Running Dropbox Remote Update') . '. . .');
}
$this->update_remote_catalog(); $this->update_remote_catalog();
if (!defined('SSE_OUTPUT')) {
UI::show_box_bottom(); UI::show_box_bottom();
}
return true; return true;
} // add_to_catalog } // add_to_catalog
@ -279,16 +283,12 @@ class Catalog_dropbox extends Catalog
$this->count = 0; $this->count = 0;
$this->add_files($client, $this->path); $this->add_files($client, $this->path);
echo "\n<br />" . UI::update_text('', sprintf(T_('Catalog Update Finished. Total Media: [%s]'), $this->count));
printf(T_('Catalog Update Finished. Total Media: [%s]'), $this->count);
echo '<br />';
if ($this->count == 0) { 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 { } else {
echo "<p>" . T_('API Error: cannot connect to Dropbox.') . "</p><hr />\n"; Error::add('general', T_('API Error: cannot connect to Dropbox.'));
flush();
} }
return true; return true;
@ -321,8 +321,7 @@ class Catalog_dropbox extends Catalog
$this->add_file($client, $metadata); $this->add_file($client, $metadata);
} }
} else { } else {
echo "<p>" . T_('API Error: Cannot access file/folder at ' . $this->path . '.') . "</p><hr />\n"; Error::add('general', T_('API Error: Cannot access file/folder at ' . $this->path . '.'));
flush();
} }
} }
@ -432,8 +431,7 @@ class Catalog_dropbox extends Catalog
} }
} }
} else { } else {
echo "<p>" . T_('API Error: cannot connect to Dropbox.') . "</p><hr />\n"; Error::add('general', T_('API Error: cannot connect to Dropbox.'));
flush();
} }
return $dead; return $dead;

View file

@ -426,8 +426,10 @@ class Catalog_local extends Catalog
$this->added_songs_to_gather = array(); $this->added_songs_to_gather = array();
$this->added_videos_to_gather = array(); $this->added_videos_to_gather = array();
if (!defined('SSE_OUTPUT')) {
require AmpConfig::get('prefix') . '/templates/show_adds_catalog.inc.php'; require AmpConfig::get('prefix') . '/templates/show_adds_catalog.inc.php';
flush(); flush();
}
/* Set the Start time */ /* Set the Start time */
$start_time = time(); $start_time = time();
@ -457,8 +459,10 @@ class Catalog_local extends Catalog
if ($options['gather_art']) { if ($options['gather_art']) {
$catalog_id = $this->id; $catalog_id = $this->id;
if (!defined('SSE_OUTPUT')) {
require AmpConfig::get('prefix') . '/templates/show_gather_art.inc.php'; require AmpConfig::get('prefix') . '/templates/show_gather_art.inc.php';
flush(); flush();
}
$this->gather_art($this->added_songs_to_gather, $this->added_videos_to_gather); $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; $time_diff = ($current_time - $start_time) ?: 0;
$rate = intval(($time_diff > 0) ? $this->count / $time_diff : false) ?: T_('N/A'); $rate = intval(($time_diff > 0) ? $this->count / $time_diff : false) ?: T_('N/A');
if (!defined('SSE_OUTPUT')) {
UI::show_box_top(); UI::show_box_top();
echo "\n<br />" . }
printf(T_('Catalog Update Finished. Total Time: [%s] Total Media: [%s] Media Per Second: [%s]'), 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));
date('i:s', $time_diff), $this->count, $rate); if (!defined('SSE_OUTPUT')) {
echo '<br /><br />';
UI::show_box_bottom(); UI::show_box_bottom();
}
} // add_to_catalog } // add_to_catalog
@ -491,7 +496,10 @@ class Catalog_local extends Catalog
$total_updated = 0; $total_updated = 0;
$this->count = 0; $this->count = 0;
if (!defined('SSE_OUTPUT')) {
require_once AmpConfig::get('prefix') . '/templates/show_verify_catalog.inc.php'; require_once AmpConfig::get('prefix') . '/templates/show_verify_catalog.inc.php';
flush();
}
foreach (array('video', 'song') as $media_type) { foreach (array('video', 'song') as $media_type) {
$total = $stats[$media_type . 's']; // UGLY $total = $stats[$media_type . 's']; // UGLY

View file

@ -181,9 +181,13 @@ class Catalog_remote extends Catalog
*/ */
public function add_to_catalog($options = null) public function add_to_catalog($options = null)
{ {
if (!defined('SSE_OUTPUT')) {
UI::show_box_top(T_('Running Remote Update') . '. . .'); UI::show_box_top(T_('Running Remote Update') . '. . .');
}
$this->update_remote_catalog(); $this->update_remote_catalog();
if (!defined('SSE_OUTPUT')) {
UI::show_box_bottom(); UI::show_box_bottom();
}
return true; return true;
} // add_to_catalog } // add_to_catalog
@ -239,8 +243,7 @@ class Catalog_remote extends Catalog
$remote_catalog_info = $remote_handle->info(); $remote_catalog_info = $remote_handle->info();
// Tell 'em what we've found, Johnny! // Tell 'em what we've found, Johnny!
printf(T_('%u remote catalog(s) found (%u songs)'), $remote_catalog_info['catalogs'], $remote_catalog_info['songs']); UI::update_text('', sprintf(T_('%u remote catalog(s) found (%u songs)'), $remote_catalog_info['catalogs'], $remote_catalog_info['songs']));
flush();
// Hardcoded for now // Hardcoded for now
$step = 500; $step = 500;
@ -275,8 +278,7 @@ class Catalog_remote extends Catalog
} }
} // end while } // end while
echo "<p>" . T_('Completed updating remote catalog(s).') . "</p><hr />\n"; UI::update_text('', T_('Completed updating remote catalog(s).'));
flush();
// Update the last update value // Update the last update value
$this->update_last_update(); $this->update_last_update();

View file

@ -219,9 +219,13 @@ class Catalog_soundcloud extends Catalog
$this->authcode = $options['authcode']; $this->authcode = $options['authcode'];
} }
if (!defined('SSE_OUTPUT')) {
UI::show_box_top(T_('Running SoundCloud Remote Update') . '. . .'); UI::show_box_top(T_('Running SoundCloud Remote Update') . '. . .');
}
$this->update_remote_catalog(); $this->update_remote_catalog();
if (!defined('SSE_OUTPUT')) {
UI::show_box_bottom(); UI::show_box_bottom();
}
return true; return true;
} // add_to_catalog } // add_to_catalog
@ -278,8 +282,6 @@ class Catalog_soundcloud extends Catalog
if (!Song::insert($data)) { if (!Song::insert($data)) {
debug_event('soundcloud_catalog', 'Insert failed for ' . $data['file'], 1); debug_event('soundcloud_catalog', 'Insert failed for ' . $data['file'], 1);
Error::add('general', T_('Unable to Insert Song - %s'), $data['file']); Error::add('general', T_('Unable to Insert Song - %s'), $data['file']);
Error::display('general');
flush();
} else { } else {
$songsadded++; $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"; UI::update_text('', T_('Completed updating SoundCloud catalog(s).') . " " . $songsadded . " " . T_('Songs added.'));
flush();
// Update the last update value // Update the last update value
$this->update_last_update(); $this->update_last_update();
} else { } else {
echo "<p>" . T_('API Error: cannot get song list.') . "</p><hr />\n"; Error::add('general', T_('API Error: cannot get song list.'));
flush();
} }
} else { } else {
echo "<p>" . T_('API Error: cannot connect to SoundCloud.') . "</p><hr />\n"; Error::add('general', T_('API Error: cannot connect to SoundCloud.'));
flush();
} }
} catch (Exception $ex) { } catch (Exception $ex) {
echo "<p>" . T_('SoundCloud exception: ') . $ex->getMessage() . "</p><hr />\n"; Error::add('general', T_('SoundCloud exception: ') . $ex->getMessage());
} }
return true; return true;

View file

@ -185,9 +185,13 @@ class Catalog_subsonic extends Catalog
// Prevent the script from timing out // Prevent the script from timing out
set_time_limit(0); set_time_limit(0);
if (!defined('SSE_OUTPUT')) {
UI::show_box_top(T_('Running Subsonic Remote Update') . '. . .'); UI::show_box_top(T_('Running Subsonic Remote Update') . '. . .');
}
$this->update_remote_catalog(); $this->update_remote_catalog();
if (!defined('SSE_OUTPUT')) {
UI::show_box_bottom(); UI::show_box_bottom();
}
return true; return true;
} // add_to_catalog } // add_to_catalog
@ -243,8 +247,6 @@ class Catalog_subsonic extends Catalog
if (!Song::insert($data)) { if (!Song::insert($data)) {
debug_event('subsonic_catalog', 'Insert failed for ' . $song['path'], 1); debug_event('subsonic_catalog', 'Insert failed for ' . $song['path'], 1);
Error::add('general', T_('Unable to Insert Song - %s'), $song['path']); Error::add('general', T_('Unable to Insert Song - %s'), $song['path']);
Error::display('general');
flush();
} else { } else {
$songsadded++; $songsadded++;
} }
@ -252,26 +254,22 @@ class Catalog_subsonic extends Catalog
} }
} }
} else { } else {
echo "<p>" . T_('Song Error.') . ": " . $songs['error'] . "</p><hr />\n"; Error::add('general', T_('Song Error.') . ": " . $songs['error']);
flush();
} }
} }
} }
} else { } else {
echo "<p>" . T_('Album Error.') . ": " . $albums['error'] . "</p><hr />\n"; Error::add('general', T_('Album Error.') . ": " . $albums['error']);
flush();
} }
} }
} }
echo "<p>" . T_('Completed updating Subsonic catalog(s).') . " " . $songsadded . " " . T_('Songs added.') . "</p><hr />\n"; UI::update_text('', T_('Completed updating Subsonic catalog(s).') . " " . $songsadded . " " . T_('Songs added.'));
flush();
// Update the last update value // Update the last update value
$this->update_last_update(); $this->update_last_update();
} else { } else {
echo "<p>" . T_('Artist Error.') . ": " . $artists['error'] . "</p><hr />\n"; Error::add('general', T_('Artist Error.') . ": " . $artists['error']);
flush();
} }
return true; return true;

158
server/sse.server.php Normal file
View 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;
}