function sheetnode_update_6008 in Sheetnode 6
Implementation of hook_update_N(). Remove sheetnode serialization.
File
- ./
sheetnode.install, line 428
Code
function sheetnode_update_6008(&$sandbox) {
$ret = array();
// Set up Batch API loop to update sheetnodes and templates.
if (!isset($sandbox['progress'])) {
$sandbox['progress'] = 0;
$sandbox['sheetnode_current'] = 0;
$sandbox['sheetnode_max'] = db_result(db_query("SELECT COUNT(vid) FROM {sheetnode}")) + 0;
$sandbox['template_current'] = 0;
$sandbox['template_max'] = db_result(db_query("SELECT COUNT(tid) FROM {sheetnode_template}")) + 0;
$sandbox['max'] = $sandbox['sheetnode_max'] + $sandbox['template_max'];
}
if ($sandbox['progress'] < $sandbox['sheetnode_max']) {
$sheetnodes = db_query_range("SELECT vid, value FROM {sheetnode} WHERE vid > %d ORDER BY vid ASC", $sandbox['sheetnode_current'], 0, 1);
while ($sheetnode = db_fetch_object($sheetnodes)) {
if (!empty($sheetnode->value)) {
$value = db_escape_string(unserialize($sheetnode->value));
$ret[] = update_sql("UPDATE {sheetnode} SET value = '{$value}' WHERE vid = {$sheetnode->vid}");
}
$sandbox['progress']++;
$sandbox['sheetnode_current'] = $sheetnode->vid;
}
}
else {
$templates = db_query_range("SELECT tid, value FROM {sheetnode_template} WHERE tid > %d ORDER BY tid ASC", $sandbox['template_current'], 0, 1);
while ($template = db_fetch_object($templates)) {
if (!empty($template->value)) {
$value = db_escape_string(unserialize($template->value));
$ret[] = update_sql("UPDATE {sheetnode_template} SET value = '{$value}' WHERE tid = {$template->tid}");
}
$sandbox['progress']++;
$sandbox['template_current'] = $template->tid;
}
}
$ret['#finished'] = !$sandbox['max'] ? 1 : $sandbox['progress'] / $sandbox['max'];
return $ret;
}