You are here

function panels_node_update_7302 in Panels 7.3

Set the storage type and id on existing panels nodes.

File

panels_node/panels_node.install, line 130

Code

function panels_node_update_7302() {
  if (!isset($sandbox['progress'])) {

    // Initialize batch update information.
    $sandbox['progress'] = (double) 0;
    $sandbox['current_did'] = -1;
    $sandbox['max'] = db_query("SELECT COUNT(pd.did)\n         FROM {panels_display} pd\n           JOIN {panels_node} pn ON pn.did = pd.did\n         WHERE pd.storage_type = ''")
      ->fetchField();
  }

  // Set a limit of how many rows to process per batch.
  $limit = 1000;

  // Run the query.
  $result = db_query_range("SELECT pd.did, pn.nid\n      FROM {panels_display} pd\n        JOIN {panels_node} pn ON pn.did = pd.did\n      WHERE pd.storage_type = '' AND pd.did > :current_did", 0, $limit, array(
    ':current_did' => $sandbox['current_did'],
  ));
  foreach ($result as $row) {
    db_update('panels_display')
      ->fields(array(
      'storage_type' => 'panels_node',
      'storage_id' => $row->nid,
    ))
      ->condition('did', $row->did)
      ->execute();

    // Update our progress information.
    $sandbox['progress']++;
    $sandbox['current_did'] = $row->did;
  }

  // Set the "finished" status, to tell batch engine whether this function
  // needs to run again.
  $sandbox['#finished'] = $sandbox['progress'] >= $sandbox['max'] ? TRUE : $sandbox['progress'] / $sandbox['max'];
  if ($sandbox['#finished']) {
    return t('Added the storage type for panels_node to relevant panels displays');
  }
}