Commit af0b6836 authored by kiz_0987's avatar kiz_0987

bugfix: update errors (#226452)

parent 9eef4acf
......@@ -54,10 +54,13 @@ function gallery_update_1() {
$ret = gallery_update_variables($migrate, $obsolete);
// Update the blocks
$ret[] = update_sql("UPDATE {blocks} SET delta = 'image-0' WHERE module = 'gallery' AND delta = 0");
$ret[] = update_sql("UPDATE {blocks} SET delta = 'navigation' WHERE module = 'gallery' AND delta = 1");
$ret[] = update_sql("UPDATE {blocks} SET delta = 'grid-0' WHERE module = 'gallery' AND delta = 2");
db_query("UPDATE {blocks} SET delta = '%s' WHERE module = '%s' AND delta = '%d'", 'image-0', 'gallery', 0);
$ret[] = array('success' => TRUE, 'query' => 'Updating block [image-0]');
db_query("UPDATE {blocks} SET delta = '%s' WHERE module = '%s' AND delta = '%d'", 'navigation', 'gallery', 1);
$ret[] = array('success' => TRUE, 'query' => 'Updating block [navigation]');
db_query("UPDATE {blocks} SET delta = '%s' WHERE module = '%s' AND delta = '%d'", 'grid-0', 'gallery', 2);
$ret[] = array('success' => TRUE, 'query' => 'Updating block [grid-0]');
// Mark gallery configuration invalid. This does NOT reset the configuration, but
// forces the user to run the install wizard to (re)set and verify critical settings.
variable_set('gallery_valid', FALSE);
......@@ -102,7 +105,8 @@ function gallery_update_6000() {
'gallery_block_image_'. $i .'_link_target' => 'gallery_block_'. $delta .'_imageblock_link_target',
'gallery_block_image_'. $i .'_link' => 'gallery_block_'. $delta .'_imageblock_link'
);
$ret[] = update_sql("UPDATE {blocks} SET delta = 'block-%d' WHERE module = 'gallery' AND delta = 'image-%d'", $delta, $i);
db_query("UPDATE {blocks} SET delta = '%s' WHERE module = '%s' AND delta = '%s'", 'block-'. $delta, 'gallery', 'image-'. $i);
$ret[] = array('success' => TRUE, 'query' => 'Updating block [image-'. $i .']');
}
// Grid block settings
......@@ -114,7 +118,6 @@ function gallery_update_6000() {
'gallery_block_grid_'. $i .'_blockid' => 'gallery_block_'. $delta .'_blockid',
'gallery_block_grid_'. $i .'_num_cols' => 'gallery_block_'. $delta .'_imageblock_num_cols',
'gallery_block_grid_'. $i .'_num_rows' => 'gallery_block_'. $delta .'_imageblock_num_rows',
'gallery_block_grid_'. $i .'_block_block' => 'gallery_block_'. $delta .'_imageblock_block_block',
'gallery_block_grid_'. $i .'_item_id' => 'gallery_block_'. $delta .'_imageblock_item_id',
'gallery_block_grid_'. $i .'_block_show' => 'gallery_block_'. $delta .'_imageblock_block_show',
'gallery_block_grid_'. $i .'_size_method' => 'gallery_block_'. $delta .'_imageblock_size_method',
......@@ -124,9 +127,16 @@ function gallery_update_6000() {
'gallery_block_grid_'. $i .'_link_target' => 'gallery_block_'. $delta .'_imageblock_link_target',
'gallery_block_grid_'. $i .'_link' => 'gallery_block_'. $delta .'_imageblock_link'
);
$ret[] = update_sql("UPDATE {blocks} SET delta = 'block-%d' WHERE module = 'gallery' AND delta = 'grid-%d'", $delta, $i);
db_query("UPDATE {blocks} SET delta = '%s' WHERE module = '%s' AND delta = '%s'", 'block-'. $delta, 'gallery', 'grid-'. $i);
$ret[] = array('success' => TRUE, 'query' => 'Updating block [grid-'. $i .']');
// gallery_block_grid_X_block_block must be handled differently. In D5 this was a single value,
// but in D6 it is an array of size cols*rows (to allow different values for each item).
$num_images = variable_get('gallery_block_grid_'. $i .'_num_cols', 2) * variable_get('gallery_block_grid_'. $i .'_num_rows', 2);
$old_block = variable_get('gallery_block_grid_'. $i .'_block_block', array('randomImage'));
$new_block = array_fill(0, $num_images, $old_block);
$new['gallery_block_'. $delta .'_imageblock_block_block'] = $new_block;
}
$new['gallery_block_num'] = $delta;
// Array containing obsolete variables
......@@ -138,13 +148,13 @@ function gallery_update_6000() {
);
// Update variables
$ret = gallery_update_variables($migrate, $obsolete);
$ret += gallery_update_variables($migrate, $obsolete);
// Add new variables
foreach ($new as $name => $value) {
db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", $name, $value);
db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", $name, serialize($value));
$ret[] = array('success' => TRUE, 'query' => 'Adding variable ['. $name .']');
}
cache_clear_all('variables', 'cache');
menu_rebuild();
......@@ -159,13 +169,13 @@ function gallery_update_variables($migrate, $obsolete) {
$variables = array();
// Fetch all gallery-related variables
$result = db_query("SELECT * FROM {variable} WHERE name LIKE 'gallery_%'");
$result = db_query("SELECT * FROM {variable} WHERE name LIKE '%s'", 'gallery_%');
while ($var = db_fetch_object($result)) {
$variables[$var->name] = $var->value;
}
// Remove old variables
db_query("DELETE FROM {variable} WHERE name LIKE 'gallery_%'");
db_query("DELETE FROM {variable} WHERE name LIKE '%s'", 'gallery_%');
// Migrate old variables
foreach ($migrate as $old => $new) {
......@@ -183,13 +193,13 @@ function gallery_update_variables($migrate, $obsolete) {
$ret[] = array('success' => TRUE, 'query' => 'Removing variable ['. $var .']');
}
}
// Save resulting variables array
// (all variables not migrated or unset are taken over directly)
foreach ($variables as $name => $value) {
foreach ($variables as $name => $serialized_value) {
// We dont use variable_set() to reduce overhead
// (i.e. unserialize => serialize and cache_clear_all() for each variable)
db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", $name, $value);
// (i.e. unserialize/serialize cache_clear_all() for each variable)
// Cannot use update_sql with % substitution.
db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", $name, $serialized_value);
}
return $ret;
......@@ -200,7 +210,7 @@ function gallery_update_variables($migrate, $obsolete) {
*/
function gallery_uninstall() {
// Remove all gallery related variables and blocks
db_query("DELETE FROM {variable} WHERE name LIKE 'gallery_%'");
db_query("DELETE FROM {blocks} WHERE module = 'gallery'");
db_query("DELETE FROM {variable} WHERE name LIKE '%s'", 'gallery_%');
db_query("DELETE FROM {blocks} WHERE module = '%s'", 'gallery');
cache_clear_all('variables', 'cache');
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment