2017-08-08 12:06:05 +02:00
|
|
|
<?php if ( ! defined( 'ABSPATH' ) ) exit;
|
|
|
|
|
|
|
|
|
|
require_once( ABSPATH . 'wp-admin/includes/upgrade.php');
|
|
|
|
|
|
|
|
|
|
abstract class NF_Abstracts_Migration
|
|
|
|
|
{
|
|
|
|
|
public $table_name = '';
|
|
|
|
|
|
|
|
|
|
public $charset_collate = '';
|
|
|
|
|
|
|
|
|
|
public $flag = '';
|
|
|
|
|
|
|
|
|
|
public function __construct( $table_name, $flag )
|
|
|
|
|
{
|
|
|
|
|
$this->table_name = $table_name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function table_name()
|
|
|
|
|
{
|
|
|
|
|
global $wpdb;
|
|
|
|
|
return $wpdb->prefix . $this->table_name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function charset_collate()
|
|
|
|
|
{
|
|
|
|
|
global $wpdb;
|
2017-12-11 16:34:19 +01:00
|
|
|
return $wpdb->get_charset_collate();
|
2017-08-08 12:06:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function _run()
|
|
|
|
|
{
|
|
|
|
|
// Check the flag
|
|
|
|
|
if( get_option( $this->flag, FALSE ) ) return;
|
|
|
|
|
|
|
|
|
|
// Run the migration
|
|
|
|
|
$this->run();
|
|
|
|
|
|
|
|
|
|
// Set the Flag
|
|
|
|
|
update_option( $this->flag, TRUE );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected abstract function run();
|
|
|
|
|
|
|
|
|
|
public function _drop()
|
|
|
|
|
{
|
|
|
|
|
global $wpdb;
|
|
|
|
|
if( ! $this->table_name ) return;
|
2018-04-16 15:29:38 +02:00
|
|
|
if( 0 == $wpdb->query( $wpdb->prepare( "SHOW TABLES LIKE '%s'", $this->table_name() ) ) ) return;
|
|
|
|
|
$wpdb->query( "DROP TABLE " . $this->table_name() );
|
2017-08-08 12:06:05 +02:00
|
|
|
return $this->drop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function drop()
|
|
|
|
|
{
|
|
|
|
|
// This section intentionally left blank.
|
|
|
|
|
}
|
|
|
|
|
}
|