homebox.install in Homebox 6.2
Same filename and directory in other branches
The install file for Homebox allows the module to install (and uninstall) itself. This is required as this module uses its own table.
File
homebox.installView source
<?php
/**
* @file
* The install file for Homebox allows the module to install (and uninstall) itself. This is required as this module uses its own table.
*/
/**
* Implementation of hook_install().
*/
function homebox_install() {
// Since there will be no upgrade path from 1.x to 2.x,
// we need to make sure that hook_install ran and that
// this wasn't simply enabled
variable_set('homebox_version', 2);
drupal_install_schema('homebox');
}
function homebox_schema() {
// Schema for homebox pages
$schema['homebox_pages'] = array(
'fields' => array(
'name' => array(
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
),
'settings' => array(
'type' => 'blob',
'size' => 'big',
'not null' => TRUE,
'serialize' => TRUE,
'object default' => array(),
),
),
'primary key' => array(
'name',
),
);
// Schema for user custom settings
$schema['homebox_users'] = array(
'fields' => array(
'uid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'name' => array(
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
),
'settings' => array(
'type' => 'text',
'size' => 'big',
'not null' => TRUE,
'serialize' => TRUE,
'object default' => array(),
),
),
'primary key' => array(
'uid',
'name',
),
);
return $schema;
}
/**
* Implementation of hook_uninstall().
*/
function homebox_uninstall() {
// Remove variables
variable_del('homebox_user_tab');
variable_del('homebox_version');
// Remove schema
drupal_uninstall_schema('homebox');
}
/**
* Add {homebox_users} primary key.
*/
function homebox_update_6000() {
$return = array();
db_add_primary_key($return, 'homebox_users', array(
'uid',
'name',
));
return $return;
}
/**
* Use 'custom' delta for homebox blocks.
*/
function homebox_update_6001() {
$return = array();
$result = db_query("SELECT uid, name, settings FROM {homebox_users}");
while ($row = db_fetch_object($result)) {
$row->settings = unserialize($row->settings);
foreach ($row->settings as $key => $block) {
if (isset($block['module']) && $block['module'] === 'homebox') {
// Save the new key for later.
$new_key = 'homebox_custom-' . $block['delta'];
// Set delta to standard.
$block['delta'] = 'custom';
// Move title.
$block['title_custom'] = $block['title'];
$block['title'] = '';
// Move block to new key.
unset($row->settings[$key]);
$row->settings[$new_key] = $block;
}
}
drupal_write_record('homebox_users', $row, array(
'uid',
'name',
));
}
return $return;
}
/**
* Replace page custom setting with a regular block.
*/
function homebox_update_6002() {
$return = array();
$result = db_query('SELECT name, settings FROM {homebox_pages}');
while ($row = db_fetch_object($result)) {
$row->settings = unserialize($row->settings);
if ($row->settings['custom']) {
unset($row->settings['custom']);
$row->settings['blocks']['homebox_custom'] = array(
'module' => 'homebox',
'delta' => 'custom',
'region' => 1,
'movable' => 1,
'status' => 0,
'open' => 1,
'closable' => 1,
'title' => '',
'weight' => -45,
);
}
drupal_write_record('homebox_pages', $row, 'name');
}
return $return;
}
/**
* Make sure all user blocks have a module and delta.
*/
function homebox_update_6003() {
$return = array();
$result = db_query("SELECT uid, name, settings FROM {homebox_users}");
while ($row = db_fetch_object($result)) {
$row->settings = unserialize($row->settings);
if ($page = homebox_get_page($row->name)) {
foreach ($row->settings as $key => $block) {
if ((!isset($block['module']) || !isset($block['delta'])) && isset($page->settings['blocks'][$key])) {
$row->settings[$key]['module'] = $page->settings['blocks'][$key]['module'];
$row->settings[$key]['delta'] = $page->settings['blocks'][$key]['delta'];
}
}
drupal_write_record('homebox_users', $row, array(
'uid',
'name',
));
}
}
return $return;
}
Functions
Name | Description |
---|---|
homebox_install | Implementation of hook_install(). |
homebox_schema | |
homebox_uninstall | Implementation of hook_uninstall(). |
homebox_update_6000 | Add {homebox_users} primary key. |
homebox_update_6001 | Use 'custom' delta for homebox blocks. |
homebox_update_6002 | Replace page custom setting with a regular block. |
homebox_update_6003 | Make sure all user blocks have a module and delta. |