| Versionen | |
|---|---|
| drupal6 – drupal7 | system_install() |
Implementation of hook_install().
modules/
<?php
function system_install() {
if (db_driver() == 'pgsql') {
// We create some functions using global names instead of prefixing them
// like we do with table names. If this function is ever called again (for
// example, by the test framework when creating prefixed test databases),
// the global names will already exist. We therefore avoid trying to create
// them again in that case.
// Create functions.
db_query('CREATE OR REPLACE FUNCTION "greatest"(numeric, numeric) RETURNS numeric AS
\'SELECT CASE WHEN (($1 > $2) OR ($2 IS NULL)) THEN $1 ELSE $2 END;\'
LANGUAGE \'sql\''
);
db_query('CREATE OR REPLACE FUNCTION "greatest"(numeric, numeric, numeric) RETURNS numeric AS
\'SELECT greatest($1, greatest($2, $3));\'
LANGUAGE \'sql\''
);
// Don't use {} around pg_proc table.
if (!db_query("SELECT COUNT(*) FROM pg_proc WHERE proname = 'rand'")->fetchField()) {
db_query('CREATE OR REPLACE FUNCTION "rand"() RETURNS float AS
\'SELECT random();\'
LANGUAGE \'sql\''
);
}
// Don't use {} around pg_proc table.
if (!db_query("SELECT COUNT(*) FROM pg_proc WHERE proname = 'concat'")->fetchField()) {
db_query('CREATE OR REPLACE FUNCTION "concat"(text, text) RETURNS text AS
\'SELECT $1 || $2;\'
LANGUAGE \'sql\''
);
}
db_query('CREATE OR REPLACE FUNCTION "if"(boolean, text, text) RETURNS text AS
\'SELECT CASE WHEN $1 THEN $2 ELSE $3 END;\'
LANGUAGE \'sql\''
);
db_query('CREATE OR REPLACE FUNCTION "if"(boolean, integer, integer) RETURNS integer AS
\'SELECT CASE WHEN $1 THEN $2 ELSE $3 END;\'
LANGUAGE \'sql\''
);
}
// Create tables.
$modules = array('system', 'filter', 'user', 'node');
foreach ($modules as $module) {
drupal_install_schema($module);
}
// Load system theme data appropriately.
system_theme_data();
// Inserting uid 0 here confuses MySQL -- the next user might be created as
// uid 2 which is not what we want. So we insert the first user here, the
// anonymous user. uid is 1 here for now, but very soon it will be changed
// to 0.
db_query("INSERT INTO {users} (name, mail) VALUES('%s', '%s')", '', '');
// We need some placeholders here as name and mail are uniques and data is
// presumed to be a serialized array. Install will change uid 1 immediately
// anyways. So we insert the superuser here, the uid is 2 here for now, but
// very soon it will be changed to 1.
db_query("INSERT INTO {users} (name, mail, created, status, data) VALUES('%s', '%s', %d, %d, '%s')", 'placeholder-for-uid-1', 'placeholder-for-uid-1', REQUEST_TIME, 1, serialize(array()));
// This sets the above two users uid 0 (anonymous). We avoid an explicit 0
// otherwise MySQL might insert the next auto_increment value.
db_query("UPDATE {users} SET uid = uid - uid WHERE name = '%s'", '');
// This sets uid 1 (superuser). We skip uid 2 but that's not a big problem.
db_query("UPDATE {users} SET uid = 1 WHERE name = '%s'", 'placeholder-for-uid-1');
// Built-in roles.
db_query("INSERT INTO {role} (name) VALUES ('%s')", 'anonymous user');
db_query("INSERT INTO {role} (name) VALUES ('%s')", 'authenticated user');
// Anonymous role permissions.
db_query("INSERT INTO {role_permission} (rid, permission) VALUES (%d, '%s')", 1, 'access content');
// Authenticated role permissions.
db_query("INSERT INTO {role_permission} (rid, permission) VALUES (%d, '%s')", 2, 'access comments');
db_query("INSERT INTO {role_permission} (rid, permission) VALUES (%d, '%s')", 2, 'access content');
db_query("INSERT INTO {role_permission} (rid, permission) VALUES (%d, '%s')", 2, 'post comments');
db_query("INSERT INTO {role_permission} (rid, permission) VALUES (%d, '%s')", 2, 'post comments without approval');
db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", 'theme_default', 's:7:"garland";');
db_query("UPDATE {system} SET status = %d WHERE type = '%s' AND name = '%s'", 1, 'theme', 'garland');
db_query("INSERT INTO {node_access} (nid, gid, realm, grant_view, grant_update, grant_delete) VALUES (%d, %d, '%s', %d, %d, %d)", 0, 0, 'all', 1, 0, 0);
// Add text formats.
db_query("INSERT INTO {filter_format} (name, roles, cache) VALUES ('%s', '%s', %d)", 'Filtered HTML', ',1,2,', 1);
db_query("INSERT INTO {filter_format} (name, roles, cache) VALUES ('%s', '%s', %d)", 'Full HTML', '', 1);
// Enable filters for each text format.
// Filtered HTML:
// URL filter.
db_query("INSERT INTO {filter} (format, module, delta, weight) VALUES (%d, '%s', %d, %d)", 1, 'filter', 2, 0);
// HTML filter.
db_query("INSERT INTO {filter} (format, module, delta, weight) VALUES (%d, '%s', %d, %d)", 1, 'filter', 0, 1);
// Line break filter.
db_query("INSERT INTO {filter} (format, module, delta, weight) VALUES (%d, '%s', %d, %d)", 1, 'filter', 1, 2);
// HTML corrector filter.
db_query("INSERT INTO {filter} (format, module, delta, weight) VALUES (%d, '%s', %d, %d)", 1, 'filter', 3, 10);
// Full HTML:
// URL filter.
db_query("INSERT INTO {filter} (format, module, delta, weight) VALUES (%d, '%s', %d, %d)", 2, 'filter', 2, 0);
// Line break filter.
db_query("INSERT INTO {filter} (format, module, delta, weight) VALUES (%d, '%s', %d, %d)", 2, 'filter', 1, 1);
// HTML corrector filter.
db_query("INSERT INTO {filter} (format, module, delta, weight) VALUES (%d, '%s', %d, %d)", 2, 'filter', 3, 10);
db_query("INSERT INTO {variable} (name, value) VALUES ('%s','%s')", 'filter_html_1', 'i:1;');
db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", 'node_options_forum', 'a:1:{i:0;s:6:"status";}');
$cron_key = serialize(md5(mt_rand()));
db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", 'cron_key', $cron_key);
}
?>
Kommentare
Kommentar hinzufügen