install.inc 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340
  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 string[] $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. * @see module_enable()
  693. */
  694. function drupal_uninstall_modules($module_list = array(), $uninstall_dependents = TRUE) {
  695. if ($uninstall_dependents) {
  696. // Get all module data so we can find dependents and sort.
  697. $module_data = system_rebuild_module_data();
  698. // Create an associative array with weights as values.
  699. $module_list = array_flip(array_values($module_list));
  700. $profile = drupal_get_profile();
  701. while (list($module) = each($module_list)) {
  702. if (!isset($module_data[$module]) || drupal_get_installed_schema_version($module) == SCHEMA_UNINSTALLED) {
  703. // This module doesn't exist or is already uninstalled. Skip it.
  704. unset($module_list[$module]);
  705. continue;
  706. }
  707. $module_list[$module] = $module_data[$module]->sort;
  708. // If the module has any dependents which are not already uninstalled and
  709. // not included in the passed-in list, abort. It is not safe to uninstall
  710. // them automatically because uninstalling a module is a destructive
  711. // operation.
  712. foreach (array_keys($module_data[$module]->required_by) as $dependent) {
  713. if (!isset($module_list[$dependent]) && drupal_get_installed_schema_version($dependent) != SCHEMA_UNINSTALLED && $dependent != $profile) {
  714. return FALSE;
  715. }
  716. }
  717. }
  718. // Sort the module list by pre-calculated weights.
  719. asort($module_list);
  720. $module_list = array_keys($module_list);
  721. }
  722. foreach ($module_list as $module) {
  723. // Uninstall the module.
  724. module_load_install($module);
  725. module_invoke($module, 'uninstall');
  726. drupal_uninstall_schema($module);
  727. watchdog('system', '%module module uninstalled.', array('%module' => $module), WATCHDOG_INFO);
  728. drupal_set_installed_schema_version($module, SCHEMA_UNINSTALLED);
  729. }
  730. if (!empty($module_list)) {
  731. // Let other modules react.
  732. module_invoke_all('modules_uninstalled', $module_list);
  733. }
  734. return TRUE;
  735. }
  736. /**
  737. * Verifies the state of the specified file.
  738. *
  739. * @param $file
  740. * The file to check for.
  741. * @param $mask
  742. * An optional bitmask created from various FILE_* constants.
  743. * @param $type
  744. * The type of file. Can be file (default), dir, or link.
  745. *
  746. * @return
  747. * TRUE on success or FALSE on failure. A message is set for the latter.
  748. */
  749. function drupal_verify_install_file($file, $mask = NULL, $type = 'file') {
  750. $return = TRUE;
  751. // Check for files that shouldn't be there.
  752. if (isset($mask) && ($mask & FILE_NOT_EXIST) && file_exists($file)) {
  753. return FALSE;
  754. }
  755. // Verify that the file is the type of file it is supposed to be.
  756. if (isset($type) && file_exists($file)) {
  757. $check = 'is_' . $type;
  758. if (!function_exists($check) || !$check($file)) {
  759. $return = FALSE;
  760. }
  761. }
  762. // Verify file permissions.
  763. if (isset($mask)) {
  764. $masks = array(FILE_EXIST, FILE_READABLE, FILE_WRITABLE, FILE_EXECUTABLE, FILE_NOT_READABLE, FILE_NOT_WRITABLE, FILE_NOT_EXECUTABLE);
  765. foreach ($masks as $current_mask) {
  766. if ($mask & $current_mask) {
  767. switch ($current_mask) {
  768. case FILE_EXIST:
  769. if (!file_exists($file)) {
  770. if ($type == 'dir') {
  771. drupal_install_mkdir($file, $mask);
  772. }
  773. if (!file_exists($file)) {
  774. $return = FALSE;
  775. }
  776. }
  777. break;
  778. case FILE_READABLE:
  779. if (!is_readable($file) && !drupal_install_fix_file($file, $mask)) {
  780. $return = FALSE;
  781. }
  782. break;
  783. case FILE_WRITABLE:
  784. if (!is_writable($file) && !drupal_install_fix_file($file, $mask)) {
  785. $return = FALSE;
  786. }
  787. break;
  788. case FILE_EXECUTABLE:
  789. if (!is_executable($file) && !drupal_install_fix_file($file, $mask)) {
  790. $return = FALSE;
  791. }
  792. break;
  793. case FILE_NOT_READABLE:
  794. if (is_readable($file) && !drupal_install_fix_file($file, $mask)) {
  795. $return = FALSE;
  796. }
  797. break;
  798. case FILE_NOT_WRITABLE:
  799. if (is_writable($file) && !drupal_install_fix_file($file, $mask)) {
  800. $return = FALSE;
  801. }
  802. break;
  803. case FILE_NOT_EXECUTABLE:
  804. if (is_executable($file) && !drupal_install_fix_file($file, $mask)) {
  805. $return = FALSE;
  806. }
  807. break;
  808. }
  809. }
  810. }
  811. }
  812. return $return;
  813. }
  814. /**
  815. * Creates a directory with the specified permissions.
  816. *
  817. * @param $file
  818. * The name of the directory to create;
  819. * @param $mask
  820. * The permissions of the directory to create.
  821. * @param $message
  822. * (optional) Whether to output messages. Defaults to TRUE.
  823. *
  824. * @return
  825. * TRUE/FALSE whether or not the directory was successfully created.
  826. */
  827. function drupal_install_mkdir($file, $mask, $message = TRUE) {
  828. $mod = 0;
  829. $masks = array(FILE_READABLE, FILE_WRITABLE, FILE_EXECUTABLE, FILE_NOT_READABLE, FILE_NOT_WRITABLE, FILE_NOT_EXECUTABLE);
  830. foreach ($masks as $m) {
  831. if ($mask & $m) {
  832. switch ($m) {
  833. case FILE_READABLE:
  834. $mod |= 0444;
  835. break;
  836. case FILE_WRITABLE:
  837. $mod |= 0222;
  838. break;
  839. case FILE_EXECUTABLE:
  840. $mod |= 0111;
  841. break;
  842. }
  843. }
  844. }
  845. if (@drupal_mkdir($file, $mod)) {
  846. return TRUE;
  847. }
  848. else {
  849. return FALSE;
  850. }
  851. }
  852. /**
  853. * Attempts to fix file permissions.
  854. *
  855. * The general approach here is that, because we do not know the security
  856. * setup of the webserver, we apply our permission changes to all three
  857. * digits of the file permission (i.e. user, group and all).
  858. *
  859. * To ensure that the values behave as expected (and numbers don't carry
  860. * from one digit to the next) we do the calculation on the octal value
  861. * using bitwise operations. This lets us remove, for example, 0222 from
  862. * 0700 and get the correct value of 0500.
  863. *
  864. * @param $file
  865. * The name of the file with permissions to fix.
  866. * @param $mask
  867. * The desired permissions for the file.
  868. * @param $message
  869. * (optional) Whether to output messages. Defaults to TRUE.
  870. *
  871. * @return
  872. * TRUE/FALSE whether or not we were able to fix the file's permissions.
  873. */
  874. function drupal_install_fix_file($file, $mask, $message = TRUE) {
  875. // If $file does not exist, fileperms() issues a PHP warning.
  876. if (!file_exists($file)) {
  877. return FALSE;
  878. }
  879. $mod = fileperms($file) & 0777;
  880. $masks = array(FILE_READABLE, FILE_WRITABLE, FILE_EXECUTABLE, FILE_NOT_READABLE, FILE_NOT_WRITABLE, FILE_NOT_EXECUTABLE);
  881. // FILE_READABLE, FILE_WRITABLE, and FILE_EXECUTABLE permission strings
  882. // can theoretically be 0400, 0200, and 0100 respectively, but to be safe
  883. // we set all three access types in case the administrator intends to
  884. // change the owner of settings.php after installation.
  885. foreach ($masks as $m) {
  886. if ($mask & $m) {
  887. switch ($m) {
  888. case FILE_READABLE:
  889. if (!is_readable($file)) {
  890. $mod |= 0444;
  891. }
  892. break;
  893. case FILE_WRITABLE:
  894. if (!is_writable($file)) {
  895. $mod |= 0222;
  896. }
  897. break;
  898. case FILE_EXECUTABLE:
  899. if (!is_executable($file)) {
  900. $mod |= 0111;
  901. }
  902. break;
  903. case FILE_NOT_READABLE:
  904. if (is_readable($file)) {
  905. $mod &= ~0444;
  906. }
  907. break;
  908. case FILE_NOT_WRITABLE:
  909. if (is_writable($file)) {
  910. $mod &= ~0222;
  911. }
  912. break;
  913. case FILE_NOT_EXECUTABLE:
  914. if (is_executable($file)) {
  915. $mod &= ~0111;
  916. }
  917. break;
  918. }
  919. }
  920. }
  921. // chmod() will work if the web server is running as owner of the file.
  922. // If PHP safe_mode is enabled the currently executing script must also
  923. // have the same owner.
  924. if (@chmod($file, $mod)) {
  925. return TRUE;
  926. }
  927. else {
  928. return FALSE;
  929. }
  930. }
  931. /**
  932. * Sends the user to a different installer page.
  933. *
  934. * This issues an on-site HTTP redirect. Messages (and errors) are erased.
  935. *
  936. * @param $path
  937. * An installer path.
  938. */
  939. function install_goto($path) {
  940. global $base_url;
  941. include_once DRUPAL_ROOT . '/includes/common.inc';
  942. header('Location: ' . $base_url . '/' . $path);
  943. header('Cache-Control: no-cache'); // Not a permanent redirect.
  944. drupal_exit();
  945. }
  946. /**
  947. * Returns the URL of the current script, with modified query parameters.
  948. *
  949. * This function can be called by low-level scripts (such as install.php and
  950. * update.php) and returns the URL of the current script. Existing query
  951. * parameters are preserved by default, but new ones can optionally be merged
  952. * in.
  953. *
  954. * This function is used when the script must maintain certain query parameters
  955. * over multiple page requests in order to work correctly. In such cases (for
  956. * example, update.php, which requires the 'continue=1' parameter to remain in
  957. * the URL throughout the update process if there are any requirement warnings
  958. * that need to be bypassed), using this function to generate the URL for links
  959. * to the next steps of the script ensures that the links will work correctly.
  960. *
  961. * @param $query
  962. * (optional) An array of query parameters to merge in to the existing ones.
  963. *
  964. * @return
  965. * The URL of the current script, with query parameters modified by the
  966. * passed-in $query. The URL is not sanitized, so it still needs to be run
  967. * through check_url() if it will be used as an HTML attribute value.
  968. *
  969. * @see drupal_requirements_url()
  970. */
  971. function drupal_current_script_url($query = array()) {
  972. $uri = $_SERVER['SCRIPT_NAME'];
  973. $query = array_merge(drupal_get_query_parameters(), $query);
  974. if (!empty($query)) {
  975. $uri .= '?' . drupal_http_build_query($query);
  976. }
  977. return $uri;
  978. }
  979. /**
  980. * Returns a URL for proceeding to the next page after a requirements problem.
  981. *
  982. * This function can be called by low-level scripts (such as install.php and
  983. * update.php) and returns a URL that can be used to attempt to proceed to the
  984. * next step of the script.
  985. *
  986. * @param $severity
  987. * The severity of the requirements problem, as returned by
  988. * drupal_requirements_severity().
  989. *
  990. * @return
  991. * A URL for attempting to proceed to the next step of the script. The URL is
  992. * not sanitized, so it still needs to be run through check_url() if it will
  993. * be used as an HTML attribute value.
  994. *
  995. * @see drupal_current_script_url()
  996. */
  997. function drupal_requirements_url($severity) {
  998. $query = array();
  999. // If there are no errors, only warnings, append 'continue=1' to the URL so
  1000. // the user can bypass this screen on the next page load.
  1001. if ($severity == REQUIREMENT_WARNING) {
  1002. $query['continue'] = 1;
  1003. }
  1004. return drupal_current_script_url($query);
  1005. }
  1006. /**
  1007. * Translates a string when some systems are not available.
  1008. *
  1009. * Used during the install process, when database, theme, and localization
  1010. * system is possibly not yet available.
  1011. *
  1012. * Use t() if your code will never run during the Drupal installation phase.
  1013. * Use st() if your code will only run during installation and never any other
  1014. * time. Use get_t() if your code could run in either circumstance.
  1015. *
  1016. * @see t()
  1017. * @see get_t()
  1018. * @ingroup sanitization
  1019. */
  1020. function st($string, array $args = array(), array $options = array()) {
  1021. static $locale_strings = NULL;
  1022. global $install_state;
  1023. if (empty($options['context'])) {
  1024. $options['context'] = '';
  1025. }
  1026. if (!isset($locale_strings)) {
  1027. $locale_strings = array();
  1028. if (isset($install_state['parameters']['profile']) && isset($install_state['parameters']['locale'])) {
  1029. // If the given locale was selected, there should be at least one .po file
  1030. // with its name ending in {$install_state['parameters']['locale']}.po
  1031. // This might or might not be the entire filename. It is also possible
  1032. // that multiple files end with the same extension, even if unlikely.
  1033. $po_files = file_scan_directory('./profiles/' . $install_state['parameters']['profile'] . '/translations', '/'. $install_state['parameters']['locale'] .'\.po$/', array('recurse' => FALSE));
  1034. if (count($po_files)) {
  1035. require_once DRUPAL_ROOT . '/includes/locale.inc';
  1036. foreach ($po_files as $po_file) {
  1037. _locale_import_read_po('mem-store', $po_file);
  1038. }
  1039. $locale_strings = _locale_import_one_string('mem-report');
  1040. }
  1041. }
  1042. }
  1043. // Transform arguments before inserting them
  1044. foreach ($args as $key => $value) {
  1045. switch ($key[0]) {
  1046. // Escaped only
  1047. case '@':
  1048. $args[$key] = check_plain($value);
  1049. break;
  1050. // Escaped and placeholder
  1051. case '%':
  1052. default:
  1053. $args[$key] = '<em>' . check_plain($value) . '</em>';
  1054. break;
  1055. // Pass-through
  1056. case '!':
  1057. }
  1058. }
  1059. return strtr((!empty($locale_strings[$options['context']][$string]) ? $locale_strings[$options['context']][$string] : $string), $args);
  1060. }
  1061. /**
  1062. * Checks an installation profile's requirements.
  1063. *
  1064. * @param $profile
  1065. * Name of installation profile to check.
  1066. * @return
  1067. * Array of the installation profile's requirements.
  1068. */
  1069. function drupal_check_profile($profile) {
  1070. include_once DRUPAL_ROOT . '/includes/file.inc';
  1071. $profile_file = DRUPAL_ROOT . "/profiles/$profile/$profile.profile";
  1072. if (!isset($profile) || !file_exists($profile_file)) {
  1073. throw new Exception(install_no_profile_error());
  1074. }
  1075. $info = install_profile_info($profile);
  1076. // Collect requirement testing results.
  1077. $requirements = array();
  1078. foreach ($info['dependencies'] as $module) {
  1079. module_load_install($module);
  1080. $function = $module . '_requirements';
  1081. if (function_exists($function)) {
  1082. $requirements = array_merge($requirements, $function('install'));
  1083. }
  1084. }
  1085. return $requirements;
  1086. }
  1087. /**
  1088. * Extracts the highest severity from the requirements array.
  1089. *
  1090. * @param $requirements
  1091. * An array of requirements, in the same format as is returned by
  1092. * hook_requirements().
  1093. *
  1094. * @return
  1095. * The highest severity in the array.
  1096. */
  1097. function drupal_requirements_severity(&$requirements) {
  1098. $severity = REQUIREMENT_OK;
  1099. foreach ($requirements as $requirement) {
  1100. if (isset($requirement['severity'])) {
  1101. $severity = max($severity, $requirement['severity']);
  1102. }
  1103. }
  1104. return $severity;
  1105. }
  1106. /**
  1107. * Checks a module's requirements.
  1108. *
  1109. * @param $module
  1110. * Machine name of module to check.
  1111. *
  1112. * @return
  1113. * TRUE or FALSE, depending on whether the requirements are met.
  1114. */
  1115. function drupal_check_module($module) {
  1116. module_load_install($module);
  1117. if (module_hook($module, 'requirements')) {
  1118. // Check requirements
  1119. $requirements = module_invoke($module, 'requirements', 'install');
  1120. if (is_array($requirements) && drupal_requirements_severity($requirements) == REQUIREMENT_ERROR) {
  1121. // Print any error messages
  1122. foreach ($requirements as $requirement) {
  1123. if (isset($requirement['severity']) && $requirement['severity'] == REQUIREMENT_ERROR) {
  1124. $message = $requirement['description'];
  1125. if (isset($requirement['value']) && $requirement['value']) {
  1126. $message .= ' (' . t('Currently using !item !version', array('!item' => $requirement['title'], '!version' => $requirement['value'])) . ')';
  1127. }
  1128. drupal_set_message($message, 'error');
  1129. }
  1130. }
  1131. return FALSE;
  1132. }
  1133. }
  1134. return TRUE;
  1135. }
  1136. /**
  1137. * Retrieves information about an installation profile from its .info file.
  1138. *
  1139. * The information stored in a profile .info file is similar to that stored in
  1140. * a normal Drupal module .info file. For example:
  1141. * - name: The real name of the installation profile for display purposes.
  1142. * - description: A brief description of the profile.
  1143. * - dependencies: An array of shortnames of other modules that this install
  1144. * profile requires.
  1145. *
  1146. * Additional, less commonly-used information that can appear in a profile.info
  1147. * file but not in a normal Drupal module .info file includes:
  1148. * - distribution_name: The name of the Drupal distribution that is being
  1149. * installed, to be shown throughout the installation process. Defaults to
  1150. * 'Drupal'.
  1151. * - exclusive: If the install profile is intended to be the only eligible
  1152. * choice in a distribution, setting exclusive = TRUE will auto-select it
  1153. * during installation, and the install profile selection screen will be
  1154. * skipped. If more than one profile is found where exclusive = TRUE then
  1155. * this property will have no effect and the profile selection screen will
  1156. * be shown as normal with all available profiles shown.
  1157. *
  1158. * Note that this function does an expensive file system scan to get info file
  1159. * information for dependencies. If you only need information from the info
  1160. * file itself, use system_get_info().
  1161. *
  1162. * Example of .info file:
  1163. * @code
  1164. * name = Minimal
  1165. * description = Start fresh, with only a few modules enabled.
  1166. * dependencies[] = block
  1167. * dependencies[] = dblog
  1168. * @endcode
  1169. *
  1170. * @param $profile
  1171. * Name of profile.
  1172. * @param $locale
  1173. * Name of locale used (if any).
  1174. *
  1175. * @return
  1176. * The info array.
  1177. */
  1178. function install_profile_info($profile, $locale = 'en') {
  1179. $cache = &drupal_static(__FUNCTION__, array());
  1180. if (!isset($cache[$profile])) {
  1181. // Set defaults for module info.
  1182. $defaults = array(
  1183. 'dependencies' => array(),
  1184. 'description' => '',
  1185. 'distribution_name' => 'Drupal',
  1186. 'version' => NULL,
  1187. 'hidden' => FALSE,
  1188. 'php' => DRUPAL_MINIMUM_PHP,
  1189. );
  1190. $info = drupal_parse_info_file("profiles/$profile/$profile.info") + $defaults;
  1191. $info['dependencies'] = array_unique(array_merge(
  1192. drupal_required_modules(),
  1193. $info['dependencies'],
  1194. ($locale != 'en' && !empty($locale) ? array('locale') : array()))
  1195. );
  1196. // drupal_required_modules() includes the current profile as a dependency.
  1197. // Since a module can't depend on itself we remove that element of the array.
  1198. array_shift($info['dependencies']);
  1199. $cache[$profile] = $info;
  1200. }
  1201. return $cache[$profile];
  1202. }
  1203. /**
  1204. * Ensures the environment for a Drupal database on a predefined connection.
  1205. *
  1206. * This will run tasks that check that Drupal can perform all of the functions
  1207. * on a database, that Drupal needs. Tasks include simple checks like CREATE
  1208. * TABLE to database specific functions like stored procedures and client
  1209. * encoding.
  1210. */
  1211. function db_run_tasks($driver) {
  1212. db_installer_object($driver)->runTasks();
  1213. return TRUE;
  1214. }
  1215. /**
  1216. * Returns a database installer object.
  1217. *
  1218. * @param $driver
  1219. * The name of the driver.
  1220. */
  1221. function db_installer_object($driver) {
  1222. Database::loadDriverFile($driver, array('install.inc'));
  1223. $task_class = 'DatabaseTasks_' . $driver;
  1224. return new $task_class();
  1225. }