[mb-commits] r10095 - in mb_server/branches/Discographies-BRANCH: cgi-bin/MusicBrainz/Server cgi-bin/MusicBrainz/Server/Handlers/WS/1 htdocs/comp htdocs/user
root at musicbrainz.org
root at musicbrainz.org
Sat Jul 12 21:55:40 UTC 2008
Author: niklas
Date: 2008-07-12 21:55:39 +0000 (Sat, 12 Jul 2008)
New Revision: 10095
Modified:
mb_server/branches/Discographies-BRANCH/cgi-bin/MusicBrainz/Server/Collection.pm
mb_server/branches/Discographies-BRANCH/cgi-bin/MusicBrainz/Server/CollectionInfo.pm
mb_server/branches/Discographies-BRANCH/cgi-bin/MusicBrainz/Server/Handlers/WS/1/Collection.pm
mb_server/branches/Discographies-BRANCH/htdocs/comp/collection
mb_server/branches/Discographies-BRANCH/htdocs/user/collectionpreferences.html
Log:
fixes
Modified: mb_server/branches/Discographies-BRANCH/cgi-bin/MusicBrainz/Server/Collection.pm
===================================================================
--- mb_server/branches/Discographies-BRANCH/cgi-bin/MusicBrainz/Server/Collection.pm 2008-07-11 22:40:10 UTC (rev 10094)
+++ mb_server/branches/Discographies-BRANCH/cgi-bin/MusicBrainz/Server/Collection.pm 2008-07-12 21:55:39 UTC (rev 10095)
@@ -62,16 +62,11 @@
$collectionId = $this->{collectionId};
- print "adding albumsa:\n";
-
-
-
#iterate over the album MBID's to be added
foreach my $item (@albums)
{
$this->AddRelease($item);
- print "$item\n";
}
@@ -85,7 +80,6 @@
my ($this, @albums) = @_;
$this->{removeAlbum}=1;
- print "REMOVE ALBUM";
foreach my $item (@albums)
{
@@ -106,8 +100,6 @@
# make sure this is valid format for a mbid
if($mbid =~ m/[a-z0-9]{8}[:-][a-z0-9]{4}[:-][a-z0-9]{4}[:-][a-z0-9]{4}[:-][a-z0-9]{12}/)
{
- print "VALID MBID!\n";
-
my $releaseId;
eval
@@ -139,17 +131,12 @@
{
$rosql->Commit();
}
+
- use Data::Dumper;
- print Dumper($releaseId);
-
-
eval
{
$rawsql->Begin();
- use Data::Dumper;
- print Dumper($releaseId);
# add MBID to the collection
my $attributes={id => 456, collection_info => $collectionId, album => $releaseId};
@@ -174,12 +161,9 @@
{
$rawsql->Commit();
}
-
- print "adding mbid " . $mbid . " for user " . $collectionId . "\n";
}
else
{
- print "NOT VALID MBID:'$mbid'\n";
$this->{addAlbum_invalidMBIDCount}++; # increase invalid mbid count
}
}
@@ -198,9 +182,7 @@
my $rosql = $this->{RODBH};
- print "\nremoving $mbid\n";
-
# get id for realease with specified mbid
my $albumId;
@@ -258,44 +240,4 @@
}
}
-
-
-# Print XML response
-sub PrintResultXML
-{
- my ($this)=@_;
-
- print "\n\nduplicates:\n";
- for my $duplicate (@{$this->{addAlbum_duplicateArray}})
- {
- print "$duplicate\n";
- }
-
- print "\n\not existing MBIDs:\n";
- for my $notExisting (@{$this->{addAlbum_notExistingArray}})
- {
- print "$notExisting\n";
- }
-
- print "\n\ninsert count: " .$this->{addAlbum_insertCount}. "\n";
-
-
-
-
- print '<?xml version="1.0" encoding="UTF-8"?>';
- print '<response>';
-
- if($this->{addAlbum}==1 || $this->{removeAlbum}==1) # print details for uuidtype album
- {
- print '<details uuidtype="album">';
- print '<addcount>'.$this->{addAlbum_insertCount}.'</addcount>';
- print '<removecount>'.$this->{removeAlbum_removeCount}.'</removecount>';
- print '<addinvalidmbidcount>'.$this->{addAlbum_invalidMBIDCount}.'</addinvalidmbidcount>';
- print '<removeinvalidmbidcount>'.$this->{removeAlbum_invalidMBIDCount}.'</removeinvalidmbidcount>';
- print '<error></error>'; # <--
- print '</details>';
- }
- print '</response>';
-}
-
1;
\ No newline at end of file
Modified: mb_server/branches/Discographies-BRANCH/cgi-bin/MusicBrainz/Server/CollectionInfo.pm
===================================================================
--- mb_server/branches/Discographies-BRANCH/cgi-bin/MusicBrainz/Server/CollectionInfo.pm 2008-07-11 22:40:10 UTC (rev 10094)
+++ mb_server/branches/Discographies-BRANCH/cgi-bin/MusicBrainz/Server/CollectionInfo.pm 2008-07-12 21:55:39 UTC (rev 10095)
@@ -1,3 +1,8 @@
+#
+# TODO:
+# remove notificationinterval etc from query in CreateCollection and set them as default values in CreateTables.sql instead
+#
+
#!/usr/bin/perl -w
use strict;
@@ -61,6 +66,7 @@
else
{
print 'DO NOT HAVE COLLECTION';
+ CreateCollection($userId, $rawdbh);
}
}
@@ -70,12 +76,42 @@
{
my ($userId, $rawdbh) = @_;
- my $sql = Sql->new($rawdbh);
+ my $rawsql = Sql->new($rawdbh);
- my $query = "INSERT INTO collection_info";
+ my $query = "INSERT INTO collection_info (moderator, publiccollection, emailnotifications, notificationinterval) VALUES ($userId, TRUE, TRUE, 7)";
+
+
+ eval
+ {
+ $rawsql->Begin();
+ $rawsql->Do($query);
+ };
+
+ if($@)
+ {
+ $rawsql->Commit();
+ print $@;
+ }
+ else
+ {
+ $rawsql->Commit();
+ }
}
+sub GetCollectionIdForUser
+{
+ my ($userId, $rawdbh) = @_;
+
+ my $sqlraw = Sql->new($rawdbh);
+
+ my $collectionIdQuery = "SELECT id FROM collection_info WHERE moderator='". $userId ."'";
+ my $collectionId=$sqlraw->SelectSingleValue($collectionIdQuery);
+
+ return $collectionId;
+}
+
+
sub GetHasReleases
{
my ($this) = @_;
Modified: mb_server/branches/Discographies-BRANCH/cgi-bin/MusicBrainz/Server/Handlers/WS/1/Collection.pm
===================================================================
--- mb_server/branches/Discographies-BRANCH/cgi-bin/MusicBrainz/Server/Handlers/WS/1/Collection.pm 2008-07-11 22:40:10 UTC (rev 10094)
+++ mb_server/branches/Discographies-BRANCH/cgi-bin/MusicBrainz/Server/Handlers/WS/1/Collection.pm 2008-07-12 21:55:39 UTC (rev 10095)
@@ -8,19 +8,18 @@
use MusicBrainz::Server::Handlers::WS::1::Common;
use Apache::Constants qw( OK BAD_REQUEST AUTH_REQUIRED DECLINED SERVER_ERROR NOT_FOUND FORBIDDEN);
+
sub handler
{
- my $r = shift;
-
# URLs are of the form:
# POST http://server/ws/1/collection/?addalbums=<mbid1>,<mbid2>&removealbums=<mbid3>,<mbid4>
+ my $r = shift;
+ #return bad_req($r, 'test');
- # make sure we are getting POST data
- #if($r->method != "POST") print "Only accepting POST data";
- # perhaps the above check should not be done? why not allow GET...
- # RAK: You should allow GET so that people can fetch their collection information.
+
+
- # store
+
my %args=$r->args;
# get the albums from the POST data
@@ -41,16 +40,18 @@
my $sqlro = Sql->new($mbro->{DBH});
+
+
# get user id for logged on user
my $userId = $sqlro->SelectSingleValue("SELECT id FROM moderator WHERE name='". $r->user ."'");
+
# get collection_info id
-
- # RAK: Should this be done by CollectionInfo? I'd like to remove most of the collection
- # specific SQL from this module and have it all reside in your Collection(Info) objects.
- my $collectionIdQuery = "SELECT id FROM collection_info WHERE moderator='". $userId ."'";
- my $collectionId=$sqlraw->SelectSingleValue($collectionIdQuery);
+ my $collectionId = MusicBrainz::Server::CollectionInfo::GetCollectionIdForUser($userId, $mbraw->{DBH});
+ # make sure the user has a collection_info tuple
+ MusicBrainz::Server::CollectionInfo::AssureCollection($userId, $mbraw->{DBH});
+
# instantiate Collection object
my $collection = MusicBrainz::Server::Collection->new($mbro->{DBH}, $mbraw->{DBH}, $collectionId);
@@ -64,13 +65,51 @@
# RAK:
# please use STDERR to print the debug output and then tail -f <error_log> to see the output
# this way the output does not interfere with the operations.
- print STDERR 'asfgfgfgd\n';
+ #print STDERR 'asfgfgfgd\n';
+
+ print 'asd';
+
+ my $printer = sub {
+ print_xml($collection);
+ };
+
+ send_response($r, $printer);
+ return Apache::Constants::OK();
+}
- # RAK: Please use a similar construct as to this:
- # http://bugs.musicbrainz.org/browser/mb_server/branches/Discographies-BRANCH/cgi-bin/MusicBrainz/Server/Handlers/WS/1/Artist.pm#L112
- # This uses the send_response() function, which does all the proper header setting: http://bugs.musicbrainz.org/browser/mb_server/branches/Discographies-BRANCH/cgi-bin/MusicBrainz/Server/Handlers/WS/1/Common.pm#L281
- # Also, the actual XML output code should also live in this module, much like the other WS modules
- $collection->PrintResultXML();
+
+sub print_xml
+{
+ my ($collection) = @_;
+
+# print "\n\nduplicates:\n";
+# for my $duplicate (@{$collection->{addAlbum_duplicateArray}})
+# {
+# print STDERR "$duplicate\n";
+# }
+#
+# print "\n\not existing MBIDs:\n";
+# for my $notExisting (@{$collection->{addAlbum_notExistingArray}})
+# {
+# print STDERR "$notExisting\n";
+# }
+
+
+
+ print '<?xml version="1.0" encoding="UTF-8"?>';
+ print '<response>';
+
+ if($collection->{addAlbum}==1 || $collection->{removeAlbum}==1) # print details for uuidtype album
+ {
+ print '<details uuidtype="album">';
+ print '<addcount>'.$collection->{addAlbum_insertCount}.'</addcount>';
+ print '<removecount>'.$collection->{removeAlbum_removeCount}.'</removecount>';
+ print '<addinvalidmbidcount>'.$collection->{addAlbum_invalidMBIDCount}.'</addinvalidmbidcount>';
+ print '<removeinvalidmbidcount>'.$collection->{removeAlbum_invalidMBIDCount}.'</removeinvalidmbidcount>';
+ print '<error></error>'; # <--
+ print '</details>';
+ }
+ print '</response>';
}
1;
Modified: mb_server/branches/Discographies-BRANCH/htdocs/comp/collection
===================================================================
--- mb_server/branches/Discographies-BRANCH/htdocs/comp/collection 2008-07-11 22:40:10 UTC (rev 10094)
+++ mb_server/branches/Discographies-BRANCH/htdocs/comp/collection 2008-07-12 21:55:39 UTC (rev 10095)
@@ -12,7 +12,16 @@
<%perl>
-if(1==1) # Check if there are releases to display
+
+my $sql=Sql->new($dbh);
+
+# Get all releases in collection
+use MusicBrainz::Server::CollectionInfo;
+my $collectionInfo=MusicBrainz::Server::CollectionInfo->new($session{uid}, $rodbh, $rawdbh);
+my $releases = $collectionInfo->GetHasMBIDs();
+my $count=@$releases;
+
+if($count>0) # Check if there are releases to display
{
my $rownum=0;
</%perl>
@@ -38,16 +47,7 @@
<%perl>
-my $sql=Sql->new($dbh);
-# Get all releases in collection
-use MusicBrainz::Server::CollectionInfo;
-my $collectionInfo=MusicBrainz::Server::CollectionInfo->new($session{uid}, $rodbh, $rawdbh);
-
-
-#my $releases=$collectionInfo->GetHasMBIDs();
-my $releases = $collectionInfo->GetHasMBIDs();
-
use MusicBrainz::Server::Release;
$collectionInfo->GetHasMBIDsForArtist('357465');
Modified: mb_server/branches/Discographies-BRANCH/htdocs/user/collectionpreferences.html
===================================================================
--- mb_server/branches/Discographies-BRANCH/htdocs/user/collectionpreferences.html 2008-07-11 22:40:10 UTC (rev 10094)
+++ mb_server/branches/Discographies-BRANCH/htdocs/user/collectionpreferences.html 2008-07-12 21:55:39 UTC (rev 10095)
@@ -13,6 +13,9 @@
my $mbraw = MusicBrainz->new();
$mbraw->Login(db => 'RAWDATA');
+ # make sure the user has a collection_info tuple
+ MusicBrainz::Server::CollectionInfo::AssureCollection($session{uid}, $mbraw->{DBH});
+
require CollectionPreference;
my $preferences = CollectionPreference->new($mbraw->{DBH}, $session{uid});
More information about the MusicBrainz-commits
mailing list