You are here

function menu_token_update_6000 in Menu Token 6

Implementation of hook_update_N().

File

./menu_token.install, line 51
Install file for menu_token module.

Code

function menu_token_update_6000() {
  $ret = array();
  $schema['menu_token'] = array(
    'description' => t('Menu token properties'),
    'fields' => array(
      'mlid' => array(
        'description' => t('The menu link {menu_links}.mlid'),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'link_path' => array(
        'description' => t('The actual path with tokens'),
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
    ),
    'primary key' => array(
      'mlid',
    ),
  );

  // Create schema.
  db_create_table($ret, 'menu_token', $schema['menu_token']);

  // Insert records.
  foreach (variable_get('menu_token_enabled', array()) as $mlid => $link_path) {
    $link_path = db_escape_string($link_path);
    $ret[] = update_sql("INSERT INTO {menu_token} (mlid, link_path) VALUES ({$mlid}, '{$link_path}')");
  }

  // Delete variable in case of all queries were successful.
  $success = true;
  foreach ($ret as $r) {
    $success = $success && $r['success'];
  }
  if ($success) {
    variable_del('menu_token_enabled');
  }
  return $ret;
}