install.inc

  1. 7.x drupal-7.x/includes/install.inc
  2. 7.x drupal-7.x/includes/database/mysql/install.inc
  3. 7.x drupal-7.x/includes/database/pgsql/install.inc
  4. 7.x drupal-7.x/includes/database/sqlite/install.inc
  5. 6.x drupal-6.x/includes/install.inc

File

drupal-6.x/includes/install.inc
View source
  1. <?php
  2. define('SCHEMA_UNINSTALLED', -1);
  3. define('SCHEMA_INSTALLED', 0);
  4. define('REQUIREMENT_INFO', -1);
  5. define('REQUIREMENT_OK', 0);
  6. define('REQUIREMENT_WARNING', 1);
  7. define('REQUIREMENT_ERROR', 2);
  8. define('FILE_EXIST', 1);
  9. define('FILE_READABLE', 2);
  10. define('FILE_WRITABLE', 4);
  11. define('FILE_EXECUTABLE', 8);
  12. define('FILE_NOT_EXIST', 16);
  13. define('FILE_NOT_READABLE', 32);
  14. define('FILE_NOT_WRITABLE', 64);
  15. define('FILE_NOT_EXECUTABLE', 128);
  16. /**
  17. * Initialize the update system by loading all installed module's .install files.
  18. */
  19. function drupal_load_updates() {
  20. foreach (drupal_get_installed_schema_version(NULL, FALSE, TRUE) as $module => $schema_version) {
  21. if ($schema_version > -1) {
  22. module_load_install($module);
  23. }
  24. }
  25. }
  26. /**
  27. * Returns an array of available schema versions for a module.
  28. *
  29. * @param $module
  30. * A module name.
  31. * @return
  32. * If the module has updates, an array of available updates sorted by version.
  33. * Otherwise, FALSE.
  34. */
  35. function drupal_get_schema_versions($module) {
  36. $updates = array();
  37. $functions = get_defined_functions();
  38. foreach ($functions['user'] as $function) {
  39. if (strpos($function, $module .'_update_') === 0) {
  40. $version = substr($function, strlen($module .'_update_'));
  41. if (is_numeric($version)) {
  42. $updates[] = $version;
  43. }
  44. }
  45. }
  46. if (count($updates) == 0) {
  47. return FALSE;
  48. }
  49. sort($updates, SORT_NUMERIC);
  50. return $updates;
  51. }
  52. /**
  53. * Returns the currently installed schema version for a module.
  54. *
  55. * @param $module
  56. * A module name.
  57. * @param $reset
  58. * Set to TRUE after modifying the system table.
  59. * @param $array
  60. * Set to TRUE if you want to get information about all modules in the
  61. * system.
  62. * @return
  63. * The currently installed schema version.
  64. */
  65. function drupal_get_installed_schema_version($module, $reset = FALSE, $array = FALSE) {
  66. static $versions = array();
  67. if ($reset) {
  68. $versions = array();
  69. }
  70. if (!$versions) {
  71. $versions = array();
  72. $result = db_query("SELECT name, schema_version FROM {system} WHERE type = '%s'", 'module');
  73. while ($row = db_fetch_object($result)) {
  74. $versions[$row->name] = $row->schema_version;
  75. }
  76. }
  77. return $array ? $versions : $versions[$module];
  78. }
  79. /**
  80. * Update the installed version information for a module.
  81. *
  82. * @param $module
  83. * A module name.
  84. * @param $version
  85. * The new schema version.
  86. */
  87. function drupal_set_installed_schema_version($module, $version) {
  88. db_query("UPDATE {system} SET schema_version = %d WHERE name = '%s'", $version, $module);
  89. }
  90. /**
  91. * Loads the profile definition, extracting the profile's defined name.
  92. *
  93. * @return
  94. * The name defined in the profile's _profile_details() hook.
  95. */
  96. function drupal_install_profile_name() {
  97. global $profile;
  98. static $name = NULL;
  99. if (!isset($name)) {
  100. // Load profile details.
  101. $function = $profile .'_profile_details';
  102. if (function_exists($function)) {
  103. $details = $function();
  104. }
  105. $name = isset($details['name']) ? $details['name'] : 'Drupal';
  106. }
  107. return $name;
  108. }
  109. /**
  110. * Auto detect the base_url with PHP predefined variables.
  111. *
  112. * @param $file
  113. * The name of the file calling this function so we can strip it out of
  114. * the URI when generating the base_url.
  115. *
  116. * @return
  117. * The auto-detected $base_url that should be configured in settings.php
  118. */
  119. function drupal_detect_baseurl($file = 'install.php') {
  120. global $profile;
  121. $proto = $_SERVER['HTTPS'] ? 'https://' : 'http://';
  122. $host = $_SERVER['SERVER_NAME'];
  123. $port = ($_SERVER['SERVER_PORT'] == 80 ? '' : ':'. $_SERVER['SERVER_PORT']);
  124. $uri = preg_replace("/\?.*/", '', $_SERVER['REQUEST_URI']);
  125. $dir = str_replace("/$file", '', $uri);
  126. return "$proto$host$port$dir";
  127. }
  128. /**
  129. * Detect all databases supported by Drupal that are compiled into the current
  130. * PHP installation.
  131. *
  132. * @return
  133. * An array of database types compiled into PHP.
  134. */
  135. function drupal_detect_database_types() {
  136. $databases = array();
  137. foreach (array('mysql', 'mysqli', 'pgsql') as $type) {
  138. if (file_exists('./includes/install.'. $type .'.inc')) {
  139. include_once './includes/install.'. $type .'.inc';
  140. $function = $type .'_is_available';
  141. if ($function()) {
  142. $databases[$type] = $type;
  143. }
  144. }
  145. }
  146. return $databases;
  147. }
  148. /**
  149. * Read settings.php into a buffer line by line, changing values specified in
  150. * $settings array, then over-writing the old settings.php file.
  151. *
  152. * @param $settings
  153. * An array of settings that need to be updated.
  154. */
  155. function drupal_rewrite_settings($settings = array(), $prefix = '') {
  156. $default_settings = './sites/default/default.settings.php';
  157. $settings_file = './'. conf_path(FALSE, TRUE) .'/'. $prefix .'settings.php';
  158. // Build list of setting names and insert the values into the global namespace.
  159. $keys = array();
  160. foreach ($settings as $setting => $data) {
  161. $GLOBALS[$setting] = $data['value'];
  162. $keys[] = $setting;
  163. }
  164. $buffer = NULL;
  165. $first = TRUE;
  166. if ($fp = fopen($default_settings, 'r')) {
  167. // Step line by line through settings.php.
  168. while (!feof($fp)) {
  169. $line = fgets($fp);
  170. if ($first && substr($line, 0, 5) != '<?php') {
  171. $buffer = "<?php\n\n";
  172. }
  173. $first = FALSE;
  174. // Check for constants.
  175. if (substr($line, 0, 7) == 'define(') {
  176. preg_match('/define\(\s*[\'"]([A-Z_-]+)[\'"]\s*,(.*?)\);/', $line, $variable);
  177. if (in_array($variable[1], $keys)) {
  178. $setting = $settings[$variable[1]];
  179. $buffer .= str_replace($variable[2], " '". $setting['value'] ."'", $line);
  180. unset($settings[$variable[1]]);
  181. unset($settings[$variable[2]]);
  182. }
  183. else {
  184. $buffer .= $line;
  185. }
  186. }
  187. // Check for variables.
  188. elseif (substr($line, 0, 1) == '$') {
  189. preg_match('/\$([^ ]*) /', $line, $variable);
  190. if (in_array($variable[1], $keys)) {
  191. // Write new value to settings.php in the following format:
  192. // $'setting' = 'value'; // 'comment'
  193. $setting = $settings[$variable[1]];
  194. $buffer .= '$'. $variable[1] ." = '". $setting['value'] ."';". (!empty($setting['comment']) ? ' // '. $setting['comment'] ."\n" : "\n");
  195. unset($settings[$variable[1]]);
  196. }
  197. else {
  198. $buffer .= $line;
  199. }
  200. }
  201. else {
  202. $buffer .= $line;
  203. }
  204. }
  205. fclose($fp);
  206. // Add required settings that were missing from settings.php.
  207. foreach ($settings as $setting => $data) {
  208. if ($data['required']) {
  209. $buffer .= "\$$setting = '". $data['value'] ."';\n";
  210. }
  211. }
  212. $fp = fopen($settings_file, 'w');
  213. if ($fp && fwrite($fp, $buffer) === FALSE) {
  214. drupal_set_message(st('Failed to modify %settings, please verify the file permissions.', array('%settings' => $settings_file)), 'error');
  215. }
  216. }
  217. else {
  218. drupal_set_message(st('Failed to open %settings, please verify the file permissions.', array('%settings' => $default_settings)), 'error');
  219. }
  220. }
  221. /**
  222. * Get list of all .install files.
  223. *
  224. * @param $module_list
  225. * An array of modules to search for their .install files.
  226. */
  227. function drupal_get_install_files($module_list = array()) {
  228. $installs = array();
  229. foreach ($module_list as $module) {
  230. $installs = array_merge($installs, drupal_system_listing($module .'.install$', 'modules'));
  231. }
  232. return $installs;
  233. }
  234. /**
  235. * Verify a profile for installation.
  236. *
  237. * @param profile
  238. * Name of profile to verify.
  239. * @param locale
  240. * Name of locale used (if any).
  241. * @return
  242. * The list of modules to install.
  243. */
  244. function drupal_verify_profile($profile, $locale) {
  245. include_once './includes/file.inc';
  246. include_once './includes/common.inc';
  247. $profile_file = "./profiles/$profile/$profile.profile";
  248. if (!isset($profile) || !file_exists($profile_file)) {
  249. install_no_profile_error();
  250. }
  251. require_once($profile_file);
  252. // Get a list of modules required by this profile.
  253. $function = $profile .'_profile_modules';
  254. $module_list = array_merge(drupal_required_modules(), $function(), ($locale != 'en' && !empty($locale) ? array('locale') : array()));
  255. // Get a list of modules that exist in Drupal's assorted subdirectories.
  256. $present_modules = array();
  257. foreach (drupal_system_listing('\.module$', 'modules', 'name', 0) as $present_module) {
  258. $present_modules[] = $present_module->name;
  259. }
  260. // Verify that all of the profile's required modules are present.
  261. $missing_modules = array_diff($module_list, $present_modules);
  262. if (count($missing_modules)) {
  263. foreach ($missing_modules as $module) {
  264. drupal_set_message(st('The %module module is required but was not found. Please move it into the <em>modules</em> subdirectory.', array('%module' => $module)), 'error');
  265. }
  266. }
  267. else {
  268. return $module_list;
  269. }
  270. }
  271. /**
  272. * Calls the install function and updates the system table for a given list of
  273. * modules.
  274. *
  275. * @param module_list
  276. * The modules to install.
  277. */
  278. function drupal_install_modules($module_list = array()) {
  279. $files = module_rebuild_cache();
  280. $module_list = array_flip(array_values($module_list));
  281. do {
  282. $moved = FALSE;
  283. foreach ($module_list as $module => $weight) {
  284. $file = $files[$module];
  285. if (isset($file->info['dependencies']) && is_array($file->info['dependencies'])) {
  286. foreach ($file->info['dependencies'] as $dependency) {
  287. if (isset($module_list[$dependency]) && $module_list[$module] < $module_list[$dependency] +1) {
  288. $module_list[$module] = $module_list[$dependency] +1;
  289. $moved = TRUE;
  290. }
  291. }
  292. }
  293. }
  294. } while ($moved);
  295. asort($module_list);
  296. $module_list = array_keys($module_list);
  297. array_filter($module_list, '_drupal_install_module');
  298. module_enable($module_list);
  299. }
  300. /**
  301. * Callback to install an individual profile module.
  302. *
  303. * Used during installation to install modules one at a time and then
  304. * enable them, or to install a number of modules at one time
  305. * from admin/build/modules.
  306. */
  307. function _drupal_install_module($module) {
  308. if (drupal_get_installed_schema_version($module, TRUE) == SCHEMA_UNINSTALLED) {
  309. module_load_install($module);
  310. module_invoke($module, 'install');
  311. $versions = drupal_get_schema_versions($module);
  312. drupal_set_installed_schema_version($module, $versions ? max($versions) : SCHEMA_INSTALLED);
  313. return TRUE;
  314. }
  315. }
  316. /**
  317. * Callback to install the system module.
  318. *
  319. * Separated from the installation of other modules so core system
  320. * functions can be made available while other modules are installed.
  321. */
  322. function drupal_install_system() {
  323. $system_path = dirname(drupal_get_filename('module', 'system', NULL));
  324. require_once './'. $system_path .'/system.install';
  325. module_invoke('system', 'install');
  326. $system_versions = drupal_get_schema_versions('system');
  327. $system_version = $system_versions ? max($system_versions) : SCHEMA_INSTALLED;
  328. db_query("INSERT INTO {system} (filename, name, type, owner, status, throttle, bootstrap, schema_version) VALUES('%s', '%s', '%s', '%s', %d, %d, %d, %d)", $system_path .'/system.module', 'system', 'module', '', 1, 0, 0, $system_version);
  329. // Now that we've installed things properly, bootstrap the full Drupal environment
  330. drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
  331. module_rebuild_cache();
  332. }
  333. /**
  334. * Calls the uninstall function and updates the system table for a given module.
  335. *
  336. * @param $module
  337. * The module to uninstall.
  338. */
  339. function drupal_uninstall_module($module) {
  340. // First, retrieve all the module's menu paths from db.
  341. drupal_load('module', $module);
  342. $paths = module_invoke($module, 'menu');
  343. // Uninstall the module(s).
  344. module_load_install($module);
  345. module_invoke($module, 'uninstall');
  346. // Now remove the menu links for all paths declared by this module.
  347. if (!empty($paths)) {
  348. $paths = array_keys($paths);
  349. // Clean out the names of load functions.
  350. foreach ($paths as $index => $path) {
  351. $parts = explode('/', $path, MENU_MAX_PARTS);
  352. foreach ($parts as $k => $part) {
  353. if (preg_match('/^%[a-z_]*$/', $part)) {
  354. $parts[$k] = '%';
  355. }
  356. }
  357. $paths[$index] = implode('/', $parts);
  358. }
  359. $placeholders = implode(', ', array_fill(0, count($paths), "'%s'"));
  360. $result = db_query('SELECT * FROM {menu_links} WHERE router_path IN ('. $placeholders .') AND external = 0 ORDER BY depth DESC', $paths);
  361. // Remove all such items. Starting from those with the greatest depth will
  362. // minimize the amount of re-parenting done by menu_link_delete().
  363. while ($item = db_fetch_array($result)) {
  364. _menu_delete_item($item, TRUE);
  365. }
  366. }
  367. drupal_set_installed_schema_version($module, SCHEMA_UNINSTALLED);
  368. }
  369. /**
  370. * Verify the state of the specified file.
  371. *
  372. * @param $file
  373. * The file to check for.
  374. * @param $mask
  375. * An optional bitmask created from various FILE_* constants.
  376. * @param $type
  377. * The type of file. Can be file (default), dir, or link.
  378. * @return
  379. * TRUE on success or FALSE on failure. A message is set for the latter.
  380. */
  381. function drupal_verify_install_file($file, $mask = NULL, $type = 'file') {
  382. $return = TRUE;
  383. // Check for files that shouldn't be there.
  384. if (isset($mask) && ($mask & FILE_NOT_EXIST) && file_exists($file)) {
  385. return FALSE;
  386. }
  387. // Verify that the file is the type of file it is supposed to be.
  388. if (isset($type) && file_exists($file)) {
  389. $check = 'is_'. $type;
  390. if (!function_exists($check) || !$check($file)) {
  391. $return = FALSE;
  392. }
  393. }
  394. // Verify file permissions.
  395. if (isset($mask)) {
  396. $masks = array(FILE_EXIST, FILE_READABLE, FILE_WRITABLE, FILE_EXECUTABLE, FILE_NOT_READABLE, FILE_NOT_WRITABLE, FILE_NOT_EXECUTABLE);
  397. foreach ($masks as $current_mask) {
  398. if ($mask & $current_mask) {
  399. switch ($current_mask) {
  400. case FILE_EXIST:
  401. if (!file_exists($file)) {
  402. if ($type == 'dir') {
  403. drupal_install_mkdir($file, $mask);
  404. }
  405. if (!file_exists($file)) {
  406. $return = FALSE;
  407. }
  408. }
  409. break;
  410. case FILE_READABLE:
  411. if (!is_readable($file) && !drupal_install_fix_file($file, $mask)) {
  412. $return = FALSE;
  413. }
  414. break;
  415. case FILE_WRITABLE:
  416. if (!is_writable($file) && !drupal_install_fix_file($file, $mask)) {
  417. $return = FALSE;
  418. }
  419. break;
  420. case FILE_EXECUTABLE:
  421. if (!is_executable($file) && !drupal_install_fix_file($file, $mask)) {
  422. $return = FALSE;
  423. }
  424. break;
  425. case FILE_NOT_READABLE:
  426. if (is_readable($file) && !drupal_install_fix_file($file, $mask)) {
  427. $return = FALSE;
  428. }
  429. break;
  430. case FILE_NOT_WRITABLE:
  431. if (is_writable($file) && !drupal_install_fix_file($file, $mask)) {
  432. $return = FALSE;
  433. }
  434. break;
  435. case FILE_NOT_EXECUTABLE:
  436. if (is_executable($file) && !drupal_install_fix_file($file, $mask)) {
  437. $return = FALSE;
  438. }
  439. break;
  440. }
  441. }
  442. }
  443. }
  444. return $return;
  445. }
  446. /**
  447. * Create a directory with specified permissions.
  448. *
  449. * @param file
  450. * The name of the directory to create;
  451. * @param mask
  452. * The permissions of the directory to create.
  453. * @param $message
  454. * (optional) Whether to output messages. Defaults to TRUE.
  455. *
  456. * @return
  457. * TRUE/FALSE whether or not the directory was successfully created.
  458. */
  459. function drupal_install_mkdir($file, $mask, $message = TRUE) {
  460. $mod = 0;
  461. $masks = array(FILE_READABLE, FILE_WRITABLE, FILE_EXECUTABLE, FILE_NOT_READABLE, FILE_NOT_WRITABLE, FILE_NOT_EXECUTABLE);
  462. foreach ($masks as $m) {
  463. if ($mask & $m) {
  464. switch ($m) {
  465. case FILE_READABLE:
  466. $mod += 444;
  467. break;
  468. case FILE_WRITABLE:
  469. $mod += 222;
  470. break;
  471. case FILE_EXECUTABLE:
  472. $mod += 111;
  473. break;
  474. }
  475. }
  476. }
  477. if (@mkdir($file, intval("0$mod", 8))) {
  478. return TRUE;
  479. }
  480. else {
  481. return FALSE;
  482. }
  483. }
  484. /**
  485. * Attempt to fix file permissions.
  486. *
  487. * The general approach here is that, because we do not know the security
  488. * setup of the webserver, we apply our permission changes to all three
  489. * digits of the file permission (i.e. user, group and all).
  490. *
  491. * To ensure that the values behave as expected (and numbers don't carry
  492. * from one digit to the next) we do the calculation on the octal value
  493. * using bitwise operations. This lets us remove, for example, 0222 from
  494. * 0700 and get the correct value of 0500.
  495. *
  496. * @param $file
  497. * The name of the file with permissions to fix.
  498. * @param $mask
  499. * The desired permissions for the file.
  500. * @param $message
  501. * (optional) Whether to output messages. Defaults to TRUE.
  502. *
  503. * @return
  504. * TRUE/FALSE whether or not we were able to fix the file's permissions.
  505. */
  506. function drupal_install_fix_file($file, $mask, $message = TRUE) {
  507. $mod = fileperms($file) & 0777;
  508. $masks = array(FILE_READABLE, FILE_WRITABLE, FILE_EXECUTABLE, FILE_NOT_READABLE, FILE_NOT_WRITABLE, FILE_NOT_EXECUTABLE);
  509. // FILE_READABLE, FILE_WRITABLE, and FILE_EXECUTABLE permission strings
  510. // can theoretically be 0400, 0200, and 0100 respectively, but to be safe
  511. // we set all three access types in case the administrator intends to
  512. // change the owner of settings.php after installation.
  513. foreach ($masks as $m) {
  514. if ($mask & $m) {
  515. switch ($m) {
  516. case FILE_READABLE:
  517. if (!is_readable($file)) {
  518. $mod |= 0444;
  519. }
  520. break;
  521. case FILE_WRITABLE:
  522. if (!is_writable($file)) {
  523. $mod |= 0222;
  524. }
  525. break;
  526. case FILE_EXECUTABLE:
  527. if (!is_executable($file)) {
  528. $mod |= 0111;
  529. }
  530. break;
  531. case FILE_NOT_READABLE:
  532. if (is_readable($file)) {
  533. $mod &= ~0444;
  534. }
  535. break;
  536. case FILE_NOT_WRITABLE:
  537. if (is_writable($file)) {
  538. $mod &= ~0222;
  539. }
  540. break;
  541. case FILE_NOT_EXECUTABLE:
  542. if (is_executable($file)) {
  543. $mod &= ~0111;
  544. }
  545. break;
  546. }
  547. }
  548. }
  549. // chmod() will work if the web server is running as owner of the file.
  550. // If PHP safe_mode is enabled the currently executing script must also
  551. // have the same owner.
  552. if (@chmod($file, $mod)) {
  553. return TRUE;
  554. }
  555. else {
  556. return FALSE;
  557. }
  558. }
  559. /**
  560. * Send the user to a different installer page. This issues an on-site HTTP
  561. * redirect. Messages (and errors) are erased.
  562. *
  563. * @param $path
  564. * An installer path.
  565. */
  566. function install_goto($path) {
  567. global $base_url;
  568. header('Location: '. $base_url .'/'. $path);
  569. header('Cache-Control: no-cache'); // Not a permanent redirect.
  570. exit();
  571. }
  572. /**
  573. * Hardcoded function for doing the equivalent of t() during
  574. * the install process, when database, theme, and localization
  575. * system is possibly not yet available.
  576. */
  577. function st($string, $args = array()) {
  578. static $locale_strings = NULL;
  579. global $profile, $install_locale;
  580. if (!isset($locale_strings)) {
  581. $locale_strings = array();
  582. $filename = './profiles/'. $profile .'/translations/'. $install_locale .'.po';
  583. if (file_exists($filename)) {
  584. require_once './includes/locale.inc';
  585. $file = (object) array('filepath' => $filename);
  586. _locale_import_read_po('mem-store', $file);
  587. $locale_strings = _locale_import_one_string('mem-report');
  588. }
  589. }
  590. require_once './includes/theme.inc';
  591. // Transform arguments before inserting them
  592. foreach ($args as $key => $value) {
  593. switch ($key[0]) {
  594. // Escaped only
  595. case '@':
  596. $args[$key] = check_plain($value);
  597. break;
  598. // Escaped and placeholder
  599. case '%':
  600. default:
  601. $args[$key] = '<em>'. check_plain($value) .'</em>';
  602. break;
  603. // Pass-through
  604. case '!':
  605. }
  606. }
  607. return strtr((!empty($locale_strings[$string]) ? $locale_strings[$string] : $string), $args);
  608. }
  609. /**
  610. * Check a profile's requirements.
  611. *
  612. * @param profile
  613. * Name of profile to check.
  614. */
  615. function drupal_check_profile($profile) {
  616. include_once './includes/file.inc';
  617. $profile_file = "./profiles/$profile/$profile.profile";
  618. if (!isset($profile) || !file_exists($profile_file)) {
  619. install_no_profile_error();
  620. }
  621. require_once($profile_file);
  622. // Get a list of modules required by this profile.
  623. $function = $profile .'_profile_modules';
  624. $module_list = array_unique(array_merge(drupal_required_modules(), $function()));
  625. // Get a list of all .install files.
  626. $installs = drupal_get_install_files($module_list);
  627. // Collect requirement testing results
  628. $requirements = array();
  629. foreach ($installs as $install) {
  630. require_once $install->filename;
  631. if (module_hook($install->name, 'requirements')) {
  632. $requirements = array_merge($requirements, module_invoke($install->name, 'requirements', 'install'));
  633. }
  634. }
  635. return $requirements;
  636. }
  637. /**
  638. * Extract highest severity from requirements array.
  639. */
  640. function drupal_requirements_severity(&$requirements) {
  641. $severity = REQUIREMENT_OK;
  642. foreach ($requirements as $requirement) {
  643. if (isset($requirement['severity'])) {
  644. $severity = max($severity, $requirement['severity']);
  645. }
  646. }
  647. return $severity;
  648. }
  649. /**
  650. * Check a module's requirements.
  651. */
  652. function drupal_check_module($module) {
  653. // Include install file
  654. $install = drupal_get_install_files(array($module));
  655. if (isset($install[$module])) {
  656. require_once $install[$module]->filename;
  657. // Check requirements
  658. $requirements = module_invoke($module, 'requirements', 'install');
  659. if (is_array($requirements) && drupal_requirements_severity($requirements) == REQUIREMENT_ERROR) {
  660. // Print any error messages
  661. foreach ($requirements as $requirement) {
  662. if (isset($requirement['severity']) && $requirement['severity'] == REQUIREMENT_ERROR) {
  663. $message = $requirement['description'];
  664. if (isset($requirement['value']) && $requirement['value']) {
  665. $message .= ' ('. t('Currently using !item !version', array('!item' => $requirement['title'], '!version' => $requirement['value'])) .')';
  666. }
  667. drupal_set_message($message, 'error');
  668. }
  669. }
  670. return FALSE;
  671. }
  672. }
  673. return TRUE;
  674. }