PluginMeta_2.php
1.56 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
<?php
/**
* Content Control Migrations
*
* @package ContentControl\Plugin
*/
namespace ContentControl\Upgrades;
defined( 'ABSPATH' ) || exit;
/**
* Version 2 migration.
*/
class PluginMeta_2 extends \ContentControl\Base\Upgrade {
const TYPE = 'plugin_meta';
const VERSION = 2;
/**
* Get the label for the upgrade.
*
* @return string
*/
public function label() {
return __( 'Update plugin meta', 'content-control' );
}
/**
* Get the dependencies for this upgrade.
*
* @return string[]
*/
public function get_dependencies() {
return [
'backup-2',
];
}
/**
* Get the remaps for this upgrade.
*
* @var array<string,string>
*/
private $remaps = [
'jp_cc_reviews_installed_on' => 'content_control_installed_on',
];
/**
* Check if the upgrade is required.
*
* @return bool
*/
public function is_required() {
$remaps = $this->remaps;
foreach ( $remaps as $key => $new_key ) {
$value = \get_option( $key, null );
if ( null !== $value ) {
return true;
}
}
return false;
}
/**
* Run the upgrade.
*
* @return void
*/
public function run() {
// Gets a stream or mock stream for sending events.
$stream = $this->stream();
$stream->start_task( __( 'Migrating plugin meta', 'content-control' ) );
$remaps = $this->remaps;
foreach ( $remaps as $key => $new_key ) {
$value = \get_option( $key, null );
if ( null !== $value ) {
\update_option( $new_key, $value );
\delete_option( $key );
}
}
$stream->complete_task( __( 'Plugin meta migrated', 'content-control' ) );
}
}