install_profile_api.module

Tracking 5.x-2.x branch
  1. drupal
    1. 5 contributions/install_profile_api/install_profile_api.module
    2. 6 contributions/install_profile_api/install_profile_api.module

Set of utility functions for helping to run your Drupal install profile.

Install profile API project: http://drupal.org/project/install_profile_api

Functions & methods

NameDescription
install_includeInclude all the needed include files for modules that have been enabled.
install_last_insert_idReturn the last insert id. This function is thread safe.

File

View source
  1. <?php
  2. /**
  3. * @file
  4. * Set of utility functions for helping to run your Drupal install profile.
  5. *
  6. * Install profile API project: http://drupal.org/project/install_profile_api
  7. */
  8. /**
  9. * Include all the needed include files for modules that have been enabled.
  10. *
  11. * This function must be called as early as possible in the install profile. It
  12. * is recommended to include these files within the hook_profile_final()
  13. * function such as this:
  14. *
  15. * @code
  16. * function [profile name]_profile_tasks() {
  17. * install_include([profile name]_profile_modules());
  18. *
  19. * // Additional profile tasks.
  20. *
  21. * }
  22. * @endcode
  23. */
  24. function install_include($modules) {
  25. // We intentionally avoid drupal_get_path() here, as it relies on the system
  26. // database table. Avoiding drupal_get_path() allows this function to be
  27. // called even when the database has not been initialized.
  28. $path = dirname(__FILE__);
  29. foreach ($modules as $module) {
  30. if (file_exists($path .'/contrib/'. $module .'.inc')) {
  31. require_once $path .'/contrib/'. $module .'.inc';
  32. }
  33. elseif (file_exists($path .'/core/'. $module .'.inc')) {
  34. require_once $path .'/core/'. $module .'.inc';
  35. }
  36. }
  37. }
  38. /**
  39. * Return the last insert id. This function is thread safe.
  40. *
  41. * Backported from D6 core's db_last_insert_id().
  42. *
  43. * @param $table
  44. * The name of the table you inserted into.
  45. * @param $field
  46. * The name of the autoincrement field.
  47. */
  48. function install_last_insert_id($table, $field) {
  49. switch ($GLOBALS['db_type']) {
  50. case 'mysql':
  51. case 'mysqli':
  52. return db_result(db_query('SELECT LAST_INSERT_ID()'));
  53. case 'pgsql':
  54. return db_result(db_query("SELECT CURRVAL('{". db_escape_table($table) ."}_". db_escape_table($field) ."_seq')"));
  55. }
  56. }