AddPrimaryKeyToTable.php
956 Bytes
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
<?php
namespace WPML\Upgrade\Commands;
abstract class AddPrimaryKeyToTable extends \WPML_Upgrade_Run_All {
/**
* @return string
*/
abstract protected function get_table();
/**
* @return string
*/
abstract protected function get_key_name();
/**
* @return array
*/
abstract protected function get_key_columns();
/**
* @var \WPML_Upgrade_Schema
*/
private $upgrade_schema;
/**
* @param array $args
*/
public function __construct( array $args ) {
$this->upgrade_schema = $args[0];
}
/**
* @return bool
*/
protected function run() {
$this->result = false;
if ( $this->upgrade_schema->does_table_exist( $this->get_table() ) ) {
if ( ! $this->upgrade_schema->does_key_exist( $this->get_table(), $this->get_key_name() ) ) {
$this->result = $this->upgrade_schema->add_primary_key( $this->get_table(), $this->get_key_columns() );
} else {
$this->result = true;
}
}
return $this->result;
}
}