0

I am developing an install script for a custom module, but I can't figure out how to trigger the script once it has already been run once. I know that install scripts are by design intended to only be run once, but what do you do when you need to debug an install script?

I'm running Xdebug so I would prefer if I could trigger the script from the browser UI somehow as opposed to Drush, which will not pause for the debugger.

3

You can do different things depending on your use case.

  1. If you really need to test your install script again you need to uninstall your module rather than just disabling it. You can do that by running drush dis mymodule && drush pm-uninstall mymodule followed by drush en mymodule again. As @Clive mentions if you have the Devel module installed you can also drush dre mymodule (Devel reinstall). Or disable the module at http://example.com/admin/modules and then uninstall the module at http://example.com/admin/modules/uninstall . You should probably have a hook_uninstall function set up to clean up after your install. For example you may need to drop some tables or delete temporary files. See the link below for hook_uninstall.
  2. If you have an update to already the installed module you should use hook_update_n instead of hook_install. Then you can visit http://example.com/update.php or run drush updb Link below.
  3. Lastly, you can probably change the database table that records the installation. I don't recall exactly how to do that but I don't think its preferable.

Here are the docs on writing uninstall hooks. https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_uninstall/7

Here are the docs on writing update hooks. Basically the way I do it is make sure that hook_install runs the update functions after it runs itself. https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_update_N/7

eg:

/* 
 * Implements hook_install
 */
function mymodule_install() {
// do some things

// then run the updates
    mymodule_update_7000();
    mymodule_update_7001();
}

/* 
 * Implements hook_install
 */
function mymodule_update_7000() {
// do some other things
}

/* 
 * Implements hook_install
 */
function mymodule_update_7001() {
// do some more things
}
2
  • Thanks a lot! pm-uninstall was what I was looking for :) – funkylaundry Aug 8 '15 at 0:33
  • 2
    @funkylaundry If you have the devel module installed you can reinstall all in one step with drush dre module_name – Clive Aug 8 '15 at 1:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.