function weight_update_7202 in Weight 7.2
Move existing node weights to weight_weights table and restore sticky values.
File
- ./
weight.install, line 217
Code
function weight_update_7202(&$sandbox) {
if (!isset($sandbox['progress'])) {
$sandbox['progress'] = 0;
$sandbox['last'] = 0;
$sandbox['max'] = db_query("SELECT COUNT(nid) FROM {node}")
->fetchField();
}
$query = db_select('node', 'n');
$query
->fields('n', array(
'nid',
'type',
'sticky',
))
->condition('n.nid', $sandbox['last'], '>')
->orderBy('n.nid')
->range(0, 200);
$nodes = $query
->execute();
foreach ($nodes as $node) {
$values = _weight_update_7202_decode($node->sticky);
if ($values['weight'] != NULL) {
$query = db_insert('weight_weights')
->fields(array(
'entity_id' => $node->nid,
'entity_type' => 'node',
'weight' => $values['weight'],
))
->execute();
}
db_update('node')
->fields(array(
'sticky' => $values['sticky'],
))
->condition('nid', $node->nid)
->execute();
db_update('node_revision')
->fields(array(
'sticky' => $values['sticky'],
))
->condition('nid', $node->nid)
->execute();
$sandbox['progress']++;
$sandbox['last'] = $node->nid;
}
$sandbox['#finished'] = empty($sandbox['max']) ? 1 : $sandbox['progress'] / $sandbox['max'];
}