| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 3 // $Id: station_playlist.install,v 1.14 2009/11/26 03:55:14 drewish Exp $ 4 5 /** 6 * Implementation of hook_schema(). 7 */ 8 function station_playlist_install() { 9 drupal_install_schema('station_playlist'); 10 11 // To deal with the possibility that we're being installed at the same time 12 // as CCK and the field modules we depend on, we need to manually enable the 13 // the modules to ensure they're available before we create our fields. 14 module_enable(array('content', 'nodereference', 'date')); 15 16 # var_export(content_fields('field_station_program', 'station_playlist')); 17 $program_field = array( 18 'field_name' => 'field_station_program', 19 'type_name' => 'station_playlist', 20 'display_settings' => 21 array( 22 'weight' => '-2', 23 'parent' => '', 24 'label' => 25 array( 26 'format' => 'hidden', 27 ), 28 'teaser' => 29 array( 30 'format' => 'hidden', 31 'exclude' => 0, 32 ), 33 'full' => 34 array( 35 'format' => 'hidden', 36 'exclude' => 0, 37 ), 38 4 => 39 array( 40 'format' => 'default', 41 'exclude' => 0, 42 ), 43 2 => 44 array( 45 'format' => 'default', 46 'exclude' => 0, 47 ), 48 3 => 49 array( 50 'format' => 'default', 51 'exclude' => 0, 52 ), 53 'token' => 54 array( 55 'format' => 'default', 56 'exclude' => 0, 57 ), 58 ), 59 'widget_active' => '1', 60 'type' => 'nodereference', 61 'required' => '1', 62 'multiple' => '0', 63 'db_storage' => '1', 64 'module' => 'nodereference', 65 'active' => '1', 66 'locked' => '1', 67 'columns' => 68 array( 69 'nid' => 70 array( 71 'type' => 'int', 72 'unsigned' => TRUE, 73 'not null' => FALSE, 74 ), 75 ), 76 'referenceable_types' => 77 array( 78 'station_program' => 'station_program', 79 ), 80 'advanced_view' => '--', 81 'advanced_view_args' => '', 82 'widget' => 83 array( 84 'autocomplete_match' => 'contains', 85 'default_value' => 86 array( 87 0 => 88 array( 89 'nid' => NULL, 90 '_error_element' => 'default_value_widget][field_station_playlist_program][0][nid][nid', 91 ), 92 ), 93 'default_value_php' => NULL, 94 'label' => 'Program', 95 'weight' => '-2', 96 'description' => 'The name of the program. If you filled in for someone else, enter the name of their program.', 97 'type' => 'nodereference_autocomplete', 98 'module' => 'nodereference', 99 ), 100 ); 101 102 # var_export(content_fields('field_station_playlist_date', 'station_playlist')); 103 $date_field = array( 104 'field_name' => 'field_station_playlist_date', 105 'type_name' => 'station_playlist', 106 'display_settings' => 107 array( 108 'weight' => '-1', 109 'parent' => '', 110 'label' => 111 array( 112 'format' => 'hidden', 113 ), 114 'teaser' => 115 array( 116 'format' => 'hidden', 117 'exclude' => 0, 118 ), 119 'full' => 120 array( 121 'format' => 'hidden', 122 'exclude' => 0, 123 ), 124 4 => 125 array( 126 'format' => 'default', 127 'exclude' => 0, 128 ), 129 2 => 130 array( 131 'format' => 'default', 132 'exclude' => 0, 133 ), 134 3 => 135 array( 136 'format' => 'default', 137 'exclude' => 0, 138 ), 139 'token' => 140 array( 141 'format' => 'default', 142 'exclude' => 0, 143 ), 144 ), 145 'widget_active' => '1', 146 'type' => 'datestamp', 147 'required' => '1', 148 'multiple' => '0', 149 'db_storage' => '1', 150 'module' => 'date', 151 'active' => '1', 152 'locked' => '1', 153 'columns' => 154 array( 155 'value' => 156 array( 157 'type' => 'int', 158 'not null' => FALSE, 159 'sortable' => TRUE, 160 ), 161 ), 162 'granularity' => 163 array( 164 'year' => 'year', 165 'month' => 'month', 166 'day' => 'day', 167 ), 168 'timezone_db' => '', 169 'tz_handling' => 'none', 170 'todate' => '', 171 'repeat' => 0, 172 'repeat_collapsed' => '', 173 'output_format_date' => 'm/d/Y - H:i', 174 'output_format_custom' => '', 175 'output_format_date_long' => 'l, F j, Y - H:i', 176 'output_format_custom_long' => '', 177 'output_format_date_medium' => 'D, m/d/Y - H:i', 178 'output_format_custom_medium' => '', 179 'output_format_date_short' => 'm/d/Y - H:i', 180 'output_format_custom_short' => '', 181 'widget' => 182 array( 183 'default_value' => 'now', 184 'default_value_code' => '', 185 'default_value2' => 'same', 186 'default_value_code2' => '', 187 'input_format' => 'm/d/Y - H:i:s', 188 'input_format_custom' => '', 189 'increment' => '1', 190 'text_parts' => 191 array( 192 ), 193 'year_range' => '-3:+3', 194 'label_position' => 'within', 195 'label' => 'Date', 196 'weight' => '-3', 197 'description' => 'The date the program aired. 198 ', 199 'type' => 'date_select', 200 'module' => 'date', 201 ), 202 ); 203 204 // Create the fields. 205 module_load_include('inc', 'content', 'includes/content.crud'); 206 content_field_instance_create($program_field); 207 content_field_instance_create($date_field); 208 209 // switch ($GLOBALS['db_type']) { 210 // case 'mysql': 211 // case 'mysqli': 212 // db_query(" 213 // CREATE TABLE {station_playlist_track} ( 214 // `nid` int(10) unsigned NOT NULL default '0', 215 // `weight` tinyint(4) unsigned NOT NULL default '0', 216 // `artist` varchar(255) NOT NULL default '', 217 // `album` varchar(255) NOT NULL default '', 218 // `title` varchar(255) NOT NULL default '', 219 // `label` varchar(255) NOT NULL default '', 220 // `link` varchar(255) NOT NULL default '', 221 // KEY `station_playlist_artist` (`artist`), 222 // KEY `station_playlist_nid_weight` (`nid`,`weight`), 223 // KEY `station_playlist_title` (`title`), 224 // KEY `station_playlist_album` (`album`), 225 // KEY `station_playlist_label` (`label`) 226 // ) /*!40100 DEFAULT CHARACTER SET utf8 */; 227 // "); 228 // break; 229 // } 230 } 231 232 /** 233 * Implementation of hook_uninstall(). 234 */ 235 function station_playlist_uninstall() { 236 if (module_exists('content')) { 237 module_load_include('inc', 'content', 'includes/content.crud'); 238 content_field_instance_delete('field_station_program', 'station_playlist'); 239 content_field_instance_delete('field_station_playlist_date', 'station_playlist'); 240 } 241 242 drupal_uninstall_schema('station_playlist'); 243 244 variable_del('station_playlist_track_autocomplete_source'); 245 variable_del('station_playlist_title_dateformat'); 246 variable_del('station_playlist_program_dateformat'); 247 } 248 249 /** 250 * Implementation of hook_schema(). 251 */ 252 function station_playlist_schema() { 253 $schema['station_playlist_track'] = array( 254 'description' => t('Information tracks played in a playlist.'), 255 'fields' => array( 256 'nid' => array( 257 'description' => t("The playlist's {node}.nid."), 258 'type' => 'int', 259 'unsigned' => TRUE, 260 'not null' => TRUE, 261 'default' => 0, 262 ), 263 'weight' => array( 264 'type' => 'int', 265 'not null' => TRUE, 266 'default' => 0, 267 'size' => 'tiny', 268 'description' => t('The weight of this track in relation to other tracks.'), 269 ), 270 'artist' => array( 271 'description' => t('Name of the artist.'), 272 'type' => 'varchar', 273 'length' => 255, 274 'not null' => TRUE, 275 'default' => '', 276 ), 277 'album' => array( 278 'description' => t('Name of the album.'), 279 'type' => 'varchar', 280 'length' => 255, 281 'not null' => TRUE, 282 'default' => '', 283 ), 284 'title' => array( 285 'description' => t('Title of the song.'), 286 'type' => 'varchar', 287 'length' => 255, 288 'not null' => TRUE, 289 'default' => '', 290 ), 291 'label' => array( 292 'description' => t('Name of the label that released the album.'), 293 'type' => 'varchar', 294 'length' => 255, 295 'not null' => TRUE, 296 'default' => '', 297 ), 298 'link' => array( 299 'description' => t('Link to more info on the track.'), 300 'type' => 'varchar', 301 'length' => 255, 302 'not null' => TRUE, 303 'default' => '', 304 ), 305 ), 306 'indexes' => array( 307 'station_playlist_artist' => array('artist'), 308 'station_playlist_nid_weight' => array('nid', 'weight'), 309 'station_playlist_title' => array('album'), 310 'station_playlist_album' => array('album'), 311 'station_playlist_label' => array('label'), 312 ), 313 // 'primary key' => array('vid', 'weight'), 314 ); 315 316 return $schema; 317 } 318 319 /** 320 * Implementation of hook_update_last_removed(). 321 */ 322 function station_playlist_update_last_removed() { 323 // We've removed the 5.x-1.x version of mymodule, including database updates. 324 // The next update function is mymodule_update_5200(). 325 return 101; 326 } 327 328 /** 329 * Create CCK fields and migrate the data to them. 330 */ 331 function station_playlist_update_6000() { 332 $ret = array(); 333 334 // Make sure they've enabled CCK and link modules 335 if (!module_exists('content') || !module_exists('nodereference') || !module_exists('date')) { 336 $ret['#abort'] = array('success' => FALSE, 'query' => t('Station Playlist now requires CCK, Node Reference, and Link modules. Some updates are still pending.<br/>Please re-run the update script.')); 337 return $ret; 338 } 339 // Make sure there's no pending CCK updates 340 drupal_load('module', 'content'); 341 if ($abort = content_check_update('nodereference')) { 342 return $abort; 343 } 344 if ($abort = content_check_update('date')) { 345 return $abort; 346 } 347 348 # var_export(content_fields('field_station_program', 'station_playlist')); 349 $program_field = array( 350 'field_name' => 'field_station_program', 351 'type_name' => 'station_playlist', 352 'display_settings' => 353 array( 354 'weight' => '-2', 355 'parent' => '', 356 'label' => 357 array( 358 'format' => 'hidden', 359 ), 360 'teaser' => 361 array( 362 'format' => 'hidden', 363 'exclude' => 0, 364 ), 365 'full' => 366 array( 367 'format' => 'hidden', 368 'exclude' => 0, 369 ), 370 4 => 371 array( 372 'format' => 'default', 373 'exclude' => 0, 374 ), 375 2 => 376 array( 377 'format' => 'default', 378 'exclude' => 0, 379 ), 380 3 => 381 array( 382 'format' => 'default', 383 'exclude' => 0, 384 ), 385 'token' => 386 array( 387 'format' => 'default', 388 'exclude' => 0, 389 ), 390 ), 391 'widget_active' => '1', 392 'type' => 'nodereference', 393 'required' => '1', 394 'multiple' => '0', 395 'db_storage' => '1', 396 'module' => 'nodereference', 397 'active' => '1', 398 'locked' => '1', 399 'columns' => 400 array( 401 'nid' => 402 array( 403 'type' => 'int', 404 'unsigned' => TRUE, 405 'not null' => FALSE, 406 ), 407 ), 408 'referenceable_types' => 409 array( 410 'station_program' => 'station_program', 411 ), 412 'advanced_view' => '--', 413 'advanced_view_args' => '', 414 'widget' => 415 array( 416 'autocomplete_match' => 'contains', 417 'default_value' => 418 array( 419 0 => 420 array( 421 'nid' => NULL, 422 '_error_element' => 'default_value_widget][field_station_playlist_program][0][nid][nid', 423 ), 424 ), 425 'default_value_php' => NULL, 426 'label' => 'Program', 427 'weight' => '-2', 428 'description' => 'The name of the program. If you filled in for someone else, enter the name of their program.', 429 'type' => 'nodereference_autocomplete', 430 'module' => 'nodereference', 431 ), 432 ); 433 434 # var_export(content_fields('field_station_playlist_date', 'station_playlist')); 435 $date_field = array( 436 'field_name' => 'field_station_playlist_date', 437 'type_name' => 'station_playlist', 438 'display_settings' => 439 array( 440 'weight' => '-1', 441 'parent' => '', 442 'label' => 443 array( 444 'format' => 'hidden', 445 ), 446 'teaser' => 447 array( 448 'format' => 'hidden', 449 'exclude' => 0, 450 ), 451 'full' => 452 array( 453 'format' => 'hidden', 454 'exclude' => 0, 455 ), 456 4 => 457 array( 458 'format' => 'default', 459 'exclude' => 0, 460 ), 461 2 => 462 array( 463 'format' => 'default', 464 'exclude' => 0, 465 ), 466 3 => 467 array( 468 'format' => 'default', 469 'exclude' => 0, 470 ), 471 'token' => 472 array( 473 'format' => 'default', 474 'exclude' => 0, 475 ), 476 ), 477 'widget_active' => '1', 478 'type' => 'datestamp', 479 'required' => '1', 480 'multiple' => '0', 481 'db_storage' => '1', 482 'module' => 'date', 483 'active' => '1', 484 'locked' => '1', 485 'columns' => 486 array( 487 'value' => 488 array( 489 'type' => 'int', 490 'not null' => FALSE, 491 'sortable' => TRUE, 492 ), 493 ), 494 'granularity' => 495 array( 496 'year' => 'year', 497 'month' => 'month', 498 'day' => 'day', 499 ), 500 'timezone_db' => '', 501 'tz_handling' => 'none', 502 'todate' => '', 503 'repeat' => 0, 504 'repeat_collapsed' => '', 505 'output_format_date' => 'm/d/Y - H:i', 506 'output_format_custom' => '', 507 'output_format_date_long' => 'l, F j, Y - H:i', 508 'output_format_custom_long' => '', 509 'output_format_date_medium' => 'D, m/d/Y - H:i', 510 'output_format_custom_medium' => '', 511 'output_format_date_short' => 'm/d/Y - H:i', 512 'output_format_custom_short' => '', 513 'widget' => 514 array( 515 'default_value' => 'now', 516 'default_value_code' => '', 517 'default_value2' => 'same', 518 'default_value_code2' => '', 519 'input_format' => 'm/d/Y - H:i:s', 520 'input_format_custom' => '', 521 'increment' => '1', 522 'text_parts' => 523 array( 524 ), 525 'year_range' => '-3:+3', 526 'label_position' => 'within', 527 'label' => 'Date', 528 'weight' => '-3', 529 'description' => 'The date the program aired. 530 ', 531 'type' => 'date_select', 532 'module' => 'date', 533 ), 534 ); 535 536 // Create the fields. 537 module_load_include('inc', 'content', 'includes/content.crud'); 538 content_field_instance_create($program_field); 539 content_field_instance_create($date_field); 540 541 542 // Now the tricky part is to migrate the data. 543 // The procedure I'm using here is a bit overkill for migrating two fields 544 // but I'm planning on re-using it so it makes sense to go ahead and just be 545 // robust. 546 // We've got to assume that CCK's table might only have records for half of 547 // the nodes we're migrating so the strategy is to INSERT then UPDATE. 548 $migrations = array( 549 array( 550 'cck_field' => $program_field, 551 'from_table' => 'station_playlist', 552 'from_col' => 'program_nid', 553 'from_join' => 'nid', 554 'to_col' => 'nid', 555 'to_join' => 'nid', 556 ), 557 array( 558 'cck_field' => $date_field, 559 'from_table' => 'station_playlist', 560 'from_col' => 'timestamp', 561 'from_join' => 'nid', 562 'to_col' => 'value', 563 'to_join' => 'nid', 564 ), 565 ); 566 foreach ($migrations as $migration) { 567 // Might be needlessly escaping the names here but it shouldn't hurt 568 // anything. 569 $from_table = db_escape_table($migration['from_table']); 570 $from_col = db_escape_table($migration['from_col']); 571 $from_join = db_escape_table($migration['from_join']); 572 573 $db_info = content_database_info($migration['cck_field']); 574 $to_table = db_escape_table($db_info['table']); 575 $to_col = db_escape_table($db_info['columns'][$migration['to_col']]['column']); 576 $to_join = db_escape_table($migration['to_join']); 577 578 // Make sure there's a record in CCK's table for every one in the source 579 // table, then do an update of all the records. 580 $ret[] = update_sql("INSERT INTO {{$to_table}} (nid, vid) SELECT n.nid, n.vid FROM {{$from_table}} f INNER JOIN {node} n ON f.$from_join = n.nid WHERE NOT EXISTS ( SELECT * FROM {{$to_table}} t WHERE f.$from_join = t.$to_join)"); 581 $ret[] = update_sql("UPDATE {{$to_table}} t INNER JOIN {{$from_table}} f ON t.$to_join = f.$from_join SET t.$to_col = f.$from_col"); 582 } 583 584 # db_drop_table($ret, 'station_playlist'); 585 586 return $ret; 587 } 588 589 // TODO Update to add a vid and a primary key on it.
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |