I get this error when enabling "migrate_example_baseball":

Warning: copy(profiles/sample/modules/contrib/migrate/migrate_example_baseball/data/gl2000_09.zip): failed to open stream: No such file or directory in migrate_example_baseball_get_files()

It looks like the module folder isn't writable, which I can correct, but this is because migrate was installed by Aegir as part of an installation profile we have. I looked at the code and it seems to expect that the module folder will be writable. Should this write to the site public "files/" folder instead? That one should always be writable.

Anyway. Here's a patch for your reviewing pleasure.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mikeryan’s picture

Good catch, it should be using public://. Uninstall should remove the files, and we'll need an update function to move the files if they already exist.

markie’s picture

Issue summary: View changes
Status: Active » Needs review
FileSize
1.17 KB

I ran into this today and thought I'd share my fix. I updated the path to public:// and changed the update hook_update_7201() as well, and added hook_update_7202() in case they have run 7201() checking to see if they are missing. I think I needed to change 7201 because that would cause the update script to fail. I didn't write the removal script because the folder should be removed on the next module update anyway.

Let me know if you have any questions.

mikeryan’s picture

Status: Needs review » Needs work
  1. +++ b/migrate_example_baseball/migrate_example_baseball.install
    @@ -6,7 +6,7 @@
    +  $path = drupal_realpath('public://data');
    

    Let's namespace this by the module name - public://migrate_example_baseball.

  2. +++ b/migrate_example_baseball/migrate_example_baseball.install
    @@ -60,5 +60,16 @@ function migrate_example_baseball_disable() {
    +  }
    

    Please also delete the data subdirectory and its contents from migrate_example_baseball if it's there.

    You also need to update the source_file argument in migrate_status for each game migration to point at the new location.

markie’s picture

Status: Needs work » Needs review
FileSize
1.62 KB

Updated as requested. I still don't think the data folder needs to be removed because when they update the module to the next revision, it should delete it then. But it was a neat exercise.

Also, isn't the source of the migration done on line 13 of migrate_example_baseball/migrate_example_baseball.install?

Migration::registerMigration('GameBaseball',
      pathinfo($file, PATHINFO_FILENAME),
      array('source_file' => $path . '/' . $file, 'group_name' => 'baseball'));
mikeryan’s picture

Status: Needs review » Needs work

Here's what I did:

  1. Enabled migrate_example_baseball. The data files were downloaded to migrate_example_baseball/data.
  2. Applied the latest patch.
  3. Ran drush -y updatedb to execute the update function (which took a while, since it was freshly downloading the data files).
  4. Observed that the migrate_example_baseball/data directory still has the data files. Deleted this directory.
  5. Did drush ms - got a bunch of errors like file(/Users/mryan/Sites/m7/sites/all/modules/migrate/migrate_example_baseball/data/GL2000.TXT): failed to open stream: No such file or directory csv.inc:155, because migrate_status was not updated to point to the new data file location.

The old data directory should be removed in the update function rather than hook_disable(). Better yet, move the data files to save on download time! Also, you do need to reregister the migration in the update function, the registration you pointed to only happens at install time, not update time.

Thanks.

mikeryan’s picture

One more thing (discovered when disabling the module again) - you're just doing an rmdir on public://migrate_example_baseball, which fails because it still contains the files, you need to explicitly remove the files before removing the directory.