You are here

function nodewords_update_6113 in Nodewords: D6 Meta Tags 6

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

Implements hook_update_N().

2 string references to 'nodewords_update_6113'
nodewords_uninstall in ./nodewords.install
Implements hook_uninstall().
nodewords_update_6137 in ./nodewords.install
Implements hook_update_N().

File

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

Code

function nodewords_update_6113(&$sandbox) {
  $ret = array();
  if (!isset($sandbox['progress'])) {
    if (db_table_exists('nodewords_tmp')) {
      db_drop_table($ret, 'nodewords_tmp');
    }
    db_rename_table($ret, 'nodewords', 'nodewords_tmp');
    $sandbox['progress'] = 0;
    $sandbox['max'] = db_result(db_query("SELECT COUNT(*) FROM {nodewords_tmp}"));
    $schema['nodewords'] = array(
      'fields' => array(
        'mtid' => array(
          'type' => 'serial',
          'not null' => TRUE,
        ),
        'type' => array(
          'type' => 'varchar',
          'length' => 16,
          'not null' => TRUE,
          'default' => '',
        ),
        'id' => array(
          'type' => 'varchar',
          'length' => 255,
          'not null' => TRUE,
          'default' => '',
        ),
        'name' => array(
          'type' => 'varchar',
          'length' => 32,
          'not null' => TRUE,
          'default' => '',
        ),
        'content' => array(
          'type' => 'text',
          'size' => 'big',
          'not null' => TRUE,
        ),
      ),
      'indexes' => array(
        'nodewords_id' => array(
          array(
            'id',
            6,
          ),
        ),
        'nodewords_type' => array(
          array(
            'type',
            6,
          ),
        ),
      ),
      'unique keys' => array(
        'tin' => array(
          'type',
          'id',
          'name',
        ),
      ),
      'primary key' => array(
        'mtid',
      ),
    );
    db_create_table($ret, 'nodewords', $schema['nodewords']);
  }
  if ($sandbox['max']) {
    $metatags = db_query_range("SELECT * FROM {nodewords_tmp}", $sandbox['progress'], 10);
    while ($metatag = db_fetch_object($metatags)) {
      switch ($metatag->name) {
        case 'location':
          if (empty($metatag->content)) {
            $metatag->content = serialize(array(
              'latitude' => 0,
              'longitude' => 0,
            ));
          }
          else {
            $coordinates = array_map('trim', explode(',', $metatag->content));
            $coordinates[] = 0;
            $coordinates[] = 0;
            $coordinates = array_splice($coordinates, 0, 2);
            $metatag->content = serialize(array(
              'latitude' => $coordinates[0],
              'longitude' => $coordinates[1],
            ));
          }
          break;
        case 'robots':
          if (empty($metatag->content)) {
            $metatag->content = serialize(array(
              'value' => array(),
            ));
          }
          else {
            $content = array_map('trim', explode(',', $metatag->content));
            $new_content = array(
              'noarchive' => 0,
              'nofollow' => in_array('nofollow', $content) ? 'nofollow' : 0,
              'noindex' => in_array('noindex', $content) ? 'noindex' : 0,
              'noodp' => 0,
              'nosnippet' => 0,
              'noydir' => 0,
            );
            $metatag->content = serialize($new_content);
          }
          break;
      }
      db_query("INSERT INTO {nodewords} (type, id, name, content) VALUES ('%s', '%s', '%s', '%s')", $metatag->type, $metatag->id, $metatag->name, $metatag->content);
      $sandbox['progress']++;
    }
  }
  $ret['#finished'] = empty($sandbox['max']) ? 1 : $sandbox['progress'] / $sandbox['max'];
  if ($ret['#finished'] == 1) {
    db_drop_table($ret, 'nodewords_tmp');
    variable_set('nodewords_update_6113', TRUE);
  }
  return $ret;
}