5.x-2.x branch
Set of utility functions for helping to run your Drupal install profile.
Install profile API project: http://drupal.org/project/install_profile_api
| Name | Description |
|---|---|
| install_include | Include all the needed include files for modules that have been enabled. |
| install_last_insert_id | Return the last insert id. This function is thread safe. |
- <?php
-
- /**
- * @file
- * Set of utility functions for helping to run your Drupal install profile.
- *
- * Install profile API project: http://drupal.org/project/install_profile_api
- */
-
- /**
- * Include all the needed include files for modules that have been enabled.
- *
- * This function must be called as early as possible in the install profile. It
- * is recommended to include these files within the hook_profile_final()
- * function such as this:
- *
- * @code
- * function [profile name]_profile_tasks() {
- * install_include([profile name]_profile_modules());
- *
- * // Additional profile tasks.
- *
- * }
- * @endcode
- */
- function install_include($modules) {
- // We intentionally avoid drupal_get_path() here, as it relies on the system
- // database table. Avoiding drupal_get_path() allows this function to be
- // called even when the database has not been initialized.
- $path = dirname(__FILE__);
-
- foreach ($modules as $module) {
- if (file_exists($path .'/contrib/'. $module .'.inc')) {
- require_once $path .'/contrib/'. $module .'.inc';
- }
- elseif (file_exists($path .'/core/'. $module .'.inc')) {
- require_once $path .'/core/'. $module .'.inc';
- }
- }
- }
-
- /**
- * Return the last insert id. This function is thread safe.
- *
- * Backported from D6 core's db_last_insert_id().
- *
- * @param $table
- * The name of the table you inserted into.
- * @param $field
- * The name of the autoincrement field.
- */
- function install_last_insert_id($table, $field) {
- switch ($GLOBALS['db_type']) {
- case 'mysql':
- case 'mysqli':
- return db_result(db_query('SELECT LAST_INSERT_ID()'));
-
- case 'pgsql':
- return db_result(db_query("SELECT CURRVAL('{". db_escape_table($table) ."}_". db_escape_table($field) ."_seq')"));
- }
- }
-
-