function context_ui_rebuild in Context 5
Cache system contexts
4 calls to context_ui_rebuild()
- context_ui_admin in context_ui/
context_ui_admin.inc - Page callback for context_ui admin landing page.
- context_ui_delete_confirm_submit in context_ui/
context_ui_admin.inc - Submit hook for context_ui delete confirmation form.
- context_ui_form_submit in context_ui/
context_ui_admin.inc - Submit handler for main context_ui form.
- context_ui_menu in context_ui/
context_ui.module - Implementation of hook_menu().
File
- context_ui/
context_ui_admin.inc, line 523
Code
function context_ui_rebuild() {
$default_contexts = context_ui_defaults();
$types = context_ui_types();
// Grab existing user defined contexts
$ui = context_ui_tree('ui');
// Retrieve existing system contexts
$system = array();
$result = db_query("SELECT * FROM {context_ui} WHERE system = 1");
while ($existing = db_fetch_object($result)) {
$system[$existing->cid] = true;
}
// Insert or update system contexts
foreach ($default_contexts as $c) {
// Check that the context definition is reasonable
if (!empty($c->namespace) && !empty($c->attribute)) {
// Check that the providing module has not explicitly set system + status
// If it has, we trust that the module knows what it is doing. Otherwise,
// flag this context's type + status.
if (!isset($c->system) && !isset($c->status)) {
$c->system = 1;
$c->status = isset($ui[$c->namespace][$c->attribute][$c->value]) ? 0 : 1;
}
if ($context = context_ui_context('load', $c)) {
$c->cid = $context->cid;
context_ui_context('update', $c);
unset($system[$c->cid]);
// remove this context from unused list
}
else {
context_ui_context('insert', $c);
}
}
}
// Remove any unused contexts
foreach ($system as $c => $dummy) {
context_ui_context('delete', $c);
}
}