Пример #1
0
 /**
  * update
  * This function takes a key'd array of data and updates this object
  * as needed
  * @param array $data
  * @return int
  */
 public function update(array $data)
 {
     $year = isset($data['year']) ? $data['year'] : $this->year;
     $artist = isset($data['artist']) ? intval($data['artist']) : $this->artist_id;
     $album_artist = isset($data['album_artist']) ? intval($data['album_artist']) : $this->album_artist;
     $name = isset($data['name']) ? $data['name'] : $this->name;
     $disk = isset($data['disk']) ? $data['disk'] : $this->disk;
     $mbid = isset($data['mbid']) ? $data['mbid'] : $this->mbid;
     $mbid_group = isset($data['mbid_group']) ? $data['mbid_group'] : $this->mbid_group;
     $release_type = isset($data['release_type']) ? $data['release_type'] : $this->release_type;
     $current_id = $this->id;
     $updated = false;
     $songs = null;
     if ($artist != $this->artist_id && $artist) {
         // Update every song
         $songs = $this->get_songs();
         foreach ($songs as $song_id) {
             Song::update_artist($artist, $song_id);
         }
         $updated = true;
         Artist::gc();
     }
     if (!empty($data['album_artist_name'])) {
         // Need to create new artist according the name
         $album_artist = Artist::check($data['album_artist_name']);
     }
     $album_id = self::check($name, $year, $disk, $mbid, $mbid_group, $album_artist, $release_type);
     if ($album_id != $this->id) {
         if (!is_array($songs)) {
             $songs = $this->get_songs();
         }
         foreach ($songs as $song_id) {
             Song::update_album($album_id, $song_id);
             Song::update_year($year, $song_id);
             Song::write_id3_for_song($song_id);
         }
         $current_id = $album_id;
         $updated = true;
         Stats::migrate('album', $this->id, $album_id);
         Art::migrate('album', $this->id, $album_id);
         self::gc();
     } else {
         Album::update_year($year, $album_id);
         Album::update_mbid_group($mbid_group, $album_id);
         Album::update_release_type($release_type, $album_id);
     }
     $this->year = $year;
     $this->mbid_group = $mbid_group;
     $this->release_type = $release_type;
     $this->name = $name;
     $this->disk = $disk;
     $this->mbid = $mbid;
     $this->album_artist = $album_artist;
     if ($updated && is_array($songs)) {
         foreach ($songs as $song_id) {
             Song::update_utime($song_id);
         }
         // foreach song of album
         Stats::gc();
         Rating::gc();
         Userflag::gc();
         Useractivity::gc();
     }
     // if updated
     $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;
 }
Пример #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;
 }
Пример #3
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;
 }