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