2

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.

2
  • You can try to run drupal_cron_run(); before the hook you want to call. Commented Nov 12, 2014 at 14:57
  • sounds like you need hook_enable Commented Jan 3, 2017 at 23:43

5 Answers 5

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(); } 
5
  • Thanks for your message, but that's not what I am looking for exactly. I updated the question. Commented Jun 17, 2014 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'); Commented Jun 17, 2014 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. Commented Jun 17, 2014 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/… Commented Jun 17, 2014 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. Commented Jun 17, 2014 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

1
  • Thanks for your message, but that's not what I am looking for exactly. I updated the question. Commented Jun 17, 2014 at 8:42
0

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.