| 1 |
<?php
|
| 2 |
// $Id: block_class.install,v 1.6 2009/04/21 15:39:31 shannonlucas Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file block_class.install
|
| 6 |
* Provides the (un)install and update logic for block_class.
|
| 7 |
*/
|
| 8 |
|
| 9 |
|
| 10 |
/**
|
| 11 |
* Implementation of hook_schema().
|
| 12 |
*
|
| 13 |
* @return array The schema information.
|
| 14 |
*/
|
| 15 |
function block_class_schema() {
|
| 16 |
$schema['block_class'] = array(
|
| 17 |
'fields' => array(
|
| 18 |
'module' => array(
|
| 19 |
'type' => 'varchar',
|
| 20 |
'length' => '64',
|
| 21 |
'not null' => TRUE,
|
| 22 |
'description' => t('The module the block belongs to.'),
|
| 23 |
),
|
| 24 |
'delta' => array(
|
| 25 |
'type' => 'varchar',
|
| 26 |
'length' => '32',
|
| 27 |
'not null' => TRUE,
|
| 28 |
'description' => t("The ID of the module's block's."),
|
| 29 |
),
|
| 30 |
'css_class' => array(
|
| 31 |
'type' => 'text',
|
| 32 |
'size' => 'big',
|
| 33 |
'description' => t('A serialized PHP array containing the classes for the block.'),
|
| 34 |
),
|
| 35 |
),
|
| 36 |
'primary key' => array('module', 'delta'),
|
| 37 |
);
|
| 38 |
|
| 39 |
return $schema;
|
| 40 |
}
|
| 41 |
|
| 42 |
|
| 43 |
/**
|
| 44 |
* Implementation of hook_install().
|
| 45 |
*/
|
| 46 |
function block_class_install() {
|
| 47 |
drupal_install_schema('block_class');
|
| 48 |
}
|
| 49 |
|
| 50 |
|
| 51 |
/**
|
| 52 |
* Implementation of hook_uninstall().
|
| 53 |
*/
|
| 54 |
function block_class_uninstall() {
|
| 55 |
drupal_uninstall_schema('block_class');
|
| 56 |
}
|
| 57 |
|
| 58 |
|
| 59 |
/**
|
| 60 |
* Implementation of hook_update_N(). Alters the structure of the
|
| 61 |
* block_class schema.
|
| 62 |
*
|
| 63 |
* @return array The results of the updates.
|
| 64 |
*
|
| 65 |
* @TODO Upgrade from previous version needs to be tested to ensure data
|
| 66 |
* integrity after upgrade.
|
| 67 |
*/
|
| 68 |
function block_class_update_6100() {
|
| 69 |
$status = array();
|
| 70 |
|
| 71 |
//-- Update the schema.
|
| 72 |
db_drop_primary_key($status, 'block_class');
|
| 73 |
|
| 74 |
db_change_field($status, 'block_class', 'module', 'module',
|
| 75 |
array(
|
| 76 |
'type' => 'varchar',
|
| 77 |
'length' => '64',
|
| 78 |
'not null' => TRUE,
|
| 79 |
'description' => t('The module the block belongs to.'),
|
| 80 |
)
|
| 81 |
);
|
| 82 |
|
| 83 |
db_change_field($status, 'block_class', 'css_class', 'css_class',
|
| 84 |
array(
|
| 85 |
'type' => 'text',
|
| 86 |
'size' => 'big',
|
| 87 |
'description' => t('A serialized PHP array containing the classes for the block.'),
|
| 88 |
)
|
| 89 |
);
|
| 90 |
|
| 91 |
//-- Restore the primary key.
|
| 92 |
db_add_primary_key($status, 'block_class', array('module', 'delta'));
|
| 93 |
|
| 94 |
//-- Convert the existing arbitrary CSS classes to the new format.
|
| 95 |
$blocks = array();
|
| 96 |
$result = db_query('SELECT `module`, `delta`, `css_class` FROM {block_class}');
|
| 97 |
while($row = db_fetch_array($result)) {
|
| 98 |
$blocks[] = array(
|
| 99 |
'module' => $row['module'],
|
| 100 |
'delta' => $row['delta'],
|
| 101 |
'css_class' => serialize(array('_' => $row['css_class'])),
|
| 102 |
);
|
| 103 |
}
|
| 104 |
|
| 105 |
$key = array('module', 'delta', 'theme');
|
| 106 |
foreach($blocks as $block) {
|
| 107 |
drupal_write_record('block_class', $block, $key);
|
| 108 |
}
|
| 109 |
|
| 110 |
return $status;
|
| 111 |
}
|