| 1 |
<?php |
| 2 |
/** |
| 3 |
* Models |
| 4 |
* |
| 5 |
* @package Models |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace LassoLite\Models; |
| 9 |
|
| 10 |
/** |
| 11 |
* Model |
| 12 |
*/ |
| 13 |
class Revert extends Model { |
| 14 |
/** |
| 15 |
* Table name |
| 16 |
* |
| 17 |
* @var string |
| 18 |
*/ |
| 19 |
protected $table = 'lasso_lite_revert'; |
| 20 |
|
| 21 |
/** |
| 22 |
* Columns of the table |
| 23 |
* |
| 24 |
* @var array |
| 25 |
*/ |
| 26 |
protected $columns = array( |
| 27 |
'id', |
| 28 |
'lasso_id', |
| 29 |
'post_data', |
| 30 |
'old_uri', |
| 31 |
'plugin', |
| 32 |
|
| 33 |
'revert_dt', |
| 34 |
); |
| 35 |
|
| 36 |
/** |
| 37 |
* Primary key of the table |
| 38 |
* |
| 39 |
* @var string |
| 40 |
*/ |
| 41 |
protected $primary_key = 'id'; |
| 42 |
|
| 43 |
/** |
| 44 |
* Create table |
| 45 |
*/ |
| 46 |
public function create_table() { |
| 47 |
$columns_sql = ' |
| 48 |
id bigint(10) NOT NULL AUTO_INCREMENT, |
| 49 |
lasso_id bigint(20) NOT NULL, |
| 50 |
post_data text NULL, |
| 51 |
old_uri varchar(500) NOT NULL, |
| 52 |
plugin varchar(200) NOT NULL, |
| 53 |
revert_dt datetime NOT NULL, |
| 54 |
PRIMARY KEY (id), |
| 55 |
KEY ix_lasso_id (lasso_id) |
| 56 |
'; |
| 57 |
$sql = ' |
| 58 |
CREATE TABLE ' . $this->get_table_name() . ' ( |
| 59 |
' . $columns_sql . ' |
| 60 |
) ' . $this->get_charset_collate(); |
| 61 |
|
| 62 |
return $this->modify_table( $sql, $this->get_table_name() ); |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Update DB structure and data for v228 |
| 67 |
*/ |
| 68 |
public function update_for_v228() { |
| 69 |
// ? change datetime column to not null |
| 70 |
$query = ' |
| 71 |
ALTER TABLE ' . $this->get_table_name() . ' |
| 72 |
CHANGE `revert_dt` `revert_dt` DATETIME NOT NULL |
| 73 |
'; |
| 74 |
self::query( $query ); |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Add lasso_id index for revert lookups (v152+). |
| 79 |
*/ |
| 80 |
public function update_for_v152() { |
| 81 |
$index_name = 'ix_lasso_id'; |
| 82 |
$table = $this->get_table_name(); |
| 83 |
$exists = self::get_var( |
| 84 |
"SHOW INDEX FROM {$table} WHERE Key_name = '{$index_name}'" |
| 85 |
); |
| 86 |
if ( ! $exists ) { |
| 87 |
self::query( "ALTER TABLE {$table} ADD KEY {$index_name} (lasso_id)" ); |
| 88 |
} |
| 89 |
} |
| 90 |
} |
| 91 |
|