page_theme.install in Page Theme 7.2
Same filename and directory in other branches
Install, update and uninstall functions for the page_theme module.
File
page_theme.installView source
<?php
/**
* @file
* Install, update and uninstall functions for the page_theme module.
*/
/**
* Implements hook_install().
*/
function page_theme_install() {
db_update('system')
->fields(array(
'weight' => 50,
))
->condition('name', 'page_theme')
->execute();
}
/**
* Implements hook_schema().
*/
function page_theme_schema() {
$schema['page_theme'] = array(
'description' => 'Stores page theme rules.',
'fields' => array(
'ptid' => array(
'description' => 'Primary Key: Unique rule ID.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'rule' => array(
'description' => 'Rule machine-name.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'name' => array(
'description' => 'Rule name.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'theme' => array(
'description' => 'Theme name.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'pages' => array(
'description' => 'List of paths to which the theme is assigned.',
'type' => 'text',
'not null' => TRUE,
),
'status' => array(
'description' => 'Rule enabled status. (1 = enabled, 0 = disabled)',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'weight' => array(
'description' => 'Rule weight within the rule list.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array(
'ptid',
),
'unique keys' => array(
'rule' => array(
'rule',
),
),
'indexes' => array(
'list' => array(
'weight',
'rule',
),
),
);
$schema['page_theme_role'] = array(
'description' => 'Sets up access permissions for page theme rules based on user roles',
'fields' => array(
'ptid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => "The page theme's rule ID from {page_theme}.ptid.",
),
'rid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => "The user's role ID from {users_roles}.rid.",
),
),
'primary key' => array(
'ptid',
'rid',
),
'indexes' => array(
'rid' => array(
'rid',
),
),
);
return $schema;
}
/**
* Add status and weight field.
*/
function page_theme_update_6100() {
db_add_field('page_theme', 'status', array(
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
));
db_add_field('page_theme', 'weight', array(
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
));
$result = db_query('SELECT theme FROM {page_theme}');
foreach ($result as $page_theme) {
db_update('page_theme')
->fields(array(
'status' => 1,
))
->condition('theme', $page_theme->theme)
->execute();
}
}
/**
* Add preview field.
*/
function page_theme_update_6101() {
db_add_field('page_theme', 'preview', array(
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
));
$result = db_query('SELECT theme FROM {page_theme}');
foreach ($result as $page_theme) {
db_update('page_theme')
->fields(array(
'preview' => 1,
))
->condition('theme', $page_theme->theme)
->execute();
}
}
/**
* Rename field preview to editpage.
*/
function page_theme_update_6102() {
db_change_field('page_theme', 'preview', 'editpage', array(
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
));
}
/**
* Fix default value for theme field.
*/
function page_theme_update_6103() {
db_drop_primary_key('page_theme');
db_change_field('page_theme', 'theme', 'theme', array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
), array(
'primary key' => array(
'theme',
),
));
}
/**
* Add page theme ID field and update table indices.
*/
function page_theme_update_6104() {
db_drop_primary_key('page_theme');
db_add_field('page_theme', 'ptid', array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
), array(
'primary key' => array(
'ptid',
),
));
db_add_unique_key('page_theme', 'theme', array(
'theme',
));
db_add_index('page_theme', 'list', array(
'theme',
'weight',
));
}
/**
* Drop editpage field which is no longer used.
*/
function page_theme_update_6105() {
db_drop_field('page_theme', 'editpage');
}
/**
* Change the weight column to normal int.
*/
function page_theme_update_7000() {
db_drop_index('page_theme', 'list');
db_change_field('page_theme', 'weight', 'weight', array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
), array(
'indexes' => array(
'list' => array(
'theme',
'weight',
),
),
));
}
/**
* Check if all defined themes are available otherwise display a notice.
*/
function page_theme_update_7001() {
$themes = page_theme_get_themes();
$result = db_query('SELECT theme FROM {page_theme}');
foreach ($result as $page_theme) {
if (!isset($themes[$page_theme->theme])) {
return t('Not all defined themes are available, please check your configuration.');
}
}
}
/**
* Branch 7.x-2.x
*/
/**
* Add fields {page_theme}.rule and {page_theme}.name.
*/
function page_theme_update_7200() {
db_drop_unique_key('page_theme', 'theme');
db_drop_index('page_theme', 'list');
db_add_field('page_theme', 'rule', array(
'description' => 'Rule machine-name.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
));
db_add_field('page_theme', 'name', array(
'description' => 'Rule name.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
));
$result = db_query('SELECT theme FROM {page_theme}');
foreach ($result as $page_theme) {
db_update('page_theme')
->fields(array(
'rule' => $page_theme->theme,
'name' => $page_theme->theme,
))
->condition('theme', $page_theme->theme)
->execute();
}
db_add_unique_key('page_theme', 'rule', array(
'rule',
));
db_add_index('page_theme', 'list', array(
'weight',
'rule',
));
}
/**
* Create table {page_theme_role}.
*/
function page_theme_update_7201() {
$schema = array(
'description' => 'Sets up access permissions for page theme rules based on user roles',
'fields' => array(
'ptid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => "The page theme's rule ID from {page_theme}.ptid.",
),
'rid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => "The user's role ID from {users_roles}.rid.",
),
),
'primary key' => array(
'ptid',
'rid',
),
'indexes' => array(
'rid' => array(
'rid',
),
),
);
db_create_table('page_theme_role', $schema);
}
/**
* Set module's weight to 50.
*/
function page_theme_update_7202() {
db_update('system')
->fields(array(
'weight' => 50,
))
->condition('name', 'page_theme')
->execute();
}
Functions
Name![]() |
Description |
---|---|
page_theme_install | Implements hook_install(). |
page_theme_schema | Implements hook_schema(). |
page_theme_update_6100 | Add status and weight field. |
page_theme_update_6101 | Add preview field. |
page_theme_update_6102 | Rename field preview to editpage. |
page_theme_update_6103 | Fix default value for theme field. |
page_theme_update_6104 | Add page theme ID field and update table indices. |
page_theme_update_6105 | Drop editpage field which is no longer used. |
page_theme_update_7000 | Change the weight column to normal int. |
page_theme_update_7001 | Check if all defined themes are available otherwise display a notice. |
page_theme_update_7200 | Add fields {page_theme}.rule and {page_theme}.name. |
page_theme_update_7201 | Create table {page_theme_role}. |
page_theme_update_7202 | Set module's weight to 50. |