blockcache_alter.install in Block Cache Alter 7
Same filename and directory in other branches
Install file.
File
blockcache_alter.installView source
<?php
/**
* @file
* Install file.
*/
/**
* Implements hook_schema().
*/
function blockcache_alter_schema() {
$schema = array();
$schema['blockcache_alter'] = array(
'description' => 'Stores blockcache alter cache values',
'fields' => array(
'bid' => array(
'type' => 'serial',
'not null' => TRUE,
'description' => 'Primary Key: Unique block ID.',
),
'module' => array(
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
'description' => "The module from which the block originates; for example, 'user' for the Who's Online block, and 'block' for any custom blocks.",
),
'delta' => array(
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '0',
'description' => 'Unique ID for block within a module.',
),
'cache' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 1,
'size' => 'tiny',
'description' => 'Binary flag to indicate block cache mode. (-2: Custom cache, -1: Do not cache, 1: Cache per role, 2: Cache per user, 4: Cache per page, 8: Block cache global) See DRUPAL_CACHE_* constants in ../includes/common.inc for more detailed information.',
),
),
'primary key' => array(
'bid',
),
);
return $schema;
}
/**
* Add the "bid" column to {blockcache_alter} and backfill block IDs.
*/
function blockcache_alter_update_7000() {
// Ensure we don't run this update for existing installs; D6 updates only.
if (!db_field_exists('blockcache_alter', 'bid')) {
// Define the bid column and primary key.
$spec = array(
'type' => 'serial',
'not null' => TRUE,
'description' => 'Primary Key: Unique block ID.',
);
$keys = array(
'primary key' => array(
'bid',
),
);
// Add the bid column along with the new primary key.
db_add_field('blockcache_alter', 'bid', $spec, $keys);
// If there are existing block cache alter entries, find their block IDs.
$bcas = db_select('blockcache_alter', 'bca', array(
'fetch' => PDO::FETCH_ASSOC,
))
->fields('bca');
$bcas
->join('block', 'b', 'bca.module = %alias.module AND bca.delta = %alias.delta');
$bcas
->fields('b', array(
'bid',
));
$results = $bcas
->execute();
// If results were returned, truncate the existing block cache alter table,
// then insert all of the database records we previously found/built.
if (!empty($results)) {
db_truncate('blockcache_alter')
->execute();
$insert = db_insert('blockcache_alter')
->fields(array(
'module',
'delta',
'cache',
'bid',
));
foreach ($results as $bca) {
$insert
->values($bca);
}
$insert
->execute();
}
}
}
/**
* Fix the length of the delta VARCHAR to 64.
*/
function blockcache_alter_update_7001() {
db_change_field('blockcache_alter', 'delta', 'delta', array(
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '0',
'description' => 'Unique ID for block within a module.',
));
}
Functions
Name | Description |
---|---|
blockcache_alter_schema | Implements hook_schema(). |
blockcache_alter_update_7000 | Add the "bid" column to {blockcache_alter} and backfill block IDs. |
blockcache_alter_update_7001 | Fix the length of the delta VARCHAR to 64. |