Update.php
958 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
51
52
53
54
55
56
<?php
namespace AC\Plugin;
abstract class Update {
/**
* @var string
*/
protected $stored_version;
/**
* @var string Assumes this regex for versions: ^[1-9]\.[0-9]\.[1-9][0-9]?$
*/
protected $version;
public function __construct( $stored_version ) {
$this->stored_version = $stored_version;
$this->set_version();
}
/**
* Check if this update needs to be applied
* @return bool
*/
public function needs_update() {
return $this->is_less_or_equal_stored_version();
}
/**
* @return bool
*/
protected function is_less_or_equal_stored_version() {
return version_compare( $this->version, $this->stored_version, '>' );
}
/**
* Apply this update
* @return void
*/
abstract public function apply_update();
/**
* @return string
*/
public function get_version() {
return $this->version;
}
/**
* Set the version this update applies to
* @return void
*/
abstract protected function set_version();
}