class-wpml-upgrade-add-column-to-table.php
1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/**
* Abstract class to upgrade a table by adding a column to it.
*
* @package WPML
*/
/**
* Class WPML_Upgrade_Add_Column_To_Table
*/
abstract class WPML_Upgrade_Add_Column_To_Table implements IWPML_Upgrade_Command {
/**
* Get table name.
*
* @return string
*/
abstract protected function get_table();
/**
* Get column name.
*
* @return string
*/
abstract protected function get_column();
/**
* Get column definition.
*
* @return string
*/
abstract protected function get_column_definition();
/**
* Upgrade schema.
*
* @var WPML_Upgrade_Schema
*/
private $upgrade_schema;
/**
* WPML_Upgrade_Add_Column_To_Table constructor.
*
* @param array $args Arguments.
*/
public function __construct( array $args ) {
$this->upgrade_schema = $args[0];
}
/**
* Run the table upgrade.
*
* @return bool
*/
private function run() {
if ( $this->upgrade_schema->does_table_exist( $this->get_table() ) ) {
if ( ! $this->upgrade_schema->does_column_exist( $this->get_table(), $this->get_column() ) ) {
$this->upgrade_schema->add_column( $this->get_table(), $this->get_column(), $this->get_column_definition() );
}
}
return true;
}
/**
* Run in admin.
*
* @return bool
*/
public function run_admin() {
return $this->run();
}
/**
* Run in ajax.
*
* @return bool
*/
public function run_ajax() {
return $this->run();
}
/**
* Run in frontend.
*
* @return bool
*/
public function run_frontend() {
return $this->run();
}
/**
* Get upgrade results.
*
* @return bool
*/
public function get_results() {
return true;
}
}