PluginProbe
Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More / 2.0.4
Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More v2.0.4
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.0.4, at classes/Base/Upgrade.php

145 lines 2.4 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 /**
15 * Base Upgrade class.
16 */
17 abstract class Upgrade implements \ContentControl\Interfaces\Upgrade {
18
19 /**
20 * Type.
21 *
22 * @var string Uses data versioning types.
23 */
24 const TYPE = '';
25
26 /**
27 * Version.
28 *
29 * @var int
30 */
31 const VERSION = 1;
32
33 /**
34 * Stream.
35 *
36 * @var \ContentControl\Services\UpgradeStream
37 */
38 public $stream;
39
40 /**
41 * Upgrade constructor.
42 */
43 public function __construct() {
44 }
45
46 /**
47 * Upgrade label
48 *
49 * @return string
50 */
51 abstract public function label();
52
53 /**
54 * Return full description for this upgrade.
55 *
56 * @return string
57 */
58 public function description() {
59 return '';
60 }
61
62 /**
63 * Check if the upgrade is required.
64 *
65 * @return bool
66 */
67 public function is_required() {
68 $current_version = \ContentControl\get_data_version( static::TYPE );
69 return $current_version && $current_version < static::VERSION;
70 }
71
72 /**
73 * Get the type of upgrade.
74 *
75 * @return string
76 */
77 public function get_type() {
78 return static::TYPE;
79 }
80
81 /**
82 * Check if the prerequisites are met.
83 *
84 * @return bool
85 */
86 public function prerequisites_met() {
87 return true;
88 }
89
90 /**
91 * Get the dependencies for this upgrade.
92 *
93 * @return string[]
94 */
95 public function get_dependencies() {
96 return [];
97 }
98
99 /**
100 * Run the upgrade.
101 *
102 * @return void|WP_Error|false
103 */
104 abstract public function run();
105
106 /**
107 * Run the upgrade.
108 *
109 * @param \ContentControl\Services\UpgradeStream $stream Stream.
110 *
111 * @return void|WP_Error|false
112 */
113 public function stream_run( $stream ) {
114 $this->stream = $stream;
115
116 $return = $this->run();
117
118 unset( $this->stream );
119
120 return $return;
121 }
122
123 /**
124 * Return the stream.
125 *
126 * @return \ContentControl\Services\UpgradeStream|Object $stream Stream.
127 */
128 public function stream() {
129 $noop = function () {};
130
131 return isset( $this->stream ) ? $this->stream : (object) [
132 'send_event' => $noop,
133 'send_error' => $noop,
134 'send_data' => $noop,
135 'update_status' => $noop,
136 'update_task_status' => $noop,
137 'start_upgrades' => $noop,
138 'complete_upgrades' => $noop,
139 'start_task' => $noop,
140 'update_task_progress' => $noop,
141 'complete_task' => $noop,
142 ];
143 }
144 }
145