<?php
// $Id: xmlsitemap_engines.install,v 1.5 2010/01/18 07:46:29 davereid Exp $

/**
 * @file
 * Install, update and uninstall functions for the xmlsitemap_engines module.
 */

/**
 * Implements hook_install().
 */
function xmlsitemap_engines_install() {
  // Set this module's weight to 1 so xmlsitemap_engines_cron() runs after
  // the sitemap has been generated in xmlsitemap_cron().
  db_update('system')
    ->fields(array('weight' => 2))
    ->condition('type', 'module')
    ->condition('name', 'xmlsitemap_engines')
    ->execute();
}

/**
 * Implements hook_uninstall().
 */
function xmlsitemap_engines_uninstall() {
  variable_del('xmlsitemap_engines_engines');
  variable_del('xmlsitemap_engines_custom_urls');
  variable_del('xmlsitemap_engines_minimum_lifetime');
  variable_del('xmlsitemap_engines_submit_last');
  variable_del('xmlsitemap_engines_submit_updated');
}

/**
 * Filter the xmlsitemap_engines_submit variable.
 */
function xmlsitemap_engines_update_1() {
  variable_set('xmlsitemap_engines_submit', array_filter(variable_get('xmlsitemap_engines_submit', array())));
}

/**
 * Rename the xmlsitemap_engines_engines variable to xmlsitemap_engines_submit.
 */
function xmlsitemap_engines_update_2() {
  variable_set('xmlsitemap_engines_engines', variable_get('xmlsitemap_engines_submit', array()));
  variable_del('xmlsitemap_engines_submit');
}

/**
 * Increase the module weight so it always runs after sitemap generation.
 */
function xmlsitemap_engines_update_3() {
  db_update('system')
    ->fields(array('weight' => 2))
    ->condition('type', 'module')
    ->condition('name', 'xmlsitemap_engines')
    ->execute();
}

/**
 * Update Windows Live search to Bing.
 */
function xmlsitemap_engines_update_4() {
  $engines = variable_get('xmlsitemap_engines_engines', array());
  $index = array_search('windows_live', $engines);
  if ($index !== FALSE) {
    $engines[$index] = 'bing';
  }
  variable_set('xmlsitemap_engines_engines', $engines);
}
