Updater.php
982 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
57
58
59
<?php
namespace AC\Plugin;
abstract class Updater {
/**
* @var Update[]
*/
protected $updates;
/**
* @param Version|null $version
*
* @return bool
*/
abstract protected function update_stored_version( Version $version = null );
/**
* @return bool
*/
abstract public function is_new_install();
/**
* @param Update $update
*
* @return $this
*/
public function add_update( Update $update ) {
$this->updates[ $update->get_version() ] = $update;
return $this;
}
public function parse_updates() {
if ( $this->is_new_install() ) {
$this->update_stored_version();
return;
}
if ( empty( $this->updates ) ) {
return;
}
// Sort by version number
uksort( $this->updates, 'version_compare' );
foreach ( $this->updates as $update ) {
if ( $update->needs_update() ) {
$update->apply_update();
$this->update_stored_version( new Version( $update->get_version() ) );
}
}
$this->update_stored_version();
}
}