bondjimbond / islandora_westvault

Automated preservation for Islandora objects
GNU General Public License v3.0
1 stars 1 forks source link

Move bags to directory after creation #7

Closed bondjimbond closed 5 years ago

bondjimbond commented 5 years ago

Bags must be moved to their target directory immediately after creation, so they aren't clogging up the /tmp folder, taking up unwanted storage space, and causing confusion in multisites.

@mjordan's suggestion is to use hook_islandora_bagit_post_create() to do the moving: https://github.com/bondjimbond/islandora_westvault/blob/move_bags/islandora_westvault.module#L100

@mjordan can you advise on how that might work?

mjordan commented 5 years ago

Yes, let me take a look this evening and I will provide some sample code.

mjordan commented 5 years ago

This is an example of how you'd move the Bag:

/**
 * Implements hook_islandora_bagit_post_create($pid, $bag_path).
 */
function islandora_westvault_islandora_bagit_post_create($pid, $bag_path) {
  $basename = basename($bag_path);
  rename(realpath($bag_path), '/tmp/foo/' . $basename);
}

However, on my islandora_vagrant I'm getting permission denied errors from rename(). Not sure why, since the Bag file, and the files directory, are both owned by www-data. But you get the idea.

bondjimbond commented 5 years ago

Thanks!

However, on my islandora_vagrant I'm getting permission denied errors from rename(). Not sure why, since the Bag file, and the files directory, are both owned by www-data. But you get the idea.

Perhaps you have to make the directory first?

I've pushed some changes to the move_bags branch -- but I get a 500 error when I try to call the function. I'm probably just doing something obviously wrong..

islandora_westvault_bagit_post_create($object, variable_get('islandora_bagit_bag_output_dir', '/tmp'));

Where $object is the PID...

How did you call it?

mjordan commented 5 years ago

($pid, $bag_path) is what you need to use as parameters to the hook implementation. The $bag_path variable is passed from within the Islandora BagIt module and will have a predefined value. If you want to see what that value is, use dd($bag_path) to write it to /tmp/drupal_debug.txt (of course, you will need to have the Debug module enabled to use dd()). What you want to accomplish in this hook implementation is copying the Bag file from where Bagit wrote it to where you want it.

bondjimbond commented 5 years ago

Update @mjordan - Never mind, it works! I'm not exactly sure what I did differently, but it works.

So we now have:

Next up:

bondjimbond commented 5 years ago

So it looks like the big issue was that I didn't need to actually call the function at all! Hooks are weird, man.