You are here

function nodewords_update_6158 in Nodewords: D6 Meta Tags 6

Same name and namespace in other branches
  1. 6.2 nodewords.install \nodewords_update_6158()

Implements hook_update_N().

File

./nodewords.install, line 1108
Installation file for nodewords.module.

Code

function nodewords_update_6158(&$sandbox) {
  $names = array(
    'dc.date',
    'location',
    'robots',
  );
  $ret = array();
  if (!isset($sandbox['progress'])) {
    $sandbox['progress'] = 0;
    $sandbox['max'] = (int) db_result(db_query("SELECT COUNT(*) FROM {nodewords}"));
    $sandbox['current_mtid'] = 0;
  }
  if ($sandbox['max']) {
    $metatags = db_query_range("SELECT * FROM {nodewords} WHERE mtid > %d ORDER BY mtid ASC", $sandbox['current_mtid'], 0, 20);
    while ($metatag = db_fetch_object($metatags)) {
      if (!in_array($metatag->name, $names)) {

        // Verify if the meta tag content has been already serialized, and
        // serialize it if it is not.
        // The error is being suppressed because if unserialize() returns an error,
        // then the passed value has not been serialiazed.
        if (@unserialize($metatag->content) === FALSE) {
          $content = serialize(array(
            'value' => $metatag->content,
          ));
          db_query("UPDATE {nodewords} SET content = '%s' WHERE mtid = %d", $content, $metatag->mtid);
        }
      }
      $sandbox['current_mtid'] = $metatag->mtid;
      $sandbox['progress']++;
    }
  }
  $ret['#finished'] = empty($sandbox['max']) ? 1 : $sandbox['progress'] / $sandbox['max'];
  if ($ret['#finished'] == 1) {
    variable_set('nodewords_update_6156', TRUE);
  }
  return $ret;
}