You are here

function panels_update_6292 in Panels 6.3

Update panels pane fields using batch API.

File

./panels.install, line 938

Code

function panels_update_6292(&$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_pane}'));
  }

  // configuration
  $result = db_query_range("SELECT pid, access, configuration FROM {panels_pane} ORDER BY pid ASC", $sandbox['progress'], 20);
  while ($pane = db_fetch_object($result)) {

    // access
    if (!empty($pane->access)) {
      $rids = explode(', ', $pane->access);

      // For safety, eliminate any non-numeric rids, as we occasionally had
      // problems with nulls and such getting in here:
      foreach ($rids as $id => $rid) {
        if (!is_numeric($rid)) {
          unset($rids[$id]);
        }
      }
      if (empty($rids)) {
        $pane->access = array();
      }
      else {

        // The old access style was just a role based system, so let's convert
        // it to that.
        $pane->access = array(
          'plugins' => array(
            array(
              'name' => 'role',
              'context' => 'logged-in-user',
              'settings' => array(
                'rids' => array_values($rids),
              ),
            ),
          ),
        );
      }
    }
    else {
      $pane->access = array();
    }

    // Move style from configuration.
    $pane->configuration = unserialize($pane->configuration);
    $pane->style = array();
    if (!empty($pane->configuration['style'])) {
      $pane->style['style'] = $pane->configuration['style'];
      unset($pane->configuration['style']);
    }
    $pane->css = array();

    // Move css configuration from configuration
    if (isset($pane->configuration['css_id'])) {
      $pane->css['css_id'] = $pane->configuration['css_id'];
      unset($pane->configuration['css_id']);
    }
    if (isset($pane->configuration['css_class'])) {
      $pane->css['css_class'] = $pane->configuration['css_class'];
      unset($pane->configuration['css_class']);
    }

    // Make sure extras is an array. This isn't used by anything in Panels
    // yet, so an empty array is just fine.
    $pane->extras = array();
    db_query("UPDATE {panels_pane} SET " . "access = '%s', css = '%s', style = '%s', configuration = '%s', extras = '%s'" . " WHERE pid = %d", serialize($pane->access), serialize($pane->css), serialize($pane->style), serialize($pane->configuration), serialize($pane->extras), $pane->pid);
    $sandbox['progress']++;
  }
  $ret['#finished'] = empty($sandbox['max']) ? 1 : $sandbox['progress'] / $sandbox['max'];
  if ($ret['#finished'] === 1) {
    $ret[] = array(
      'success' => TRUE,
      'query' => t('Panel panes were updated'),
    );
  }
  return $ret;
}