summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--artists.php117
-rwxr-xr-xdocs/CHANGELOG1
-rw-r--r--lib/class/artist.class.php81
-rw-r--r--lib/class/catalog.class.php55
-rw-r--r--lib/class/error.class.php2
-rw-r--r--lib/ui.lib.php30
-rw-r--r--modules/init.php2
-rw-r--r--modules/lib.php30
-rw-r--r--templates/show_artist.inc4
-rw-r--r--templates/show_install_config.inc2
-rw-r--r--templates/show_rename_artist.inc.php (renamed from templates/show_rename_artist.php.inc)28
11 files changed, 269 insertions, 83 deletions
diff --git a/artists.php b/artists.php
index e361e27d..75f1f2eb 100644
--- a/artists.php
+++ b/artists.php
@@ -46,7 +46,7 @@ switch($action) {
case 'show_all_songs':
$artist = get_artist_name(scrub_in($_REQUEST['artist']));
echo "<h2>" . _("All songs by") . " $artist</h2>";
- $song_ids = get_song_ids_from_artist($_REQUEST['artist']);
+ $song_ids = get_song_ids_from_artist($_REQUEST['artist']);
show_songs($song_ids);
break;
@@ -63,40 +63,95 @@ switch($action) {
echo "<a href=\"" . conf('web_path') . "/artists.php?action=show&amp;artist=" . $_REQUEST['artist'] . "\">[" . _("Return") . "]</a>";
break;
- case 'match':
- case 'Match':
- $match = scrub_in($_REQUEST['match']);
- preg_match("/^(\w*)/", $match, $matches);
- show_alphabet_list('artists','artists.php',$match);
- if ($match === "Browse") {
- show_alphabet_form('',_("Show Artists starting with"),"artists.php?action=match");
- show_artists();
- }
- elseif ($match === "Show_all") {
- show_alphabet_form('',_("Show Artists starting with"),"artists.php?action=match");
- $_SESSION['view_offset_limit'] = 999999;
- show_artists();
- }
- else {
- $chr = preg_replace("/[^a-zA-Z0-9]/", "", $matches[1]);
- show_alphabet_form($chr,_("Show Artists starting with"),"artists.php?action=match");
-
- if ($chr == '') {
- show_artists('A');
+ case 'rename':
+ //die if not enough permissions
+ if (!$user->has_access('100')) { access_denied(); }
+
+ /* Get the artist */
+ $artist = new Artist($_REQUEST['artist']);
+ $catalog = new Catalog();
+
+ //check if we've been given a target
+ if ((isset($_POST['artist_id']) && $_POST['artist_id'] != $artist->id ) || (isset($_POST['artist_name']) && $_POST['artist_name'] != "")) {
+
+ //if we want to update id3 tags, then get the array of ids now, it's too late afterwards
+ if (make_bool($_POST['update_id3']))
+ $songs = $artist->get_songs();
+
+ //the manual rename takes priority
+ if ($_POST['artist_name'] != "") {
+ //then just change the name of the artist in the db
+ $newid = $artist->rename($_POST['artist_name']);
+
+ }
+ elseif ($_POST['artist_id'] != $artist->id) {
+ if ($_POST['test_stats'] == 'yes') {
+ $catalog->merge_stats("artist",$artist->id,$_POST['artist_id']);
+ }
+ else {
+ //merge with other artist
+ $artist->merge($_POST['artist_id']);
+ $newid = $_POST['artist_id'];
+ }
+ } // elseif different artist and id
+
+ //now flag for id3tag update if selected, and song id changed
+ if ($_POST['update_id3'] == "yes" && $newid != $artist->id) {
+
+ /* Set the rename information in the db */
+ foreach ($songs as $song) {
+ $flag_qstring = "REPLACE INTO flagged " .
+ "SET type = 'setid3', song = '" . $song->id . "', date = '" . time() . "', user = '" . $GLOBALS['user']->username . "'";
+ mysql_query($flag_qstring, dbh());
+ }
+
+ } // end if they wanted to update
+
+ } // if we've got the needed variables
+
+ /* Else we've got an error! */
+ else {
+ require (conf('prefix') . '/templates/show_rename_artist.inc.php');
+ }
+ break;
+ case 'show_rename':
+ $artist = new Artist($_REQUEST['artist']);
+ require (conf('prefix') . '/templates/show_rename_artist.inc.php');
+ break;
+ case 'match':
+ case 'Match':
+ $match = scrub_in($_REQUEST['match']);
+ preg_match("/^(\w*)/", $match, $matches);
+ show_alphabet_list('artists','artists.php',$match);
+ if ($match === "Browse") {
+ show_alphabet_form('',_("Show Artists starting with"),"artists.php?action=match");
+ show_artists();
}
- else {
- show_artists($chr);
+ elseif ($match === "Show_all") {
+ show_alphabet_form('',_("Show Artists starting with"),"artists.php?action=match");
+ $_SESSION['view_offset_limit'] = 999999;
+ show_artists();
+ }
+ else {
+ $chr = preg_replace("/[^a-zA-Z0-9]/", "", $matches[1]);
+ show_alphabet_form($chr,_("Show Artists starting with"),"artists.php?action=match");
+
+ if ($chr == '') {
+ show_artists('A');
+ }
+ else {
+ show_artists($chr);
+ }
}
- }
+ break;
+ default:
+ show_alphabet_list('artists','artists.php');
+ show_alphabet_form('',_("Show Artists starting with"),"artists.php?action=match");
+ show_artists('A');
break;
+} // end switch
- default:
- show_alphabet_list('artists','artists.php');
- show_alphabet_form('',_("Show Artists starting with"),"artists.php?action=match");
- show_artists('A');
- break;
-}
-echo "<br /><br />";
+show_clear();
show_page_footer ('Artists', '',$user->prefs['display_menu']);
?>
diff --git a/docs/CHANGELOG b/docs/CHANGELOG
index a4e2db04..58c2c41f 100755
--- a/docs/CHANGELOG
+++ b/docs/CHANGELOG
@@ -4,6 +4,7 @@
--------------------------------------------------------------------------
v.3.3.2-Alpha4
+ - Added ability to Rename/Merge artists (Thx SpComb)
- Fixed a flaw in album art search which only returned a single
result, now shows all results and allows you to pick
the correct one.
diff --git a/lib/class/artist.class.php b/lib/class/artist.class.php
index 2a6e3308..534281d6 100644
--- a/lib/class/artist.class.php
+++ b/lib/class/artist.class.php
@@ -180,6 +180,87 @@ class Artist {
} // format_artist
+ /*!
+ @function rename
+ @discussion changes the name of the artist in the db,
+ and then merge()s songs
+ @param $newname the artist's new name, either a new
+ artist will be created or songs added to existing
+ artist if name exists already
+ @return the id of the new artist
+ */
+ function rename($newname) {
+
+ /*
+ * There is this nifty function called check_artists in catalog that does exactly what we want it to do
+ * to use it, we first have to hax us a catalog
+ */
+ $catalog = new Catalog();
+
+ /* now we can get the new artist id in question */
+ $newid = $catalog->check_artist($newname);
+
+ /* check that it wasn't just whitespace that we were called to change */
+ if ($newid == $this->id) {
+ $GLOBALS['error']->add_error('artist_name',_("Error: Name Identical"));
+ return $newid;
+ }
+
+ /* now we can just call merge */
+ $this->merge($newid);
+
+ //now return id
+ return $newid;
+
+ } // rename
+
+ /*!
+ @function merge
+ @discussion changes the artist id of all songs by this artist
+ to the given id and deletes self from db
+ @param $newid the new artist id that this artist's songs should have
+ */
+ function merge($newid) {
+
+ $catalog = new Catalog();
+
+ /* Make sure this is a valid ID */
+ if (!is_numeric($newid)) {
+ $GLOBALS['error']->add_error('general',"Error: Invalid Artist ID");
+ return false;
+ }
+
+ // First check newid exists
+ $check_exists_qstring = "SELECT name FROM artist WHERE id='" . sql_escape($newid) . "'";
+ $check_exists_query = mysql_query($check_exists_qstring, dbh());
+
+ if (mysql_num_rows($check_exists_query)) {
+
+ // Get the name, for use in output
+ $check_exists_result = mysql_fetch_assoc($check_exists_query);
+
+ $NewName = $check_exists_result['name'];
+
+ // Now the query
+ $sql = "UPDATE song SET artist='" . sql_escape($newid) . "' " .
+ "WHERE artist='" . sql_escape($this->id) . "'";
+ $db_results = mysql_query($sql, dbh());
+
+ $num_stats_changed = $catalog->merge_stats("artist",$this->id,$newid);
+
+ /* If we've done the merege we need to clean up
+ $catalog->clean_artists();
+ $catalog->clean_albums();
+
+ }
+
+ else {
+ $GLOBALS['error']->add_error('general',"Error: Invalid Artist ID");
+ return false;
+ }
+
+ } // merge
+
/*!
@function show_albums
diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php
index 5e79fa81..75736af0 100644
--- a/lib/class/catalog.class.php
+++ b/lib/class/catalog.class.php
@@ -2003,6 +2003,61 @@ class Catalog {
} // import_m3u
+ /*!
+ @function merge_stats
+ @discussion merge stats entries
+ @param $type the object_type row in object_count to use
+ @param $oldid the old object_id
+ @param $newid the new object_id to merge to
+ @return the number of stats changed
+ @todo move this to the right file
+ */
+ function merge_stats ($type,$oldid,$newid) {
+
+ //check data
+ $accepted_types = array ("artist");
+ if (!in_array($type,$accepted_types)) { return false; }
+
+ //now retrieve all of type and oldid
+ $stats_qstring = "SELECT id,count,userid," .
+ "(SELECT id FROM object_count WHERE object_type = '$type' AND object_id = '$newid' AND userid=o.userid) AS existingid " .
+ "FROM object_count AS o WHERE object_type = '$type' AND object_id = '$oldid'";
+
+ $stats_query = mysql_query($stats_qstring,dbh());
+ $oldstats = array();
+ //now collect needed data into a array
+ while ($stats_result = mysql_fetch_array($stats_query,MYSQL_ASSOC)) {
+ $userid = $stats_result['userid'];
+ $oldstats[$userid]['id'] = $stats_result['id'];
+ $oldstats[$userid]['count'] = $stats_result['count'];
+ $oldstats[$userid]['existingid'] = $stats_result['existingid'];
+ }
+ //now foreach that array, changeing/updateing object_count and if needed deleting old row
+ $num_changed = 0;
+ foreach ($oldstats as $userid => $stats) {
+ //first check if it is a update or insert
+ if (is_numeric($stats['existingid'])) {
+
+ $stats_count_change_qstring = "UPDATE object_count SET count = count + '" . $stats['count'] . "' WHERE id = '" . $stats['existingid'] . "'";
+ mysql_query($stats_count_change_qstring,dbh());
+
+ //then, delete old row
+ $old_stats_delete_qstring = "DELETE FROM object_count WHERE id ='" . $stats['id'] . "'";
+ mysql_query($old_stats_delete_qstring,dbh());
+
+ $num_changed++;
+ } else {
+ //hasn't yet listened, just change object_id
+ $stats_artist_change_qstring = "UPDATE object_count SET object_id = '$newid' WHERE id ='" . $stats['id'] . "'";
+ mysql_query($stats_artist_change_qstring,dbh());
+ //done!
+ $num_changed++;
+ }
+ }
+ return $num_changed;
+
+ } // merge_stats
+
/*!
@function delete_catalog
@discussion Deletes the catalog and everything assoicated with it
diff --git a/lib/class/error.class.php b/lib/class/error.class.php
index 9283e29d..5515e41c 100644
--- a/lib/class/error.class.php
+++ b/lib/class/error.class.php
@@ -24,8 +24,6 @@
@header Error handler requires error_results() function
*/
-
-
class Error {
//Basic Componets
diff --git a/lib/ui.lib.php b/lib/ui.lib.php
index c7b4a758..781dbe33 100644
--- a/lib/ui.lib.php
+++ b/lib/ui.lib.php
@@ -728,4 +728,34 @@ function show_random_play_bar() {
} // show_random_play_bar()
+/*
+ * show_artist_pulldown()
+ *
+ * Helper functions for album and artist functions
+ *
+ */
+function show_artist_pulldown ($artist_id,$select_name='artist') {
+
+ $query = "SELECT id FROM artist ORDER BY name";
+ $db_result = mysql_query($query, dbh());
+
+ echo "\n<select name=\"$select_name\">\n";
+
+ while ($r = mysql_fetch_assoc($db_result)) {
+
+ $artist = new Artist($r['id']);
+ $artist->get_count();
+
+ if ( $artist_id == $r['id'] ) {
+ echo "\t<option value=\"" . $artist->id . "\" selected=\"selected\">". scrub_out($artist->name) . " (" . $artist->songs . ")</option>\n";
+ }
+ else {
+ echo "\t<option value=\"" . $artist->id . "\">". scrub_out($artist->name) ."</option>\n";
+ }
+
+ } // end while fetching artists
+
+ echo "</select>\n";
+
+} // show_artist_pulldown
?>
diff --git a/modules/init.php b/modules/init.php
index c3eea572..69d3480c 100644
--- a/modules/init.php
+++ b/modules/init.php
@@ -83,7 +83,7 @@ if (!$results['conf']['allow_stream_playback']) {
}
$results['conf']['web_path'] = $http_type . $_SERVER['HTTP_HOST'] . $results['conf']['web_path'];
-$results['conf']['version'] = '3.3.2-Alpha4 (Build 001)';
+$results['conf']['version'] = '3.3.2-Alpha4 (Build 002)';
$results['conf']['catalog_file_pattern']= 'mp3|mpc|m4p|m4a|mp4|aac|ogg|rm|wma|asf|flac|spx';
$results['libglue']['local_table'] = 'session';
$results['libglue']['local_sid'] = 'id';
diff --git a/modules/lib.php b/modules/lib.php
index 57601af2..6a825255 100644
--- a/modules/lib.php
+++ b/modules/lib.php
@@ -10,36 +10,6 @@
*/
/*
- * show_artist_pulldown()
- *
- * Helper functions for album and artist functions
- *
- */
-
-function show_artist_pulldown ($artist) {
-
- global $settings;
- $dbh = dbh();
-
- $query = "SELECT id,name FROM artist ORDER BY name";
- $db_result = mysql_query($query, $dbh);
- echo "\n<select name=\"artist\">\n";
-
- while ( $r = mysql_fetch_row($db_result) ) {
- // $r[0] = id, $r[1] = name
- if ( $artist == $r[0] ) {
- echo "<option value=\"$r[0]\" selected=\"selected\">". htmlspecialchars($r[1]) ."</option>\n";
- }
- else {
- echo "<option value=\"$r[0]\">". htmlspecialchars($r[1]) ."</option>\n";
- }
- }
-
- echo " </select>";
-} // show_artist_pulldown()
-
-
-/*
* show_album_pulldown()
*
*/
diff --git a/templates/show_artist.inc b/templates/show_artist.inc
index 4d948707..bb3f6f51 100644
--- a/templates/show_artist.inc
+++ b/templates/show_artist.inc
@@ -23,6 +23,7 @@
//FIXME: I don't like having to re-create this friggin object.. :(
global $user;
$artist_id = $artist->id;
+$web_path = conf('web_path');
?>
<br />
<table class="text-box">
@@ -34,7 +35,8 @@ $artist_id = $artist->id;
<li><a href="<?php print $web_path; ?>/song.php?action=m3u&amp;artist=<?php print $artist_id; ?>"><?php print _("Play All Songs By") . " " . $artist->full_name; ?></a></li>
<li><a href="<?php print $web_path; ?>/song.php?action=m3u&amp;artist_random=<?php print $artist_id; ?>"><?php print _("Play Random Songs By") . " " . $artist->full_name; ?></a></li>
<?php if ($user->has_access('100')) { ?>
- <li><a href="<?php print $web_path; ?>/artists.php?action=update_from_tags&amp;artist=<?php print $artist_id; ?>"><?php print _("Update from tags"); ?></a></li>
+ <li><a href="<?php echo $web_path; ?>/artists.php?action=update_from_tags&amp;artist=<?php print $artist_id; ?>"><?php print _("Update from tags"); ?></a></li>
+ <li><a href="<?php echo $web_path; ?>/artists.php?action=show_rename&amp;artist=<?php echo $artist_id; ?>"><?php echo _("Rename Artist"); ?></a></li>
<?php } ?>
</ul>
</td>
diff --git a/templates/show_install_config.inc b/templates/show_install_config.inc
index fda681d3..2f58215d 100644
--- a/templates/show_install_config.inc
+++ b/templates/show_install_config.inc
@@ -104,7 +104,7 @@
<?php echo _("Ampache.cfg.php Configured?"); ?>
</td>
<td valign="top">[
- <?
+ <?php
$results = read_config($configfile, 0, 0);
if (!check_config_values($results)) {
$status['parse_config'] = 'false';
diff --git a/templates/show_rename_artist.php.inc b/templates/show_rename_artist.inc.php
index cc99ec96..17ee4eda 100644
--- a/templates/show_rename_artist.php.inc
+++ b/templates/show_rename_artist.inc.php
@@ -26,34 +26,28 @@
}
</script>
-<form name="rename_artist" method="post" action="<?php echo conf('web_path'); ?>/artists.php?action=rename&amp;artist=<?php echo $artist->id; ?>">
-<table class="text-box">
-<tr class="table-header">
- <th colspan="3">
- <?php echo _("Renaming") . " " . $artist->name; ?>
+<form name="rename_artist" method="post" action="<?php echo conf('web_path'); ?>/artists.php?action=rename&amp;artist=<?php echo $artist->id; ?>" style="Display:inline;">
+<table class="text-box" cellspacing="0">
+<tr>
+ <th align="left">
+ <span class="header2"><?php echo _("Rename") . " " . $artist->name . " " . _("to"); ?></span>
</th>
</tr>
-<tr class="odd">
- <td>
- <?php echo _("New name"); ?>
- </td>
+<tr>
<td>
<?php show_artist_pulldown($artist->id,"artist_id",4); ?>
<br />
<?php echo _("OR"); ?><br />
- <input type="text" name="artist_name" size="30" value=<?php echo scrub_out($_REQUEST['artist_name']); ?>" id="artist_name" />
- <a href="javascript:insert()"><?php echo _("Insert current"); ?></a>
+ <input type="text" name="artist_name" size="30" value="<?php echo scrub_out($_REQUEST['artist_name']); ?>" id="artist_name" />
+ <a href="javascript:insert()">[<?php echo _("Insert current"); ?>]</a>
<?php $GLOBALS['error']->print_error('artist_name'); ?>
</td>
</tr>
-<tr class="even">
- <td>&nbsp;</td>
+<tr>
<td><input type="checkbox" name="update_id3" value="1" />&nbsp; <?php echo _("Update id3 tags"); ?></td>
- <td>&nbsp;</td>
</tr>
-<tr class="odd">
- <td>&nbsp;</td>
- <td colspan="2">
+<tr>
+ <td>
<input type="submit" value="<?php echo _("Rename"); ?>" />
</td>
</tr>