Skip to content
Mark Jordan edited this page Apr 19, 2018 · 7 revisions

MIK can run scripts after it has completed processing all packages. These scripts are called "shutdown hooks" and are enabled in the .ini file's [WRITER] section like this:

[WRITER]
shutdownhooks[] = "/path/to/first/script"
shutdownhooks[] = "/path/to/second/script"

These scripts differ from post-write hooks, which run after MIK writes the import package for each object, in that they run after all packages have been generated.

Shutdown hook scripts can be written in any language. They are passed the path to the current MIK configuration file, so any configuration option defined in your .ini file is available within a shutdown hook script.

Every script registered in the shutdownhooks[] list is executed in the order it is listed. Unlike post-write hooks scripts, each shutdown hook script must complete running before the next one starts.

Shutdown hook scripts are run as foreground processes, unlike post-write hook scripts, which are run as background processes, but they do share some characteristics with post-write hook scripts:

  • The scripts cannot send any data back to the main MIK script.
  • If the scripts write output files or modify files created by other parts of MIK, the location of those files must be determined from data that is passed into the script as arguments or from within the .ini file.

Example shutdown scripts

MIK provides three shutdown scripts that are ready to use. Register them in your .ini file like this:

[WRITER]
shutdownhooks[] = "php extras/scripts/shutdownhooks/apply_xslt_with_saxon.php"
shutdownhooks[] = "php extras/scripts/shutdownhooks/delete_temp_files.php"
shutdownhooks[] = "php extras/scripts/shutdownhooks/create_structure_files.php"

The first, developed by Louisiana State University Library, runs a set of XSLT 2.0 cleanup tasks on MODS XML files. To use this script, you will need to have Saxon installed and will need to add the following section to your .ini file:

[XSLT]
working_dir   = 'hnoc-delcroix/hnoc-xslt'
step_thru     = TRUE
stylesheets[] = 'extras/lsu/xsl/titleNonSort.xsl'
stylesheets[] = 'extras/lsu/xsl/subjectSplit.xsl'
stylesheets[] = 'extras/lsu/xsl/dateCreatedSplit.xsl'
stylesheets[] = 'extras/lsu/xsl/locationMerge.xsl'
stylesheets[] = 'extras/lsu/xsl/blankNodes.xsl'
stylesheets[] = 'extras/lsu/xsl/OrderedTemplates.xsl'

This script also illustrates how to use Monolog for logging within shutdown scripts.

The second included shutdown script, delete_temp_files.php, simply deletes the contents of the MIK temporary directory. You may want to use this shutdown script while you are testing the generation of MODS XML files.

create_structure_files.php generates structure.xml for compound objects, for use with the Islandora Compound Batch module. If you use this shutdown hook script, you will not need to generate structure.xml files in a separate step as described in that module's README file - you can have MIK do it for you.

Clone this wiki locally