You are here

function nodewords_update_6113 in Nodewords: D6 Meta Tags 6.2

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

Implements hook_update_N().

1 string reference to 'nodewords_update_6113'
nodewords_admin_install in nodewords_admin/nodewords_admin.install
Implements hook_install().

File

./nodewords.install, line 330
Install, update and uninstall functions for the 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');
  }
  return $ret;
}