PluginProbe
Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More / 2.6.2
Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More v2.6.2
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.10 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 47 releases
content-control / classes / Base / Upgrade.php

Upgrade.php in Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More 2.6.2, at classes/Base/Upgrade.php

171 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin controller.
4 *
5 * @copyright (c) 2021, Code Atlantic LLC.
6 *
7 * @package ContentControl
8 */
9
10 namespace ContentControl\Base;
11
12 defined( 'ABSPATH' ) || exit;
13
14 use Closure;
15 use stdClass;
16
17 /**
18 * Base Upgrade class.
19 */
20 abstract class Upgrade implements \ContentControl\Interfaces\Upgrade {
21
22 /**
23 * Type.
24 *
25 * @var string Uses data versioning types.
26 */
27 const TYPE = '';
28
29 /**
30 * Version.
31 *
32 * @var int
33 */
34 const VERSION = 1;
35
36 /**
37 * Stream.
38 *
39 * @var \ContentControl\Services\UpgradeStream|null
40 */
41 public $stream;
42
43 /**
44 * Upgrade constructor.
45 */
46 public function __construct() {
47 }
48
49 /**
50 * Upgrade label
51 *
52 * @return string
53 */
54 abstract public function label();
55
56 /**
57 * Return full description for this upgrade.
58 *
59 * @return string
60 */
61 public function description() {
62 return '';
63 }
64
65 /**
66 * Check if the upgrade is required.
67 *
68 * @return bool
69 */
70 public function is_required() {
71 $current_version = \ContentControl\get_data_version( static::TYPE );
72 return $current_version && $current_version < static::VERSION;
73 }
74
75 /**
76 * Get the type of upgrade.
77 *
78 * @return string
79 */
80 public function get_type() {
81 return static::TYPE;
82 }
83
84 /**
85 * Check if the prerequisites are met.
86 *
87 * @return bool
88 */
89 public function prerequisites_met() {
90 return true;
91 }
92
93 /**
94 * Get the dependencies for this upgrade.
95 *
96 * @return string[]
97 */
98 public function get_dependencies() {
99 return [];
100 }
101
102 /**
103 * Run the upgrade.
104 *
105 * @return void|\WP_Error|false
106 */
107 abstract public function run();
108
109 /**
110 * Run the upgrade.
111 *
112 * @param \ContentControl\Services\UpgradeStream $stream Stream.
113 *
114 * @return bool|\WP_Error
115 */
116 public function stream_run( $stream ) {
117 $this->stream = $stream;
118
119 $return = $this->run();
120
121 unset( $this->stream );
122
123 if ( is_bool( $return ) || is_wp_error( $return ) ) {
124 return $return;
125 }
126
127 return true;
128 }
129
130 /**
131 * Return the stream.
132 *
133 * If no stream is available it returns a mock object with no-op methods to prevent errors.
134 *
135 * @return \ContentControl\Services\UpgradeStream|(object{
136 * send_event: Closure,
137 * send_error: Closure,
138 * send_data: Closure,
139 * update_status: Closure,
140 * update_task_status: Closure,
141 * start_upgrades: Closure,
142 * complete_upgrades: Closure,
143 * start_task: Closure,
144 * update_task_progress:Closure,
145 * complete_task: Closure
146 * }&\stdClass) Stream.
147 */
148 public function stream() {
149 $noop =
150 /**
151 * No-op.
152 *
153 * @return void
154 */
155 function () {};
156
157 return is_a( $this->stream, '\ContentControl\Services\UpgradeStream' ) ? $this->stream : (object) [
158 'send_event' => $noop,
159 'send_error' => $noop,
160 'send_data' => $noop,
161 'update_status' => $noop,
162 'update_task_status' => $noop,
163 'start_upgrades' => $noop,
164 'complete_upgrades' => $noop,
165 'start_task' => $noop,
166 'update_task_progress' => $noop,
167 'complete_task' => $noop,
168 ];
169 }
170 }
171