You are here

function drush_ip2country_update in IP-based Determination of a Visitor's Country 7

Same name and namespace in other branches
  1. 8 ip2country.drush.inc \drush_ip2country_update()

Implements drush_hook_COMMAND() for the ip2country-update command.

Updates the database from the selected registry.

File

./ip2country.drush.inc, line 129

Code

function drush_ip2country_update() {
  module_load_include('inc', 'ip2country');
  $watchdog = variable_get('ip2country_watchdog', TRUE);
  $registry = (string) drush_get_option('registry', variable_get('ip2country_rir', 'arin'));
  drush_print(dt('Updating ... '), 0, NULL, FALSE);
  $status = ip2country_update_database($registry);
  if ($status != FALSE) {
    drush_print(dt('Completed.'));
    drush_print(dt('Database updated from @registry server. Table contains @rows rows.', array(
      '@registry' => mb_strtoupper($registry),
      '@rows' => $status,
    )));

    // Log update to watchdog, if ip2country logging is enabled.
    if ($watchdog) {
      watchdog('ip2country', 'Drush-initiated database update from @registry server.', array(
        '@registry' => mb_strtoupper($registry),
      ), WATCHDOG_NOTICE);
    }
  }
  else {
    drush_print(dt('Failed.'));
    drush_print(dt('Database update from @registry server FAILED.', array(
      '@registry' => mb_strtoupper($registry),
    )));

    // Log update failure to watchdog, if ip2country logging is enabled.
    if ($watchdog) {
      watchdog('ip2country', 'Drush-initiated database update from @registry server FAILED.', array(
        '@registry' => mb_strtoupper($registry),
      ), WATCHDOG_WARNING);
    }
  }
}