While upgrading from 7.x-2.0-beta3 to 7.x-2.2 some of the weight values are not pulled across to the new database table weight_weight.

The missing information only affects entities with id's after 249 (for me anyway).

Similar issues:
http://drupal.org/node/1509676

CommentFileSizeAuthor
weight_example_order.jpg98.03 KBswim

Comments

swim’s picture

So I had to quickly import my previous weighting values into the new schema.

warning; unclean code lives below.

/**
 * Grab old weighting data
 */
function upgrade_weight_values() {
  // Starting offset to provide 'batch' like importing.
  $offset = 3000;
  
  $query = db_select('field_data_weight', 'n');
  $query
    ->fields('n', array('entity_id', 'weight_value'))
    ->condition('n.entity_id', $offset, '>')
    ->orderBy('n.entity_id')
    ->range(0, 3000);
  $entities = $query->execute();
  
  foreach ($entities as $entity) {
    upgrade_weight_value_check($entity->entity_id, $entity->weight_value);
  } 
}

/**
 * Check if value exists & import.
 */
function upgrade_weight_value_check($entity_id, $weight_value) {
  $query = db_select('weight_weights', 'n');
  $query
    ->fields('n', array('entity_id', 'weight'))
    ->condition('n.entity_id', $entity_id)
    ->range(0, 3000);
  $weights = $query->execute();

  foreach ($weights as $weight) {
    // Only target empty fields.
    if ($weight->weight == 0 && $weight->entity_id == $entity_id) {
      $query = db_update('weight_weights')
        ->fields(array(
          'weight' => $weight_value,
        ))
        ->condition('entity_id', $entity_id)
        ->execute();
    }
  }
}

The offset will need to be manually updated in relation to the range obv. Very basic & slap dash but it works.

davisben’s picture

All values should have been converted. Were there any entries in the error log related to this update?

swim’s picture

I only updated this module during my tests and received no errors relating to weight module or anything else.

I still have the old database and if you'd like I can test updating again. The site in question has around 100k + nodes, 30k of which implement the weight module.

swim’s picture

Issue summary: View changes

Updated description.

davisben’s picture

Issue summary: View changes
Status: Active » Closed (cannot reproduce)

I am unable to reproduce this.