Example #1
0
 /**
  * update
  * This function takes a key'd array of data and updates this object
  * as needed
  */
 public function update($data)
 {
     $year = $data['year'];
     $artist = $data['artist'];
     $name = $data['name'];
     $disk = $data['disk'];
     $mbid = $data['mbid'];
     $current_id = $this->id;
     $updated = false;
     $songs = null;
     if ($artist != $this->artist_id and $artist) {
         // Update every song
         $songs = $this->get_songs();
         foreach ($songs as $song_id) {
             Song::update_artist($artist, $song_id);
         }
         $updated = true;
         Artist::gc();
     }
     $album_id = self::check($name, $year, $disk, $mbid);
     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);
         }
         $current_id = $album_id;
         $updated = true;
         self::gc();
     }
     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();
     }
     // if updated
     $override_songs = false;
     if ($data['apply_childs'] == 'checked') {
         $override_songs = true;
     }
     $this->update_tags($data['edit_tags'], $override_songs, $current_id);
     return $current_id;
 }
Example #2
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;
 }