summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Davis2013-02-05 16:04:10 (GMT)
committer Ben Davis2013-02-05 16:04:10 (GMT)
commit3e155625e10e2bd33c8c8921ca483aae0fa4bae2 (patch)
tree466d4180af399d4023e71ff529a702da0af692ea
parent70024dc44a64d61211f2855858f41c3a1a27c888 (diff)
Issue #1773448 by davisben: Nodes with no weight not sorting properly.7.x-2.2
-rw-r--r--weight.install50
1 files changed, 50 insertions, 0 deletions
diff --git a/weight.install b/weight.install
index d02891f..c5f2044 100644
--- a/weight.install
+++ b/weight.install
@@ -330,6 +330,56 @@ function weight_update_7209() {
}
/**
+ * Ensure all nodes of enabled types have a weight.
+ */
+function weight_update_7210(&$sandbox) {
+ $types = array();
+ $defaults = array();
+ $result = db_query('SELECT type, weight_default FROM {weight_settings} WHERE weight_enabled=1');
+ foreach ($result as $row) {
+ $types[] = $row->type;
+ $defaults[$row->type] = $row->weight_default;
+ }
+
+ if (!empty($types)) {
+ if (!isset($sandbox['progress'])) {
+ $sandbox['progress'] = 0;
+ $sandbox['last'] = 0;
+ $sandbox['max'] = db_query("SELECT COUNT(n.nid) FROM {node} n
+ LEFT OUTER JOIN {weight_weights} w ON w.entity_id = n.nid
+ WHERE type IN (:types) AND w.entity_id IS NULL",
+ array(':types' => $types))->fetchField();
+ }
+
+ $query = db_select('node', 'n');
+ $query->leftJoin('weight_weights', 'w', 'w.entity_id = n.nid');
+ $query
+ ->fields('n', array('nid', 'type'))
+ ->condition('n.type', $types, 'IN')
+ ->condition('n.nid', $sandbox['last'], '>')
+ ->isNull('w.entity_id')
+ ->orderBy('n.nid')
+ ->range(0, 200);
+ $nodes = $query->execute();
+
+ foreach ($nodes as $node) {
+ db_insert('weight_weights')
+ ->fields(array(
+ 'entity_id' => $node->nid,
+ 'entity_type' => 'node',
+ 'weight' => $defaults[$node->type],
+ ))
+ ->execute();
+
+ $sandbox['progress']++;
+ $sandbox['last'] = $node->nid;
+ }
+
+ $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
+ }
+}
+
+/**
* Decode weight from sticky column.
*/
function _weight_update_7202_decode($sticky) {