Exemple #1
0
 /**
  * update
  * This takes a key'd array of data as input and updates a movie entry
  */
 public function update(array $data)
 {
     parent::update($data);
     if (isset($data['original_name'])) {
         $trimmed = Catalog::trim_prefix(trim($data['original_name']));
         $name = $trimmed['string'];
         $prefix = $trimmed['prefix'];
     } else {
         $name = $this->original_name;
         $prefix = $this->prefix;
     }
     $summary = isset($data['summary']) ? $data['summary'] : $this->summary;
     $year = isset($data['year']) ? $data['summary'] : $this->year;
     $sql = "UPDATE `movie` SET `original_name` = ?, `prefix` = ?, `summary` = ?, `year` = ? WHERE `id` = ?";
     Dba::write($sql, array($name, $prefix, $summary, $year, $this->id));
     $this->original_name = $name;
     $this->prefix = $prefix;
     $this->summary = $summary;
     $this->year = $year;
     return $this->id;
 }
Exemple #2
0
 /**
  * update
  * This takes a key'd array of data and updates the current tv show
  */
 public function update(array $data)
 {
     // Save our current ID
     $current_id = $this->id;
     $name = isset($data['name']) ? $data['name'] : $this->name;
     $year = isset($data['year']) ? $data['year'] : $this->year;
     $summary = isset($data['summary']) ? $data['summary'] : $this->summary;
     // Check if name is different than current name
     if ($this->name != $name || $this->year != $year) {
         $tvshow_id = self::check($name, $year, true);
         // If it's changed we need to update
         if ($tvshow_id != $this->id && $tvshow_id != null) {
             $seasons = $this->get_seasons();
             foreach ($seasons as $season_id) {
                 Season::update_tvshow($tvshow_id, $season_id);
             }
             $current_id = $tvshow_id;
             Stats::migrate('tvshow', $this->id, $tvshow_id);
             Art::migrate('tvshow', $this->id, $tvshow_id);
             self::gc();
         }
         // end if it changed
     }
     $trimmed = Catalog::trim_prefix(trim($name));
     $name = $trimmed['string'];
     $prefix = $trimmed['prefix'];
     $sql = 'UPDATE `tvshow` SET `name` = ?, `prefix` = ?, `year` = ?, `summary` = ? WHERE `id` = ?';
     Dba::write($sql, array($name, $prefix, $year, $summary, $current_id));
     $this->name = $name;
     $this->prefix = $prefix;
     $this->year = $year;
     $this->summary = $summary;
     $override_childs = false;
     if ($data['overwrite_childs'] == 'checked') {
         $override_childs = true;
     }
     $add_to_childs = false;
     if ($data['add_to_childs'] == 'checked') {
         $add_to_childs = true;
     }
     if (isset($data['edit_tags'])) {
         $this->update_tags($data['edit_tags'], $override_childs, $add_to_childs, $current_id, true);
     }
     return $current_id;
 }
Exemple #3
0
 /**
  * update
  * This takes a key'd array of data and updates the current artist
  */
 public function update($data)
 {
     // Save our current ID
     $current_id = $this->id;
     // Check if name is different than current name
     if ($this->name != $data['name']) {
         $artist_id = self::check($data['name'], $this->mbid);
         $updated = false;
         $songs = array();
         // If it's changed we need to update
         if ($artist_id != $this->id) {
             $songs = $this->get_songs();
             foreach ($songs as $song_id) {
                 Song::update_artist($artist_id, $song_id);
             }
             $updated = true;
             $current_id = $artist_id;
             self::gc();
         }
         // end if it changed
         if ($updated) {
             foreach ($songs as $song_id) {
                 Song::update_utime($song_id);
             }
             Stats::gc();
             Rating::gc();
             Userflag::gc();
         }
         // if updated
     } else {
         if ($this->mbid != $data['mbid']) {
             $sql = 'UPDATE `artist` SET `mbid` = ? WHERE `id` = ?';
             Dba::write($sql, array($data['mbid'], $current_id));
         }
     }
     // Update artist name (if we don't want to use the MusicBrainz name)
     $trimmed = Catalog::trim_prefix(trim($data['name']));
     $name = $trimmed['string'];
     if ($name != '' && $name != $this->name) {
         $sql = 'UPDATE `artist` SET `name` = ? WHERE `id` = ?';
         Dba::write($sql, array($name, $current_id));
     }
     $override_childs = false;
     if ($data['apply_childs'] == 'checked') {
         $override_childs = true;
     }
     $this->update_tags($data['edit_tags'], $override_childs, $current_id);
     return $current_id;
 }
Exemple #4
0
 /**
  * check
  *
  * Searches for an album; if none is found, insert a new one.
  */
 public static function check($name, $year = 0, $disk = 0, $mbid = null, $readonly = false)
 {
     if ($mbid == '') {
         $mbid = null;
     }
     $trimmed = Catalog::trim_prefix(trim($name));
     $name = $trimmed['string'];
     $prefix = $trimmed['prefix'];
     // Not even sure if these can be negative, but better safe than llama.
     $year = abs(intval($year));
     $disk = abs(intval($disk));
     if (!$name) {
         $name = T_('Unknown (Orphaned)');
         $year = 0;
         $disk = 0;
     }
     if (isset(self::$_mapcache[$name][$year][$disk][$mbid])) {
         return self::$_mapcache[$name][$year][$disk][$mbid];
     }
     $sql = 'SELECT `id` FROM `album` WHERE `name` = ? AND `disk` = ? AND `year` = ? AND `mbid` ';
     $params = array($name, $disk, $year);
     if ($mbid) {
         $sql .= '= ? ';
         $params[] = $mbid;
     } else {
         $sql .= 'IS NULL ';
     }
     $sql .= 'AND `prefix` ';
     if ($prefix) {
         $sql .= '= ?';
         $params[] = $prefix;
     } else {
         $sql .= 'IS NULL';
     }
     $db_results = Dba::read($sql, $params);
     if ($row = Dba::fetch_assoc($db_results)) {
         $id = $row['id'];
         self::$_mapcache[$name][$year][$disk][$mbid] = $id;
         return $id;
     }
     if ($readonly) {
         return null;
     }
     $sql = 'INSERT INTO `album` (`name`, `prefix`, `year`, `disk`, `mbid`) VALUES (?, ?, ?, ?, ?)';
     $db_results = Dba::write($sql, array($name, $prefix, $year, $disk, $mbid));
     if (!$db_results) {
         return null;
     }
     $id = Dba::insert_id();
     // Remove from wanted album list if any request on it
     if (!empty($mbid) && AmpConfig::get('wanted')) {
         try {
             Wanted::delete_wanted_release($mbid);
         } catch (Exception $e) {
             debug_event('wanted', 'Cannot process wanted releases auto-removal check: ' . $e->getMessage(), '1');
         }
     }
     self::$_mapcache[$name][$year][$disk][$mbid] = $id;
     return $id;
 }
 /**
  * get_artists_like
  * Returns a list of similar artists
  */
 public static function get_artists_like($artist_id, $limit = 10, $local_only = true)
 {
     $artist = new Artist($artist_id);
     $cache = self::get_recommendation_cache('artist', $artist_id, true);
     if (!$cache['id']) {
         $similars = array();
         $query = 'artist=' . rawurlencode($artist->name);
         $xml = self::get_lastfm_results('artist.getsimilar', $query);
         foreach ($xml->similarartists->children() as $child) {
             $name = $child->name;
             $mbid = (string) $child->mbid;
             $local_id = null;
             // First we check by MBID
             if ($mbid) {
                 $sql = "SELECT `artist`.`id` FROM `artist` WHERE `mbid` = ?";
                 if (AmpConfig::get('catalog_disable')) {
                     $sql .= " AND " . Catalog::get_enable_filter('artist', '`artist`.`id`');
                 }
                 $db_result = Dba::read($sql, array($mbid));
                 if ($result = Dba::fetch_assoc($db_result)) {
                     $local_id = $result['id'];
                 }
             }
             // Then we fall back to the less likely to work exact
             // name match
             if (is_null($local_id)) {
                 $searchname = Catalog::trim_prefix($name);
                 $searchname = Dba::escape($searchname['string']);
                 $sql = "SELECT `artist`.`id` FROM `artist` WHERE `name` = ?";
                 if (AmpConfig::get('catalog_disable')) {
                     $sql .= " AND " . Catalog::get_enable_filter('artist', '`artist`.`id`');
                 }
                 $db_result = Dba::read($sql, array($searchname));
                 if ($result = Dba::fetch_assoc($db_result)) {
                     $local_id = $result['id'];
                 }
             }
             // Then we give up
             if (is_null($local_id)) {
                 debug_event('Recommendation', "{$name} did not match any local artist", 5);
                 $similars[] = array('id' => null, 'name' => $name, 'mbid' => $mbid);
             } else {
                 debug_event('Recommendation', "{$name} matched local artist " . $local_id, 5);
                 $similars[] = array('id' => $local_id, 'name' => $name);
             }
         }
         if (count($similars) > 0) {
             self::update_recommendation_cache('artist', $artist_id, $similars);
         }
     }
     if (!isset($similars) || count($similars) == 0) {
         $similars = $cache['items'];
     }
     if ($similars) {
         $results = array();
         foreach ($similars as $similar) {
             if (!$local_only || !is_null($similar['id'])) {
                 $results[] = $similar;
             }
             if ($limit && count($results) >= $limit) {
                 break;
             }
         }
     }
     if (isset($results)) {
         return $results;
     }
     return false;
 }
Exemple #6
0
 /**
  * update
  * This takes a key'd array of data and updates the current artist
  * @param array $data
  * @return int
  */
 public function update(array $data)
 {
     // Save our current ID
     $name = isset($data['name']) ? $data['name'] : $this->name;
     $mbid = isset($data['mbid']) ? $data['mbid'] : $this->mbid;
     $summary = isset($data['summary']) ? $data['summary'] : $this->summary;
     $placeformed = isset($data['placeformed']) ? $data['placeformed'] : $this->placeformed;
     $yearformed = isset($data['yearformed']) ? $data['yearformed'] : $this->yearformed;
     $current_id = $this->id;
     // Check if name is different than current name
     if ($this->name != $name) {
         $artist_id = self::check($name, $mbid, true);
         $updated = false;
         $songs = array();
         // If it's changed we need to update
         if ($artist_id != null && $artist_id != $this->id) {
             $songs = $this->get_songs();
             foreach ($songs as $song_id) {
                 Song::update_artist($artist_id, $song_id);
             }
             $updated = true;
             $current_id = $artist_id;
             Stats::migrate('artist', $this->id, $artist_id);
             Art::migrate('artist', $this->id, $artist_id);
             self::gc();
         }
         // end if it changed
         if ($updated) {
             foreach ($songs as $song_id) {
                 Song::update_utime($song_id);
             }
             Stats::gc();
             Rating::gc();
             Userflag::gc();
             Useractivity::gc();
         }
         // if updated
     } else {
         if ($this->mbid != $mbid) {
             $sql = 'UPDATE `artist` SET `mbid` = ? WHERE `id` = ?';
             Dba::write($sql, array($mbid, $current_id));
         }
     }
     // Update artist name (if we don't want to use the MusicBrainz name)
     $trimmed = Catalog::trim_prefix(trim($name));
     $name = $trimmed['string'];
     if ($name != '' && $name != $this->name) {
         $sql = 'UPDATE `artist` SET `name` = ? WHERE `id` = ?';
         Dba::write($sql, array($name, $current_id));
     }
     $this->update_artist_info($summary, $placeformed, $yearformed, true);
     $this->name = $name;
     $this->mbid = $mbid;
     $override_childs = false;
     if ($data['overwrite_childs'] == 'checked') {
         $override_childs = true;
     }
     $add_to_childs = false;
     if ($data['add_to_childs'] == 'checked') {
         $add_to_childs = true;
     }
     if (isset($data['edit_tags'])) {
         $this->update_tags($data['edit_tags'], $override_childs, $add_to_childs, $current_id, true);
     }
     if (AmpConfig::get('label') && isset($data['edit_labels'])) {
         Label::update_label_list($data['edit_labels'], $this->id, true);
     }
     return $current_id;
 }