migrate_example_baseball.install 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * @file
  4. * Set up the migration baseball example module.
  5. */
  6. function migrate_example_baseball_enable() {
  7. $path = dirname(__FILE__) . '/data';
  8. migrate_example_baseball_get_files($path);
  9. for ($i=0; $i<=9; $i++) {
  10. $file = 'gl200' . $i . '.txt';
  11. Migration::registerMigration('GameBaseball',
  12. pathinfo($file, PATHINFO_FILENAME),
  13. array('source_file' => $path . '/' . $file));
  14. }
  15. }
  16. /**
  17. * Obtain our sample data from Retrosheet.
  18. *
  19. * @param $path
  20. */
  21. function migrate_example_baseball_get_files($path) {
  22. // Don't replace old upper-case names
  23. if (!file_exists("$path/GL2000.TXT") && !file_exists("$path/gl2000.txt")) {
  24. file_prepare_directory($path, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
  25. $result = copy('http://www.retrosheet.org/gamelogs/gl2000_09.zip',
  26. $path . '/gl2000_09.zip');
  27. if ($result) {
  28. $zip = new ZipArchive();
  29. $zip->open($path . '/gl2000_09.zip');
  30. $zip->extractTo($path);
  31. $zip->close();
  32. unlink("$path/gl2000_09.zip");
  33. }
  34. }
  35. }
  36. function migrate_example_baseball_uninstall() {
  37. $bundle = 'migrate_example_baseball';
  38. $field_names = array('field_park', 'field_home_team', 'field_home_game_number',
  39. 'field_home_score', 'field_visiting_score', 'field_outs', 'field_attendance',
  40. 'field_duration', 'field_home_batters', 'field_visiting_batters',
  41. 'field_home_pitcher', 'field_visiting_pitcher', 'field_visiting_team',
  42. 'field_start_date');
  43. foreach ($field_names as $field_name) {
  44. $instance = field_info_instance('node', $field_name, $bundle);
  45. field_delete_instance($instance);
  46. field_delete_field($field_name);
  47. }
  48. node_type_delete($bundle);
  49. }
  50. function migrate_example_baseball_disable() {
  51. for ($i=0; $i<=9; $i++) {
  52. $file = 'gl200' . $i . '.txt';
  53. Migration::deregisterMigration(pathinfo($file, PATHINFO_FILENAME));
  54. $filename = dirname(__FILE__) . '/data/' . $file;
  55. if (file_exists($filename)) {
  56. unlink($filename);
  57. }
  58. }
  59. }
  60. /**
  61. * Get a copy of the sample CSV data if necessary.
  62. */
  63. function migrate_example_baseball_update_7201() {
  64. migrate_example_baseball_get_files(dirname(__FILE__) . '/data');
  65. }