PluginProbe
Stream – Activity Log & Audit Trail / 3.8.0
Stream – Activity Log & Audit Trail v3.8.0
4.4.0 4.3.0 4.2.2 4.2.1 trunk 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.1 3.1.1 3.10.0 3.2.0 3.2.1 3.2.2 3.2.3 All 50 releases
← All changes | classes/class-install.php +29 -98 3.2.33.8.0 View file →
@@ -1,10 +1,20 @@
1 1 <?php
2 +/**
3 + * Handles database migrations
4 + *
5 + * @package WP_Stream
6 + */
7 +
2 8 namespace WP_Stream;
3 9
10 +/**
11 + * Class - Install
12 + */
4 13 class Install {
5 14 /**
6 - * Hold Plugin class
15 + * Holds Instance of plugin object
16 + *
7 17 * @var Plugin
8 18 */
9 19 public $plugin;
10 20
@@ -51,8 +61,10 @@
51 61 public $success_db;
52 62
53 63 /**
54 64 * Class constructor
65 + *
66 + * @param Plugin $plugin Instance of plugin object.
55 67 */
56 68 public function __construct( $plugin ) {
57 69 $this->plugin = $plugin;
58 70
@@ -58,14 +70,8 @@
58 70
59 71 $this->db_version = $this->get_db_version();
60 72 $this->stream_url = self_admin_url( $this->plugin->admin->admin_parent_page . '&page=' . $this->plugin->admin->settings_page_slug );
61 73
62 - // Check DB and display an admin notice if there are tables missing
63 - add_action( 'init', array( $this, 'verify_db' ) );
64 -
65 - // Install the plugin
66 - add_action( 'wp_stream_before_db_notices', array( $this, 'check' ) );
67 -
68 74 register_activation_hook( $this->plugin->locations['plugin'], array( $this, 'check' ) );
69 75 }
70 76
71 77 /**
@@ -96,9 +102,11 @@
96 102
97 103 if ( ! $update ) {
98 104 $this->update_required = true;
99 105 $this->success_db = $this->update(
100 - $this->db_version, $this->plugin->get_version(), array(
106 + $this->db_version,
107 + $this->plugin->get_version(),
108 + array(
101 109 'type' => 'auto',
102 110 )
103 111 );
104 112 }
@@ -104,9 +112,11 @@
104 112 }
105 113
106 114 if ( 'update_and_continue' === $update ) {
107 115 $this->success_db = $this->update(
108 - $this->db_version, $this->plugin->get_version(), array(
116 + $this->db_version,
117 + $this->plugin->get_version(),
118 + array(
109 119 'type' => 'user',
110 120 )
111 121 );
112 122 }
@@ -121,93 +131,12 @@
121 131 $this->update_db_option();
122 132 }
123 133
124 134 /**
125 - * Verify that the required DB tables exists
126 - *
127 - * @return void
128 - */
129 - public function verify_db() {
130 - /**
131 - * Filter will halt install() if set to true
132 - *
133 - * @param bool
134 - *
135 - * @return bool
136 - */
137 - if ( apply_filters( 'wp_stream_no_tables', false ) ) {
138 - return;
139 - }
140 -
141 - if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
142 - require_once ABSPATH . '/wp-admin/includes/plugin.php';
143 - }
144 -
145 - /**
146 - * Fires before admin notices are triggered for missing database tables.
147 - */
148 - do_action( 'wp_stream_before_db_notices' );
149 -
150 - global $wpdb;
151 -
152 - $database_message = '';
153 - $uninstall_message = '';
154 -
155 - // Check if all needed DB is present
156 - $missing_tables = array();
157 -
158 - foreach ( $this->plugin->db->get_table_names() as $table_name ) {
159 - $table_search = $wpdb->get_var(
160 - $wpdb->prepare( 'SHOW TABLES LIKE %s', $table_name )
161 - );
162 - if ( $table_search !== $table_name ) {
163 - $missing_tables[] = $table_name;
164 - }
165 - }
166 -
167 - if ( $missing_tables ) {
168 - $database_message .= sprintf(
169 - '%s <strong>%s</strong>',
170 - _n(
171 - 'The following table is not present in the WordPress database:',
172 - 'The following tables are not present in the WordPress database:',
173 - count( $missing_tables ),
174 - 'stream'
175 - ),
176 - esc_html( implode( ', ', $missing_tables ) )
177 - );
178 - }
179 -
180 - if ( is_plugin_active_for_network( $this->plugin->locations['plugin'] ) && current_user_can( 'manage_network_plugins' ) ) {
181 - $uninstall_message = sprintf(
182 - // translators: Placeholders refer to HTML Link tags (e.g. "<a href="https://foo.com/wp-admin/">")
183 - __( 'Please %1$suninstall%2$s the Stream plugin and activate it again.', 'stream' ),
184 - '<a href="' . network_admin_url( 'plugins.php#stream' ) . '">',
185 - '</a>'
186 - );
187 - } elseif ( current_user_can( 'activate_plugins' ) ) {
188 - $uninstall_message = sprintf(
189 - // translators: Placeholders refer to HTML Link tags (e.g. "<a href="https://foo.com/wp-admin/">")
190 - __( 'Please %1$suninstall%2$s the Stream plugin and activate it again.', 'stream' ),
191 - '<a href="' . admin_url( 'plugins.php#stream' ) . '">',
192 - '</a>'
193 - );
194 - }
195 -
196 - if ( ! empty( $database_message ) ) {
197 - $this->plugin->admin->notice( $database_message );
198 -
199 - if ( ! empty( $uninstall_message ) ) {
200 - $this->plugin->admin->notice( $uninstall_message );
201 - }
202 - }
203 - }
204 -
205 - /**
206 135 * Register a routine to be called when stream or a stream connector has been updated
207 136 * It works by comparing the current version with the version previously stored in the database.
208 137 *
209 - * @param string $file A reference to the main plugin file
138 + * @param string $file A reference to the main plugin file.
210 139 * @param string $callback The function to run when the hook is called.
211 140 * @param string $version The version to which the plugin is updating.
212 141 *
213 142 * @return void
@@ -218,9 +147,9 @@
218 147 }
219 148
220 149 $plugin = plugin_basename( $file );
221 150
222 - if ( is_plugin_active_for_network( $plugin ) ) {
151 + if ( $this->plugin->is_network_activated() ) {
223 152 $current_versions = get_site_option( $this->option_key . '_connectors', array() );
224 153 $network = true;
225 154 } elseif ( is_plugin_active( $plugin ) ) {
226 155 $current_versions = get_option( $this->option_key . '_connectors', array() );
@@ -242,8 +171,10 @@
242 171 }
243 172 }
244 173
245 174 /**
175 + * Returns the database version.
176 + *
246 177 * @return string
247 178 */
248 179 public function get_db_version() {
249 180 return get_site_option( $this->option_key );
@@ -249,9 +180,9 @@
249 180 return get_site_option( $this->option_key );
250 181 }
251 182
252 183 /**
253 - * @return void
184 + * Checks if migration was successful.
254 185 */
255 186 public function update_db_option() {
256 187 if ( $this->success_db ) {
257 188 $success_op = update_site_option( $this->option_key, $this->plugin->get_version() );
@@ -338,9 +269,9 @@
338 269 <p><strong><?php esc_html_e( 'Update Complete', 'stream' ); ?></strong></p>
339 270 <p>
340 271 <?php
341 272 printf(
342 - // translators: Placeholders refer to version numbers (e.g. "4.2")
273 + /* translators: %1$s: old version, %2$s: new version (e.g. "4.2") */
343 274 esc_html__( 'Your Stream database has been successfully updated from %1$s to %2$s!', 'stream' ),
344 275 esc_html( $this->db_version ),
345 276 esc_html( $this->plugin->get_version() )
346 277 );
@@ -381,11 +312,11 @@
381 312
382 313 /**
383 314 * Database user controlled update routine
384 315 *
385 - * @param int $db_version
386 - * @param int $current_version
387 - * @param array $update_args
316 + * @param int $db_version Next database version.
317 + * @param int $current_version Current database version.
318 + * @param array $update_args Update options.
388 319 *
389 320 * @return mixed Version number on success, true on no update needed, mysql error message on error
390 321 */
391 322 public function update( $db_version, $current_version, $update_args ) {
@@ -413,9 +344,9 @@
413 344
414 345 /**
415 346 * Initial database install routine
416 347 *
417 - * @param string $current_version
348 + * @param string $current_version Current database version.
418 349 *
419 350 * @return string
420 351 */
421 352 public function install( $current_version ) {