install.inc 42 KB

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