Newer
Older
The Great Git Migration
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
/**
* Implementation of hook_install().
*/
function context_install() {
drupal_install_schema('context');
}
/**
* Implementation of hook_uninstall().
*/
function context_uninstall() {
drupal_uninstall_schema('context');
}
/**
* Implementation of hook_schema().
*/
function context_schema() {
$schema['context'] = array(
'description' => t('Storage for normal (user-defined) contexts.'),
'fields' => array(
'cid' => array(
'description' => t('The primary identifier for a context.'),
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'namespace' => array(
'description' => t('The namespace for a context.'),
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
),
'attribute' => array(
'description' => t('The attribute for a context.'),
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
),
'value' => array(
'description' => t('The value for a context.'),
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
),
'data' => array(
'description' => t('Serialized storage of all associated context items.'),
'type' => 'text',
'size' => 'big',
'not null' => TRUE,
'default' => '',
),
),
'unique keys' => array(
'key1' => array('namespace', 'attribute', 'value'),
),
'primary key' => array('cid'),
);
return $schema;
}
/**
* Update script for context that installs the context schema and migrates
* any existing context data from deprecated context_ui tables.
*/
function context_update_6001() {
$ret = array();
if (!db_table_exists('context')) {
drupal_install_schema('context');
}
if (db_table_exists('context_ui')) {
// Clear the schema cache and rebuild
drupal_get_schema(NULL, TRUE);
// Migrate existing contexts to context table
$result = db_query("SELECT * FROM {context_ui}");
while ($context = db_fetch_object($result)) {
// Load setters
$setter_result = db_query("SELECT * FROM {context_ui_setter} WHERE cid = %d", $context->cid);
while ($row = db_fetch_object($setter_result)) {
$context->{$row->type}[$row->id] = $row->id;
}
// Load getters
$getter_result = db_query("SELECT * FROM {context_ui_getter} WHERE cid = %d", $context->cid);
while ($row = db_fetch_object($getter_result)) {
$context->{$row->type} = unserialize($row->data);
}
// Load blocks
$block_result = db_query("SELECT module, delta, region, weight FROM {context_ui_block} WHERE cid = %d", $context->cid);
while ($block = db_fetch_object($block_result)) {
if (!isset($context->block)) {
$context->block = array();
}
$block->bid = $block->module ."_". $block->delta;
$context->block[$block->bid] = $block;
}
// Clear out identifier
unset($context->cid);
context_save_context($context);
}
}
module_enable(array('context_contrib'));
The Great Git Migration
committed
return $ret;
}
/**
* Update script for API change in path condition.
*/
function context_update_6002() {
// Iterate through all DB-stored contexts and incorporate path
// wildcards into their path conditions. Any exported/default
// contexts will need to be updated by hand.
$contexts = context_enabled_contexts();
foreach ($contexts as $context) {
if (($context->type == CONTEXT_STORAGE_NORMAL || $context->type == CONTEXT_STORAGE_OVERRIDDEN) && (!empty($context->path) && is_array($context->path))) {
$changed = FALSE;
foreach ($context->path as $k => $v) {
if ($v != '<front>' && strpos($v, '*') === FALSE) {
$changed = TRUE;
$context->path[$k] = "{$v}*";
}
}
if ($changed) {
context_save_context($context);
}
}
}
}