| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Config\Migrations; |
| 4 |
|
| 5 |
use Yoast\WP\Lib\Migrations\Migration; |
| 6 |
|
| 7 |
/** |
| 8 |
* CreateExpiringStoreTable class. |
| 9 |
* |
| 10 |
* Creates a network-wide table for reliable temporary storage with expiration. |
| 11 |
*/ |
| 12 |
class CreateExpiringStoreTable extends Migration { |
| 13 |
|
| 14 |
/** |
| 15 |
* The plugin this migration belongs to. |
| 16 |
* |
| 17 |
* @var string |
| 18 |
*/ |
| 19 |
public static $plugin = 'free'; |
| 20 |
|
| 21 |
/** |
| 22 |
* Migration up. |
| 23 |
* |
| 24 |
* @return void |
| 25 |
*/ |
| 26 |
public function up() { |
| 27 |
$table_name = $this->get_table_name(); |
| 28 |
$adapter = $this->get_adapter(); |
| 29 |
|
| 30 |
if ( ! $adapter->table_exists( $table_name ) ) { |
| 31 |
$table = $this->create_table( $table_name, [ 'id' => false ] ); |
| 32 |
|
| 33 |
$table->column( |
| 34 |
'key_name', |
| 35 |
'string', |
| 36 |
[ |
| 37 |
'limit' => 255, |
| 38 |
'null' => false, |
| 39 |
'primary_key' => true, |
| 40 |
], |
| 41 |
); |
| 42 |
|
| 43 |
$table->column( 'value', 'text', [ 'null' => false ] ); |
| 44 |
|
| 45 |
$table->column( 'exp', 'datetime', [ 'null' => false ] ); |
| 46 |
|
| 47 |
$table->finish(); |
| 48 |
|
| 49 |
$this->add_index( $table_name, 'exp', [ 'name' => 'exp_index' ] ); |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Migration down. |
| 55 |
* |
| 56 |
* @return void |
| 57 |
*/ |
| 58 |
public function down() { |
| 59 |
$this->drop_table( $this->get_table_name() ); |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Retrieves the table name to use. |
| 64 |
* |
| 65 |
* Uses base_prefix so the table is shared across the entire multisite network. |
| 66 |
* |
| 67 |
* @return string The table name to use. |
| 68 |
*/ |
| 69 |
protected function get_table_name() { |
| 70 |
global $wpdb; |
| 71 |
|
| 72 |
return $wpdb->base_prefix . 'yoast_expiring_store'; |
| 73 |
} |
| 74 |
} |
| 75 |
|