1

I'm stuck writing an installation profile.
There are certain things that I want to do only after the installation is completed.

I analyzed top ten installation profiles and checked the documentation, but I couldn't find it. I might be missing something small though.

Is there such hook? If not, how can I execute something at the end of the installation?

Thanks!


UPDATE

I know for hook_install and hook_install_tasks, and they are not exactly what am I looking for.

They both are called during the installation. I want to execute code after the installation has been completed.

For example, setup Backup & Migrate schedules. If I do this using hook_install_tasks(), the cron run at the end of installation does not seem to work properly/in full, and I get errors when backup_migrate tries to write to private directory. Private directory is set up properly and if I just re-run the cron afterwards, it works as it should.

  • You can try to run drupal_cron_run(); before the hook you want to call. – tvl Nov 12 '14 at 14:57
  • sounds like you need hook_enable – Felix Eve Jan 3 '17 at 23:43
2

Move your post-installation hooks to a module/part-of-your-profile (that can implement any hook and move things around even after the system modules is installed).

That way you can overcome problems like custom block's BLOCK_VISIBILITY_LISTED not working on profile installation hook_install()?, and have a solid last installation step, that makes all your final configs.

bonus * why not even choose or make configs in that installation step's form_alter() ;)

1

Here's an example of a feature revert done at the end of the installation.

/**
 * Implements hook_install_tasks().
 */
function MYPROFILE_install_tasks($install_state){
  $tasks = array(
    'MYPROFILE_setup_cleanup' => array(
      'display_name' => st('Cleanup'),
      'display' => FALSE,
      'type' => 'normal'
    ),
  );

  return $tasks;
}

/**
 * Cleanup install task.
 */
function MYPROFILE_setup_cleanup() {
  features_revert();
}
  • Thanks for your message, but that's not what I am looking for exactly. I updated the question. – Aram Boyajyan Jun 17 '14 at 8:43
  • @Ivanhoe123 could you try setting the private files directory in a feature or in a install task? variable_set('file_private_path', 'mypath'); – Pontus Nilsson Jun 17 '14 at 8:47
  • I'm setting it up in an install task actually; I create the folder, set chmod and add .htaccess. However, I think that's not the issue. – Aram Boyajyan Jun 17 '14 at 8:51
  • Do you also setup file_default_scheme "Default download method"? Or maybe just execute this whole form :) api.drupal.org/api/drupal/modules%21system%21system.admin.inc/… – Pontus Nilsson Jun 17 '14 at 9:10
  • Thanks again. I set everything manually, and I don't setup the file default scheme. I pasted the code I use here. I think it's not the main issue simply because private file system works properly after the installation. – Aram Boyajyan Jun 17 '14 at 9:38
1

Module Site pre-install and post-install hooks might just do what you need. It's installed as a library and registered with your installation profile. The module provides two hooks: hook_site_pre_install() and hook_site_post_install(). They are run before the installation tasks and then after Finished task.

From module page:

Sample Use Cases

Here are some scenarios where you'd want to use this approach:

You need to configure certain site settings before installing a module that requires those settings (hook_site_pre_install()). You need to modify user passwords, tweak menu paths, or adjust settings (such as the site name) that would otherwise be bashed if set in hook_install() in the installation profile (hook_site_post_install()).

I usually use it to e.g. enable Shield module in certain environments at the very end of the installation.

0

It's hooks hook_install and hook_install_tasks

  • Thanks for your message, but that's not what I am looking for exactly. I updated the question. – Aram Boyajyan Jun 17 '14 at 8:42
0

You can add tasks to be run after the "Finished" task by implementing hook_install_tasks_alter().

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.