Changeset 10203
- Timestamp:
- 2008-08-03 01:03:01 (4 months ago)
- Files:
-
- mb_server/branches/Discographies-BRANCH/admin/SendReleaseNotifications (moved) (moved from mb_server/branches/Discographies-BRANCH/admin/SendReleaseNotifications.pl) (2 diffs)
- mb_server/branches/Discographies-BRANCH/cgi-bin/CollectionPreference.pm (modified) (14 diffs)
- mb_server/branches/Discographies-BRANCH/cgi-bin/MusicBrainz/Server/CollectionInfo.pm (modified) (6 diffs)
- mb_server/branches/Discographies-BRANCH/htdocs/user/collectionpreferences.html (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
mb_server/branches/Discographies-BRANCH/admin/SendReleaseNotifications
r10138 r10203 6 6 use lib "$FindBin::Bin/../cgi-bin"; 7 7 8 use MusicBrainz::Server::CollectionInfo; 9 use MusicBrainz::Server::Release; 10 use Data::Dumper; 8 11 9 12 … … 24 27 my $collections = $sqlraw->SelectSingleColumnArray('SELECT id FROM collection_info WHERE emailnotifications = TRUE'); 25 28 29 print 'collections:'.Dumper($collections); 30 31 # iterate over all collections to be notified and send out e-mails(if any new releases) 32 foreach my $currentCollectionId (@$collections) 33 { 34 my $currentPreferences = undef; 35 my $currentCollection = MusicBrainz::Server::CollectionInfo->newFromCollectionId($currentCollectionId, $mbro->{DBH}, $mbraw->{DBH}, $currentPreferences); 36 37 my $newReleases = $currentCollection->GetNewReleases(); 38 39 my $count = @{$newReleases}; 40 41 #print Dumper($newReleases); 42 43 my $userId = $currentCollection->GetUserId(); 44 45 if($count>0) # notifications should be sent 46 { 47 sendMail($currentCollection, $newReleases, $userId, $mbro->{DBH}); 48 } 49 } 50 26 51 27 52 exit 1; 28 53 29 54 30 sub sendMail ($collectionId, @releasesIds)55 sub sendMail 31 56 { 57 my ($collectionId, $releaseIds, $userId, $rodbh) = @_; 32 58 59 #my $user = UserStuff->newFromId(); 60 61 print Dumper(@$releaseIds); 62 my $subject = 'New releases'; 63 my $message = 'The following releases are about to be released:\n'; 64 65 66 for my $releaseId (@{$releaseIds}) 67 { 68 my $release = MusicBrainz::Server::Release->new($rodbh); 69 $release->SetId($releaseId); 70 $release->LoadFromId(); 71 72 $message = $message . $release->GetName() . '\n'; 73 } 74 75 print $message; 33 76 } mb_server/branches/Discographies-BRANCH/cgi-bin/CollectionPreference.pm
r10147 r10203 3 3 # check values 4 4 # if possible insert all tuples in setMissing... in one INSERT query 5 # make another new sub which does not get values from db, as the values are known from POST data(when sent) 5 6 # 6 7 … … 14 15 package CollectionPreference; 15 16 16 #use Carp qw( carp );17 use Carp qw( carp ); 17 18 18 19 … … 25 26 26 27 # get collection id 27 my $sql=Sql->new($rawdbh); 28 my $collectionId=$sql->SelectSingleValue('SELECT id FROM collection_info WHERE moderator=?', $userId); 29 #my $collectionId = $this:: 28 my $rawsql = Sql->new($rawdbh); 29 my $collectionId = $rawsql->SelectSingleValue('SELECT id FROM collection_info WHERE moderator=?', $userId); 30 30 31 31 # select artist id's of artists to display missing releases of … … 58 58 $object->addpref('notificationinterval', 7, sub { check_int(1,31,@_) }); 59 59 #print Dumper($object->{artistsMissing}); 60 61 62 # load the preference keys and values into the prefs hash 63 my $selectprefs = $rawsql->SelectSingleRowHash('SELECT emailnotifications, notificationinterval, lastcheck FROM collection_info WHERE id = ?', $collectionId); 64 65 66 my $prefs = { 67 'emailnotifications' => {'KEY' => 'emailnotifications', VALUE => $selectprefs->{emailnotifications}, 'CHECK' => undef}, 68 'notificationinterval' => {'KEY' => 'notificationinterval', VALUE => $selectprefs->{notificationinterval}, 'CHECK' => undef} 69 }; 70 71 $object->{prefs} = $prefs; 72 73 74 60 75 return $object; 61 76 } … … 95 110 96 111 $this->{prefs}{$key} = {KEY => $key, VALUE => $value, CHECK => $check}; 97 98 #use Data::Dumper;99 #print 'after addpref: '.Dumper($this->{prefs});100 112 101 113 … … 118 130 use Data::Dumper; 119 131 my $prefs=$this->{prefs}; 120 print 'asdsdsa: '.Dumper(keys %$prefs);121 132 #return keys %prefs; 122 133 #my $prefs=$this->{prefs}; … … 158 169 my $info = $this->{prefs}->{$key} 159 170 or carp("CollectionPreference::get called with invalid key '$key'"), return undef; 160 171 172 161 173 return $info->{VALUE}; 162 174 … … 176 188 177 189 190 # TO DO: 191 # use check functions 178 192 sub set 179 193 { 180 194 my ($this, $key, $value) = @_; 195 181 196 182 197 my $rawsql=Sql->new($this->{RAWDBH}); … … 191 206 my $oldkey = $info->{KEY}; 192 207 my $oldvalue = $info->{VALUE}; 193 194 print '<br/><br/>key: '.$key.'<br/>value: '.$value.'<br/>collectionId: '.$this->{collectionId}.'<br/>'; 208 my $oldcheck = $info->{CHECK}; 209 210 211 212 213 195 214 196 215 #$sql->InsertRow("UPDATE collection_info SET $key='TRUE' WHERE id='".$this->{collectionId}."'"); … … 209 228 210 229 # update setting in collection_info table 211 $rawsql->Do("UPDATE collection_info SET $key ='TRUE' WHERE id='".$this->{collectionId}."'");230 $rawsql->Do("UPDATE collection_info SET $key = ? WHERE id='".$this->{collectionId}."'", $value); 212 231 #$sql->Do("UPDATE collection_info SET emailnotifications=FALSE WHERE id='0';"); 213 232 }; … … 224 243 { 225 244 # update setting in object hash 226 $info->{$value}=0; 227 228 print Dumper($this->{prefs}); 229 245 #$info->{$value}=0; 246 $this->{prefs}{$key} = {'KEY' => $key, 'VALUE' => $value, 'CHECK' => $oldcheck}; 247 230 248 $rawsql->Commit(); 231 249 } … … 237 255 238 256 239 print 'stored '.$key.', '.$value.'<br/>'240 257 # my ($key, $value) = @_; 241 258 # my $info = $prefs{$key} … … 254 271 { 255 272 my ($this, @artistsMissing) = @_; 256 #print 'artists:'.Dumper(@artistsMissing);257 #print 'RAWDBH:'.Dumper($this->{RAWDBH});273 274 258 275 my $rawsql = Sql->new($this->{RAWDBH}); 259 276 … … 403 420 my $rawsql = Sql->new($mbraw->{DBH}); 404 421 405 print STDERR 'userId:'.$userId;422 #print STDERR 'userId:'.$userId; 406 423 use Data::Dumper; 407 print STDERR Dumper($mbraw->{DBH});424 #print STDERR Dumper($mbraw->{DBH}); 408 425 409 426 my $collectionId = MusicBrainz::Server::CollectionInfo::GetCollectionIdForUser($userId, $mbraw->{DBH}); mb_server/branches/Discographies-BRANCH/cgi-bin/MusicBrainz/Server/CollectionInfo.pm
r10146 r10203 20 20 my ($this, $userId, $rodbh, $rawdbh, $preferences)=@_; 21 21 22 my %collectionHash;23 my %artistHash;24 25 22 26 23 my $sql = Sql->new($rawdbh); … … 36 33 RAWDBH => $rawdbh, # raw database 37 34 preferences => $preferences, 38 result => $result,39 35 collectionId => $result->{id}, 40 36 hasReleases => undef, # lets see if this and missingReleases will be used … … 44 40 } 45 41 42 sub newFromCollectionId 43 { 44 my ($this, $collectionId, $rodbh, $rawdbh, $preferences)=@_; 45 46 47 my $sql = Sql->new($rawdbh); 48 49 my $userId=$sql->SelectSingleValue("SELECT moderator FROM collection_info WHERE id=?", $collectionId); 50 51 52 53 bless( 54 { 55 userId => $userId, 56 RODBH => $rodbh, # read only database 57 RAWDBH => $rawdbh, # raw database 58 preferences => $preferences, 59 collectionId => $collectionId, 60 hasReleases => undef, # lets see if this and missingReleases will be used 61 missingReleases => undef 62 #artistHash => {} 63 }, $this); 64 } 65 66 67 sub newMissingCollectionInfo 68 { 69 } 70 46 71 47 72 … … 114 139 115 140 return $collectionId; 141 } 142 143 144 sub GetUserId 145 { 146 my ($this) = @_; 147 148 return 0; 116 149 } 117 150 … … 281 314 my ($this, $artistId) = @_; 282 315 283 my $ sql=$this->{RODBH};316 my $rosql = Sql->new($this->{RODBH}); 284 317 285 318 #my $query="SELECT * FROM album WHERE artist IN (SELECT artist FROM collection_discography_artist_join WHERE collection_info='123')"; 286 319 287 my $result = $ sql->SelectListOfHashes("SELECT gid FROM album WHERE artist=", $artistId);320 my $result = $rosql->SelectListOfHashes("SELECT gid FROM album WHERE artist=", $artistId); 288 321 289 322 use Data::Dumper; … … 293 326 294 327 328 # NOTES: 329 # xlotlu: select foo, foo + '1 day'::interval as foo_tomorrow 330 # xlotlu: niklas: extract (epoch from datefield) 331 # xlotlu: niklas: you can use to_timestamp(date_string, date_format) ... 332 # to_timestamp('1234-12-12', 'YYYY-MM-DD') 333 # '1234-12-12'::TIMESTAMP 334 sub GetNewReleases 335 { 336 my ($this) = @_; 337 338 my $rosql = Sql->new($this->{RODBH}); 339 340 my $lastCheck = $this->GetLastCheck(); 341 342 #my $newReleases = ['685970', '696912']; # while testing 343 #my $newReleases = $rosql->SelectSingleColumnArray("SELECT id FROM album WHERE id IN(SELECT album FROM release WHERE to_date(releasedate, 'YYYY-MM-DD') > (CURRENT_DATE - '14 days'::INTERVAL) AND to_date(releasedate, 'YYYY-MM-DD') < (CURRENT_DATE + '14 days'::INTERVAL)) LIMIT 10"); 344 #my $newReleases = $rosql->SelectSingleColumnArray("SELECT id FROM album WHERE id IN (SELECT id FROM albummeta WHERE dateadded > (CURRENT_TIMESTAMP - '14 days'::INTERVAL) AND dateadded < (CURRENT_TIMESTAMP + '14 days'::INTERVAL)) LIMIT 3"); 345 346 #my $newReleases = $rosql->SelectSingleColumnArray("SELECT id FROM album WHERE id IN (SELECT album FROM release WHERE to_date(releasedate, 'YYYY-MM-DD') > (CURRENT_DATE - '14 days'::INTERVAL) AND to_date(releasedate, 'YYYY-MM-DD') < (CURRENT_DATE + '14 days'::INTERVAL)) LIMIT 10"); 347 348 my $newReleases = $rosql->SelectSingleColumnArray("SELECT id FROM album WHERE id IN(SELECT album FROM release WHERE to_date(releasedate, 'YYYY-MM-DD') > (CURRENT_DATE - '14 days'::INTERVAL) AND to_date(releasedate, 'YYYY-MM-DD') < (CURRENT_DATE + '14 days'::INTERVAL)) LIMIT 10");#, $this->GetLastCheck()); 349 350 351 print 'last check: '.$this->GetLastCheck(); 352 353 return $newReleases; 354 355 #my $newReleases = $rosql->SelectSingleColumnArray('SELECT id FROM album WHERE id IN (SELECT album FROM release WHERE releasedate < CURRENT_DATE + '14 days'::INTERVAL and releasedate > something)'); 356 # SELECT id FROM album WHERE id IN(SELECT album FROM release WHERE to_date(releasedate, 'YYYY-MM-DD') > '2007-01-01'::DATE); 357 # SELECT gid FROM album WHERE id IN(SELECT album FROM release WHERE to_date(releasedate, 'YYYY-MM-DD') > '2007-01-01'::DATE); 358 # SELECT gid,id,name FROM album WHERE id IN(SELECT album FROM release WHERE to_date(releasedate, 'YYYY-MM-DD') > (CURRENT_DATE - '14 days'::INTERVAL) AND to_date(releasedate, 'YYYY-MM-DD') < (CURRENT_DATE + '14 days'::INTERVAL)) LIMIT 10; 359 } 360 361 362 363 sub GetLastCheck 364 { 365 my ($this) = @_; 366 367 my $rawsql = Sql->new($this->{RAWDBH}); 368 369 my $lastCheck = $rawsql->SelectSingleValue('SELECT lastcheck FROM collection_info WHERE id = ?', $this->{collectionId}); 370 371 return $lastCheck; 372 } 373 374 375 376 sub UpdateLastCheck 377 { 378 my ($this) = @_; 379 380 my $rawsql = Sql->new($this->{RAWDBH}); 381 382 $rawsql->Do('UPDATE collection_info SET lastcheck = CURRENT_TIMESTAMP WHERE id = ?', $this->{collectionId}); 383 } 384 385 386 295 387 # ? 296 388 sub LoadHas mb_server/branches/Discographies-BRANCH/htdocs/user/collectionpreferences.html
r10147 r10203 27 27 for my $key ($preferences->valid_keys()) 28 28 { 29 print ' got key ' . $key . ' value '.$ARGS{$key}.'</br>'; 30 $preferences->set($key, $ARGS{$key}) 31 if defined $ARGS{$key}; 29 my $value = $ARGS{$key}; 30 31 32 # convert the value from "on" or empty to a boolean value 33 if($value eq 'on') 34 { 35 $value = 1; 36 } 37 elsif($value eq '') 38 { 39 $value = 0; 40 } 41 42 43 $preferences->set($key, $value); 32 44 } 33 } 45 } 46 34 47 35 48 … … 41 54 <div> 42 55 How long time in advance do you want to be notified about upcoming releases? 43 <select name=" pref_notificationinterval">56 <select name="notificationinterval"> 44 57 <& /comp/options, 45 58 [ 46 [ "1", "A day" ],47 [ "7", "A week" ],48 [ "14", "Two weeks" ],49 [ "31", "A month" ],59 [ 1, "A day" ], 60 [ 7, "A week" ], 61 [ 14, "Two weeks" ], 62 [ 31, "A month" ], 50 63 ], 51 64 $preferences->get('notificationinterval') &> … … 55 68 <div> 56 69 <input type="checkbox" name="emailnotifications" id="pref_emailnotifications" 57 % $m->out($preferences->get('emailnotifications') ? ' checked="checked" ' : "" );70 % $m->out($preferences->get('emailnotifications')==1 ? ' checked="checked" ' : "" ); 58 71 /> 59 72 <label for="pref_vote_abs_default">