1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
|
<?php
/*
Copyright (c) 2001 - 2007 Ampache.org
All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License v2
as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/**
* Update Class
* this class handles updating from one version of
* maintain to the next. Versions are a 6 digit number
* 220000
* ^
* Major Revision
*
* 220000
* ^
* Minor Revision
*
* The last 4 digits are a build number...
* If Minor can't go over 9 Major can go as high as we want
*/
class Update {
public $key;
public $value;
public static $versions; // array containing version information
/**
* Update
* Constructor, pulls out information about the desired key
*/
function Update ( $key=0 ) {
if (!$key) { return false; }
$this->key = intval($key);
$info = $this->_get_info();
$this->value = $info['value'];
$this->versions = $this->populate_version();
} // constructor
/**
* _get_info
* gets the information for the zone
*/
private function _get_info() {
$sql = "SELECT * FROM `update_info` WHERE `key`='$this->key'";
$db_results = Dba::query($sql);
return Dba::fetch_assoc($db_results);
} // _get_info
/**
* get_version
* this checks to see what version you are currently running
* because we may not have the update_info table we have to check
* for it's existance first.
*/
public static function get_version() {
/* Make sure that update_info exits */
$sql = "SHOW TABLES LIKE 'update_info'";
$db_results = Dba::query($sql);
if (!is_resource(Dba::dbh())) { header("Location: test.php"); }
// If no table
if (!Dba::num_rows($db_results)) {
$version = '310000';
} // if table isn't found
else {
// If we've found the update_info table, let's get the version from it
$sql = "SELECT * FROM `update_info` WHERE `key`='db_version'";
$db_results = Dba::query($sql);
$results = Dba::fetch_assoc($db_results);
$version = $results['value'];
}
return $version;
} // get_version
/**
* format_version
* make the version number pretty
*/
public static function format_version($data) {
$new_version = substr($data,0,strlen($data) - 5) . "." . substr($data,strlen($data)-5,1) . " Build:" .
substr($data,strlen($data)-4,strlen($data));
return $new_version;
} // format_version
/**
* need_update
* checks to see if we need to update
* maintain at all
*/
public static function need_update() {
$current_version = self::get_version();
if (!is_array(self::$versions)) {
self::$versions = self::populate_version();
}
/*
Go through the versions we have and see if
we need to apply any updates
*/
foreach (self::$versions as $update) {
if ($update['version'] > $current_version) {
return true;
}
} // end foreach version
return false;
} // need_update
/**
* plugins_installed
* This function checks to make sure that there are no plugins
* installed before allowing you to run the update. this is
* to protect the integrity of the database
*/
public static function plugins_installed() {
/* Pull all version info */
$sql = "SELECT * FROM `update_info`";
$db_results = Dba::query($sql);
while ($results = Dba::fetch_assoc($db_results)) {
/* We have only one allowed string */
if ($results['key'] != 'db_version') {
return false;
}
} // while update_info results
return true;
} // plugins_installed
/**
* populate_version
* just sets an array the current differences
* that require an update
*/
public static function populate_version() {
/* Define the array */
$version = array();
$update_string = '- Moved back to ID for user tracking internally.<br />' .
'- Added date to user_vote to allow sorting by vote time.<br />' .
'- Added Random Method and Object Count Preferences.<br />' .
'- Removed some unused tables/fields.<br />' .
'- Added Label, Catalog # and Language to Extended Song Data Table.';
$version[] = array('version' => '340001','description' => $update_string);
$update_string = '- Added Offset Limit to Preferences and removed from user table.';
$version[] = array('version' => '340002','description' => $update_string);
$update_string = '- Moved Art from the Album table into album_data to improve performance.<br />' .
'- Made some minor changes to song table to reduce size of each row.<br />' .
'- Moved song_ext_data to song_data to match album_data pattern.<br />' .
'- Added Playlist Method and Rate Limit Preferences.<br />' .
'- Renamed preferences and ratings to preference and rating to fit table pattern.<br />' .
'- Fixed rating table, renamed user_rating to rating and switched 00 for -1.<br />';
$version[] = array('version' => '340003','description' => $update_string);
$update_string = '- Alter the Session.id to be VARCHAR(64) to account for all potential configs.<br />' .
'- Added new user_shout table for Sticky objects / shoutbox.<br />' .
'- Added new playlist preferences, and new preference catagory of playlist.<br />' .
'- Tweaked Now Playing Table.<br />';
$version[] = array('version' => '340004','description' => $update_string);
$update_string = '- Altered Ratings table so the fields make more sense.<br />' .
'- Moved Random Method to Playlist catagory.<br />' .
'- Added Transcode Method to Streaming.<br />';
$version[] = array('version' => '340005','description' => $update_string);
$update_string = '- Remove Random Method config option, ended up being useless.<br />' .
'- Check and change album_data.art to a MEDIUMBLOB if needed.<br />';
$version[] = array('version' => '340006','description' => $update_string);
$update_string = '- Added new session_stream table for sessions tied directly to stream instances.<br />' .
'- Altered the session table, making value a LONGTEXT.<br />';
$version[] = array('version' => '340007','description' => $update_string);
$update_string = '- Modified Playlist_Data table to account for multiple object types.<br />' .
'- Verified previous updates, adjusting as needed.<br />' .
'- Dropped Allow Downsampling pref, configured in cfg file.<br />' .
'- Renamed Downsample Rate --> Transcode Rate to reflect new terminiology.<br />';
$version[] = array('version' => '340008','description' => $update_string);
$update_string = '- Added disk to Album table.<br />' .
'- Added artist_data for artist images and bios.<br />' .
'- Added DNS to access list to allow for dns based ACLs.<br />';
$version[] = array('version' => '340009','description' => $update_string);
return $version;
} // populate_version
/**
* display_update
* This displays a list of the needed
* updates to the database. This will actually
* echo out the list...
*/
public static function display_update() {
$current_version = self::get_version();
if (!is_array(self::$versions)) {
self::$versions = self::populate_version();
}
echo "<ul>\n";
foreach (self::$versions as $version) {
if ($version['version'] > $current_version) {
$updated = true;
echo "<li><b>Version: " . self::format_version($version['version']) . "</b><br />";
echo $version['description'] . "<br /></li>\n";
} // if newer
} // foreach versions
echo "</ul>\n";
if (!$updated) { echo "<p align=\"center\">No Updates Needed [<a href=\"" . Config::get('web_path') . "\">Return]</a></p>"; }
} // display_update
/**
* run_update
* This function actually updates the db.
* it goes through versions and finds the ones
* that need to be run. Checking to make sure
* the function exists first.
*/
public static function run_update() {
/* Nuke All Active session before we start the mojo */
$sql = "TRUNCATE session";
$db_results = Dba::query($sql);
// Prevent the script from timing out, which could be bad
set_time_limit(0);
/* Verify that there are no plugins installed
//FIXME: provide a link to remove all plugins, otherwise this could turn into a catch 22
if (!$self::plugins_installed()) {
$GLOBALS['error']->add_error('general',_('Plugins detected, please remove all Plugins and try again'));
return false;
} */
$methods = array();
$current_version = self::get_version();
$methods = get_class_methods('Update');
if (!is_array((self::$versions))) {
self::$versions = self::populate_version();
}
foreach (self::$versions as $version) {
// If it's newer than our current version
// let's see if a function exists and run the
// bugger
if ($version['version'] > $current_version) {
$update_function = "update_" . $version['version'];
if (in_array($update_function,$methods)) {
call_user_func(array('Update',$update_function));
}
}
} // end foreach version
} // run_update
/**
* set_version
* This updates the 'update_info' which is used by the updater
* and plugins
*/
private static function set_version($key,$value) {
$sql = "UPDATE update_info SET value='$value' WHERE `key`='$key'";
$db_results = Dba::query($sql);
} //set_version
/**
* update_340001
* This update moves back to the ID for user UID and
* adds date to the user_vote so that it can be sorted
* correctly
*/
private function update_340001() {
// Build the User -> ID map using the username as the key
$sql = "SELECT `id`,`username` FROM `user`";
$db_results = Dba::query($sql);
$user_array = array();
while ($r = mysql_fetch_assoc($db_results)) {
$username = $r['username'];
$user_array[$username] = Dba::escape($r['id']);
} // end while
// Alter the user table so that you can't have an ID beyond the
// range of the other tables which have to allow for -1
$sql = "ALTER TABLE `user` CHANGE `id` `id` INT ( 11 ) NOT NULL AUTO_INCREMENT";
$db_results = Dba::query($sql);
// Now pull the access list users, alter table and then re-insert
$sql = "SELECT DISTINCT(`user`) FROM `access_list`";
$db_results = Dba::query($sql);
while ($r = Dba::fetch_assoc($db_results)) {
// Build the new SQL
$username = $r['user'];
$user_id = $user_array[$username];
$username = Dba::escape($username);
$sql = "UPDATE `access_list` SET `user`='$user_id' WERE `user`='$username'";
$update_results = Dba::query($sql);
} // end while access_list
// Alter the table
$sql = "ALTER TABLE `access_list` CHANGE `user` `user` INT ( 11 ) NOT NULL";
$db_results = Dba::query($sql);
// Now pull flagged users, update and alter
$sql = "SELECT DISTINCT(`user`) FROM `flagged`";
$db_results = Dba::query($sql);
while ($r = Dba::fetch_assoc($db_results)) {
$username = $r['user'];
$user_id = $user_array[$username];
$username = Dba::escape($username);
$sql = "UPDATE `flagged` SET `user`='$user_id' WHERE `user`='$username'";
$update_results = Dba::query($sql);
} // end while
// Alter the table
$sql = "ALTER TABLE `flagged` CHANGE `user` `user` INT ( 11 ) NOT NULL";
$db_results = Dba::query($sql);
// Now fix up the ip history
$sql = "SELECT DISTINCT(`user`) FROM `ip_history`";
$db_results = Dba::query($sql);
while ($r = Dba::fetch_assoc($db_results)) {
$username = $r['user'];
$user_id = $user_array[$username];
$username = Dba::escape($username);
$sql = "UPDATE `ip_history` SET `user`='$user_id' WHERE `user`='$username'";
$update_results = Dba::query($sql);
} // end while
// Alter the table
$sql = "ALTER TABLE `ip_history` CHANGE `user` `user` INT ( 11 ) NOT NULL";
$db_results = Dba::query($sql);
// Now fix now playing
$sql = "SELECT DISTINCT(`user`) FROM `now_playing`";
$db_results = Dba::query($sql);
while ($r = Dba::fetch_assoc($db_results)) {
$username = $r['user'];
$user_id = $user_array[$username];
$username = Dba::escape($username);
$sql = "UPDATE `now_playing` SET `user`='$user_id' WHERE `user`='$username'";
$update_results = Dba::query($sql);
} // end while
// Alter the table
$sql = "ALTER TABLE `now_playing` CHANGE `user` `user` INT ( 11 ) NOT NULL";
$db_results = Dba::query($sql);
// Now fix the playlist table
$sql = "SELECT DISTINCT(`user`) FROM `playlist`";
$db_results = Dba::query($sql);
while ($r = Dba::fetch_assoc($db_results)) {
$username = $r['user'];
$user_id = $user_array[$username];
$username = Dba::escape($username);
$sql = "UPDATE `playlist` SET `user`='$user_id' WHERE `user`='$username'";
$update_results = Dba::query($sql);
} // end while
// Alter the table
$sql = "ALTER TABLE `playlist` CHANGE `user` `user` INT ( 11 ) NOT NULL";
$db_results = Dba::query($sql);
// Drop unused table
$sql = "DROP TABLE `playlist_permission`";
$db_results = Dba::query($sql);
// Now fix the ratings table
$sql = "SELECT DISTINCT(`user`) FROM `ratings`";
$db_results = Dba::query($sql);
while ($r = Dba::fetch_assoc($db_results)) {
$username = $r['user'];
$user_id = $user_array[$username];
$username = Dba::escape($username);
$sql = "UPDATE `ratings` SET `user`='$user_id' WHERE `user`='$username'";
$update_results = Dba::query($sql);
} // end while
$sql = "ALTER TABLE `ratings` CHANGE `user` `user` INT ( 11 ) NOT NULL";
$db_results = Dba::query($sql);
// Now work on the tag_map
$sql = "ALTER TABLE `tag_map` CHANGE `user_id` `user` INT ( 11 ) NOT NULL";
$db_results = Dba::query($sql);
// Now fix user preferences
$sql = "SELECT DISTINCT(`user`) FROM `user_preference`";
$db_results = Dba::query($sql);
while ($r = Dba::fetch_assoc($db_results)) {
$username = $r['user'];
$user_id = $user_array[$username];
$username = Dba::escape($username);
$sql = "UPDATE `user_preference` SET `user`='$user_id' WHERE `user`='$username'";
$update_results = Dba::query($sql);
} // end while
// Alter the table
$sql = "ALTER TABLE `user_preference` CHANGE `user` `user` INT ( 11 ) NOT NULL";
$db_results = Dba::query($sql);
// Add a date to the user_vote
$sql = "ALTER TABLE `user_vote` ADD `date` INT( 11 ) UNSIGNED NOT NULL";
$db_results = Dba::query($sql);
// Add the index for said field
$sql = "ALTER TABLE `user_vote` ADD INDEX(`date`)";
$db_results = Dba::query($sql);
// Add the thumb fields to album
$sql = "ALTER TABLE `album` ADD `thumb` TINYBLOB NULL ,ADD `thumb_mime` VARCHAR( 128 ) NULL";
$db_results = Dba::query($sql);
// Now add in the min_object_count preference and the random_method
$sql = "INSERT INTO `preferences` (`name`,`value`,`description`,`level`,`type`,`catagory`) " .
"VALUES('min_object_count','1','Min Element Count','5','integer','interface')";
$db_results = Dba::query($sql);
$sql = "INSERT INTO `preferences` (`name`,`value`,`description`,`level`,`type`,`catagory`) " .
"VALUES('random_method','default','Random Method','5','string','interface')";
$db_results = Dba::query($sql);
// Delete old preference
$sql = "DELETE FROM `preferences` WHERE `name`='min_album_size'";
$db_results = Dba::query($sql);
// Make Hash a non-required field and smaller
$sql = "ALTER TABLE `song` CHANGE `hash` `hash` VARCHAR ( 64 ) NULL";
$db_results = Dba::query($sql);
// Make user access an int, nothing else
$sql = "UPDATE `user` SET `access`='100' WHERE `access`='admin'";
$db_results = Dba::query($sql);
$sql = "UPDATE `user` SET `access`='25' WHERE `access`='user'";
$db_results = Dba::query($sql);
$sql = "UPDATE `user` SET `access`='5' WHERE `access`='guest'";
$db_results = Dba::query($sql);
// Alter the table
$sql = "ALTER TABLE `user` CHANGE `access` `access` TINYINT ( 4 ) UNSIGNED NOT NULL";
$db_results = Dba::query($sql);
// Add in Label and Catalog # and language
$sql = "ALTER TABLE `song_ext_data` ADD `label` VARCHAR ( 128 ) NULL, ADD `catalog_number` VARCHAR ( 128 ) NULL, ADD `language` VARCHAR ( 128 ) NULL";
$db_results = Dba::query($sql);
/* Fix every users preferences */
$sql = "SELECT `id` FROM `user`";
$db_results = Dba::query($sql);
User::fix_preferences('-1');
while ($r = Dba::fetch_assoc($db_results)) {
User::fix_preferences($r['id']);
} // while results
self::set_version('db_version','340001');
return true;
} //update_340001
/**
* update_340002
* This update tweaks the preferences a little more and make sure that the
* min_object_count has a rational value
*/
private function update_340002() {
/* Add the offset_limit preference and remove it from the user table */
$sql = "INSERT INTO `preferences` (`name`,`value`,`description`,`level`,`type`,`catagory`) " .
"VALUES ('offset_limit','50','Offset Limit','5','integer','interface')";
$db_results = Dba::query($sql);
self::set_version('db_version','340002');
return true;
} // update_340002
/**
* update_340003
* This update moves the album art out of the album table
* and puts it in an album_data table. It also makes some
* minor changes to the song table in an attempt to reduce
* the size of each row
*/
public static function update_340003() {
$sql = "ALTER TABLE `song` CHANGE `mode` `mode` ENUM( 'abr', 'vbr', 'cbr' ) NULL DEFAULT 'cbr'";
$db_results = Dba::query($sql);
$sql = "ALTER TABLE `song` CHANGE `time` `time` SMALLINT( 5 ) UNSIGNED NOT NULL DEFAULT '0'";
$db_results = Dba::query($sql);
$sql = "ALTER TABLE `song` CHANGE `rate` `rate` MEDIUMINT( 8 ) UNSIGNED NOT NULL DEFAULT '0'";
$db_results = Dba::query($sql);
$sql = "ALTER TABLE `song` CHANGE `bitrate` `bitrate` MEDIUMINT( 8 ) UNSIGNED NOT NULL DEFAULT '0'";
$db_results = Dba::query($sql);
$sql = "ALTER TABLE `song` CHANGE `track` `track` SMALLINT( 5 ) UNSIGNED NULL DEFAULT NULL ";
$db_results = Dba::query($sql);
$sql = "ALTER TABLE `user` CHANGE `disabled` `disabled` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0'";
$db_results = Dba::query($sql);
$sql = "CREATE TABLE `album_data` (" .
"`album_id` INT( 11 ) UNSIGNED NOT NULL , " .
"`art` MEDIUMBLOB NULL , " .
"`art_mime` VARCHAR( 64 ) NULL , " .
"`thumb` BLOB NULL , " .
"`thumb_mime` VARCHAR( 64 ) NULL , " .
"UNIQUE ( `album_id` )" .
") ENGINE = MYISAM";
$db_results = Dba::query($sql);
/* Foreach the Albums and move the data into the new album_data table */
$sql = "SELECT * FROM album";
$db_results = Dba::query($sql);
while ($data = Dba::fetch_assoc($db_results)) {
$id = $data['id'];
$art = Dba::escape($data['art']);
$art_mime = Dba::escape($data['art_mime']);
$thumb = Dba::escape($data['thumb']);
$thumb_mime = Dba::escape($data['thumb_mime']);
$sql = "INSERT INTO `album_data` (`album_id`,`art`,`art_mime`,`thumb`,`thumb_mime`)" .
" VALUES ('$id','$art','$art_mime','$thumb','$thumb_mime')";
$insert_results = Dba::query($sql);
} // end while
$sql = "RENAME TABLE `song_ext_data` TO `song_data`";
$db_results = Dba::query($sql);
$sql = "RENAME TABLE `preferences` TO `preference`";
$db_results = Dba::query($sql);
$sql = "RENAME TABLE `ratings` TO `rating`";
$db_results = Dba::query($sql);
// Go ahead and drop the art/thumb stuff
$sql = "ALTER TABLE `album` DROP `art`, DROP `art_mime`, DROP `thumb`, DROP `thumb_mime`";
$db_results = Dba::query($sql);
// We need to fix the user_vote table
$sql = "ALTER TABLE `user_vote` CHANGE `user` `user` INT( 11 ) UNSIGNED NOT NULL";
$db_results = Dba::query($sql);
// Remove offset limit from the user
$sql = "ALTER TABLE `user` DROP `offset_limit`";
$db_results = Dba::query($sql);
$sql = "ALTER TABLE `rating` CHANGE `user_rating` `rating` ENUM( '-1', '0', '1', '2', '3', '4', '5' ) NOT NULL DEFAULT '0'";
$db_results = Dba::query($sql);
/* Add the rate_limit preference */
$sql = "INSERT INTO `preference` (`name`,`value`,`description`,`level`,`type`,`catagory`) " .
"VALUES ('rate_limit','8192','Rate Limit','100','integer','streaming')";
$db_results = Dba::query($sql);
/* Add the playlist_method preference and remove it from the user table */
$sql = "INSERT INTO `preference` (`name`,`value`,`description`,`level`,`type`,`catagory`) " .
"VALUES ('playlist_method','normal','Playlist Method','5','string','streaming')";
$db_results = Dba::query($sql);
$sql = "ALTER TABLE `update_info` ADD UNIQUE (`key`)";
$db_results = Dba::query($sql);
$sql = "SELECT `id` FROM `user`";
$db_results = Dba::query($sql);
User::fix_preferences('-1');
while ($r = Dba::fetch_assoc($db_results)) {
User::fix_preferences($r['id']);
}
self::set_version('db_version','340003');
} // update_340003
/**
* update_340004
* Update the session.id to varchar(64) to handle
* newer configs
*/
public static function update_340004() {
/* Alter the session.id so that it's 64 */
$sql = "ALTER TABLE `session` CHANGE `id` `id` VARCHAR( 64 ) NOT NULL";
$db_results = Dba::query($sql);
/* Add Playlist Related Preferences */
$sql = "INSERT INTO `preference` (`name`,`value`,`description`,`level`,`type`,`catagory`) " .
"VALUES ('playlist_add','append','Add Behavior','5','string','playlist')";
$db_results = Dba::query($sql);
// Switch the existing preferences over to this new catagory
$sql = "UPDATE `preference` SET `catagory`='playlist' WHERE `name`='playlist_method' " .
" OR `name`='playlist_type'";
$db_results = Dba::query($sql);
// Change the default value for playlist_method
$sql = "UPDATE `preference` SET `value`='normal' WHERE `name`='playlist_method'";
$db_results = Dba::query($sql);
// Add in the shoutbox
$sql = "CREATE TABLE `user_shout` (`id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , " .
"`user` INT( 11 ) NOT NULL , " .
"`text` TEXT NOT NULL , " .
"`date` INT( 11 ) UNSIGNED NOT NULL , " .
"`sticky` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0', " .
"`object_id` INT( 11 ) UNSIGNED NOT NULL , " .
"`object_type` VARCHAR( 32 ) NOT NULL " .
") ENGINE = MYISAM";
$db_results = Dba::query($sql);
$sql = "ALTER TABLE `user_shout` ADD INDEX ( `sticky` )";
$db_results = Dba::query($sql);
$sql = "ALTER TABLE `user_shout` ADD INDEX ( `date` )";
$db_results = Dba::query($sql);
$sql = "ALTER TABLE `user_shout` ADD INDEX ( `user` )";
$db_results = Dba::query($sql);
$sql = "ALTER TABLE `now_playing` CHANGE `start_time` `expire` INT( 11 ) UNSIGNED NOT NULL DEFAULT '0'";
$db_results = Dba::query($sql);
$sql = "OPTIMIZE TABLE `album`";
$db_results = Dba::query($sql);
$sql = "SELECT `id` FROM `user`";
$db_results = Dba::query($sql);
User::fix_preferences('-1');
while ($r = Dba::fetch_assoc($db_results)) {
User::fix_preferences($r['id']);
}
// Update our database version now that we are all done
self::set_version('db_version','340004');
return true;
} // update_340004
/**
* update_340005
* This update fixes the preferences types
*/
public static function update_340005() {
// Turn user_rating into a tinyint and call it score
$sql = "ALTER TABLE `rating` CHANGE `user_rating` `score` TINYINT( 4 ) UNSIGNED NOT NULL DEFAULT '0'";
$db_results = Dba::query($sql);
$sql = "UPDATE `preference` SET `catagory`='playlist' WHERE `name`='random_method'";
$db_results = Dba::query($sql);
$sql = "INSERT INTO `preference` (`name`,`value`,`description`,`level`,`type`,`catagory`) " .
"VALUES ('transcode','default','Transcoding','25','string','streaming')";
$db_results = Dba::query($sql);
/* We need to check for playlist_method here because I fubar'd an earlier update */
$sql = "SELECT * FROM `preference` WHERE `name`='playlist_method'";
$db_results = Dba::query($sql);
if (!Dba::num_rows($db_results)) {
/* Add the playlist_method preference and remove it from the user table */
$sql = "INSERT INTO `preference` (`name`,`value`,`description`,`level`,`type`,`catagory`) " .
"VALUES ('playlist_method','default','Playlist Method','5','string','playlist')";
$db_results = Dba::query($sql);
}
// Add in the object_type to the tmpplaylist data table so that we can have non-songs in there
$sql = "ALTER TABLE `tmp_playlist_data` ADD `object_type` VARCHAR( 32 ) NULL AFTER `tmp_playlist`";
$db_results = Dba::query($sql);
$sql = "SELECT `id` FROM `user`";
$db_results = Dba::query($sql);
User::fix_preferences('-1');
while ($r = Dba::fetch_assoc($db_results)) {
User::fix_preferences($r['id']);
}
self::set_version('db_version','340005');
return true;
} // update_340005
/**
* update_340006
* This just updates the size of the album_data table
* and removes the random_method config option
*/
public static function update_340006() {
$sql = "DESCRIBE `album_data`";
$db_results = Dba::query($sql);
while ($row = Dba::fetch_assoc($db_results)) {
if ($row['Field'] == 'art' AND $row['Type'] == 'blob') {
$blob_needed = true;
}
} // end while
if ($blob_needed) {
$sql = "ALTER TABLE `album_data` CHANGE `art` `art` MEDIUMBLOB NULL DEFAULT NULL";
$db_results = Dba::query($sql);
}
// No matter what remove that random method preference
$sql = "DELETE FROM `preference` WHERE `name`='random_method'";
$db_results = Dba::query($sql);
$sql = "SELECT `id` FROM `user`";
$db_results = Dba::query($sql);
User::fix_preferences('-1');
while ($r = Dba::fetch_assoc($db_results)) {
User::fix_preferences($r['id']);
}
self::set_version('db_version','340006');
return true;
} // update_340006
/**
* update_340007
* This update converts the session.value to a longtext
* and adds a session_stream table
*/
public static function update_340007() {
// Tweak the session table to handle larger session vars for my page-a-nation hotness
$sql = "ALTER TABLE `session` CHANGE `value` `value` LONGTEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL";
$db_results = Dba::query($sql);
// Create the new stream table where we will store stream SIDs
$sql = "CREATE TABLE `session_stream` ( " .
"`id` VARCHAR( 64 ) NOT NULL , " .
"`user` INT( 11 ) UNSIGNED NOT NULL , " .
"`agent` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL , " .
"`expire` INT( 11 ) UNSIGNED NOT NULL , " .
"`ip` INT( 11 ) UNSIGNED NULL , " .
"PRIMARY KEY ( `id` ) " .
") ENGINE = MYISAM";
$db_results = Dba::query($sql);
// Change the now playing to use stream session ids for its ID
$sql = "ALTER TABLE `now_playing` CHANGE `id` `id` VARCHAR( 64 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL";
$db_results = Dba::query($sql);
// Now longer needed because of the new hotness
$sql = "ALTER TABLE `now_playing` DROP `session`";
$db_results = Dba::query($sql);
self::set_version('db_version','340007');
return true;
} // update_340007
/**
* update_340008
* This modifies the playlist table to handle the different types of objects that it needs to be able to
* store, and tweaks how dynamic playlist stuff works
*/
public static function update_340008() {
$sql = "ALTER TABLE `playlist_data` CHANGE `song` `object_id` INT( 11 ) UNSIGNED NULL DEFAULT NULL";
$db_results = Dba::query($sql);
$sql = "ALTER TABLE `playlist_data` CHANGE `dyn_song` `dynamic_song` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL";
$db_results = Dba::query($sql);
$sql = "ALTER TABLE `playlist_data` ADD `object_type` VARCHAR( 32 ) NOT NULL DEFAULT 'song' AFTER `object_id`";
$db_results = Dba::query($sql);
$sql = "ALTER TABLE `playlist` ADD `genre` INT( 11 ) UNSIGNED NOT NULL AFTER `type`";
$db_results = Dba::query($sql);
$sql = "DELETE FROM `preference` WHERE `name`='allow_downsample_playback'";
$db_results = Dba::query($sql);
$sql = "UPDATE `preference` SET `description`='Transcode Bitrate' WHERE `name`='sample_rate'";
$db_results = Dba::query($sql);
// Check for old tables and drop if found, seems like there was a glitch that caused them
// not to get droped.. *shrug*
$sql = "DROP TABLE IF EXISTS `preferences`";
$db_results = Dba::query($sql);
$sql = "DROP TABLE IF EXISTS `song_ext_data`";
$db_results = Dba::query($sql);
$sql = "DROP TABLE IF EXISTS `ratings`";
$db_results = Dba::query($sql);
$sql = "SELECT `id` FROM `user`";
$db_results = Dba::query($sql);
User::fix_preferences('-1');
while ($r = Dba::fetch_assoc($db_results)) {
User::fix_preferences($r['id']);
}
self::set_version('db_version','340008');
} // update_340008
/**
* update_340009
* This modifies the song table to handle pos fields
*/
public static function update_340009() {
$sql = "ALTER TABLE `album` ADD `disk` smallint(5) UNSIGNED DEFAULT NULL";
$db_results = Dba::query($sql);
$sql = "ALTER TABLE `album` ADD INDEX (`disk`)";
$db_results = Dba::query($sql);
$sql = "ALTER TABLE `access_list` ADD `dns` VARCHAR( 255 ) NOT NULL AFTER `end`";
$db_results = Dba::query($sql);
$sql = "CREATE TABLE `artist_data` (" .
"`artist_id` INT( 11 ) UNSIGNED NOT NULL ," .
"`art` MEDIUMBLOB NOT NULL ," .
"`art_mime` VARCHAR( 32 ) NOT NULL ," .
"`thumb` BLOB NOT NULL ," .
"`thumb_mime` VARCHAR( 32 ) NOT NULL ," .
"`bio` TEXT NOT NULL , " .
"UNIQUE (`artist_id`) ) ENGINE = MYISAM";
$db_results = Dba::query($sql);
self::set_version('db_version','340009');
} // update_340009
} // end update class
?>
|