You are here

function panels_update_6293 in Panels 6.3

Update panels display fields using batch API.

File

./panels.install, line 1034

Code

function panels_update_6293(&$sandbox) {
  $ret = array();
  if (!module_exists('panels')) {
    $ret['#abort'] = array(
      'success' => FALSE,
      'query' => t('The Panels module cannot be updated while disabled. If you wish to update Panels, please enable it. If you do not wish to update Panels, please uninstall it.'),
    );
    return $ret;
  }
  if (!isset($sandbox['progress'])) {
    $sandbox['progress'] = 0;

    // We'll -1 to disregard the uid 0...
    $sandbox['max'] = db_result(db_query('SELECT COUNT(*) FROM {panels_display}'));
  }

  // configuration
  $result = db_query_range("SELECT did, panel_settings FROM {panels_display} ORDER BY did ASC", $sandbox['progress'], 20);
  while ($display = db_fetch_object($result)) {
    if (empty($display->panel_settings)) {
      $display->panel_settings = array();
    }
    else {
      $display->panel_settings = unserialize($display->panel_settings);
      if (!is_array($display->panel_settings)) {
        $display->panel_settings = array();
      }
    }
    if (isset($display->panel_settings['panel'])) {
      foreach ($display->panel_settings['panel'] as $key => $settings) {
        $display->panel_settings[$key] = $settings;
      }
      unset($display->panel_settings['panel']);
    }
    if (isset($display->panel_settings['individual'])) {
      unset($display->panel_settings['individual']);
    }
    db_query("UPDATE {panels_display} SET " . "panel_settings = '%s'" . " WHERE did = %d", serialize($display->panel_settings), $display->did);
    $sandbox['progress']++;
  }
  $ret['#finished'] = empty($sandbox['max']) ? 1 : $sandbox['progress'] / $sandbox['max'];
  if ($ret['#finished'] === 1) {
    $ret[] = array(
      'success' => TRUE,
      'query' => t('Panel displays were updated'),
    );
  }
  return $ret;
}