You are here

function simplemeta_update_6200 in Simple Meta 6.2

Initinal update for 6.2.x

File

./simplemeta.install, line 74

Code

function simplemeta_update_6200(&$sandbox) {
  if (!isset($sandbox['progress'])) {
    $sandbox['progress'] = -1;
    $sandbox['total'] = db_result(db_query("SELECT COUNT(*) FROM {simplemeta_data}"));
    $sandbox['last'] = 0;
  }
  $ret = array();
  if ($sandbox['progress'] == -1) {
    $schema = _simplemeta_schema_6200();
    db_create_table($ret, 'simplemeta', $schema['simplemeta']);
    db_create_table($ret, 'cache_simplemeta', $schema['cache_simplemeta']);
    db_query("UPDATE {system} SET weight = %d WHERE type = '%s' AND name = '%s'", array(
      10,
      'module',
      'simplemeta',
    ));
    $sandbox['progress'] = 0;
    $ret['#finished'] = 0;
    return $ret;
  }
  $last = $sandbox['last'];
  $result = db_query("SELECT * FROM {simplemeta_data} WHERE sid > %d  ORDER BY sid ASC LIMIT 0, 50", $last);
  while ($row = db_fetch_object($result)) {
    $data = array(
      'title' => $row->title,
      'description' => $row->description,
      'keywords' => $row->keywords,
    );
    $query_args = array(
      $row->sid,
      $row->path,
      serialize($data),
    );
    db_query("INSERT INTO {simplemeta} (sid, path, data) VALUES (%d, '%s', %b)", $query_args);
    $sandbox['progress']++;
    $sandbox['last'] = $row->sid;
  }
  if ($last == $sandbox['last']) {
    $ret['#finished'] = 1;
  }
  else {
    $ret['#finished'] = $sandbox['total'] > 0 ? $sandbox['progress'] / $sandbox['total'] : 1;
  }
  if ($ret['#finished'] == 1) {
    db_drop_table($ret, 'simplemeta_data');
  }
  return $ret;
}