function panels_update_5209 in Panels 6.3
Same name and namespace in other branches
- 5.2 panels.install \panels_update_5209()
File
- ./
panels.install, line 562
Code
function panels_update_5209() {
if (!empty($GLOBALS['SKIP_PANELS_UPDATES'])) {
return array();
}
$ret = array();
$ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN relationships longtext");
$result = db_query("SELECT * FROM {panels_page}");
// This code removed due to call to panels_get_argument(). People with
// older versions will just have to suffer.
return $ret;
ctools_include('plugins', 'panels');
while ($page = db_fetch_object($result)) {
$args = unserialize($page->arguments);
$arguments = $ids = $keywords = array();
if (!empty($args)) {
// Update each argument
foreach ($args as $id => $argument) {
$name = $argument['name'];
$info = panels_get_argument($name);
if (!$info) {
continue;
}
// Make sure the id is valid
if (empty($argument['id'])) {
if (empty($ids[$name])) {
$ids[$name] = 1;
}
else {
$ids[$name]++;
}
$argument['id'] = $ids[$name];
}
// Give it an identifier if it doesn't already have one
if (empty($argument['identifier'])) {
$argument['identifier'] = $info['title'] . ($id > 1 ? ' ' . $id : '');
}
// Give it a unique keyword if it doesn't already have one
if (empty($argument['keyword'])) {
$keyword = $base = $info['keyword'];
$count = 0;
while (!empty($keywords[$keyword])) {
$keyword = $base . '_' . ++$count;
}
$keywords[$keyword] = TRUE;
$argument['keyword'] = $keyword;
}
$arguments[$id] = $argument;
}
}
// Move old relationships (stored as contexts) to relationships, where
// the belong
$rels = unserialize($page->contexts);
// Not resetting $keywords!
$relationships = $ids = array();
if (!empty($rels)) {
foreach ($rels as $id => $relationship) {
$name = $relationship['name'];
$info = panels_get_relationship($name);
if (!$info) {
continue;
}
// Make sure the id is valid
if (empty($relationship['id'])) {
if (empty($ids[$name])) {
$ids[$name] = 1;
}
else {
$ids[$name]++;
}
$relationship['id'] = $ids[$name];
}
// Give it an identifier if it doesn't already have one
if (empty($relationship['identifier'])) {
$relationship['identifier'] = $info['title'] . ($id > 1 ? ' ' . $id : '');
}
// Give it a unique keyword if it doesn't already have one
if (empty($relationship['keyword'])) {
$keyword = $base = $info['keyword'];
$count = 0;
while (!empty($keywords[$keyword])) {
$keyword = $base . '_' . ++$count;
}
$keywords[$keyword] = TRUE;
$relationship['keyword'] = $keyword;
}
$relationships[$id] = $relationship;
}
}
db_query("UPDATE {panels_page} " . "SET arguments = '%s', " . "relationships = '%s', " . "contexts = '%s' " . "WHERE pid = {$page->pid}", serialize($arguments), serialize($relationships), serialize(array()), $page->pid);
}
return $ret;
}