public function Ip2CountryCommands::update in IP-based Determination of a Visitor's Country 8
Updates the Ip2Country database from a Regional Internet Registry.
@command ip2country:update @aliases ip-update,ip2country-update
@option registry Registry used to obtain data. Can be one of afrnic, apnic, arin, lapnic, or ripe. @option md5 Validate data integrity with MD5 checksum. @option batch_size Row insertion batch size. Defaults to '200' rows per insert.
@usage drush ip2country:update --registry=ripe Updates Ip2Country database of ip/country associations. @usage drush ip2country:update --registry=apnic --batch_size=200 --md5 Updates Ip2Country database with a batch size of 200 rows and verifies the updated data with the MD5 checksum.
@validate-module-enabled ip2country
Parameters
array $options: Registry used to obtain data.
File
- src/
Commands/ Ip2CountryCommands.php, line 112
Class
- Ip2CountryCommands
- Drush 9+ commands for the IP2Country module.
Namespace
Drupal\ip2country\CommandsCode
public function update(array $options = [
'registry' => NULL,
'batch_size' => NULL,
]) {
$ip2country_config = $this->configFactory
->get('ip2country.settings');
$watchdog = $ip2country_config
->get('watchdog');
if (empty($options['registry'])) {
$options['registry'] = $ip2country_config
->get('rir');
}
if (empty($options['md5'])) {
$options['md5'] = $ip2country_config
->get('md5_checksum');
}
if (empty($options['batch_size'])) {
$options['batch_size'] = $ip2country_config
->get('batch_size');
}
// Tell the user we're working on it ...
$this->output
->write(dt('Updating ... '), FALSE);
$status = $this->ip2countryManager
->updateDatabase((string) $options['registry'], (bool) $options['md5_checksum'], (int) $options['batch_size']);
if ($status != FALSE) {
$this->output
->writeln(dt('Completed.'));
$this->output
->writeln(dt('Database updated from @registry server. Table contains @rows rows.', [
'@registry' => mb_strtoupper($options['registry']),
'@rows' => $status,
]));
// Log update to watchdog, if ip2country logging is enabled.
if ($watchdog) {
\Drupal::logger('ip2country')
->notice('Drush-initiated database update from @registry server.', [
'@registry' => mb_strtoupper($options['registry']),
]);
}
}
else {
$this->output
->writeln(dt('Failed.'));
$this->output
->writeln(dt('Database update from @registry server FAILED.', [
'@registry' => mb_strtoupper($options['registry']),
]));
// Log update failure to watchdog, if ip2country logging is enabled.
if ($watchdog) {
\Drupal::logger('ip2country')
->warning('Drush-initiated database update from @registry server FAILED.', [
'@registry' => mb_strtoupper($options['registry']),
]);
}
}
}