1
0
Fork 0
mirror of https://github.com/Yetangitu/ampache synced 2025-10-05 10:49:37 +02:00

Fix scrobbler thread autoloader and global variables

This commit is contained in:
Afterster 2014-01-11 12:34:40 +01:00
parent 5cdcf4b12f
commit 41f5d0b7fd
13 changed files with 42 additions and 39 deletions

View file

@ -222,10 +222,10 @@ class Plugin
* load
* This calls the plugin's load function
*/
public function load()
public function load($user)
{
$GLOBALS['user']->set_preferences();
return $this->_plugin->load();
$user->set_preferences();
return $this->_plugin->load($user);
}
/**

View file

@ -241,7 +241,7 @@ class Rating extends database_object
foreach (Plugin::get_plugins('save_rating') as $plugin_name) {
$plugin = new Plugin($plugin_name);
if ($plugin->load()) {
if ($plugin->load($GLOBALS['user'])) {
$plugin->_plugin->save_rating($this, $rating);
}
}

View file

@ -22,16 +22,18 @@
class scrobbler_async extends Thread
{
public function __construct($arg)
public function __construct($user, $song_info)
{
$this->arg = $arg;
$this->user = $user;
$this->song_info = $song_info;
}
public function run()
{
if($this->arg)
{
User::save_songplay($this->arg);
spl_autoload_register(array('Core', 'autoload'), true, true);
Requests::register_autoloader();
if ($this->song_info) {
User::save_songplay($this->user, $this->song_info);
}
}
}
}

View file

@ -1098,7 +1098,7 @@ class Song extends database_object implements media
foreach (Plugin::get_plugins('get_lyrics') as $plugin_name) {
$plugin = new Plugin($plugin_name);
if ($plugin->load()) {
if ($plugin->load($GLOBALS['user'])) {
$lyrics = $plugin->_plugin->get_lyrics($this);
if ($lyrics != false) {
return $lyrics;

View file

@ -593,17 +593,18 @@ class User extends database_object
if (!strlen($song_info->file)) { return false; }
$this->set_preferences();
// If pthreads available, we call save_songplay in a new thread to quickly return
if (class_exists("Thread", false))
{
if (class_exists("Thread", false)) {
debug_event('user.class.php', 'Calling save_songplay plugins in a new thread...', '5');
$thread = new scrobbler_async($song_info);
$thread->start();
}
else
{
User::save_songplay($song_info);
$thread = new scrobbler_async($GLOBALS['user'], $song_info);
if ($thread->start()) {
$thread->join();
} else {
debug_event('user.class.php', 'Error when starting the thread.', '1');
}
} else {
User::save_songplay($GLOBALS['user'], $song_info);
}
// Do this last so the 'last played checks are correct'
@ -614,13 +615,13 @@ class User extends database_object
return true;
} // update_stats
public static function save_songplay($song_info)
public static function save_songplay($user, $song_info)
{
foreach (Plugin::get_plugins('save_songplay') as $plugin_name) {
try {
$plugin = new Plugin($plugin_name);
if ($plugin->load()) {
if ($plugin->load($user)) {
$plugin->_plugin->save_songplay($song_info);
}
} catch (Exeption $e) {

View file

@ -445,7 +445,7 @@ class vainfo
foreach ($tag_order as $tag_source) {
if (in_array($tag_source, $plugin_names)) {
$plugin = new Plugin($tag_source);
if ($plugin->load()) {
if ($plugin->load($GLOBALS['user'])) {
$this->tags[$tag_source] = $plugin->_plugin->get_metadata(self::clean_tag_info($this->tags, self::get_tag_type($this->tags), $this->filename));
}
}

View file

@ -176,7 +176,7 @@ class Wanted extends database_object
foreach (Plugin::get_plugins('process_wanted') as $plugin_name) {
debug_event('wanted', 'Using Wanted Process plugin: ' . $plugin_name, '5');
$plugin = new Plugin($plugin_name);
if ($plugin->load()) {
if ($plugin->load($GLOBALS['user'])) {
$plugin->_plugin->process_wanted($this);
}
}

View file

@ -60,7 +60,7 @@ class Ampachechartlyrics {
* This is a required plugin function; here it populates the prefs we
* need for this object.
*/
public function load() {
public function load($user) {
return true;
} // load

View file

@ -138,10 +138,10 @@ class AmpacheHeadphones {
* This loads up the data we need into this object, this stuff comes
* from the preferences.
*/
public function load() {
public function load($user) {
$GLOBALS['user']->set_preferences();
$data = $GLOBALS['user']->prefs;
$user->set_preferences();
$data = $user->prefs;
if (strlen(trim($data['headphones_api_url']))) {
$this->api_url = trim($data['headphones_api_url']);

View file

@ -192,10 +192,10 @@ class AmpacheLastfm {
* This loads up the data we need into this object, this stuff comes
* from the preferences.
*/
public function load() {
public function load($user) {
$GLOBALS['user']->set_preferences();
$data = $GLOBALS['user']->prefs;
$user->set_preferences();
$data = $user->prefs;
if (strlen(trim($data['lastfm_user']))) {
$this->username = trim($data['lastfm_user']);
@ -212,7 +212,7 @@ class AmpacheLastfm {
return false;
}
$this->user_id = $GLOBALS['user']->id;
$this->user_id = $user->id;
// If we don't have the other stuff try to get it before giving up
if (!$data['lastfm_host'] || !$data['lastfm_port'] || !$data['lastfm_url'] || !$data['lastfm_challenge']) {

View file

@ -191,10 +191,10 @@ class Ampachelibrefm {
* This loads up the data we need into this object, this stuff comes
* from the preferences.
*/
public function load() {
public function load($user) {
$GLOBALS['user']->set_preferences();
$data = $GLOBALS['user']->prefs;
$user->set_preferences();
$data = $user->prefs;
if (strlen(trim($data['librefm_user']))) {
$this->username = trim($data['librefm_user']);
@ -211,7 +211,7 @@ class Ampachelibrefm {
return false;
}
$this->user_id = $GLOBALS['user']->id;
$this->user_id = $user->id;
// If we don't have the other stuff try to get it before giving up
if (!$data['librefm_host'] || !$data['librefm_port'] || !$data['librefm_url'] || !$data['librefm_challenge']) {

View file

@ -60,7 +60,7 @@ class Ampachelyricwiki {
* This is a required plugin function; here it populates the prefs we
* need for this object.
*/
public function load() {
public function load($user) {
return true;
} // load

View file

@ -57,7 +57,7 @@ class AmpacheMusicBrainz {
* This is a required plugin function; here it populates the prefs we
* need for this object.
*/
public function load() {
public function load($user) {
return true;
} // load