WC_Integration_MaxMind_Geolocation::update_database
Updates the database used for geolocation queries.
Method of the class: WC_Integration_MaxMind_Geolocation{}
No Hooks.
Returns
null. Nothing (null).
Usage
$WC_Integration_MaxMind_Geolocation = new WC_Integration_MaxMind_Geolocation(); $WC_Integration_MaxMind_Geolocation->update_database( $new_database_path );
- $new_database_path(string|null)
- The path to the new database file. Null will fetch a new archive.
Default:null
WC_Integration_MaxMind_Geolocation::update_database() WC Integration MaxMind Geolocation::update database code WC 10.8.1
public function update_database( $new_database_path = null ) {
// Allow us to easily interact with the filesystem.
require_once ABSPATH . 'wp-admin/includes/file.php';
if ( ! WP_Filesystem() ) {
wc_get_logger()->warning( __( 'Failed to initialise WC_Filesystem API while trying to update the MaxMind Geolocation database.', 'woocommerce' ) );
return;
}
global $wp_filesystem;
// Remove any existing archives to comply with the MaxMind TOS.
$target_database_path = $this->database_service->get_database_path();
// If there's no database path, we can't store the database.
if ( empty( $target_database_path ) ) {
return;
}
if ( $wp_filesystem->exists( $target_database_path ) ) {
$wp_filesystem->delete( $target_database_path );
}
if ( isset( $new_database_path ) ) {
$tmp_database_path = $new_database_path;
} else {
// We can't download a database if there's no license key configured.
$license_key = $this->get_option( 'license_key' );
if ( empty( $license_key ) ) {
return;
}
$tmp_database_path = $this->database_service->download_database( $license_key );
if ( is_wp_error( $tmp_database_path ) ) {
wc_get_logger()->notice( $tmp_database_path->get_error_message(), array( 'source' => 'maxmind-geolocation' ) );
return;
}
}
// Move the new database into position.
$wp_filesystem->move( $tmp_database_path, $target_database_path, true );
$wp_filesystem->delete( dirname( $tmp_database_path ) );
}