Skip to content
Mark Jordan edited this page Mar 24, 2017 · 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 as a background process, in the order it is listed. Unlike post-write hooks scripts, each shutdown hook script must complete running before the next one starts.

Because they run as background processes, they continue to run after MIK has shut down. Some other implications of them running as background processes include:

  • 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 two 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"

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.

Clone this wiki locally