install.inc 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339
  1. <?php
  2. /**
  3. * @file
  4. * API functions for installing modules and themes.
  5. */
  6. /**
  7. * Indicates that a module has not been installed yet.
  8. */
  9. define('SCHEMA_UNINSTALLED', -1);
  10. /**
  11. * Indicates that a module has been installed.
  12. */
  13. define('SCHEMA_INSTALLED', 0);
  14. /**
  15. * Requirement severity -- Informational message only.
  16. */
  17. define('REQUIREMENT_INFO', -1);
  18. /**
  19. * Requirement severity -- Requirement successfully met.
  20. */
  21. define('REQUIREMENT_OK', 0);
  22. /**
  23. * Requirement severity -- Warning condition; proceed but flag warning.
  24. */
  25. define('REQUIREMENT_WARNING', 1);
  26. /**
  27. * Requirement severity -- Error condition; abort installation.
  28. */
  29. define('REQUIREMENT_ERROR', 2);
  30. /**
  31. * File permission check -- File exists.
  32. */
  33. define('FILE_EXIST', 1);
  34. /**
  35. * File permission check -- File is readable.
  36. */
  37. define('FILE_READABLE', 2);
  38. /**
  39. * File permission check -- File is writable.
  40. */
  41. define('FILE_WRITABLE', 4);
  42. /**
  43. * File permission check -- File is executable.
  44. */
  45. define('FILE_EXECUTABLE', 8);
  46. /**
  47. * File permission check -- File does not exist.
  48. */
  49. define('FILE_NOT_EXIST', 16);
  50. /**
  51. * File permission check -- File is not readable.
  52. */
  53. define('FILE_NOT_READABLE', 32);
  54. /**
  55. * File permission check -- File is not writable.
  56. */
  57. define('FILE_NOT_WRITABLE', 64);
  58. /**
  59. * File permission check -- File is not executable.
  60. */
  61. define('FILE_NOT_EXECUTABLE', 128);
  62. /**
  63. * Loads .install files for installed modules to initialize the update system.
  64. */
  65. function drupal_load_updates() {
  66. foreach (drupal_get_installed_schema_version(NULL, FALSE, TRUE) as $module => $schema_version) {
  67. if ($schema_version > -1) {
  68. module_load_install($module);
  69. }
  70. }
  71. }
  72. /**
  73. * Returns an array of available schema versions for a module.
  74. *
  75. * @param $module
  76. * A module name.
  77. * @return
  78. * If the module has updates, an array of available updates sorted by version.
  79. * Otherwise, FALSE.
  80. */
  81. function drupal_get_schema_versions($module) {
  82. $updates = &drupal_static(__FUNCTION__, NULL);
  83. if (!isset($updates[$module])) {
  84. $updates = array();
  85. foreach (module_list() as $loaded_module) {
  86. $updates[$loaded_module] = array();
  87. }
  88. // Prepare regular expression to match all possible defined hook_update_N().
  89. $regexp = '/^(?P<module>.+)_update_(?P<version>\d+)$/';
  90. $functions = get_defined_functions();
  91. // Narrow this down to functions ending with an integer, since all
  92. // hook_update_N() functions end this way, and there are other
  93. // possible functions which match '_update_'. We use preg_grep() here
  94. // instead of foreaching through all defined functions, since the loop
  95. // through all PHP functions can take significant page execution time
  96. // and this function is called on every administrative page via
  97. // system_requirements().
  98. foreach (preg_grep('/_\d+$/', $functions['user']) as $function) {
  99. // If this function is a module update function, add it to the list of
  100. // module updates.
  101. if (preg_match($regexp, $function, $matches)) {
  102. $updates[$matches['module']][] = $matches['version'];
  103. }
  104. }
  105. // Ensure that updates are applied in numerical order.
  106. foreach ($updates as &$module_updates) {
  107. sort($module_updates, SORT_NUMERIC);
  108. }
  109. }
  110. return empty($updates[$module]) ? FALSE : $updates[$module];
  111. }
  112. /**
  113. * Returns the currently installed schema version for a module.
  114. *
  115. * @param $module
  116. * A module name.
  117. * @param $reset
  118. * Set to TRUE after modifying the system table.
  119. * @param $array
  120. * Set to TRUE if you want to get information about all modules in the
  121. * system.
  122. * @return
  123. * The currently installed schema version, or SCHEMA_UNINSTALLED if the
  124. * module is not installed.
  125. */
  126. function drupal_get_installed_schema_version($module, $reset = FALSE, $array = FALSE) {
  127. static $versions = array();
  128. if ($reset) {
  129. $versions = array();
  130. }
  131. if (!$versions) {
  132. $versions = array();
  133. $result = db_query("SELECT name, schema_version FROM {system} WHERE type = :type", array(':type' => 'module'));
  134. foreach ($result as $row) {
  135. $versions[$row->name] = $row->schema_version;
  136. }
  137. }
  138. if ($array) {
  139. return $versions;
  140. }
  141. else {
  142. return isset($versions[$module]) ? $versions[$module] : SCHEMA_UNINSTALLED;
  143. }
  144. }
  145. /**
  146. * Update the installed version information for a module.
  147. *
  148. * @param $module
  149. * A module name.
  150. * @param $version
  151. * The new schema version.
  152. */
  153. function drupal_set_installed_schema_version($module, $version) {
  154. db_update('system')
  155. ->fields(array('schema_version' => $version))
  156. ->condition('name', $module)
  157. ->execute();
  158. // Reset the static cache of module schema versions.
  159. drupal_get_installed_schema_version(NULL, TRUE);
  160. }
  161. /**
  162. * Loads the installation profile, extracting its defined distribution name.
  163. *
  164. * @return
  165. * The distribution name defined in the profile's .info file. Defaults to
  166. * "Drupal" if none is explicitly provided by the installation profile.
  167. *
  168. * @see install_profile_info()
  169. */
  170. function drupal_install_profile_distribution_name() {
  171. // During installation, the profile information is stored in the global
  172. // installation state (it might not be saved anywhere yet).
  173. if (drupal_installation_attempted()) {
  174. global $install_state;
  175. return $install_state['profile_info']['distribution_name'];
  176. }
  177. // At all other times, we load the profile via standard methods.
  178. else {
  179. $profile = drupal_get_profile();
  180. $info = system_get_info('module', $profile);
  181. return $info['distribution_name'];
  182. }
  183. }
  184. /**
  185. * Detects the base URL using the PHP $_SERVER variables.
  186. *
  187. * @param $file
  188. * The name of the file calling this function so we can strip it out of
  189. * the URI when generating the base_url.
  190. *
  191. * @return
  192. * The auto-detected $base_url that should be configured in settings.php
  193. */
  194. function drupal_detect_baseurl($file = 'install.php') {
  195. $proto = $_SERVER['HTTPS'] ? 'https://' : 'http://';
  196. $host = $_SERVER['SERVER_NAME'];
  197. $port = ($_SERVER['SERVER_PORT'] == 80 ? '' : ':' . $_SERVER['SERVER_PORT']);
  198. $uri = preg_replace("/\?.*/", '', $_SERVER['REQUEST_URI']);
  199. $dir = str_replace("/$file", '', $uri);
  200. return "$proto$host$port$dir";
  201. }
  202. /**
  203. * Detects all supported databases that are compiled into PHP.
  204. *
  205. * @return
  206. * An array of database types compiled into PHP.
  207. */
  208. function drupal_detect_database_types() {
  209. $databases = drupal_get_database_types();
  210. foreach ($databases as $driver => $installer) {
  211. $databases[$driver] = $installer->name();
  212. }
  213. return $databases;
  214. }
  215. /**
  216. * Returns all supported database installer objects that are compiled into PHP.
  217. *
  218. * @return
  219. * An array of database installer objects compiled into PHP.
  220. */
  221. function drupal_get_database_types() {
  222. $databases = array();
  223. // We define a driver as a directory in /includes/database that in turn
  224. // contains a database.inc file. That allows us to drop in additional drivers
  225. // without modifying the installer.
  226. // Because we have no registry yet, we need to also include the install.inc
  227. // file for the driver explicitly.
  228. require_once DRUPAL_ROOT . '/includes/database/database.inc';
  229. foreach (file_scan_directory(DRUPAL_ROOT . '/includes/database', '/^[a-z]*$/i', array('recurse' => FALSE)) as $file) {
  230. if (file_exists($file->uri . '/database.inc') && file_exists($file->uri . '/install.inc')) {
  231. $drivers[$file->filename] = $file->uri;
  232. }
  233. }
  234. foreach ($drivers as $driver => $file) {
  235. $installer = db_installer_object($driver);
  236. if ($installer->installable()) {
  237. $databases[$driver] = $installer;
  238. }
  239. }
  240. // Usability: unconditionally put the MySQL driver on top.
  241. if (isset($databases['mysql'])) {
  242. $mysql_database = $databases['mysql'];
  243. unset($databases['mysql']);
  244. $databases = array('mysql' => $mysql_database) + $databases;
  245. }
  246. return $databases;
  247. }
  248. /**
  249. * Database installer structure.
  250. *
  251. * Defines basic Drupal requirements for databases.
  252. */
  253. abstract class DatabaseTasks {
  254. /**
  255. * Structure that describes each task to run.
  256. *
  257. * @var array
  258. *
  259. * Each value of the tasks array is an associative array defining the function
  260. * to call (optional) and any arguments to be passed to the function.
  261. */
  262. protected $tasks = array(
  263. array(
  264. 'function' => 'checkEngineVersion',
  265. 'arguments' => array(),
  266. ),
  267. array(
  268. 'arguments' => array(
  269. 'CREATE TABLE {drupal_install_test} (id int NULL)',
  270. 'Drupal can use CREATE TABLE database commands.',
  271. 'Failed to <strong>CREATE</strong> a test table on your database server with the command %query. The server reports the following message: %error.<p>Are you sure the configured username has the necessary permissions to create tables in the database?</p>',
  272. TRUE,
  273. ),
  274. ),
  275. array(
  276. 'arguments' => array(
  277. 'INSERT INTO {drupal_install_test} (id) VALUES (1)',
  278. 'Drupal can use INSERT database commands.',
  279. 'Failed to <strong>INSERT</strong> a value into a test table on your database server. We tried inserting a value with the command %query and the server reported the following error: %error.',
  280. ),
  281. ),
  282. array(
  283. 'arguments' => array(
  284. 'UPDATE {drupal_install_test} SET id = 2',
  285. 'Drupal can use UPDATE database commands.',
  286. 'Failed to <strong>UPDATE</strong> a value in a test table on your database server. We tried updating a value with the command %query and the server reported the following error: %error.',
  287. ),
  288. ),
  289. array(
  290. 'arguments' => array(
  291. 'DELETE FROM {drupal_install_test}',
  292. 'Drupal can use DELETE database commands.',
  293. 'Failed to <strong>DELETE</strong> a value from a test table on your database server. We tried deleting a value with the command %query and the server reported the following error: %error.',
  294. ),
  295. ),
  296. array(
  297. 'arguments' => array(
  298. 'DROP TABLE {drupal_install_test}',
  299. 'Drupal can use DROP TABLE database commands.',
  300. 'Failed to <strong>DROP</strong> a test table from your database server. We tried dropping a table with the command %query and the server reported the following error %error.',
  301. ),
  302. ),
  303. );
  304. /**
  305. * Results from tasks.
  306. *
  307. * @var array
  308. */
  309. protected $results = array();
  310. /**
  311. * Ensure the PDO driver is supported by the version of PHP in use.
  312. */
  313. protected function hasPdoDriver() {
  314. return in_array($this->pdoDriver, PDO::getAvailableDrivers());
  315. }
  316. /**
  317. * Assert test as failed.
  318. */
  319. protected function fail($message) {
  320. $this->results[$message] = FALSE;
  321. }
  322. /**
  323. * Assert test as a pass.
  324. */
  325. protected function pass($message) {
  326. $this->results[$message] = TRUE;
  327. }
  328. /**
  329. * Check whether Drupal is installable on the database.
  330. */
  331. public function installable() {
  332. return $this->hasPdoDriver() && empty($this->error);
  333. }
  334. /**
  335. * Return the human-readable name of the driver.
  336. */
  337. abstract public function name();
  338. /**
  339. * Return the minimum required version of the engine.
  340. *
  341. * @return
  342. * A version string. If not NULL, it will be checked against the version
  343. * reported by the Database engine using version_compare().
  344. */
  345. public function minimumVersion() {
  346. return NULL;
  347. }
  348. /**
  349. * Run database tasks and tests to see if Drupal can run on the database.
  350. */
  351. public function runTasks() {
  352. // We need to establish a connection before we can run tests.
  353. if ($this->connect()) {
  354. foreach ($this->tasks as $task) {
  355. if (!isset($task['function'])) {
  356. $task['function'] = 'runTestQuery';
  357. }
  358. if (method_exists($this, $task['function'])) {
  359. // Returning false is fatal. No other tasks can run.
  360. if (FALSE === call_user_func_array(array($this, $task['function']), $task['arguments'])) {
  361. break;
  362. }
  363. }
  364. else {
  365. throw new DatabaseTaskException(st("Failed to run all tasks against the database server. The task %task wasn't found.", array('%task' => $task['function'])));
  366. }
  367. }
  368. }
  369. // Check for failed results and compile message
  370. $message = '';
  371. foreach ($this->results as $result => $success) {
  372. if (!$success) {
  373. $message .= '<p class="error">' . $result . '</p>';
  374. }
  375. }
  376. if (!empty($message)) {
  377. $message = 'Resolve all issues below to continue the installation. For help configuring your database server, see the <a href="http://drupal.org/getting-started/install">installation handbook</a>, or contact your hosting provider.' . $message;
  378. throw new DatabaseTaskException($message);
  379. }
  380. }
  381. /**
  382. * Check if we can connect to the database.
  383. */
  384. protected function connect() {
  385. try {
  386. // This doesn't actually test the connection.
  387. db_set_active();
  388. // Now actually do a check.
  389. Database::getConnection();
  390. $this->pass('Drupal can CONNECT to the database ok.');
  391. }
  392. catch (Exception $e) {
  393. $this->fail(st('Failed to connect to your database server. The server reports the following message: %error.<ul><li>Is the database server running?</li><li>Does the database exist, and have you entered the correct database name?</li><li>Have you entered the correct username and password?</li><li>Have you entered the correct database hostname?</li></ul>', array('%error' => $e->getMessage())));
  394. return FALSE;
  395. }
  396. return TRUE;
  397. }
  398. /**
  399. * Run SQL tests to ensure the database can execute commands with the current user.
  400. */
  401. protected function runTestQuery($query, $pass, $fail, $fatal = FALSE) {
  402. try {
  403. db_query($query);
  404. $this->pass(st($pass));
  405. }
  406. catch (Exception $e) {
  407. $this->fail(st($fail, array('%query' => $query, '%error' => $e->getMessage(), '%name' => $this->name())));
  408. return !$fatal;
  409. }
  410. }
  411. /**
  412. * Check the engine version.
  413. */
  414. protected function checkEngineVersion() {
  415. if ($this->minimumVersion() && version_compare(Database::getConnection()->version(), $this->minimumVersion(), '<')) {
  416. $this->fail(st("The database version %version is less than the minimum required version %minimum_version.", array('%version' => Database::getConnection()->version(), '%minimum_version' => $this->minimumVersion())));
  417. }
  418. }
  419. /**
  420. * Return driver specific configuration options.
  421. *
  422. * @param $database
  423. * An array of driver specific configuration options.
  424. *
  425. * @return
  426. * The options form array.
  427. */
  428. public function getFormOptions($database) {
  429. $form['database'] = array(
  430. '#type' => 'textfield',
  431. '#title' => st('Database name'),
  432. '#default_value' => empty($database['database']) ? '' : $database['database'],
  433. '#size' => 45,
  434. '#required' => TRUE,
  435. '#description' => st('The name of the database your @drupal data will be stored in. It must exist on your server before @drupal can be installed.', array('@drupal' => drupal_install_profile_distribution_name())),
  436. );
  437. $form['username'] = array(
  438. '#type' => 'textfield',
  439. '#title' => st('Database username'),
  440. '#default_value' => empty($database['username']) ? '' : $database['username'],
  441. '#required' => TRUE,
  442. '#size' => 45,
  443. );
  444. $form['password'] = array(
  445. '#type' => 'password',
  446. '#title' => st('Database password'),
  447. '#default_value' => empty($database['password']) ? '' : $database['password'],
  448. '#required' => FALSE,
  449. '#size' => 45,
  450. );
  451. $form['advanced_options'] = array(
  452. '#type' => 'fieldset',
  453. '#title' => st('Advanced options'),
  454. '#collapsible' => TRUE,
  455. '#collapsed' => TRUE,
  456. '#description' => st("These options are only necessary for some sites. If you're not sure what you should enter here, leave the default settings or check with your hosting provider."),
  457. '#weight' => 10,
  458. );
  459. $profile = drupal_get_profile();
  460. $db_prefix = ($profile == 'standard') ? 'drupal_' : $profile . '_';
  461. $form['advanced_options']['db_prefix'] = array(
  462. '#type' => 'textfield',
  463. '#title' => st('Table prefix'),
  464. '#default_value' => '',
  465. '#size' => 45,
  466. '#description' => st('If more than one application will be sharing this database, enter a table prefix such as %prefix for your @drupal site here.', array('@drupal' => drupal_install_profile_distribution_name(), '%prefix' => $db_prefix)),
  467. '#weight' => 10,
  468. );
  469. $form['advanced_options']['host'] = array(
  470. '#type' => 'textfield',
  471. '#title' => st('Database host'),
  472. '#default_value' => empty($database['host']) ? 'localhost' : $database['host'],
  473. '#size' => 45,
  474. // Hostnames can be 255 characters long.
  475. '#maxlength' => 255,
  476. '#required' => TRUE,
  477. '#description' => st('If your database is located on a different server, change this.'),
  478. );
  479. $form['advanced_options']['port'] = array(
  480. '#type' => 'textfield',
  481. '#title' => st('Database port'),
  482. '#default_value' => empty($database['port']) ? '' : $database['port'],
  483. '#size' => 45,
  484. // The maximum port number is 65536, 5 digits.
  485. '#maxlength' => 5,
  486. '#description' => st('If your database server is listening to a non-standard port, enter its number.'),
  487. );
  488. return $form;
  489. }
  490. /**
  491. * Validates driver specific configuration settings.
  492. *
  493. * Checks to ensure correct basic database settings and that a proper
  494. * connection to the database can be established.
  495. *
  496. * @param $database
  497. * An array of driver specific configuration options.
  498. *
  499. * @return
  500. * An array of driver configuration errors, keyed by form element name.
  501. */
  502. public function validateDatabaseSettings($database) {
  503. $errors = array();
  504. // Verify the table prefix.
  505. if (!empty($database['prefix']) && is_string($database['prefix']) && !preg_match('/^[A-Za-z0-9_.]+$/', $database['prefix'])) {
  506. $errors[$database['driver'] . '][advanced_options][db_prefix'] = st('The database table prefix you have entered, %prefix, is invalid. The table prefix can only contain alphanumeric characters, periods, or underscores.', array('%prefix' => $database['prefix']));
  507. }
  508. // Verify the database port.
  509. if (!empty($database['port']) && !is_numeric($database['port'])) {
  510. $errors[$database['driver'] . '][advanced_options][port'] = st('Database port must be a number.');
  511. }
  512. return $errors;
  513. }
  514. }
  515. /**
  516. * Exception thrown if the database installer fails.
  517. */
  518. class DatabaseTaskException extends Exception {
  519. }
  520. /**
  521. * Replaces values in settings.php with values in the submitted array.
  522. *
  523. * @param $settings
  524. * An array of settings that need to be updated.
  525. */
  526. function drupal_rewrite_settings($settings = array(), $prefix = '') {
  527. $default_settings = 'sites/default/default.settings.php';
  528. drupal_static_reset('conf_path');
  529. $settings_file = conf_path(FALSE) . '/' . $prefix . 'settings.php';
  530. // Build list of setting names and insert the values into the global namespace.
  531. $keys = array();
  532. foreach ($settings as $setting => $data) {
  533. $GLOBALS[$setting] = $data['value'];
  534. $keys[] = $setting;
  535. }
  536. $buffer = NULL;
  537. $first = TRUE;
  538. if ($fp = fopen(DRUPAL_ROOT . '/' . $default_settings, 'r')) {
  539. // Step line by line through settings.php.
  540. while (!feof($fp)) {
  541. $line = fgets($fp);
  542. if ($first && substr($line, 0, 5) != '<?php') {
  543. $buffer = "<?php\n\n";
  544. }
  545. $first = FALSE;
  546. // Check for constants.
  547. if (substr($line, 0, 7) == 'define(') {
  548. preg_match('/define\(\s*[\'"]([A-Z_-]+)[\'"]\s*,(.*?)\);/', $line, $variable);
  549. if (in_array($variable[1], $keys)) {
  550. $setting = $settings[$variable[1]];
  551. $buffer .= str_replace($variable[2], " '" . $setting['value'] . "'", $line);
  552. unset($settings[$variable[1]]);
  553. unset($settings[$variable[2]]);
  554. }
  555. else {
  556. $buffer .= $line;
  557. }
  558. }
  559. // Check for variables.
  560. elseif (substr($line, 0, 1) == '$') {
  561. preg_match('/\$([^ ]*) /', $line, $variable);
  562. if (in_array($variable[1], $keys)) {
  563. // Write new value to settings.php in the following format:
  564. // $'setting' = 'value'; // 'comment'
  565. $setting = $settings[$variable[1]];
  566. $buffer .= '$' . $variable[1] . " = " . var_export($setting['value'], TRUE) . ";" . (!empty($setting['comment']) ? ' // ' . $setting['comment'] . "\n" : "\n");
  567. unset($settings[$variable[1]]);
  568. }
  569. else {
  570. $buffer .= $line;
  571. }
  572. }
  573. else {
  574. $buffer .= $line;
  575. }
  576. }
  577. fclose($fp);
  578. // Add required settings that were missing from settings.php.
  579. foreach ($settings as $setting => $data) {
  580. if ($data['required']) {
  581. $buffer .= "\$$setting = " . var_export($data['value'], TRUE) . ";\n";
  582. }
  583. }
  584. $fp = fopen(DRUPAL_ROOT . '/' . $settings_file, 'w');
  585. if ($fp && fwrite($fp, $buffer) === FALSE) {
  586. throw new Exception(st('Failed to modify %settings. Verify the file permissions.', array('%settings' => $settings_file)));
  587. }
  588. else {
  589. // The existing settings.php file might have been included already. In
  590. // case an opcode cache is enabled, the rewritten contents of the file
  591. // will not be reflected in this process. Ensure to invalidate the file
  592. // in case an opcode cache is enabled.
  593. drupal_clear_opcode_cache(DRUPAL_ROOT . '/' . $settings_file);
  594. }
  595. }
  596. else {
  597. throw new Exception(st('Failed to open %settings. Verify the file permissions.', array('%settings' => $default_settings)));
  598. }
  599. }
  600. /**
  601. * Verifies an installation profile for installation.
  602. *
  603. * @param $install_state
  604. * An array of information about the current installation state.
  605. *
  606. * @return
  607. * The list of modules to install.
  608. */
  609. function drupal_verify_profile($install_state) {
  610. $profile = $install_state['parameters']['profile'];
  611. $locale = $install_state['parameters']['locale'];
  612. include_once DRUPAL_ROOT . '/includes/file.inc';
  613. include_once DRUPAL_ROOT . '/includes/common.inc';
  614. $profile_file = DRUPAL_ROOT . "/profiles/$profile/$profile.profile";
  615. if (!isset($profile) || !file_exists($profile_file)) {
  616. throw new Exception(install_no_profile_error());
  617. }
  618. $info = $install_state['profile_info'];
  619. // Get a list of modules that exist in Drupal's assorted subdirectories.
  620. $present_modules = array();
  621. foreach (drupal_system_listing('/^' . DRUPAL_PHP_FUNCTION_PATTERN . '\.module$/', 'modules', 'name', 0) as $present_module) {
  622. $present_modules[] = $present_module->name;
  623. }
  624. // The installation profile is also a module, which needs to be installed
  625. // after all the other dependencies have been installed.
  626. $present_modules[] = drupal_get_profile();
  627. // Verify that all of the profile's required modules are present.
  628. $missing_modules = array_diff($info['dependencies'], $present_modules);
  629. $requirements = array();
  630. if (count($missing_modules)) {
  631. $modules = array();
  632. foreach ($missing_modules as $module) {
  633. $modules[] = '<span class="admin-missing">' . drupal_ucfirst($module) . '</span>';
  634. }
  635. $requirements['required_modules'] = array(
  636. 'title' => st('Required modules'),
  637. 'value' => st('Required modules not found.'),
  638. 'severity' => REQUIREMENT_ERROR,
  639. 'description' => st('The following modules are required but were not found. Move them into the appropriate modules subdirectory, such as <em>sites/all/modules</em>. Missing modules: !modules', array('!modules' => implode(', ', $modules))),
  640. );
  641. }
  642. return $requirements;
  643. }
  644. /**
  645. * Installs the system module.
  646. *
  647. * Separated from the installation of other modules so core system
  648. * functions can be made available while other modules are installed.
  649. */
  650. function drupal_install_system() {
  651. $system_path = drupal_get_path('module', 'system');
  652. require_once DRUPAL_ROOT . '/' . $system_path . '/system.install';
  653. module_invoke('system', 'install');
  654. $system_versions = drupal_get_schema_versions('system');
  655. $system_version = $system_versions ? max($system_versions) : SCHEMA_INSTALLED;
  656. db_insert('system')
  657. ->fields(array('filename', 'name', 'type', 'owner', 'status', 'schema_version', 'bootstrap'))
  658. ->values(array(
  659. 'filename' => $system_path . '/system.module',
  660. 'name' => 'system',
  661. 'type' => 'module',
  662. 'owner' => '',
  663. 'status' => 1,
  664. 'schema_version' => $system_version,
  665. 'bootstrap' => 0,
  666. ))
  667. ->execute();
  668. system_rebuild_module_data();
  669. }
  670. /**
  671. * Uninstalls a given list of disabled modules.
  672. *
  673. * @param array $module_list
  674. * The modules to uninstall. It is the caller's responsibility to ensure that
  675. * all modules in this list have already been disabled before this function
  676. * is called.
  677. * @param bool $uninstall_dependents
  678. * (optional) If TRUE, the function will check that all modules which depend
  679. * on the passed-in module list either are already uninstalled or contained in
  680. * the list, and it will ensure that the modules are uninstalled in the
  681. * correct order. This incurs a significant performance cost, so use FALSE if
  682. * you know $module_list is already complete and in the correct order.
  683. * Defaults to TRUE.
  684. *
  685. * @return bool
  686. * Returns TRUE if the operation succeeds or FALSE if it aborts due to an
  687. * unsafe condition, namely, $uninstall_dependents is TRUE and a module in
  688. * $module_list has dependents which are not already uninstalled and not also
  689. * included in $module_list).
  690. *
  691. * @see module_disable()
  692. */
  693. function drupal_uninstall_modules($module_list = array(), $uninstall_dependents = TRUE) {
  694. if ($uninstall_dependents) {
  695. // Get all module data so we can find dependents and sort.
  696. $module_data = system_rebuild_module_data();
  697. // Create an associative array with weights as values.
  698. $module_list = array_flip(array_values($module_list));
  699. $profile = drupal_get_profile();
  700. while (list($module) = each($module_list)) {
  701. if (!isset($module_data[$module]) || drupal_get_installed_schema_version($module) == SCHEMA_UNINSTALLED) {
  702. // This module doesn't exist or is already uninstalled. Skip it.
  703. unset($module_list[$module]);
  704. continue;
  705. }
  706. $module_list[$module] = $module_data[$module]->sort;
  707. // If the module has any dependents which are not already uninstalled and
  708. // not included in the passed-in list, abort. It is not safe to uninstall
  709. // them automatically because uninstalling a module is a destructive
  710. // operation.
  711. foreach (array_keys($module_data[$module]->required_by) as $dependent) {
  712. if (!isset($module_list[$dependent]) && drupal_get_installed_schema_version($dependent) != SCHEMA_UNINSTALLED && $dependent != $profile) {
  713. return FALSE;
  714. }
  715. }
  716. }
  717. // Sort the module list by pre-calculated weights.
  718. asort($module_list);
  719. $module_list = array_keys($module_list);
  720. }
  721. foreach ($module_list as $module) {
  722. // Uninstall the module.
  723. module_load_install($module);
  724. module_invoke($module, 'uninstall');
  725. drupal_uninstall_schema($module);
  726. watchdog('system', '%module module uninstalled.', array('%module' => $module), WATCHDOG_INFO);
  727. drupal_set_installed_schema_version($module, SCHEMA_UNINSTALLED);
  728. }
  729. if (!empty($module_list)) {
  730. // Let other modules react.
  731. module_invoke_all('modules_uninstalled', $module_list);
  732. }
  733. return TRUE;
  734. }
  735. /**
  736. * Verifies the state of the specified file.
  737. *
  738. * @param $file
  739. * The file to check for.
  740. * @param $mask
  741. * An optional bitmask created from various FILE_* constants.
  742. * @param $type
  743. * The type of file. Can be file (default), dir, or link.
  744. *
  745. * @return
  746. * TRUE on success or FALSE on failure. A message is set for the latter.
  747. */
  748. function drupal_verify_install_file($file, $mask = NULL, $type = 'file') {
  749. $return = TRUE;
  750. // Check for files that shouldn't be there.
  751. if (isset($mask) && ($mask & FILE_NOT_EXIST) && file_exists($file)) {
  752. return FALSE;
  753. }
  754. // Verify that the file is the type of file it is supposed to be.
  755. if (isset($type) && file_exists($file)) {
  756. $check = 'is_' . $type;
  757. if (!function_exists($check) || !$check($file)) {
  758. $return = FALSE;
  759. }
  760. }
  761. // Verify file permissions.
  762. if (isset($mask)) {
  763. $masks = array(FILE_EXIST, FILE_READABLE, FILE_WRITABLE, FILE_EXECUTABLE, FILE_NOT_READABLE, FILE_NOT_WRITABLE, FILE_NOT_EXECUTABLE);
  764. foreach ($masks as $current_mask) {
  765. if ($mask & $current_mask) {
  766. switch ($current_mask) {
  767. case FILE_EXIST:
  768. if (!file_exists($file)) {
  769. if ($type == 'dir') {
  770. drupal_install_mkdir($file, $mask);
  771. }
  772. if (!file_exists($file)) {
  773. $return = FALSE;
  774. }
  775. }
  776. break;
  777. case FILE_READABLE:
  778. if (!is_readable($file) && !drupal_install_fix_file($file, $mask)) {
  779. $return = FALSE;
  780. }
  781. break;
  782. case FILE_WRITABLE:
  783. if (!is_writable($file) && !drupal_install_fix_file($file, $mask)) {
  784. $return = FALSE;
  785. }
  786. break;
  787. case FILE_EXECUTABLE:
  788. if (!is_executable($file) && !drupal_install_fix_file($file, $mask)) {
  789. $return = FALSE;
  790. }
  791. break;
  792. case FILE_NOT_READABLE:
  793. if (is_readable($file) && !drupal_install_fix_file($file, $mask)) {
  794. $return = FALSE;
  795. }
  796. break;
  797. case FILE_NOT_WRITABLE:
  798. if (is_writable($file) && !drupal_install_fix_file($file, $mask)) {
  799. $return = FALSE;
  800. }
  801. break;
  802. case FILE_NOT_EXECUTABLE:
  803. if (is_executable($file) && !drupal_install_fix_file($file, $mask)) {
  804. $return = FALSE;
  805. }
  806. break;
  807. }
  808. }
  809. }
  810. }
  811. return $return;
  812. }
  813. /**
  814. * Creates a directory with the specified permissions.
  815. *
  816. * @param $file
  817. * The name of the directory to create;
  818. * @param $mask
  819. * The permissions of the directory to create.
  820. * @param $message
  821. * (optional) Whether to output messages. Defaults to TRUE.
  822. *
  823. * @return
  824. * TRUE/FALSE whether or not the directory was successfully created.
  825. */
  826. function drupal_install_mkdir($file, $mask, $message = TRUE) {
  827. $mod = 0;
  828. $masks = array(FILE_READABLE, FILE_WRITABLE, FILE_EXECUTABLE, FILE_NOT_READABLE, FILE_NOT_WRITABLE, FILE_NOT_EXECUTABLE);
  829. foreach ($masks as $m) {
  830. if ($mask & $m) {
  831. switch ($m) {
  832. case FILE_READABLE:
  833. $mod |= 0444;
  834. break;
  835. case FILE_WRITABLE:
  836. $mod |= 0222;
  837. break;
  838. case FILE_EXECUTABLE:
  839. $mod |= 0111;
  840. break;
  841. }
  842. }
  843. }
  844. if (@drupal_mkdir($file, $mod)) {
  845. return TRUE;
  846. }
  847. else {
  848. return FALSE;
  849. }
  850. }
  851. /**
  852. * Attempts to fix file permissions.
  853. *
  854. * The general approach here is that, because we do not know the security
  855. * setup of the webserver, we apply our permission changes to all three
  856. * digits of the file permission (i.e. user, group and all).
  857. *
  858. * To ensure that the values behave as expected (and numbers don't carry
  859. * from one digit to the next) we do the calculation on the octal value
  860. * using bitwise operations. This lets us remove, for example, 0222 from
  861. * 0700 and get the correct value of 0500.
  862. *
  863. * @param $file
  864. * The name of the file with permissions to fix.
  865. * @param $mask
  866. * The desired permissions for the file.
  867. * @param $message
  868. * (optional) Whether to output messages. Defaults to TRUE.
  869. *
  870. * @return
  871. * TRUE/FALSE whether or not we were able to fix the file's permissions.
  872. */
  873. function drupal_install_fix_file($file, $mask, $message = TRUE) {
  874. // If $file does not exist, fileperms() issues a PHP warning.
  875. if (!file_exists($file)) {
  876. return FALSE;
  877. }
  878. $mod = fileperms($file) & 0777;
  879. $masks = array(FILE_READABLE, FILE_WRITABLE, FILE_EXECUTABLE, FILE_NOT_READABLE, FILE_NOT_WRITABLE, FILE_NOT_EXECUTABLE);
  880. // FILE_READABLE, FILE_WRITABLE, and FILE_EXECUTABLE permission strings
  881. // can theoretically be 0400, 0200, and 0100 respectively, but to be safe
  882. // we set all three access types in case the administrator intends to
  883. // change the owner of settings.php after installation.
  884. foreach ($masks as $m) {
  885. if ($mask & $m) {
  886. switch ($m) {
  887. case FILE_READABLE:
  888. if (!is_readable($file)) {
  889. $mod |= 0444;
  890. }
  891. break;
  892. case FILE_WRITABLE:
  893. if (!is_writable($file)) {
  894. $mod |= 0222;
  895. }
  896. break;
  897. case FILE_EXECUTABLE:
  898. if (!is_executable($file)) {
  899. $mod |= 0111;
  900. }
  901. break;
  902. case FILE_NOT_READABLE:
  903. if (is_readable($file)) {
  904. $mod &= ~0444;
  905. }
  906. break;
  907. case FILE_NOT_WRITABLE:
  908. if (is_writable($file)) {
  909. $mod &= ~0222;
  910. }
  911. break;
  912. case FILE_NOT_EXECUTABLE:
  913. if (is_executable($file)) {
  914. $mod &= ~0111;
  915. }
  916. break;
  917. }
  918. }
  919. }
  920. // chmod() will work if the web server is running as owner of the file.
  921. // If PHP safe_mode is enabled the currently executing script must also
  922. // have the same owner.
  923. if (@chmod($file, $mod)) {
  924. return TRUE;
  925. }
  926. else {
  927. return FALSE;
  928. }
  929. }
  930. /**
  931. * Sends the user to a different installer page.
  932. *
  933. * This issues an on-site HTTP redirect. Messages (and errors) are erased.
  934. *
  935. * @param $path
  936. * An installer path.
  937. */
  938. function install_goto($path) {
  939. global $base_url;
  940. include_once DRUPAL_ROOT . '/includes/common.inc';
  941. header('Location: ' . $base_url . '/' . $path);
  942. header('Cache-Control: no-cache'); // Not a permanent redirect.
  943. drupal_exit();
  944. }
  945. /**
  946. * Returns the URL of the current script, with modified query parameters.
  947. *
  948. * This function can be called by low-level scripts (such as install.php and
  949. * update.php) and returns the URL of the current script. Existing query
  950. * parameters are preserved by default, but new ones can optionally be merged
  951. * in.
  952. *
  953. * This function is used when the script must maintain certain query parameters
  954. * over multiple page requests in order to work correctly. In such cases (for
  955. * example, update.php, which requires the 'continue=1' parameter to remain in
  956. * the URL throughout the update process if there are any requirement warnings
  957. * that need to be bypassed), using this function to generate the URL for links
  958. * to the next steps of the script ensures that the links will work correctly.
  959. *
  960. * @param $query
  961. * (optional) An array of query parameters to merge in to the existing ones.
  962. *
  963. * @return
  964. * The URL of the current script, with query parameters modified by the
  965. * passed-in $query. The URL is not sanitized, so it still needs to be run
  966. * through check_url() if it will be used as an HTML attribute value.
  967. *
  968. * @see drupal_requirements_url()
  969. */
  970. function drupal_current_script_url($query = array()) {
  971. $uri = $_SERVER['SCRIPT_NAME'];
  972. $query = array_merge(drupal_get_query_parameters(), $query);
  973. if (!empty($query)) {
  974. $uri .= '?' . drupal_http_build_query($query);
  975. }
  976. return $uri;
  977. }
  978. /**
  979. * Returns a URL for proceeding to the next page after a requirements problem.
  980. *
  981. * This function can be called by low-level scripts (such as install.php and
  982. * update.php) and returns a URL that can be used to attempt to proceed to the
  983. * next step of the script.
  984. *
  985. * @param $severity
  986. * The severity of the requirements problem, as returned by
  987. * drupal_requirements_severity().
  988. *
  989. * @return
  990. * A URL for attempting to proceed to the next step of the script. The URL is
  991. * not sanitized, so it still needs to be run through check_url() if it will
  992. * be used as an HTML attribute value.
  993. *
  994. * @see drupal_current_script_url()
  995. */
  996. function drupal_requirements_url($severity) {
  997. $query = array();
  998. // If there are no errors, only warnings, append 'continue=1' to the URL so
  999. // the user can bypass this screen on the next page load.
  1000. if ($severity == REQUIREMENT_WARNING) {
  1001. $query['continue'] = 1;
  1002. }
  1003. return drupal_current_script_url($query);
  1004. }
  1005. /**
  1006. * Translates a string when some systems are not available.
  1007. *
  1008. * Used during the install process, when database, theme, and localization
  1009. * system is possibly not yet available.
  1010. *
  1011. * Use t() if your code will never run during the Drupal installation phase.
  1012. * Use st() if your code will only run during installation and never any other
  1013. * time. Use get_t() if your code could run in either circumstance.
  1014. *
  1015. * @see t()
  1016. * @see get_t()
  1017. * @ingroup sanitization
  1018. */
  1019. function st($string, array $args = array(), array $options = array()) {
  1020. static $locale_strings = NULL;
  1021. global $install_state;
  1022. if (empty($options['context'])) {
  1023. $options['context'] = '';
  1024. }
  1025. if (!isset($locale_strings)) {
  1026. $locale_strings = array();
  1027. if (isset($install_state['parameters']['profile']) && isset($install_state['parameters']['locale'])) {
  1028. // If the given locale was selected, there should be at least one .po file
  1029. // with its name ending in {$install_state['parameters']['locale']}.po
  1030. // This might or might not be the entire filename. It is also possible
  1031. // that multiple files end with the same extension, even if unlikely.
  1032. $po_files = file_scan_directory('./profiles/' . $install_state['parameters']['profile'] . '/translations', '/'. $install_state['parameters']['locale'] .'\.po$/', array('recurse' => FALSE));
  1033. if (count($po_files)) {
  1034. require_once DRUPAL_ROOT . '/includes/locale.inc';
  1035. foreach ($po_files as $po_file) {
  1036. _locale_import_read_po('mem-store', $po_file);
  1037. }
  1038. $locale_strings = _locale_import_one_string('mem-report');
  1039. }
  1040. }
  1041. }
  1042. // Transform arguments before inserting them
  1043. foreach ($args as $key => $value) {
  1044. switch ($key[0]) {
  1045. // Escaped only
  1046. case '@':
  1047. $args[$key] = check_plain($value);
  1048. break;
  1049. // Escaped and placeholder
  1050. case '%':
  1051. default:
  1052. $args[$key] = '<em>' . check_plain($value) . '</em>';
  1053. break;
  1054. // Pass-through
  1055. case '!':
  1056. }
  1057. }
  1058. return strtr((!empty($locale_strings[$options['context']][$string]) ? $locale_strings[$options['context']][$string] : $string), $args);
  1059. }
  1060. /**
  1061. * Checks an installation profile's requirements.
  1062. *
  1063. * @param $profile
  1064. * Name of installation profile to check.
  1065. * @return
  1066. * Array of the installation profile's requirements.
  1067. */
  1068. function drupal_check_profile($profile) {
  1069. include_once DRUPAL_ROOT . '/includes/file.inc';
  1070. $profile_file = DRUPAL_ROOT . "/profiles/$profile/$profile.profile";
  1071. if (!isset($profile) || !file_exists($profile_file)) {
  1072. throw new Exception(install_no_profile_error());
  1073. }
  1074. $info = install_profile_info($profile);
  1075. // Collect requirement testing results.
  1076. $requirements = array();
  1077. foreach ($info['dependencies'] as $module) {
  1078. module_load_install($module);
  1079. $function = $module . '_requirements';
  1080. if (function_exists($function)) {
  1081. $requirements = array_merge($requirements, $function('install'));
  1082. }
  1083. }
  1084. return $requirements;
  1085. }
  1086. /**
  1087. * Extracts the highest severity from the requirements array.
  1088. *
  1089. * @param $requirements
  1090. * An array of requirements, in the same format as is returned by
  1091. * hook_requirements().
  1092. *
  1093. * @return
  1094. * The highest severity in the array.
  1095. */
  1096. function drupal_requirements_severity(&$requirements) {
  1097. $severity = REQUIREMENT_OK;
  1098. foreach ($requirements as $requirement) {
  1099. if (isset($requirement['severity'])) {
  1100. $severity = max($severity, $requirement['severity']);
  1101. }
  1102. }
  1103. return $severity;
  1104. }
  1105. /**
  1106. * Checks a module's requirements.
  1107. *
  1108. * @param $module
  1109. * Machine name of module to check.
  1110. *
  1111. * @return
  1112. * TRUE or FALSE, depending on whether the requirements are met.
  1113. */
  1114. function drupal_check_module($module) {
  1115. module_load_install($module);
  1116. if (module_hook($module, 'requirements')) {
  1117. // Check requirements
  1118. $requirements = module_invoke($module, 'requirements', 'install');
  1119. if (is_array($requirements) && drupal_requirements_severity($requirements) == REQUIREMENT_ERROR) {
  1120. // Print any error messages
  1121. foreach ($requirements as $requirement) {
  1122. if (isset($requirement['severity']) && $requirement['severity'] == REQUIREMENT_ERROR) {
  1123. $message = $requirement['description'];
  1124. if (isset($requirement['value']) && $requirement['value']) {
  1125. $message .= ' (' . t('Currently using !item !version', array('!item' => $requirement['title'], '!version' => $requirement['value'])) . ')';
  1126. }
  1127. drupal_set_message($message, 'error');
  1128. }
  1129. }
  1130. return FALSE;
  1131. }
  1132. }
  1133. return TRUE;
  1134. }
  1135. /**
  1136. * Retrieves information about an installation profile from its .info file.
  1137. *
  1138. * The information stored in a profile .info file is similar to that stored in
  1139. * a normal Drupal module .info file. For example:
  1140. * - name: The real name of the installation profile for display purposes.
  1141. * - description: A brief description of the profile.
  1142. * - dependencies: An array of shortnames of other modules that this install
  1143. * profile requires.
  1144. *
  1145. * Additional, less commonly-used information that can appear in a profile.info
  1146. * file but not in a normal Drupal module .info file includes:
  1147. * - distribution_name: The name of the Drupal distribution that is being
  1148. * installed, to be shown throughout the installation process. Defaults to
  1149. * 'Drupal'.
  1150. * - exclusive: If the install profile is intended to be the only eligible
  1151. * choice in a distribution, setting exclusive = TRUE will auto-select it
  1152. * during installation, and the install profile selection screen will be
  1153. * skipped. If more than one profile is found where exclusive = TRUE then
  1154. * this property will have no effect and the profile selection screen will
  1155. * be shown as normal with all available profiles shown.
  1156. *
  1157. * Note that this function does an expensive file system scan to get info file
  1158. * information for dependencies. If you only need information from the info
  1159. * file itself, use system_get_info().
  1160. *
  1161. * Example of .info file:
  1162. * @code
  1163. * name = Minimal
  1164. * description = Start fresh, with only a few modules enabled.
  1165. * dependencies[] = block
  1166. * dependencies[] = dblog
  1167. * @endcode
  1168. *
  1169. * @param $profile
  1170. * Name of profile.
  1171. * @param $locale
  1172. * Name of locale used (if any).
  1173. *
  1174. * @return
  1175. * The info array.
  1176. */
  1177. function install_profile_info($profile, $locale = 'en') {
  1178. $cache = &drupal_static(__FUNCTION__, array());
  1179. if (!isset($cache[$profile])) {
  1180. // Set defaults for module info.
  1181. $defaults = array(
  1182. 'dependencies' => array(),
  1183. 'description' => '',
  1184. 'distribution_name' => 'Drupal',
  1185. 'version' => NULL,
  1186. 'hidden' => FALSE,
  1187. 'php' => DRUPAL_MINIMUM_PHP,
  1188. );
  1189. $info = drupal_parse_info_file("profiles/$profile/$profile.info") + $defaults;
  1190. $info['dependencies'] = array_unique(array_merge(
  1191. drupal_required_modules(),
  1192. $info['dependencies'],
  1193. ($locale != 'en' && !empty($locale) ? array('locale') : array()))
  1194. );
  1195. // drupal_required_modules() includes the current profile as a dependency.
  1196. // Since a module can't depend on itself we remove that element of the array.
  1197. array_shift($info['dependencies']);
  1198. $cache[$profile] = $info;
  1199. }
  1200. return $cache[$profile];
  1201. }
  1202. /**
  1203. * Ensures the environment for a Drupal database on a predefined connection.
  1204. *
  1205. * This will run tasks that check that Drupal can perform all of the functions
  1206. * on a database, that Drupal needs. Tasks include simple checks like CREATE
  1207. * TABLE to database specific functions like stored procedures and client
  1208. * encoding.
  1209. */
  1210. function db_run_tasks($driver) {
  1211. db_installer_object($driver)->runTasks();
  1212. return TRUE;
  1213. }
  1214. /**
  1215. * Returns a database installer object.
  1216. *
  1217. * @param $driver
  1218. * The name of the driver.
  1219. */
  1220. function db_installer_object($driver) {
  1221. Database::loadDriverFile($driver, array('install.inc'));
  1222. $task_class = 'DatabaseTasks_' . $driver;
  1223. return new $task_class();
  1224. }