migrate_example_baseball.install 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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, 'group_name' => 'baseball'));
  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(
  39. 'field_park',
  40. 'field_home_team',
  41. 'field_home_game_number',
  42. 'field_home_score',
  43. 'field_visiting_score',
  44. 'field_outs',
  45. 'field_attendance',
  46. 'field_duration',
  47. 'field_home_batters',
  48. 'field_visiting_batters',
  49. 'field_home_pitcher',
  50. 'field_visiting_pitcher',
  51. 'field_visiting_team',
  52. 'field_start_date',
  53. );
  54. foreach ($field_names as $field_name) {
  55. $instance = field_info_instance('node', $field_name, $bundle);
  56. field_delete_instance($instance);
  57. field_delete_field($field_name);
  58. }
  59. node_type_delete($bundle);
  60. }
  61. function migrate_example_baseball_disable() {
  62. MigrateGroup::deregister('baseball');
  63. }
  64. /**
  65. * Get a copy of the sample CSV data if necessary.
  66. */
  67. function migrate_example_baseball_update_7201() {
  68. migrate_example_baseball_get_files(dirname(__FILE__) . '/data');
  69. }