function panels_update_5209 in Panels 5.2
Same name and namespace in other branches
- 6.3 panels.install \panels_update_5209()
File
- ./
panels.install, line 334
Code
function panels_update_5209() {
$ret = array();
$ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN relationships longtext");
$result = db_query("SELECT * FROM {panels_page}");
panels_load_include('plugins');
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 : '');
error_log($argument['identifier']);
}
// 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;
error_log($argument['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;
}