You are here

function panelizer_update_7302 in Panelizer 7.3

Set the storage type and ID on existing {panelizer_default} records.

1 call to panelizer_update_7302()
panelizer_update_7304 in ./panelizer.install
Rerun update 7302. Set the storage type and ID on existing {panelizer_default} records.

File

./panelizer.install, line 1251
Install, update and uninstall functions for the panelizer module.

Code

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

    // Initialize batch update information.
    $sandbox['progress'] = (double) 0;
    $sandbox['current_did'] = -1;
    $sandbox['max'] = db_query("SELECT COUNT(p.did)\n      FROM {panels_display} pd\n        JOIN {panelizer_defaults} p ON p.did = pd.did\n      WHERE p.name IS NOT NULL AND pd.storage_type = ''")
      ->fetchField();
    if (empty($sandbox['max'])) {
      return t('Nothing to be fixed in Panelizer update 7302.');
    }
  }

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

  // Run the query.
  $result = db_query_range("SELECT p.did, p.name\n    FROM {panels_display} pd\n      JOIN {panelizer_defaults} p ON p.did = pd.did\n    WHERE p.name IS NOT NULL AND pd.storage_type = '' AND p.did > :current_did\n    ORDER BY p.did ASC", 0, $limit, array(
    ':current_did' => $sandbox['current_did'],
  ));

  // No results means that it's finished.
  if (empty($result)) {
    $sandbox['progress'] = $sandbox['max'];
  }
  else {
    foreach ($result as $row) {
      db_update('panels_display')
        ->fields(array(
        'storage_type' => 'panelizer_default',
        'storage_id' => $row->name,
      ))
        ->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 panelizer_defaults to relevant panels displays');
  }
}