PluginProbe
Stream – Activity Log & Audit Trail / 3.4.2
Stream – Activity Log & Audit Trail v3.4.2
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 +73 -56 3.0.13.4.2 View file →
@@ -3,8 +3,9 @@
3 3
4 4 class Install {
5 5 /**
6 6 * Hold Plugin class
7 + *
7 8 * @var Plugin
8 9 */
9 10 public $plugin;
10 11
@@ -15,19 +16,12 @@
15 16 */
16 17 public $option_key = 'wp_stream_db';
17 18
18 19 /**
19 - * Holds the database table prefix
20 + * Holds version of database at last update
20 21 *
21 22 * @var string
22 23 */
23 - public $table_prefix;
24 -
25 - /**
26 - * Holds version of database at last update
27 -] *
28 - * @var string
29 - */
30 24 public $db_version;
31 25
32 26 /**
33 27 * URL to the Stream Admin settings page.
@@ -82,26 +76,14 @@
82 76 *
83 77 * @return void
84 78 */
85 79 public function check() {
86 - global $wpdb;
87 -
88 80 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
89 81 return;
90 82 }
91 83
92 - /**
93 - * Allows devs to alter the tables prefix, default to base_prefix
94 - *
95 - * @param string $prefix
96 - *
97 - * @return string
98 - */
99 - $this->table_prefix = apply_filters( 'wp_stream_db_tables_prefix', $wpdb->base_prefix );
100 -
101 84 if ( empty( $this->db_version ) ) {
102 85 $this->install( $this->plugin->get_version() );
103 -
104 86 return;
105 87 }
106 88
107 89 if ( $this->plugin->get_version() === $this->db_version ) {
@@ -107,26 +89,38 @@
107 89 if ( $this->plugin->get_version() === $this->db_version ) {
108 90 return;
109 91 }
110 92
111 - $update = isset( $_REQUEST['wp_stream_update'] ) ? $_REQUEST['wp_stream_update'] : null;
93 + $update = null;
94 + if ( isset( $_REQUEST['wp_stream_update'] ) && wp_verify_nonce( 'wp_stream_update_db' ) ) {
95 + $update = esc_attr( $_REQUEST['wp_stream_update'] );
96 + }
112 97
113 98 if ( ! $update ) {
114 99 $this->update_required = true;
115 - $this->success_db = $this->update( $this->db_version, $this->plugin->get_version(), array( 'type' => 'auto' ) );
116 -
117 - return;
100 + $this->success_db = $this->update(
101 + $this->db_version,
102 + $this->plugin->get_version(),
103 + array(
104 + 'type' => 'auto',
105 + )
106 + );
118 107 }
119 108
120 109 if ( 'update_and_continue' === $update ) {
121 - $this->success_db = $this->update( $this->db_version, $this->plugin->get_version(), array( 'type' => 'user' ) );
110 + $this->success_db = $this->update(
111 + $this->db_version,
112 + $this->plugin->get_version(),
113 + array(
114 + 'type' => 'user',
115 + )
116 + );
122 117 }
123 118
124 119 $versions = $this->db_update_versions();
125 120
126 - if ( version_compare( end( $versions ), $this->db_version, '>' ) ) {
121 + if ( ! $this->success_db && version_compare( end( $versions ), $this->db_version, '>' ) ) {
127 122 add_action( 'all_admin_notices', array( $this, 'update_notice_hook' ) );
128 -
129 123 return;
130 124 }
131 125
132 126 $this->update_db_option();
@@ -149,9 +143,9 @@
149 143 return;
150 144 }
151 145
152 146 if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
153 - require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
147 + require_once ABSPATH . '/wp-admin/includes/plugin.php';
154 148 }
155 149
156 150 /**
157 151 * Fires before admin notices are triggered for missing database tables.
@@ -166,9 +160,12 @@
166 160 // Check if all needed DB is present
167 161 $missing_tables = array();
168 162
169 163 foreach ( $this->plugin->db->get_table_names() as $table_name ) {
170 - if ( $wpdb->get_var( "SHOW TABLES LIKE '$table_name'" ) !== $table_name ) {
164 + $table_search = $wpdb->get_var(
165 + $wpdb->prepare( 'SHOW TABLES LIKE %s', $table_name )
166 + );
167 + if ( $table_search !== $table_name ) {
171 168 $missing_tables[] = $table_name;
172 169 }
173 170 }
174 171
@@ -184,12 +181,22 @@
184 181 esc_html( implode( ', ', $missing_tables ) )
185 182 );
186 183 }
187 184
188 - if ( is_plugin_active_for_network( $this->plugin->locations['plugin'] ) && current_user_can( 'manage_network_plugins' ) ) {
189 - $uninstall_message = sprintf( __( 'Please <a href="%s">uninstall</a> the Stream plugin and activate it again.', 'stream' ), network_admin_url( 'plugins.php#stream' ) );
185 + if ( $this->plugin->is_network_activated() && current_user_can( 'manage_network_plugins' ) ) {
186 + $uninstall_message = sprintf(
187 + // translators: Placeholders refer to HTML Link tags (e.g. "<a href="https://foo.com/wp-admin/">")
188 + __( 'Please %1$suninstall%2$s the Stream plugin and activate it again.', 'stream' ),
189 + '<a href="' . network_admin_url( 'plugins.php#stream' ) . '">',
190 + '</a>'
191 + );
190 192 } elseif ( current_user_can( 'activate_plugins' ) ) {
191 - $uninstall_message = sprintf( __( 'Please <a href="%s">uninstall</a> the Stream plugin and activate it again.', 'stream' ), admin_url( 'plugins.php#stream' ) );
193 + $uninstall_message = sprintf(
194 + // translators: Placeholders refer to HTML Link tags (e.g. "<a href="https://foo.com/wp-admin/">")
195 + __( 'Please %1$suninstall%2$s the Stream plugin and activate it again.', 'stream' ),
196 + '<a href="' . admin_url( 'plugins.php#stream' ) . '">',
197 + '</a>'
198 + );
192 199 }
193 200
194 201 if ( ! empty( $database_message ) ) {
195 202 $this->plugin->admin->notice( $database_message );
@@ -216,9 +223,9 @@
216 223 }
217 224
218 225 $plugin = plugin_basename( $file );
219 226
220 - if ( is_plugin_active_for_network( $plugin ) ) {
227 + if ( $this->plugin->is_network_activated() ) {
221 228 $current_versions = get_site_option( $this->option_key . '_connectors', array() );
222 229 $network = true;
223 230 } elseif ( is_plugin_active( $plugin ) ) {
224 231 $current_versions = get_option( $this->option_key . '_connectors', array() );
@@ -237,10 +244,8 @@
237 244 update_site_option( $this->option_key . '_registered_connectors', $current_versions );
238 245 } else {
239 246 update_option( $this->option_key . '_registered_connectors', $current_versions );
240 247 }
241 -
242 - return;
243 248 }
244 249
245 250 /**
246 251 * @return string
@@ -256,9 +261,9 @@
256 261 if ( $this->success_db ) {
257 262 $success_op = update_site_option( $this->option_key, $this->plugin->get_version() );
258 263 }
259 264
260 - if ( ! empty( $this->success_db ) && ! empty( $success_op ) ) {
265 + if ( ! empty( $this->success_db ) ) {
261 266 return;
262 267 }
263 268
264 269 wp_die(
@@ -282,9 +287,12 @@
282 287 if ( ! current_user_can( $this->plugin->admin->view_cap ) ) {
283 288 return;
284 289 }
285 290
286 - $update = isset( $_REQUEST['wp_stream_update'] ) ? $_REQUEST['wp_stream_update'] : null;
291 + $update = null;
292 + if ( isset( $_REQUEST['wp_stream_update'] ) && wp_verify_nonce( 'wp_stream_update_db' ) ) {
293 + $update = esc_attr( $_REQUEST['wp_stream_update'] );
294 + }
287 295
288 296 if ( ! $update ) {
289 297 $this->prompt_update();
290 298
@@ -306,15 +314,15 @@
306 314 */
307 315 public function prompt_update() {
308 316 ?>
309 317 <div class="error">
310 - <form method="post" action="<?php echo esc_url( remove_query_arg( 'wp_stream_update' ) ) ?>">
311 - <?php wp_nonce_field( 'wp_stream_update_db' ) ?>
318 + <form method="post" action="<?php echo esc_url( remove_query_arg( 'wp_stream_update' ) ); ?>">
319 + <?php wp_nonce_field( 'wp_stream_update_db' ); ?>
312 320 <input type="hidden" name="wp_stream_update" value="update_and_continue"/>
313 - <p><strong><?php esc_html_e( 'Stream Database Update Required', 'stream' ) ?></strong></p>
314 - <p><?php esc_html_e( 'Stream has updated! Before we send you on your way, we need to update your database to the newest version.', 'stream' ) ?></p>
315 - <p><?php esc_html_e( 'This process could take a little while, so please be patient.', 'stream' ) ?></p>
316 - <?php submit_button( esc_html__( 'Update Database', 'stream' ), 'primary', 'stream-update-db-submit' ) ?>
321 + <p><strong><?php esc_html_e( 'Stream Database Update Required', 'stream' ); ?></strong></p>
322 + <p><?php esc_html_e( 'Stream has updated! Before we send you on your way, we need to update your database to the newest version.', 'stream' ); ?></p>
323 + <p><?php esc_html_e( 'This process could take a little while, so please be patient.', 'stream' ); ?></p>
324 + <?php submit_button( esc_html__( 'Update Database', 'stream' ), 'primary', 'stream-update-db-submit' ); ?>
317 325 </form>
318 326 </div>
319 327 <?php
320 328 }
@@ -330,12 +338,21 @@
330 338
331 339 $this->update_db_option();
332 340 ?>
333 341 <div class="updated">
334 - <form method="post" action="<?php echo esc_url( remove_query_arg( 'wp_stream_update' ) ) ?>" style="display:inline;">
335 - <p><strong><?php esc_html_e( 'Update Complete', 'stream' ) ?></strong></p>
336 - <p><?php esc_html_e( sprintf( 'Your Stream database has been successfully updated from %1$s to %2$s!', esc_html( $this->db_version ), esc_html( WP_Stream::VERSION ) ), 'stream' ) ?></p>
337 - <?php submit_button( esc_html__( 'Continue', 'stream' ), 'secondary', false ) ?>
342 + <form method="post" action="<?php echo esc_url( remove_query_arg( 'wp_stream_update' ) ); ?>" style="display:inline;">
343 + <p><strong><?php esc_html_e( 'Update Complete', 'stream' ); ?></strong></p>
344 + <p>
345 + <?php
346 + printf(
347 + // translators: Placeholders refer to version numbers (e.g. "4.2")
348 + esc_html__( 'Your Stream database has been successfully updated from %1$s to %2$s!', 'stream' ),
349 + esc_html( $this->db_version ),
350 + esc_html( $this->plugin->get_version() )
351 + );
352 + ?>
353 + </p>
354 + <?php submit_button( esc_html__( 'Continue', 'stream' ), 'secondary', false ); ?>
338 355 </form>
339 356 </div>
340 357 <?php
341 358 }
@@ -351,9 +368,11 @@
351 368 * @return array
352 369 */
353 370 public function db_update_versions() {
354 371 $db_update_versions = array(
355 - '3.0.0' /* @version 3.0.0 Drop the stream_context table, changes to stream table */,
372 + '3.0.0', /* @version 3.0.0 Drop the stream_context table, changes to stream table */
373 + '3.0.2', /* @version 3.0.2 Fix uppercase values in stream table, connector column */
374 + '3.0.8', /* @version 3.0.8 Increase size of user role IDs, user_roll column */
356 375 );
357 376
358 377 /**
359 378 * Filter to alter the DB update versions array
@@ -375,9 +394,9 @@
375 394 * @return mixed Version number on success, true on no update needed, mysql error message on error
376 395 */
377 396 public function update( $db_version, $current_version, $update_args ) {
378 397 $versions = $this->db_update_versions();
379 - include_once( $this->plugin->locations['inc_dir'] . 'db-updates.php' );
398 + include_once $this->plugin->locations['inc_dir'] . 'db-updates.php';
380 399
381 400 foreach ( $versions as $version ) {
382 401 if ( ! isset( $update_args['type'] ) ) {
383 402 $update_args['type'] = 'user';
@@ -408,17 +427,15 @@
408 427 global $wpdb;
409 428
410 429 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
411 430
412 - $prefix = $this->table_prefix;
413 -
414 - $sql = "CREATE TABLE {$prefix}stream (
431 + $sql = "CREATE TABLE {$wpdb->base_prefix}stream (
415 432 ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
416 433 site_id bigint(20) unsigned NOT NULL DEFAULT '1',
417 434 blog_id bigint(20) unsigned NOT NULL DEFAULT '1',
418 435 object_id bigint(20) unsigned NULL,
419 436 user_id bigint(20) unsigned NOT NULL DEFAULT '0',
420 - user_role varchar(20) NOT NULL DEFAULT '',
437 + user_role varchar(50) NOT NULL DEFAULT '',
421 438 summary longtext NOT NULL,
422 439 created datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
423 440 connector varchar(100) NOT NULL,
424 441 context varchar(100) NOT NULL,
@@ -458,9 +475,9 @@
458 475 $sql .= ';';
459 476
460 477 \dbDelta( $sql );
461 478
462 - $sql = "CREATE TABLE {$prefix}stream_meta (
479 + $sql = "CREATE TABLE {$wpdb->base_prefix}stream_meta (
463 480 meta_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
464 481 record_id bigint(20) unsigned NOT NULL,
465 482 meta_key varchar(200) NOT NULL,
466 483 meta_value varchar(200) NOT NULL,
@@ -465,10 +482,10 @@
465 482 meta_key varchar(200) NOT NULL,
466 483 meta_value varchar(200) NOT NULL,
467 484 PRIMARY KEY (meta_id),
468 485 KEY record_id (record_id),
469 - KEY meta_key (meta_key),
470 - KEY meta_value (meta_value)
486 + KEY meta_key (meta_key(191)),
487 + KEY meta_value (meta_value(191))
471 488 )";
472 489
473 490 if ( ! empty( $wpdb->charset ) ) {
474 491 $sql .= " CHARACTER SET $wpdb->charset";