From 89e8c4cc6f9f8206360b57b3b4576dfb9613471d Mon Sep 17 00:00:00 2001 From: Chris Olbekson Date: Wed, 2 Apr 2014 19:37:47 -0500 Subject: [PATCH 01/47] Issue-379 Database update API - get_instance() of WP_Stream_Install instead of calling check() method --- stream.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stream.php b/stream.php index ad9447f7c..da25a0ed0 100644 --- a/stream.php +++ b/stream.php @@ -152,7 +152,7 @@ public static function install() { // Install plugin tables require_once WP_STREAM_INC_DIR . 'install.php'; - WP_Stream_Install::check(); + $update = WP_Stream_Install::get_instance(); } /** From 2ae72203b488cc4f504b41c3e98de529b2300ec5 Mon Sep 17 00:00:00 2001 From: Chris Olbekson Date: Wed, 2 Apr 2014 19:39:53 -0500 Subject: [PATCH 02/47] Issue-379 Database update API - Add constructor method to initiate class then call check(); - Added prompt_update() method to handle user controlled db update --- includes/install.php | 105 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 87 insertions(+), 18 deletions(-) diff --git a/includes/install.php b/includes/install.php index 9c5fc9d0c..02c82134e 100644 --- a/includes/install.php +++ b/includes/install.php @@ -4,35 +4,104 @@ class WP_Stream_Install { public static $table_prefix; - /** - * Check db version, create/update table schema accordingly - * - * @return void - */ - public static function check() { - global $wpdb; + public static $db_version; + + public static $current; - $current = WP_Stream::VERSION; + private static $instance = false; - $db_version = get_option( plugin_basename( WP_STREAM_DIR ) . '_db' ); + public static function get_instance() { + if ( empty( self::$instance ) ) { + self::$instance = new self(); + } + return self::$instance; + } + + function __construct() { + global $wpdb; + self::$current = WP_Stream::VERSION; + + //update_option( plugin_basename( WP_STREAM_DIR ) . '_db', self::$current ); + self::$db_version = get_option( plugin_basename( WP_STREAM_DIR ) . '_db' ); /** * Allows devs to alter the tables prefix, default to base_prefix * - * @param string database prefix - * @return string udpated database prefix + * @var string $prefix database prefix + * @var string $table_prefix udpated database prefix */ - self::$table_prefix = apply_filters( 'wp_stream_db_tables_prefix', $wpdb->prefix ); + if ( is_multisite() ) { + $prefix = $wpdb->prefix; //change to $wpdb->base_prefix when network stream enabled; + } + else { + $prefix = $wpdb->prefix; + } + + self::$table_prefix = apply_filters( 'wp_stream_db_tables_prefix', $prefix ); + self::check(); + } - if ( empty( $db_version ) ) { + /** + * Check db version, create/update table schema accordingly + * If database update required admin notice will be given + * on the plugin update screen + * + * @return null + */ + private static function check() { + if ( empty( self::$db_version ) ) { self::install(); - } elseif ( $db_version !== $current ) { - self::update( $db_version, $current ); - } else { - return; + + } elseif ( self::$db_version !== self::$current ) { + add_action( 'pre_current_active_plugins', array( __CLASS__, 'prompt_update' ) ); } + } - update_option( plugin_basename( WP_STREAM_DIR ) . '_db', $current ); + public static function prompt_update() { + $referrer = wp_get_referer(); + $location = 'plugins.php'; + + if ( isset( $_REQUEST['action'] ) && 'wp_stream_update' == $_REQUEST['action'] ) { + self::update( self::$db_version, self::$current ); + + } elseif ( isset( $_REQUEST['wp_stream_update'] ) && 'stream_updated' == $_REQUEST['wp_stream_update'] ) { + ?> +
+ + +
+

+

+

+

+
+
+ +
+ +
+

+

+

+
+
+ Date: Wed, 2 Apr 2014 19:54:30 -0500 Subject: [PATCH 03/47] Issue-379 Database update API - Added final code documentation to class methods --- includes/install.php | 62 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 9 deletions(-) diff --git a/includes/install.php b/includes/install.php index 02c82134e..be1892d63 100644 --- a/includes/install.php +++ b/includes/install.php @@ -2,14 +2,44 @@ class WP_Stream_Install { + /** + * Holds the database table prefix + * + * @access public + * @var mixed|void + */ public static $table_prefix; + /** + * Holds version of database at last update + * + * @access public + * @var mixed|void + */ public static $db_version; + /** + * Current version of running plugin + * + * @access public + * @var string|int + */ public static $current; + /** + * Initialized object of class + * + * @access private + * @var bool|object + */ private static $instance = false; + /** + * Gets instance of singleton class + * + * @access public + * @return bool|object|WP_Stream_Install + */ public static function get_instance() { if ( empty( self::$instance ) ) { self::$instance = new self(); @@ -17,11 +47,14 @@ public static function get_instance() { return self::$instance; } + /** + * Class constructor + * Sets static class properties + */ function __construct() { global $wpdb; self::$current = WP_Stream::VERSION; - //update_option( plugin_basename( WP_STREAM_DIR ) . '_db', self::$current ); self::$db_version = get_option( plugin_basename( WP_STREAM_DIR ) . '_db' ); /** @@ -30,12 +63,7 @@ function __construct() { * @var string $prefix database prefix * @var string $table_prefix udpated database prefix */ - if ( is_multisite() ) { - $prefix = $wpdb->prefix; //change to $wpdb->base_prefix when network stream enabled; - } - else { - $prefix = $wpdb->prefix; - } + $prefix = $wpdb->prefix; self::$table_prefix = apply_filters( 'wp_stream_db_tables_prefix', $prefix ); self::check(); @@ -46,6 +74,7 @@ function __construct() { * If database update required admin notice will be given * on the plugin update screen * + * @action pre_current_active_plugins * @return null */ private static function check() { @@ -57,6 +86,12 @@ private static function check() { } } + /** + * Action hook callback function + * Adds the user controlled database upgrade routine to the plugins updated page + * + * When database update is complete page will refresh with dismissible message to user + */ public static function prompt_update() { $referrer = wp_get_referer(); $location = 'plugins.php'; @@ -92,18 +127,21 @@ public static function prompt_update() { } elseif ( isset( $_REQUEST['action'] ) && 'dismiss_notice' == $_REQUEST['action'] ) { if ( $referrer ) { + update_option( plugin_basename( WP_STREAM_DIR ) . '_db', self::$current ); if ( false !== strpos( $referrer, $location ) ) $location = $referrer; $location = remove_query_arg( 'action', admin_url( $location ) ); - - update_option( plugin_basename( WP_STREAM_DIR ) . '_db', self::$current ); wp_redirect( admin_url( $location ) ); exit; } } } + /** + * Initial database install routine + * @uses dbDelta() + */ public static function install() { global $wpdb; @@ -189,6 +227,12 @@ public static function install() { dbDelta( $sql ); } + /** + * Database user controlled update routine + * + * @param int $db_version last updated version of database stored in plugin options + * @param int $current Current running plugin version + */ public static function update( $db_version, $current ) { global $wpdb; $prefix = self::$table_prefix; From 681844d1ded1845c1b00f932304b0a6906cdd0c8 Mon Sep 17 00:00:00 2001 From: Chris Olbekson Date: Wed, 2 Apr 2014 20:04:36 -0500 Subject: [PATCH 04/47] Issue-379 Database update API - Fixed correct $_REQUEST keys to check for during each stage of update routine --- includes/install.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/includes/install.php b/includes/install.php index be1892d63..e5b5d1c14 100644 --- a/includes/install.php +++ b/includes/install.php @@ -96,10 +96,6 @@ public static function prompt_update() { $referrer = wp_get_referer(); $location = 'plugins.php'; - if ( isset( $_REQUEST['action'] ) && 'wp_stream_update' == $_REQUEST['action'] ) { - self::update( self::$db_version, self::$current ); - - } elseif ( isset( $_REQUEST['wp_stream_update'] ) && 'stream_updated' == $_REQUEST['wp_stream_update'] ) { ?>
@@ -112,11 +108,11 @@ public static function prompt_update() {
- +

@@ -135,6 +131,15 @@ public static function prompt_update() { wp_redirect( admin_url( $location ) ); exit; } + } elseif ( isset( $_REQUEST['action'] ) && 'wp_stream_update' == $_REQUEST['action'] ) { + self::update( self::$db_version, self::$current ); + if ( false !== strpos( $referrer, $location ) ) + $location = $referrer; + + $location = remove_query_arg( 'action', admin_url( $location ) ); + $location = add_query_arg( array( 'wp_stream_update_confirmed' => 'wp_stream_update_confirmed' ), $location ); + wp_redirect( admin_url( $location ) ); + exit; } } From a95837064820bd312348789711b8df33a4e86961 Mon Sep 17 00:00:00 2001 From: Chris Olbekson Date: Wed, 2 Apr 2014 23:16:32 -0500 Subject: [PATCH 05/47] Issue-379 Database update API - Replace esc_html with esc_html_e --- includes/install.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/includes/install.php b/includes/install.php index e5b5d1c14..f0581b7a4 100644 --- a/includes/install.php +++ b/includes/install.php @@ -101,10 +101,10 @@ public static function prompt_update() {
-

-

-

-

+

+

+

+

-

-

-

+

+

+

Date: Thu, 3 Apr 2014 00:32:53 -0500 Subject: [PATCH 06/47] Issue-379 Database update API - added error_log() calls to test installing over multiple versions - fixed bug - move the update database button to the end of the function --- includes/install.php | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/includes/install.php b/includes/install.php index f0581b7a4..485fcb87c 100644 --- a/includes/install.php +++ b/includes/install.php @@ -82,6 +82,7 @@ private static function check() { self::install(); } elseif ( self::$db_version !== self::$current ) { + error_log( 'Adding update button action' ); add_action( 'pre_current_active_plugins', array( __CLASS__, 'prompt_update' ) ); } } @@ -96,20 +97,10 @@ public static function prompt_update() { $referrer = wp_get_referer(); $location = 'plugins.php'; - ?> -
- - -
-

-

-

-

-
-
-
@@ -122,6 +113,8 @@ public static function prompt_update() { 'wp_stream_update_confirmed' ), $location ); wp_redirect( admin_url( $location ) ); exit; + } else { + ?> + + + +
+

+

+

+

+
+
+ stream r JOIN $wpdb->streamcontext c From dbadcb670a5b5367d4c286cf922b51f719676269 Mon Sep 17 00:00:00 2001 From: Chris Olbekson Date: Thu, 3 Apr 2014 03:54:48 -0500 Subject: [PATCH 07/47] Issue-379 Database update API - Moved the database user upgrade process outside of the plugin list table hook. 1st Update Database notice is still there but rest of routine lives on it's own. --- includes/install.php | 158 +++++++++++++++++++++++++------------------ includes/query.php | 2 +- stream.php | 1 + 3 files changed, 94 insertions(+), 67 deletions(-) mode change 100644 => 100755 includes/install.php mode change 100644 => 100755 includes/query.php mode change 100644 => 100755 stream.php diff --git a/includes/install.php b/includes/install.php old mode 100644 new mode 100755 index 485fcb87c..3048511a0 --- a/includes/install.php +++ b/includes/install.php @@ -82,7 +82,6 @@ private static function check() { self::install(); } elseif ( self::$db_version !== self::$current ) { - error_log( 'Adding update button action' ); add_action( 'pre_current_active_plugins', array( __CLASS__, 'prompt_update' ) ); } } @@ -95,60 +94,19 @@ private static function check() { */ public static function prompt_update() { $referrer = wp_get_referer(); - $location = 'plugins.php'; - - error_log( $referrer ); - - if ( isset( $_REQUEST['wp_stream_update_confirmed'] ) && 'wp_stream_update_confirmed' == $_REQUEST['wp_stream_update_confirmed'] ) { - error_log( $_REQUEST['wp_stream_update_confirmed'] ); - ?> -
- -
-

-

-

-
-
- 'wp_stream_update_confirmed' ), $location ); - wp_redirect( admin_url( $location ) ); - exit; - } else { + $location = WP_STREAM_UPDATE_URL; ?> -
- - -
-

-

-

-

-
-
+
+
+ + +

+

+

+

+
+
stream r JOIN $wpdb->streamcontext c @@ -323,19 +281,22 @@ public static function update( $db_version, $current ) { ); } } + error_log( 'VERSION UPDATE FROM ' . $db_version . ' COMPLETE' ); } - // If version is lower than 1.3.0, do the update routine for site options - // Backward settings compatibility for old version plugins - if ( version_compare( $db_version, '1.3.0', '<' ) ) { - add_action( 'wp_stream_after_connectors_registration', 'WP_Stream_Install::migrate_old_options_to_exclude_tab' ); - } - - // If version is lower than 1.3.1, do the update routine - // Update records of Installer to Theme Editor connector - if ( version_compare( $db_version, '1.3.1', '<' ) ) { - add_action( 'wp_stream_after_connectors_registration', 'WP_Stream_Install::migrate_installer_edits_to_theme_editor_connector' ); - } +// // If version is lower than 1.3.0, do the update routine for site options +// // Backward settings compatibility for old version plugins +// if ( version_compare( $db_version, '1.3.0', '<' ) ) { +// add_action( 'wp_stream_after_connectors_registration', array( __CLASS__, 'migrate_old_options_to_exclude_tab' ) ); +// } +// +// // If version is lower than 1.3.1, do the update routine +// // Update records of Installer to Theme Editor connector +// if ( version_compare( $db_version, '1.3.1', '<' ) ) { +// add_action( 'wp_stream_after_connectors_registration', array( __CLASS__, 'migrate_installer_edits_to_theme_editor_connector' ) ); +// } + + return $db_version; } /** @@ -425,5 +386,70 @@ function( $theme ) use ( $theme_name ) { } } } - } + +if ( ! isset( $_REQUEST['wp_stream_update'] ) ) + return; + +/** + * WP Stream Update Database Administration Bootstrap + */ +require_once( ABSPATH . 'wp-admin/admin.php' ); + +if ( !current_user_can( 'activate_plugins' ) ) + wp_die( __( 'You do not have sufficient permissions to manage plugins for this site.' ) ); + + +//Clean up request URI from temporary args for screen options / paging uri's to work as expected. +$_SERVER['REQUEST_URI'] = remove_query_arg(array('error', 'deleted', 'activate', 'activate - multi', 'deactivate', 'deactivate - multi', '_error_nonce'), $_SERVER['REQUEST_URI']); + +require_once( ABSPATH . 'wp-admin/admin-header.php' ); + +$wp_stream_update = WP_Stream_Install::get_instance(); +$referrer = wp_get_referer(); + +?> + +
+

+

" . __( 'There was an error updating the database. Please try again' ) . ""; + wp_die( $go_back ); + } + ?> +

+
+ +

+

+

+
+
+ +
+ + Date: Thu, 3 Apr 2014 09:41:57 -0500 Subject: [PATCH 08/47] Code formatting --- includes/install.php | 51 ++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/includes/install.php b/includes/install.php index 3048511a0..5f068bb87 100755 --- a/includes/install.php +++ b/includes/install.php @@ -100,9 +100,9 @@ public static function prompt_update() {
-

-

-

+

+

+

@@ -396,24 +396,29 @@ function( $theme ) use ( $theme_name ) { */ require_once( ABSPATH . 'wp-admin/admin.php' ); -if ( !current_user_can( 'activate_plugins' ) ) +if ( !current_user_can( 'activate_plugins' ) ) { wp_die( __( 'You do not have sufficient permissions to manage plugins for this site.' ) ); +} - -//Clean up request URI from temporary args for screen options / paging uri's to work as expected. -$_SERVER['REQUEST_URI'] = remove_query_arg(array('error', 'deleted', 'activate', 'activate - multi', 'deactivate', 'deactivate - multi', '_error_nonce'), $_SERVER['REQUEST_URI']); +// Clean up request URI from temporary args for screen options / paging uri's to work as expected. +$_SERVER['REQUEST_URI'] = remove_query_arg( + array( + 'error', 'deleted', 'activate', + 'activate - multi', 'deactivate', + 'deactivate - multi', '_error_nonce', + ), + $_SERVER['REQUEST_URI'] +); require_once( ABSPATH . 'wp-admin/admin-header.php' ); $wp_stream_update = WP_Stream_Install::get_instance(); $referrer = wp_get_referer(); - ?> -

-

-

+

+

- + } + ?> + + Date: Thu, 3 Apr 2014 18:59:34 -0500 Subject: [PATCH 09/47] Refinement of update and redirect routines when database updates are performed --- includes/install.php | 155 +++++++++++++++++-------------------------- 1 file changed, 62 insertions(+), 93 deletions(-) diff --git a/includes/install.php b/includes/install.php index 5f068bb87..50e2dcd57 100755 --- a/includes/install.php +++ b/includes/install.php @@ -26,6 +26,13 @@ class WP_Stream_Install { */ public static $current; + /** + * URL to the Stream Admin settings page. + * @access public + * @var string + */ + public static $stream_url; + /** * Initialized object of class * @@ -52,10 +59,12 @@ public static function get_instance() { * Sets static class properties */ function __construct() { + global $wpdb; self::$current = WP_Stream::VERSION; self::$db_version = get_option( plugin_basename( WP_STREAM_DIR ) . '_db' ); + self::$stream_url = self_admin_url( WP_Stream_Admin::ADMIN_PARENT_PAGE . '&page=' . WP_Stream_Admin::SETTINGS_PAGE_SLUG ); /** * Allows devs to alter the tables prefix, default to base_prefix @@ -79,10 +88,10 @@ function __construct() { */ private static function check() { if ( empty( self::$db_version ) ) { - self::install(); + $current = self::install( self::$current ); } elseif ( self::$db_version !== self::$current ) { - add_action( 'pre_current_active_plugins', array( __CLASS__, 'prompt_update' ) ); + add_action( 'admin_notices', array( __CLASS__, 'update_notice_hook' ) ); } } @@ -93,12 +102,9 @@ private static function check() { * When database update is complete page will refresh with dismissible message to user */ public static function prompt_update() { - $referrer = wp_get_referer(); - $location = WP_STREAM_UPDATE_URL; ?>
-
- +

@@ -109,11 +115,44 @@ public static function prompt_update() { 200, 'back_link' => true ) ); + } + ?> +
+ +

+

+ + +
+ -
-

-

" . __( 'There was an error updating the database. Please try again' ) . ""; - wp_die( $go_back ); - } - ?> -

-
- -

-

-

-
-
- -
- Date: Thu, 3 Apr 2014 19:00:47 -0500 Subject: [PATCH 10/47] Added register_update_hook that can be used by connectors - Stores current connector versions and only fires callback function when version changes --- includes/admin.php | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/includes/admin.php b/includes/admin.php index b2fb2d54b..a054863be 100644 --- a/includes/admin.php +++ b/includes/admin.php @@ -289,6 +289,47 @@ public static function plugin_action_links( $links, $file ) { return $links; } + /** + * Register a routine to be called when stream or a stream connector has been updated + * It works by comparing the current version with the version previously stored in the database. + * + * @param string $file A reference to the main plugin file + * @param callback $callback The function to run when the hook is called. + * @param string $version The version to which the plugin is updating. + * @return void + */ + public static function register_update_hook( $file, $callback, $version ) { + if ( ! is_admin() ) { + return; + } + + $plugin = plugin_basename( $file ); + + if ( is_plugin_active_for_network( $plugin ) ) { + $current_versions = get_site_option( plugin_basename( WP_STREAM_DIR ) . '_connectors', array() ); + $network = true; + } elseif ( is_plugin_active( $plugin ) ) { + $current_versions = get_option( plugin_basename( WP_STREAM_DIR ) . '_connectors', array() ); + $network = false; + } else { + return; + } + + if ( version_compare( $version, $current_versions[$plugin], '>' ) ) { + call_user_func( $callback, $current_versions[$plugin], $network ); + + $current_versions[$plugin] = $version; + } + + if ( $network ) { + update_site_option( plugin_basename( WP_STREAM_DIR ) . '_registered_connectors', $current_versions ); + } else { + update_option( plugin_basename( WP_STREAM_DIR ) . '_registered_connectors', $current_versions ); + } + + return; + } + /** * Render settings page * From 1cd31293a16651229a8326135d69a4d572edd7af Mon Sep 17 00:00:00 2001 From: Chris Olbekson Date: Thu, 3 Apr 2014 19:01:58 -0500 Subject: [PATCH 11/47] Moved WP_Stream::instal() to fire on init. Needs Stream_Admin to be loaded now --- stream.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/stream.php b/stream.php index e454ca14c..5a3f800f7 100755 --- a/stream.php +++ b/stream.php @@ -115,6 +115,14 @@ private function __construct() { if ( is_admin() ) { require_once WP_STREAM_INC_DIR . 'admin.php'; add_action( 'plugins_loaded', array( 'WP_Stream_Admin', 'load' ) ); + + // Registers a hook that connectors and other plugins can use whenever a stream update happens + //add_action( 'init', array( 'WP_Stream_Admin' ), 'register_update_hook' ); + add_action( 'init', array( __CLASS__, 'install' ) ); + + add_action( 'admin_init', function() { + WP_Stream_Admin::register_update_hook( dirname( plugin_basename( __FILE__ ) ), array( __CLASS__, 'install' ), WP_Stream::VERSION ); + }, 99); } } @@ -182,8 +190,8 @@ private function verify_database_present() { } } - // Check upgrade routine - self::install(); + // Check upgrade routine /** @internal Moving this to hook into an init hook It uses properties from WP_Stream_Admin */ + //self::install(); if ( ! empty( $message ) ) { self::$messages['wp_stream_db_error'] = sprintf( From 56c1fd67dcd972c2ed0daf3ad449140d9668250e Mon Sep 17 00:00:00 2001 From: Chris Olbekson Date: Thu, 3 Apr 2014 19:05:10 -0500 Subject: [PATCH 12/47] Fixed bug with query_string matching --- includes/install.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/install.php b/includes/install.php index 50e2dcd57..ee16d099a 100755 --- a/includes/install.php +++ b/includes/install.php @@ -144,7 +144,7 @@ public static function update_notice_hook() { self::prompt_update_status(); } elseif ( 'update_required' === $_REQUEST['wp_stream_update'] ) { - self::prompt_update(); + self::prompt_update_status(); } } From 83c5c653232dbd6043597d73c97e9db1afd3686e Mon Sep 17 00:00:00 2001 From: Chris Olbekson Date: Thu, 3 Apr 2014 19:12:20 -0500 Subject: [PATCH 13/47] Final bug fixes from testing - ready to send pr - correct wp_stream_update query arg --- includes/install.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/includes/install.php b/includes/install.php index ee16d099a..0a9eef790 100755 --- a/includes/install.php +++ b/includes/install.php @@ -104,8 +104,8 @@ private static function check() { public static function prompt_update() { ?>
-
- + +

@@ -117,11 +117,9 @@ public static function prompt_update() { public static function prompt_update_status() { $success_db = self::update( self::$db_version, self::$current ); - if ( $success_db && self::$current === $success_db ) { $success_op = update_option( plugin_basename( WP_STREAM_DIR ) . '_db', $success_db ); } - if ( empty( $success_db ) || empty( $success_op ) ) { wp_die( __( 'There was an error updating the database. Please try again', 'stream' ), 'Database Update Error', array( 'response' => 200, 'back_link' => true ) ); } @@ -130,7 +128,7 @@ public static function prompt_update_status() {

- +
Date: Thu, 3 Apr 2014 19:20:56 -0500 Subject: [PATCH 14/47] Formating and white space --- stream.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/stream.php b/stream.php index 5a3f800f7..e66b0b600 100755 --- a/stream.php +++ b/stream.php @@ -116,13 +116,10 @@ private function __construct() { require_once WP_STREAM_INC_DIR . 'admin.php'; add_action( 'plugins_loaded', array( 'WP_Stream_Admin', 'load' ) ); - // Registers a hook that connectors and other plugins can use whenever a stream update happens - //add_action( 'init', array( 'WP_Stream_Admin' ), 'register_update_hook' ); add_action( 'init', array( __CLASS__, 'install' ) ); - add_action( 'admin_init', function() { - WP_Stream_Admin::register_update_hook( dirname( plugin_basename( __FILE__ ) ), array( __CLASS__, 'install' ), WP_Stream::VERSION ); - }, 99); + // Registers a hook that connectors and other plugins can use whenever a stream update happens + add_action( 'admin_init', array( __CLASS__, 'update_activation_hook' ) ); } } @@ -190,9 +187,6 @@ private function verify_database_present() { } } - // Check upgrade routine /** @internal Moving this to hook into an init hook It uses properties from WP_Stream_Admin */ - //self::install(); - if ( ! empty( $message ) ) { self::$messages['wp_stream_db_error'] = sprintf( '
%s

%s

', @@ -202,6 +196,10 @@ private function verify_database_present() { } } + static function update_activation_hook() { + WP_Stream_Admin::register_update_hook( dirname( plugin_basename( __FILE__ ) ), array( __CLASS__, 'install' ), self::VERSION ); + } + /** * Display a notice about php version * From ec614227b72462d100b007f5f69b8d12edad5399 Mon Sep 17 00:00:00 2001 From: Chris Olbekson Date: Thu, 3 Apr 2014 19:27:16 -0500 Subject: [PATCH 15/47] Added documentation to the new install / update methods --- includes/install.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/includes/install.php b/includes/install.php index 0a9eef790..17f568d67 100755 --- a/includes/install.php +++ b/includes/install.php @@ -28,6 +28,7 @@ class WP_Stream_Install { /** * URL to the Stream Admin settings page. + * * @access public * @var string */ @@ -59,7 +60,6 @@ public static function get_instance() { * Sets static class properties */ function __construct() { - global $wpdb; self::$current = WP_Stream::VERSION; @@ -83,7 +83,6 @@ function __construct() { * If database update required admin notice will be given * on the plugin update screen * - * @action pre_current_active_plugins * @return null */ private static function check() { @@ -115,6 +114,11 @@ public static function prompt_update() { Date: Thu, 3 Apr 2014 19:39:27 -0500 Subject: [PATCH 16/47] Improving output of admin alerts --- includes/install.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/includes/install.php b/includes/install.php index 17f568d67..0adaee8d5 100755 --- a/includes/install.php +++ b/includes/install.php @@ -102,13 +102,13 @@ private static function check() { */ public static function prompt_update() { ?> -
+
-

-

-

-

+

+

+

+
-

-

- +

+

+
Date: Thu, 3 Apr 2014 19:40:55 -0500 Subject: [PATCH 17/47] Space police --- includes/install.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/install.php b/includes/install.php index 0adaee8d5..baadd46d7 100755 --- a/includes/install.php +++ b/includes/install.php @@ -132,7 +132,7 @@ public static function prompt_update_status() {

- +
Date: Thu, 3 Apr 2014 20:01:37 -0500 Subject: [PATCH 18/47] Include text domain in localized string, remove extra space --- includes/install.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/install.php b/includes/install.php index baadd46d7..18df9484e 100755 --- a/includes/install.php +++ b/includes/install.php @@ -129,10 +129,10 @@ public static function prompt_update_status() { } ?>
-
+

-

- +

+
Date: Thu, 3 Apr 2014 20:07:54 -0500 Subject: [PATCH 19/47] Code formatting fixes --- includes/install.php | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/includes/install.php b/includes/install.php index 18df9484e..ac1db356b 100755 --- a/includes/install.php +++ b/includes/install.php @@ -52,6 +52,7 @@ public static function get_instance() { if ( empty( self::$instance ) ) { self::$instance = new self(); } + return self::$instance; } @@ -61,8 +62,8 @@ public static function get_instance() { */ function __construct() { global $wpdb; - self::$current = WP_Stream::VERSION; + self::$current = WP_Stream::VERSION; self::$db_version = get_option( plugin_basename( WP_STREAM_DIR ) . '_db' ); self::$stream_url = self_admin_url( WP_Stream_Admin::ADMIN_PARENT_PAGE . '&page=' . WP_Stream_Admin::SETTINGS_PAGE_SLUG ); @@ -88,7 +89,6 @@ function __construct() { private static function check() { if ( empty( self::$db_version ) ) { $current = self::install( self::$current ); - } elseif ( self::$db_version !== self::$current ) { add_action( 'admin_notices', array( __CLASS__, 'update_notice_hook' ) ); } @@ -101,16 +101,16 @@ private static function check() { * When database update is complete page will refresh with dismissible message to user */ public static function prompt_update() { - ?> -
-
- -

-

-

- -
-
+ ?> +
+
+ +

+

+

+ +
+
200, 'back_link' => true ) ); + wp_die( __( 'There was an error updating the Stream database. Please try again.', 'stream' ), 'Database Update Error', array( 'response' => 200, 'back_link' => true ) ); } ?>
@@ -147,12 +149,10 @@ public static function prompt_update_status() { public static function update_notice_hook() { if ( ! isset( $_REQUEST['wp_stream_update'] ) ) { self::prompt_update(); - } elseif ( 'user_action_required' === $_REQUEST['wp_stream_update' ] ) { self::prompt_update_status(); - } elseif ( 'update_and_continue' === $_REQUEST['wp_stream_update'] ) { - self::prompt_update_status(); + self::prompt_update_status(); } } From bb0fd0b675fcc55a54d6304860f427ff26135b4f Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Thu, 3 Apr 2014 20:15:43 -0500 Subject: [PATCH 20/47] More code formatting --- includes/admin.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/includes/admin.php b/includes/admin.php index a054863be..c803376af 100644 --- a/includes/admin.php +++ b/includes/admin.php @@ -307,18 +307,17 @@ public static function register_update_hook( $file, $callback, $version ) { if ( is_plugin_active_for_network( $plugin ) ) { $current_versions = get_site_option( plugin_basename( WP_STREAM_DIR ) . '_connectors', array() ); - $network = true; + $network = true; } elseif ( is_plugin_active( $plugin ) ) { $current_versions = get_option( plugin_basename( WP_STREAM_DIR ) . '_connectors', array() ); - $network = false; + $network = false; } else { return; } - if ( version_compare( $version, $current_versions[$plugin], '>' ) ) { - call_user_func( $callback, $current_versions[$plugin], $network ); - - $current_versions[$plugin] = $version; + if ( version_compare( $version, $current_versions[ $plugin ], '>' ) ) { + call_user_func( $callback, $current_versions[ $plugin ], $network ); + $current_versions[ $plugin ] = $version; } if ( $network ) { From 1fceb01dfeecff349f57cee922254de0bacb4ce8 Mon Sep 17 00:00:00 2001 From: Chris Olbekson Date: Thu, 3 Apr 2014 21:51:32 -0500 Subject: [PATCH 21/47] Added method to return array of plugin versions that require db update --- stream.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/stream.php b/stream.php index e66b0b600..78c9d4552 100755 --- a/stream.php +++ b/stream.php @@ -116,11 +116,12 @@ private function __construct() { require_once WP_STREAM_INC_DIR . 'admin.php'; add_action( 'plugins_loaded', array( 'WP_Stream_Admin', 'load' ) ); - add_action( 'init', array( __CLASS__, 'install' ) ); + add_action( 'admin_init', array( __CLASS__, 'install' ) ); // Registers a hook that connectors and other plugins can use whenever a stream update happens add_action( 'admin_init', array( __CLASS__, 'update_activation_hook' ) ); } + } /** @@ -200,6 +201,22 @@ static function update_activation_hook() { WP_Stream_Admin::register_update_hook( dirname( plugin_basename( __FILE__ ) ), array( __CLASS__, 'install' ), self::VERSION ); } + /** + * An array of plugin versions that require a database update + * + * @return array + */ + static function get_update_versions() { + return array( + '1.1.4', // Converted tables to correct character set + '1.1.7', // Altered the ip column to be varchar(39) and put after the created column + '1.2.5', // Changed the taxonomy records to use term_taxonomy_id instead of term_id + '1.2.8', // Support for attachments + '1.3.0', + '1.3.1', + ); + } + /** * Display a notice about php version * From 6b6d69d969dd55db627ff4cd15bc839cf2797807 Mon Sep 17 00:00:00 2001 From: Chris Olbekson Date: Thu, 3 Apr 2014 22:21:29 -0500 Subject: [PATCH 22/47] Convert each database change to a static method using update_xxx as naming convention --- includes/install.php | 159 ++++++++++++++++++++++++++----------------- 1 file changed, 95 insertions(+), 64 deletions(-) diff --git a/includes/install.php b/includes/install.php index ac1db356b..e0f43f098 100755 --- a/includes/install.php +++ b/includes/install.php @@ -34,6 +34,20 @@ class WP_Stream_Install { */ public static $stream_url; + /** + * Is plugin network activated + * + * @var bool + */ + public static $network; + + /** + * Array of plugin version numbers that require db update + * + * @var array + */ + public static $db_update_versions; + /** * Initialized object of class * @@ -62,10 +76,17 @@ public static function get_instance() { */ function __construct() { global $wpdb; - - self::$current = WP_Stream::VERSION; + self::$current = WP_Stream::VERSION; + if ( is_plugin_active_for_network( WP_STREAM_DIR ) ) { + self::$db_version = get_site_option( plugin_basename( WP_STREAM_DIR ) . '_db' ); + self::$network = true; + } else { + self::$db_version = get_option( plugin_basename( WP_STREAM_DIR ) . '_db' ); + self::$network = false; + } self::$db_version = get_option( plugin_basename( WP_STREAM_DIR ) . '_db' ); self::$stream_url = self_admin_url( WP_Stream_Admin::ADMIN_PARENT_PAGE . '&page=' . WP_Stream_Admin::SETTINGS_PAGE_SLUG ); + self::$db_update_versions = WP_Stream::get_update_versions(); /** * Allows devs to alter the tables prefix, default to base_prefix @@ -89,6 +110,7 @@ function __construct() { private static function check() { if ( empty( self::$db_version ) ) { $current = self::install( self::$current ); + } elseif ( self::$db_version !== self::$current ) { add_action( 'admin_notices', array( __CLASS__, 'update_notice_hook' ) ); } @@ -149,8 +171,10 @@ public static function prompt_update_status() { public static function update_notice_hook() { if ( ! isset( $_REQUEST['wp_stream_update'] ) ) { self::prompt_update(); + } elseif ( 'user_action_required' === $_REQUEST['wp_stream_update' ] ) { self::prompt_update_status(); + } elseif ( 'update_and_continue' === $_REQUEST['wp_stream_update'] ) { self::prompt_update_status(); } @@ -258,24 +282,42 @@ public static function update( $db_version, $current ) { global $wpdb; $prefix = self::$table_prefix; - // If version is lower than 1.1.4, do the update routine - if ( version_compare( $db_version, '1.1.4', '<' ) && ! empty( $wpdb->charset ) ) { - $tables = array( 'stream', 'stream_context', 'stream_meta' ); - $collate = ( $wpdb->collate ) ? " COLLATE {$wpdb->collate}" : null; - foreach ( $tables as $table ) { - $wpdb->query( "ALTER TABLE {$prefix}{$table} CONVERT TO CHARACTER SET {$wpdb->charset}{$collate};" ); + foreach ( self::$db_update_versions as $version ) { + + if ( version_compare( $db_version, $version, '<' ) ) { + $version_func = str_ireplace( '.', '', $version ); + call_user_func( array( __CLASS__, 'update'. $version_func ), $prefix, $wpdb ); } } - // If version is lower than 1.1.7, do the update routine - if ( version_compare( $db_version, '1.1.7', '<' ) ) { - $wpdb->query( "ALTER TABLE {$prefix}stream MODIFY ip varchar(39) NULL AFTER created" ); + return $current; + + } + + + public static function update_114( $prefix, $wpdb ) { + global $wpdb; + + if ( ! empty( $wpdb->carset ) ) { + return; + } + + $tables = array( 'stream', 'stream_context', 'stream_meta' ); + $collate = ( $wpdb->collate ) ? " COLLATE {$wpdb->collate}" : null; + foreach ( $tables as $table ) { + $wpdb->query( "ALTER TABLE {$prefix}{$table} CONVERT TO CHARACTER SET {$wpdb->charset}{$collate};" ); } + } + + public static function update_117( $prefix, $wpdb ) { + if ( ! empty( $wpdb->carset ) ) { + return; + } + $wpdb->query( "ALTER TABLE {$prefix}stream MODIFY ip varchar(39) NULL AFTER created" ); + } - // If version is lower than 1.2.5, do the update routine - // Taxonomy records switch from term_id to term_taxonomy_id - if ( version_compare( $db_version, '1.2.5', '<' ) ) { - $sql = "SELECT r.ID id, tt.term_taxonomy_id tt + public static function update_125( $prefix, $wpdb ) { + $sql = "SELECT r.ID id, tt.term_taxonomy_id tt FROM $wpdb->stream r JOIN $wpdb->streamcontext c ON r.ID = c.record_id AND c.connector = 'taxonomies' @@ -287,64 +329,52 @@ public static function update( $db_version, $current ) { ON tt.term_id = m.meta_value AND tt.taxonomy = m2.meta_value "; - $tax_records = $wpdb->get_results( $sql ); // db call ok - foreach ( $tax_records as $record ) { - if ( ! empty( $record->tt ) ) { - $wpdb->update( - $wpdb->stream, - array( 'object_id' => $record->tt ), - array( 'ID' => $record->id ), - array( '%d' ), - array( '%d' ) - ); - } + $tax_records = $wpdb->get_results( $sql ); // db call ok + foreach ( $tax_records as $record ) { + if ( ! empty( $record->tt ) ) { + $wpdb->update( + $wpdb->stream, + array( 'object_id' => $record->tt ), + array( 'ID' => $record->id ), + array( '%d' ), + array( '%d' ) + ); } } + } - // If version is lower than 1.2.8, do the update routine - // Change the context for Media connectors to the attachment type - if ( version_compare( $db_version, '1.2.8', '<' ) ) { - $sql = "SELECT r.ID id, r.object_id pid, c.meta_id mid + public static function update_128( $prefix, $wpdb ) { + $sql = "SELECT r.ID id, r.object_id pid, c.meta_id mid FROM $wpdb->stream r JOIN $wpdb->streamcontext c ON r.ID = c.record_id AND c.connector = 'media' AND c.context = 'media' "; - $media_records = $wpdb->get_results( $sql ); // db call ok - - require_once WP_STREAM_INC_DIR . 'query.php'; - require_once WP_STREAM_CLASS_DIR . 'connector.php'; - require_once WP_STREAM_DIR . 'connectors/media.php'; - - foreach ( $media_records as $record ) { - $post = get_post( $record->pid ); - $guid = isset( $post->guid ) ? $post->guid : null; - $url = $guid ? $guid : get_stream_meta( $record->id, 'url', true ); - - if ( ! empty( $url ) ) { - $wpdb->update( - $wpdb->streamcontext, - array( 'context' => WP_Stream_Connector_Media::get_attachment_type( $url ) ), - array( 'record_id' => $record->id ), - array( '%s' ), - array( '%d' ) - ); - } + $media_records = $wpdb->get_results( $sql ); // db call ok + + foreach ( $media_records as $record ) { + $post = get_post( $record->pid ); + $guid = isset( $post->guid ) ? $post->guid : null; + $url = $guid ? $guid : get_stream_meta( $record->id, 'url', true ); + + if ( ! empty( $url ) ) { + $wpdb->update( + $wpdb->streamcontext, + array( 'context' => WP_Stream_Connector_Media::get_attachment_type( $url ) ), + array( 'record_id' => $record->id ), + array( '%s' ), + array( '%d' ) + ); } } - // If version is lower than 1.3.0, do the update routine for site options - // Backward settings compatibility for old version plugins - if ( version_compare( $db_version, '1.3.0', '<' ) ) { - add_action( 'wp_stream_after_connectors_registration', array( __CLASS__, 'migrate_old_options_to_exclude_tab' ) ); - } + } - // If version is lower than 1.3.1, do the update routine - // Update records of Installer to Theme Editor connector - if ( version_compare( $db_version, '1.3.1', '<' ) ) { - add_action( 'wp_stream_after_connectors_registration', array( __CLASS__, 'migrate_installer_edits_to_theme_editor_connector' ) ); - } + public static function update_130( $prefix, $wpdb ) { + add_action( 'wp_stream_after_connectors_registration', array( __CLASS__, 'migrate_old_options_to_exclude_tab' ) ); + } - return $current; + public static function update_131( $prefix, $wpdb ) { + add_action( 'wp_stream_after_connectors_registration', array( __CLASS__, 'migrate_installer_edits_to_theme_editor_connector' ) ); } /** @@ -394,14 +424,14 @@ public static function migrate_installer_edits_to_theme_editor_connector() { $records = stream_query( $args ); foreach ( $records as $record ) { - $file_name = get_stream_meta( $record->ID, 'file', true ); + $file_name = get_stream_meta( $record->ID, 'file', true ); $theme_name = get_stream_meta( $record->ID, 'name', true ); if ( '' !== $theme_name ) { $matched_themes = array_filter( wp_get_themes(), - function( $theme ) use ( $theme_name ) { - return (string) $theme === $theme_name; + function ( $theme ) use ( $theme_name ) { + return (string)$theme === $theme_name; } ); $theme = array_shift( $matched_themes ); @@ -433,5 +463,6 @@ function( $theme ) use ( $theme_name ) { } } } + } } From e6230bd5f3abd8c27c93a7ae75e4ddf2a80f9dc6 Mon Sep 17 00:00:00 2001 From: Chris Olbekson Date: Thu, 3 Apr 2014 22:27:46 -0500 Subject: [PATCH 23/47] Revert "Added method to return array of plugin versions that require db update" Reverting the screwy conflict merges This reverts commit 1fceb01dfeecff349f57cee922254de0bacb4ce8. --- stream.php | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/stream.php b/stream.php index 78c9d4552..e66b0b600 100755 --- a/stream.php +++ b/stream.php @@ -116,12 +116,11 @@ private function __construct() { require_once WP_STREAM_INC_DIR . 'admin.php'; add_action( 'plugins_loaded', array( 'WP_Stream_Admin', 'load' ) ); - add_action( 'admin_init', array( __CLASS__, 'install' ) ); + add_action( 'init', array( __CLASS__, 'install' ) ); // Registers a hook that connectors and other plugins can use whenever a stream update happens add_action( 'admin_init', array( __CLASS__, 'update_activation_hook' ) ); } - } /** @@ -201,22 +200,6 @@ static function update_activation_hook() { WP_Stream_Admin::register_update_hook( dirname( plugin_basename( __FILE__ ) ), array( __CLASS__, 'install' ), self::VERSION ); } - /** - * An array of plugin versions that require a database update - * - * @return array - */ - static function get_update_versions() { - return array( - '1.1.4', // Converted tables to correct character set - '1.1.7', // Altered the ip column to be varchar(39) and put after the created column - '1.2.5', // Changed the taxonomy records to use term_taxonomy_id instead of term_id - '1.2.8', // Support for attachments - '1.3.0', - '1.3.1', - ); - } - /** * Display a notice about php version * From 0a24ca7c40c5eaf6e21d0669228f72aa09b7f472 Mon Sep 17 00:00:00 2001 From: Chris Olbekson Date: Thu, 3 Apr 2014 22:28:21 -0500 Subject: [PATCH 24/47] Revert "Convert each database change to a static method using update_xxx as naming convention" This reverts commit 6b6d69d969dd55db627ff4cd15bc839cf2797807. --- includes/install.php | 159 +++++++++++++++++-------------------------- 1 file changed, 64 insertions(+), 95 deletions(-) diff --git a/includes/install.php b/includes/install.php index e0f43f098..ac1db356b 100755 --- a/includes/install.php +++ b/includes/install.php @@ -34,20 +34,6 @@ class WP_Stream_Install { */ public static $stream_url; - /** - * Is plugin network activated - * - * @var bool - */ - public static $network; - - /** - * Array of plugin version numbers that require db update - * - * @var array - */ - public static $db_update_versions; - /** * Initialized object of class * @@ -76,17 +62,10 @@ public static function get_instance() { */ function __construct() { global $wpdb; - self::$current = WP_Stream::VERSION; - if ( is_plugin_active_for_network( WP_STREAM_DIR ) ) { - self::$db_version = get_site_option( plugin_basename( WP_STREAM_DIR ) . '_db' ); - self::$network = true; - } else { - self::$db_version = get_option( plugin_basename( WP_STREAM_DIR ) . '_db' ); - self::$network = false; - } + + self::$current = WP_Stream::VERSION; self::$db_version = get_option( plugin_basename( WP_STREAM_DIR ) . '_db' ); self::$stream_url = self_admin_url( WP_Stream_Admin::ADMIN_PARENT_PAGE . '&page=' . WP_Stream_Admin::SETTINGS_PAGE_SLUG ); - self::$db_update_versions = WP_Stream::get_update_versions(); /** * Allows devs to alter the tables prefix, default to base_prefix @@ -110,7 +89,6 @@ function __construct() { private static function check() { if ( empty( self::$db_version ) ) { $current = self::install( self::$current ); - } elseif ( self::$db_version !== self::$current ) { add_action( 'admin_notices', array( __CLASS__, 'update_notice_hook' ) ); } @@ -171,10 +149,8 @@ public static function prompt_update_status() { public static function update_notice_hook() { if ( ! isset( $_REQUEST['wp_stream_update'] ) ) { self::prompt_update(); - } elseif ( 'user_action_required' === $_REQUEST['wp_stream_update' ] ) { self::prompt_update_status(); - } elseif ( 'update_and_continue' === $_REQUEST['wp_stream_update'] ) { self::prompt_update_status(); } @@ -282,42 +258,24 @@ public static function update( $db_version, $current ) { global $wpdb; $prefix = self::$table_prefix; - foreach ( self::$db_update_versions as $version ) { - - if ( version_compare( $db_version, $version, '<' ) ) { - $version_func = str_ireplace( '.', '', $version ); - call_user_func( array( __CLASS__, 'update'. $version_func ), $prefix, $wpdb ); + // If version is lower than 1.1.4, do the update routine + if ( version_compare( $db_version, '1.1.4', '<' ) && ! empty( $wpdb->charset ) ) { + $tables = array( 'stream', 'stream_context', 'stream_meta' ); + $collate = ( $wpdb->collate ) ? " COLLATE {$wpdb->collate}" : null; + foreach ( $tables as $table ) { + $wpdb->query( "ALTER TABLE {$prefix}{$table} CONVERT TO CHARACTER SET {$wpdb->charset}{$collate};" ); } } - return $current; - - } - - - public static function update_114( $prefix, $wpdb ) { - global $wpdb; - - if ( ! empty( $wpdb->carset ) ) { - return; - } - - $tables = array( 'stream', 'stream_context', 'stream_meta' ); - $collate = ( $wpdb->collate ) ? " COLLATE {$wpdb->collate}" : null; - foreach ( $tables as $table ) { - $wpdb->query( "ALTER TABLE {$prefix}{$table} CONVERT TO CHARACTER SET {$wpdb->charset}{$collate};" ); + // If version is lower than 1.1.7, do the update routine + if ( version_compare( $db_version, '1.1.7', '<' ) ) { + $wpdb->query( "ALTER TABLE {$prefix}stream MODIFY ip varchar(39) NULL AFTER created" ); } - } - - public static function update_117( $prefix, $wpdb ) { - if ( ! empty( $wpdb->carset ) ) { - return; - } - $wpdb->query( "ALTER TABLE {$prefix}stream MODIFY ip varchar(39) NULL AFTER created" ); - } - public static function update_125( $prefix, $wpdb ) { - $sql = "SELECT r.ID id, tt.term_taxonomy_id tt + // If version is lower than 1.2.5, do the update routine + // Taxonomy records switch from term_id to term_taxonomy_id + if ( version_compare( $db_version, '1.2.5', '<' ) ) { + $sql = "SELECT r.ID id, tt.term_taxonomy_id tt FROM $wpdb->stream r JOIN $wpdb->streamcontext c ON r.ID = c.record_id AND c.connector = 'taxonomies' @@ -329,52 +287,64 @@ public static function update_125( $prefix, $wpdb ) { ON tt.term_id = m.meta_value AND tt.taxonomy = m2.meta_value "; - $tax_records = $wpdb->get_results( $sql ); // db call ok - foreach ( $tax_records as $record ) { - if ( ! empty( $record->tt ) ) { - $wpdb->update( - $wpdb->stream, - array( 'object_id' => $record->tt ), - array( 'ID' => $record->id ), - array( '%d' ), - array( '%d' ) - ); + $tax_records = $wpdb->get_results( $sql ); // db call ok + foreach ( $tax_records as $record ) { + if ( ! empty( $record->tt ) ) { + $wpdb->update( + $wpdb->stream, + array( 'object_id' => $record->tt ), + array( 'ID' => $record->id ), + array( '%d' ), + array( '%d' ) + ); + } } } - } - public static function update_128( $prefix, $wpdb ) { - $sql = "SELECT r.ID id, r.object_id pid, c.meta_id mid + // If version is lower than 1.2.8, do the update routine + // Change the context for Media connectors to the attachment type + if ( version_compare( $db_version, '1.2.8', '<' ) ) { + $sql = "SELECT r.ID id, r.object_id pid, c.meta_id mid FROM $wpdb->stream r JOIN $wpdb->streamcontext c ON r.ID = c.record_id AND c.connector = 'media' AND c.context = 'media' "; - $media_records = $wpdb->get_results( $sql ); // db call ok - - foreach ( $media_records as $record ) { - $post = get_post( $record->pid ); - $guid = isset( $post->guid ) ? $post->guid : null; - $url = $guid ? $guid : get_stream_meta( $record->id, 'url', true ); - - if ( ! empty( $url ) ) { - $wpdb->update( - $wpdb->streamcontext, - array( 'context' => WP_Stream_Connector_Media::get_attachment_type( $url ) ), - array( 'record_id' => $record->id ), - array( '%s' ), - array( '%d' ) - ); + $media_records = $wpdb->get_results( $sql ); // db call ok + + require_once WP_STREAM_INC_DIR . 'query.php'; + require_once WP_STREAM_CLASS_DIR . 'connector.php'; + require_once WP_STREAM_DIR . 'connectors/media.php'; + + foreach ( $media_records as $record ) { + $post = get_post( $record->pid ); + $guid = isset( $post->guid ) ? $post->guid : null; + $url = $guid ? $guid : get_stream_meta( $record->id, 'url', true ); + + if ( ! empty( $url ) ) { + $wpdb->update( + $wpdb->streamcontext, + array( 'context' => WP_Stream_Connector_Media::get_attachment_type( $url ) ), + array( 'record_id' => $record->id ), + array( '%s' ), + array( '%d' ) + ); + } } } - } + // If version is lower than 1.3.0, do the update routine for site options + // Backward settings compatibility for old version plugins + if ( version_compare( $db_version, '1.3.0', '<' ) ) { + add_action( 'wp_stream_after_connectors_registration', array( __CLASS__, 'migrate_old_options_to_exclude_tab' ) ); + } - public static function update_130( $prefix, $wpdb ) { - add_action( 'wp_stream_after_connectors_registration', array( __CLASS__, 'migrate_old_options_to_exclude_tab' ) ); - } + // If version is lower than 1.3.1, do the update routine + // Update records of Installer to Theme Editor connector + if ( version_compare( $db_version, '1.3.1', '<' ) ) { + add_action( 'wp_stream_after_connectors_registration', array( __CLASS__, 'migrate_installer_edits_to_theme_editor_connector' ) ); + } - public static function update_131( $prefix, $wpdb ) { - add_action( 'wp_stream_after_connectors_registration', array( __CLASS__, 'migrate_installer_edits_to_theme_editor_connector' ) ); + return $current; } /** @@ -424,14 +394,14 @@ public static function migrate_installer_edits_to_theme_editor_connector() { $records = stream_query( $args ); foreach ( $records as $record ) { - $file_name = get_stream_meta( $record->ID, 'file', true ); + $file_name = get_stream_meta( $record->ID, 'file', true ); $theme_name = get_stream_meta( $record->ID, 'name', true ); if ( '' !== $theme_name ) { $matched_themes = array_filter( wp_get_themes(), - function ( $theme ) use ( $theme_name ) { - return (string)$theme === $theme_name; + function( $theme ) use ( $theme_name ) { + return (string) $theme === $theme_name; } ); $theme = array_shift( $matched_themes ); @@ -463,6 +433,5 @@ function ( $theme ) use ( $theme_name ) { } } } - } } From 5d4fceaef7809f58b755371e2114210581b3d4a2 Mon Sep 17 00:00:00 2001 From: Chris Olbekson Date: Fri, 4 Apr 2014 13:18:27 -0500 Subject: [PATCH 25/47] Class method to fire the appropriate update functions - Added filter for extensions call there own update routine - Moved update routines to separate file --- includes/db-updates.php | 284 ++++++++++++++++++++++++++++++++++++++++ includes/install.php | 248 +++++++++-------------------------- 2 files changed, 343 insertions(+), 189 deletions(-) create mode 100644 includes/db-updates.php diff --git a/includes/db-updates.php b/includes/db-updates.php new file mode 100644 index 000000000..472c222d3 --- /dev/null +++ b/includes/db-updates.php @@ -0,0 +1,284 @@ +charset ) ) { + return true; + } + + do_action( 'wp_stream_before_db_update_' . $db_version, $current_version ); + $tables = array( 'stream', 'stream_context', 'stream_meta' ); + $collate = ( $wpdb->collate ) ? " COLLATE {$wpdb->collate}" : null; + foreach ( $tables as $table ) { + $wpdb->query( "ALTER TABLE {$prefix}{$table} CONVERT TO CHARACTER SET {$wpdb->charset}{$collate};" ); + } + if ( $wpdb->last_error ) { + return __( 'Database Update Error', 'stream ' ); + } + + do_action( 'wp_stream_after_db_update_' . $db_version, $current_version, $wpdb->last_error ); + + return $current_version; +} + +/** + * Update Database to current version from version 1.1.7 + * + * @param string $db_version Database version updating from + * @param string $current_version Database version updating to + * + * @return bool true if no wpdb errors + */ +function wp_stream_update_117( $db_version, $current_version ) { + global $wpdb; + $prefix = WP_Stream_Install::$table_prefix; + do_action( 'wp_stream_before_db_update_' . $db_version, $current_version ); + + if ( version_compare( $db_version, '1.1.7', '<' ) ) { + $wpdb->query( "ALTER TABLE {$prefix}stream MODIFY ip varchar(39) NULL AFTER created" ); + } + + do_action( 'wp_stream_after_db_update_' . $db_version, $current_version, $wpdb->last_error ); + if ( $wpdb->last_error ) { + return __( 'Database Update Error', 'stream ' ); + } + + return $current_version; +} + +/** + * Update Database to current version from version 1.2.5 + * + * @param string $db_version Database version updating from + * @param string $current_version Database version updating to + * + * @return bool true if no wpdb errors + */ +function wp_stream_update_125( $db_version, $current_version ) { + global $wpdb; + $prefix = WP_Stream_Install::$table_prefix; + do_action( 'wp_stream_before_db_update_' . $db_version, $current_version ); + + $sql = "SELECT r.ID id, r.object_id pid, c.meta_id mid + FROM $wpdb->stream r + JOIN $wpdb->streamcontext c + ON r.ID = c.record_id AND c.connector = 'media' AND c.context = 'media' + "; + $media_records = $wpdb->get_results( $sql ); // db call ok + + foreach ( $media_records as $record ) { + $post = get_post( $record->pid ); + $guid = isset( $post->guid ) ? $post->guid : null; + $url = $guid ? $guid : get_stream_meta( $record->id, 'url', true ); + + if ( ! empty( $url ) ) { + $wpdb->update( + $wpdb->streamcontext, + array( 'context' => WP_Stream_Connector_Media::get_attachment_type( $url ) ), + array( 'record_id' => $record->id ), + array( '%s' ), + array( '%d' ) + ); + } + } + + do_action( 'wp_stream_after_db_update_' . $db_version, $current_version, $wpdb->last_error ); + if ( $wpdb->last_error ) { + return __( 'Database Update Error', 'stream ' ); + } + return $current_version; +} + +/** + * Update Database to current version from version 1.2.8 + * + * @param string $db_version Database version updating from + * @param string $current_version Database version updating to + * + * @return bool true if no wpdb errors + */ +function wp_stream_update_128( $db_version, $current_version ) { + global $wpdb; + $prefix = WP_Stream_Install::$table_prefix; + do_action( 'wp_stream_before_db_update_' . $db_version, $current_version ); + + $sql = "SELECT r.ID id, r.object_id pid, c.meta_id mid + FROM $wpdb->stream r + JOIN $wpdb->streamcontext c + ON r.ID = c.record_id AND c.connector = 'media' AND c.context = 'media' + "; + $media_records = $wpdb->get_results( $sql ); // db call ok + + foreach ( $media_records as $record ) { + $post = get_post( $record->pid ); + $guid = isset( $post->guid ) ? $post->guid : null; + $url = $guid ? $guid : get_stream_meta( $record->id, 'url', true ); + + if ( ! empty( $url ) ) { + $wpdb->update( + $wpdb->streamcontext, + array( 'context' => WP_Stream_Connector_Media::get_attachment_type( $url ) ), + array( 'record_id' => $record->id ), + array( '%s' ), + array( '%d' ) + ); + } + } + + do_action( 'wp_stream_after_db_update_' . $db_version, $current_version, $wpdb->last_error ); + if ( $wpdb->last_error ) { + return __( 'Database Update Error', 'stream ' ); + } + return $current_version; +} + +/** + * Update Database to current version from version 1.3.0 + * + * @param string $db_version Database version updating from + * @param string $current_version Database version updating to + * + * @return bool true if no wpdb errors + */ +function wp_stream_update_130( $db_version, $current_version ) { + do_action( 'wp_stream_before_db_update_' . $db_version, $current_version ); + add_action( 'wp_stream_after_connectors_registration', 'migrate_old_options_to_exclude_tab' ); + do_action( 'wp_stream_after_db_update_' . $db_version, $current_version, false ); + + return $current_version; +} + +/** + * Update Database to current version from version 1.3.1 + * + * @param string $db_version Database version updating from + * @param string $current_version Database version updating to + * + * @return bool true if no wpdb errors + */ +function wp_stream_update_131( $db_version, $current_version ) { + do_action( 'wp_stream_before_db_update_' . $db_version, $current_version ); + add_action( 'wp_stream_after_connectors_registration', 'migrate_installer_edits_to_theme_editor_connector' ); + do_action( 'wp_stream_after_db_update_' . $db_version, $current_version, false ); + + return $current_version; +} + +/** + * Function will migrate old options from the General and Connectors tabs into the new Exclude tab + * + * @param $labels array connectors terms labels + * + * @action wp_stream_after_connectors_registration + * @return bool|int|string + */ +function migrate_old_options_to_exclude_tab( $labels ) { + global $wpdb; + $prefix = WP_Stream_Install::$table_prefix; + $db_version = WP_Stream_Install::$db_version; + $current_version = WP_Stream_Install::$current; + + do_action( 'wp_stream_before_db_update_' . $db_version, $current_version ); + + $old_options = get_option( WP_Stream_Settings::KEY, array() ); + + // Stream > Settings > General > Log Activity for + if ( isset( $old_options['general_log_activity_for'] ) ) { + WP_Stream_Settings::$options['exclude_authors_and_roles'] = array_diff( + array_keys( WP_Stream_Settings::get_roles() ), + $old_options['general_log_activity_for'] + ); + unset( WP_Stream_Settings::$options['general_log_activity_for'] ); + } + + // Stream > Settings > Connectors > Active Connectors + if ( isset( $old_options['connectors_active_connectors'] ) ) { + WP_Stream_Settings::$options['exclude_connectors'] = array_diff( + array_keys( $labels ), + $old_options['connectors_active_connectors'] + ); + unset( WP_Stream_Settings::$options['connectors_active_connectors'] ); + } + + update_option( WP_Stream_Settings::KEY, WP_Stream_Settings::$options ); + do_action( 'wp_stream_after_db_update_' . $db_version, $current_version, $wpdb->last_error ); + if ( $wpdb->last_error ) { + return false; + } + + return $current_version; +} + +/** + * Function will migrate theme file edit records from Installer connector to the Theme Editor connector + * + * @action wp_stream_after_connectors_registration + */ +function migrate_installer_edits_to_theme_editor_connector() { + global $wpdb; + $prefix = WP_Stream_Install::$table_prefix; + $db_version = WP_Stream_Install::$db_version; + $current_version = WP_Stream_Install::$current; + + $args = array( + 'connector' => 'installer', + 'context' => 'themes', + 'action' => 'edited', + ); + $records = stream_query( $args ); + + foreach ( $records as $record ) { + $file_name = get_stream_meta( $record->ID, 'file', true ); + $theme_name = get_stream_meta( $record->ID, 'name', true ); + + if ( '' !== $theme_name ) { + $matched_themes = array_filter( + wp_get_themes(), + function ( $theme ) use ( $theme_name ) { + return (string)$theme === $theme_name; + } + ); + $theme = array_shift( $matched_themes ); + + // `stream` + $wpdb->update( + $wpdb->stream, + array( + 'summary' => sprintf( WP_Stream_Connector_Editor::get_message(), $file_name, $theme_name ), + ), + array( 'ID' => $record->ID ) + ); + + // `stream_context` + $wpdb->update( + $wpdb->streamcontext, + array( + 'connector' => 'editor', + 'context' => is_object( $theme ) ? $theme->get_template() : $theme_name, + 'action' => 'updated', + ), + array( 'record_id' => $record->ID ) + ); + + update_stream_meta( $record->ID, 'theme_name', $theme_name ); + + if ( is_object( $theme ) ) { + update_stream_meta( $record->ID, 'theme_slug', $theme->get_template() ); + } + } + } + do_action( 'wp_stream_after_db_update_' . $db_version, $current_version, $wpdb->last_error ); + if ( $wpdb->last_error ) { + return false; + } + return $current_version; +} \ No newline at end of file diff --git a/includes/install.php b/includes/install.php index ac1db356b..48b73a82b 100755 --- a/includes/install.php +++ b/includes/install.php @@ -34,6 +34,14 @@ class WP_Stream_Install { */ public static $stream_url; + /** + * Array of version numbers that require database update + * + * @access public + * @var array + */ + public static $update_versions; + /** * Initialized object of class * @@ -156,6 +164,56 @@ public static function update_notice_hook() { } } + /** + * Array of database versions that require and updates + * To access or add your own update functions use the filter in the update method + * + * @access private + * @return array + */ + private static function db_update_versions() { + return array( + '1.1.4'/** @version 1.1.4 Fix mysql character set issues */, + '1.1.7'/** @version 1.1.7 Modified the ip column to varchar(39) */, + '1.2.8'/** @version 1.2.8 Change the context for Media connectors to the attachment type */, + '1.3.0'/** @version 1.3.0 Backward settings compatibility for old version plugins */, + '1.3.1'/** @version 1.3.1 Update records of Installer to Theme Editor connector */, + ); + } + + /** + * Database user controlled update routine + * + * To add your own stream extension plugin database update routine + * use the filter and return your version that updating from requires an update + * You must also make the callback function available in the global namespace on plugins loaded + * use the wp_stream_update_{version_number} version number must be a 3 character string number with no periods + * + * @filter wp_stream_db_update_versions + * + * @param int $db_version last updated version of database stored in plugin options + * @param int $current Current running plugin version + * @return mixed Version number on success, true on no update needed, mysql error message on error + */ + public static function update( $db_version, $current ) { + require_once WP_STREAM_INC_DIR . 'db-updates.php'; + $prefix = self::$table_prefix; + $versions = apply_filters( 'wp_stream_db_update_versions', self::db_update_versions(), $current, $prefix ); + + foreach ( $versions as $version ) { + $function = 'wp_stream_update_' . str_ireplace( '.', '', $version ); + + if ( version_compare( $db_version, $version, '<' ) ) { + $result = call_user_func( $function, $db_version, $current ); + if ( $current === $result ) { + return $current; + } + return false; + } + } + return true; + } + /** * Initial database install routine * @uses dbDelta() @@ -246,192 +304,4 @@ public static function install( $current ) { return $current; } - - /** - * Database user controlled update routine - * - * @param int $db_version last updated version of database stored in plugin options - * @param int $current Current running plugin version - * @return int new database version to store - */ - public static function update( $db_version, $current ) { - global $wpdb; - $prefix = self::$table_prefix; - - // If version is lower than 1.1.4, do the update routine - if ( version_compare( $db_version, '1.1.4', '<' ) && ! empty( $wpdb->charset ) ) { - $tables = array( 'stream', 'stream_context', 'stream_meta' ); - $collate = ( $wpdb->collate ) ? " COLLATE {$wpdb->collate}" : null; - foreach ( $tables as $table ) { - $wpdb->query( "ALTER TABLE {$prefix}{$table} CONVERT TO CHARACTER SET {$wpdb->charset}{$collate};" ); - } - } - - // If version is lower than 1.1.7, do the update routine - if ( version_compare( $db_version, '1.1.7', '<' ) ) { - $wpdb->query( "ALTER TABLE {$prefix}stream MODIFY ip varchar(39) NULL AFTER created" ); - } - - // If version is lower than 1.2.5, do the update routine - // Taxonomy records switch from term_id to term_taxonomy_id - if ( version_compare( $db_version, '1.2.5', '<' ) ) { - $sql = "SELECT r.ID id, tt.term_taxonomy_id tt - FROM $wpdb->stream r - JOIN $wpdb->streamcontext c - ON r.ID = c.record_id AND c.connector = 'taxonomies' - JOIN $wpdb->streammeta m - ON r.ID = m.record_id AND m.meta_key = 'term_id' - JOIN $wpdb->streammeta m2 - ON r.ID = m2.record_id AND m2.meta_key = 'taxonomy' - JOIN $wpdb->term_taxonomy tt - ON tt.term_id = m.meta_value - AND tt.taxonomy = m2.meta_value - "; - $tax_records = $wpdb->get_results( $sql ); // db call ok - foreach ( $tax_records as $record ) { - if ( ! empty( $record->tt ) ) { - $wpdb->update( - $wpdb->stream, - array( 'object_id' => $record->tt ), - array( 'ID' => $record->id ), - array( '%d' ), - array( '%d' ) - ); - } - } - } - - // If version is lower than 1.2.8, do the update routine - // Change the context for Media connectors to the attachment type - if ( version_compare( $db_version, '1.2.8', '<' ) ) { - $sql = "SELECT r.ID id, r.object_id pid, c.meta_id mid - FROM $wpdb->stream r - JOIN $wpdb->streamcontext c - ON r.ID = c.record_id AND c.connector = 'media' AND c.context = 'media' - "; - $media_records = $wpdb->get_results( $sql ); // db call ok - - require_once WP_STREAM_INC_DIR . 'query.php'; - require_once WP_STREAM_CLASS_DIR . 'connector.php'; - require_once WP_STREAM_DIR . 'connectors/media.php'; - - foreach ( $media_records as $record ) { - $post = get_post( $record->pid ); - $guid = isset( $post->guid ) ? $post->guid : null; - $url = $guid ? $guid : get_stream_meta( $record->id, 'url', true ); - - if ( ! empty( $url ) ) { - $wpdb->update( - $wpdb->streamcontext, - array( 'context' => WP_Stream_Connector_Media::get_attachment_type( $url ) ), - array( 'record_id' => $record->id ), - array( '%s' ), - array( '%d' ) - ); - } - } - } - - // If version is lower than 1.3.0, do the update routine for site options - // Backward settings compatibility for old version plugins - if ( version_compare( $db_version, '1.3.0', '<' ) ) { - add_action( 'wp_stream_after_connectors_registration', array( __CLASS__, 'migrate_old_options_to_exclude_tab' ) ); - } - - // If version is lower than 1.3.1, do the update routine - // Update records of Installer to Theme Editor connector - if ( version_compare( $db_version, '1.3.1', '<' ) ) { - add_action( 'wp_stream_after_connectors_registration', array( __CLASS__, 'migrate_installer_edits_to_theme_editor_connector' ) ); - } - - return $current; - } - - /** - * Function will migrate old options from the General and Connectors tabs into the new Exclude tab - * - * @param $labels array connectors terms labels - * @action wp_stream_after_connectors_registration - */ - public static function migrate_old_options_to_exclude_tab( $labels ) { - $old_options = get_option( WP_Stream_Settings::KEY, array() ); - - // Stream > Settings > General > Log Activity for - if ( isset( $old_options['general_log_activity_for'] ) ) { - WP_Stream_Settings::$options['exclude_authors_and_roles'] = array_diff( - array_keys( WP_Stream_Settings::get_roles() ), - $old_options['general_log_activity_for'] - ); - unset( WP_Stream_Settings::$options['general_log_activity_for'] ); - } - - // Stream > Settings > Connectors > Active Connectors - if ( isset( $old_options['connectors_active_connectors'] ) ) { - WP_Stream_Settings::$options['exclude_connectors'] = array_diff( - array_keys( $labels ), - $old_options['connectors_active_connectors'] - ); - unset( WP_Stream_Settings::$options['connectors_active_connectors'] ); - - } - - update_option( WP_Stream_Settings::KEY, WP_Stream_Settings::$options ); - } - - /** - * Function will migrate theme file edit records from Installer connector to the Theme Editor connector - * - * @action wp_stream_after_connectors_registration - */ - public static function migrate_installer_edits_to_theme_editor_connector() { - global $wpdb; - - $args = array( - 'connector' => 'installer', - 'context' => 'themes', - 'action' => 'edited', - ); - $records = stream_query( $args ); - - foreach ( $records as $record ) { - $file_name = get_stream_meta( $record->ID, 'file', true ); - $theme_name = get_stream_meta( $record->ID, 'name', true ); - - if ( '' !== $theme_name ) { - $matched_themes = array_filter( - wp_get_themes(), - function( $theme ) use ( $theme_name ) { - return (string) $theme === $theme_name; - } - ); - $theme = array_shift( $matched_themes ); - - // `stream` - $wpdb->update( - $wpdb->stream, - array( - 'summary' => sprintf( WP_Stream_Connector_Editor::get_message(), $file_name, $theme_name ), - ), - array( 'ID' => $record->ID ) - ); - - // `stream_context` - $wpdb->update( - $wpdb->streamcontext, - array( - 'connector' => 'editor', - 'context' => is_object( $theme ) ? $theme->get_template() : $theme_name, - 'action' => 'updated', - ), - array( 'record_id' => $record->ID ) - ); - - update_stream_meta( $record->ID, 'theme_name', $theme_name ); - - if ( is_object( $theme ) ) { - update_stream_meta( $record->ID, 'theme_slug', $theme->get_template() ); - } - } - } - } -} +} \ No newline at end of file From 10d8ffb2724198ae09b9872d4cc849dd16d1a65f Mon Sep 17 00:00:00 2001 From: Chris Olbekson Date: Fri, 4 Apr 2014 13:42:16 -0500 Subject: [PATCH 26/47] Class method to fire the appropriate update functions - Added filter for extensions call there own update routine - Moved update routines to separate file --- includes/install.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/install.php b/includes/install.php index 48b73a82b..2ce8d4113 100755 --- a/includes/install.php +++ b/includes/install.php @@ -187,7 +187,7 @@ private static function db_update_versions() { * To add your own stream extension plugin database update routine * use the filter and return your version that updating from requires an update * You must also make the callback function available in the global namespace on plugins loaded - * use the wp_stream_update_{version_number} version number must be a 3 character string number with no periods + * use the wp_stream_update_{version_number} version number must be a string of characters that represent the version with no periods * * @filter wp_stream_db_update_versions * From 4dcb5525c4dfe587686c1c712b7e698de0e47002 Mon Sep 17 00:00:00 2001 From: Chris Olbekson Date: Sat, 5 Apr 2014 18:26:42 -0500 Subject: [PATCH 27/47] Security and nonce checks - Added check for stream user cap required - Added nonce check to update routine --- includes/install.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/includes/install.php b/includes/install.php index 2ce8d4113..d12b813e0 100755 --- a/includes/install.php +++ b/includes/install.php @@ -112,6 +112,7 @@ public static function prompt_update() { ?>
+

@@ -128,6 +129,7 @@ public static function prompt_update() { * */ public static function prompt_update_status() { + check_admin_referer( 'wp_stream_update_db' ); $success_db = self::update( self::$db_version, self::$current ); if ( $success_db && self::$current === $success_db ) { @@ -155,6 +157,9 @@ public static function prompt_update_status() { * @return void */ public static function update_notice_hook() { + if ( ! current_user_can( WP_Stream_Admin::VIEW_CAP ) ) { + return; + } if ( ! isset( $_REQUEST['wp_stream_update'] ) ) { self::prompt_update(); } elseif ( 'user_action_required' === $_REQUEST['wp_stream_update' ] ) { From c44fe90643026a47344ff2e08d180dffa8551a0f Mon Sep 17 00:00:00 2001 From: Chris Olbekson Date: Sat, 5 Apr 2014 22:23:38 -0500 Subject: [PATCH 28/47] Don't rely on plugin_basename for db version option_name - Changed option_name to class KEY const = wp_stream_db - Added get_db_version method to query for any nonstandard option_name if version is 1.3.0 or earlier - If old option_name found update to new option name - Fixes #388 --- includes/install.php | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/includes/install.php b/includes/install.php index d12b813e0..42cf3ca01 100755 --- a/includes/install.php +++ b/includes/install.php @@ -2,6 +2,13 @@ class WP_Stream_Install { + /** + * Option key to store database version + * + * @var string + */ + const KEY = 'wp_stream_db'; + /** * Holds the database table prefix * @@ -72,14 +79,14 @@ function __construct() { global $wpdb; self::$current = WP_Stream::VERSION; - self::$db_version = get_option( plugin_basename( WP_STREAM_DIR ) . '_db' ); + self::$db_version = self::get_db_version(); self::$stream_url = self_admin_url( WP_Stream_Admin::ADMIN_PARENT_PAGE . '&page=' . WP_Stream_Admin::SETTINGS_PAGE_SLUG ); /** - * Allows devs to alter the tables prefix, default to base_prefix + * Allows developers to alter the tables prefix, default to base_prefix * * @var string $prefix database prefix - * @var string $table_prefix udpated database prefix + * @var string $table_prefix updated database prefix */ $prefix = $wpdb->prefix; @@ -96,12 +103,30 @@ function __construct() { */ private static function check() { if ( empty( self::$db_version ) ) { + $current = self::install( self::$current ); } elseif ( self::$db_version !== self::$current ) { add_action( 'admin_notices', array( __CLASS__, 'update_notice_hook' ) ); } } + public static function get_db_version() { + global $wpdb; + + $version = get_option( self::KEY ); + + if ( ! $version && version_compare( self::$current, '1.3.1', '<=' ) ) { + $old_key = $wpdb->get_col( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%wp-stream%_db'" ); + if ( ! empty( $old_key ) && is_array( $old_key ) ) { + $version = get_option( $old_key[0] ); + update_option( self::KEY, $version ); + delete_option( $old_key[0] ); + } + } + + return $version; + } + /** * Action hook callback function * Adds the user controlled database upgrade routine to the plugins updated page @@ -133,7 +158,7 @@ public static function prompt_update_status() { $success_db = self::update( self::$db_version, self::$current ); if ( $success_db && self::$current === $success_db ) { - $success_op = update_option( plugin_basename( WP_STREAM_DIR ) . '_db', $success_db ); + $success_op = update_option( self::KEY. '_db', $success_db ); } if ( empty( $success_db ) || empty( $success_op ) ) { @@ -221,7 +246,10 @@ public static function update( $db_version, $current ) { /** * Initial database install routine + * * @uses dbDelta() + * @param string $current Current version of plugin installed + * @return string Current version of plugin installed */ public static function install( $current ) { global $wpdb; From a5524453320bb7b6998168b670c2517b12a4acca Mon Sep 17 00:00:00 2001 From: Chris Olbekson Date: Sun, 6 Apr 2014 15:05:53 -0500 Subject: [PATCH 29/47] Don't rely on plugin_basename for db version option_name - Added version const wp_stream_db - Changed additional references from plugin_basename - Added get_db_version method to query for any nonstandard option_name if version is 1.3.0 or earlier - If old option_name found update to new option name - Don't run update if doing ajax. --- includes/admin.php | 15 ++++++++------- includes/install.php | 19 ++++++++++--------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/includes/admin.php b/includes/admin.php index c803376af..b411e9c2b 100644 --- a/includes/admin.php +++ b/includes/admin.php @@ -205,7 +205,7 @@ public static function admin_body_class( $classes ) { * Add menu styles for various WP Admin skins * * @action admin_enqueue_scripts - * @return wp_add_inline_style + * @return void */ public static function admin_menu_css() { wp_register_style( 'jquery-ui', '//ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/themes/base/jquery-ui.css', array(), '1.10.1' ); @@ -294,7 +294,7 @@ public static function plugin_action_links( $links, $file ) { * It works by comparing the current version with the version previously stored in the database. * * @param string $file A reference to the main plugin file - * @param callback $callback The function to run when the hook is called. + * @param string $callback The function to run when the hook is called. * @param string $version The version to which the plugin is updating. * @return void */ @@ -306,10 +306,10 @@ public static function register_update_hook( $file, $callback, $version ) { $plugin = plugin_basename( $file ); if ( is_plugin_active_for_network( $plugin ) ) { - $current_versions = get_site_option( plugin_basename( WP_STREAM_DIR ) . '_connectors', array() ); + $current_versions = get_site_option( WP_Stream_Install::KEY . '_connectors', array() ); $network = true; } elseif ( is_plugin_active( $plugin ) ) { - $current_versions = get_option( plugin_basename( WP_STREAM_DIR ) . '_connectors', array() ); + $current_versions = get_option( WP_Stream_Install::KEY . '_connectors', array() ); $network = false; } else { return; @@ -321,9 +321,10 @@ public static function register_update_hook( $file, $callback, $version ) { } if ( $network ) { - update_site_option( plugin_basename( WP_STREAM_DIR ) . '_registered_connectors', $current_versions ); - } else { - update_option( plugin_basename( WP_STREAM_DIR ) . '_registered_connectors', $current_versions ); + update_site_option( WP_Stream_Install::KEY . '_registered_connectors', $current_versions ); + } + else { + update_option( WP_Stream_Install::KEY . '_registered_connectors', $current_versions ); } return; diff --git a/includes/install.php b/includes/install.php index 42cf3ca01..80823bd4b 100755 --- a/includes/install.php +++ b/includes/install.php @@ -77,7 +77,6 @@ public static function get_instance() { */ function __construct() { global $wpdb; - self::$current = WP_Stream::VERSION; self::$db_version = self::get_db_version(); self::$stream_url = self_admin_url( WP_Stream_Admin::ADMIN_PARENT_PAGE . '&page=' . WP_Stream_Admin::SETTINGS_PAGE_SLUG ); @@ -102,8 +101,10 @@ function __construct() { * @return null */ private static function check() { + if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { + return; + } if ( empty( self::$db_version ) ) { - $current = self::install( self::$current ); } elseif ( self::$db_version !== self::$current ) { add_action( 'admin_notices', array( __CLASS__, 'update_notice_hook' ) ); @@ -114,11 +115,11 @@ public static function get_db_version() { global $wpdb; $version = get_option( self::KEY ); - if ( ! $version && version_compare( self::$current, '1.3.1', '<=' ) ) { $old_key = $wpdb->get_col( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%wp-stream%_db'" ); if ( ! empty( $old_key ) && is_array( $old_key ) ) { $version = get_option( $old_key[0] ); + update_option( self::KEY, $version ); delete_option( $old_key[0] ); } @@ -154,11 +155,12 @@ public static function prompt_update() { * */ public static function prompt_update_status() { + global $wpdb; check_admin_referer( 'wp_stream_update_db' ); $success_db = self::update( self::$db_version, self::$current ); - if ( $success_db && self::$current === $success_db ) { - $success_op = update_option( self::KEY. '_db', $success_db ); + if ( $success_db ) { + $success_op = update_option( self::KEY, self::$current ); } if ( empty( $success_db ) || empty( $success_op ) ) { @@ -187,8 +189,6 @@ public static function update_notice_hook() { } if ( ! isset( $_REQUEST['wp_stream_update'] ) ) { self::prompt_update(); - } elseif ( 'user_action_required' === $_REQUEST['wp_stream_update' ] ) { - self::prompt_update_status(); } elseif ( 'update_and_continue' === $_REQUEST['wp_stream_update'] ) { self::prompt_update_status(); } @@ -234,14 +234,15 @@ public static function update( $db_version, $current ) { $function = 'wp_stream_update_' . str_ireplace( '.', '', $version ); if ( version_compare( $db_version, $version, '<' ) ) { - $result = call_user_func( $function, $db_version, $current ); + $result = function_exists( $function ) ? call_user_func( $function, $db_version, $current ) : false; if ( $current === $result ) { return $current; } return false; } } - return true; + + return $current; } /** From 8b57839a3709cd49f4ea7a73ea6c4fe81d042b4a Mon Sep 17 00:00:00 2001 From: Chris Olbekson Date: Mon, 7 Apr 2014 11:52:09 -0500 Subject: [PATCH 30/47] Don't rely on plugin_basename for db version option_name - Update db version option key in uninstall routine - Fixes #388 --- includes/admin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/admin.php b/includes/admin.php index b411e9c2b..fdf2b5875 100644 --- a/includes/admin.php +++ b/includes/admin.php @@ -450,7 +450,7 @@ public static function uninstall_plugin() { } // Delete database option - delete_option( plugin_basename( WP_STREAM_DIR ) . '_db' ); + delete_option( WP_Stream_Install::KEY ); delete_option( WP_Stream_Settings::KEY ); delete_option( 'dashboard_stream_activity_options' ); From 74e50fb2fdd302a332df75fa2a4b78cc09dc7cc4 Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Tue, 8 Apr 2014 14:19:19 -0500 Subject: [PATCH 31/47] Change order of update functions, code formatting --- includes/admin.php | 2 +- includes/db-updates.php | 289 ++++++++++++++++++++++------------------ includes/install.php | 8 +- includes/query.php | 20 ++- stream.php | 2 + 5 files changed, 176 insertions(+), 145 deletions(-) diff --git a/includes/admin.php b/includes/admin.php index 142e31152..6c3323adc 100644 --- a/includes/admin.php +++ b/includes/admin.php @@ -67,6 +67,7 @@ public static function load() { // Enable/Disable live update per user add_action( 'wp_ajax_stream_enable_live_update', array( __CLASS__, 'enable_live_update' ) ); + // Toggle filters in list table on/off add_action( 'wp_ajax_stream_toggle_filters', array( __CLASS__, 'toggle_filters' ) ); // Ajax authors list @@ -74,7 +75,6 @@ public static function load() { // Ajax author's name by ID add_action( 'wp_ajax_wp_stream_get_author_name_by_id', array( __CLASS__, 'get_author_name_by_id' ) ); - } /** diff --git a/includes/db-updates.php b/includes/db-updates.php index 472c222d3..96c15cb57 100644 --- a/includes/db-updates.php +++ b/includes/db-updates.php @@ -1,71 +1,171 @@ charset ) ) { - return true; - } + $prefix = WP_Stream_Install::$table_prefix; + $db_version = WP_Stream_Install::$db_version; + $current_version = WP_Stream_Install::$current; - do_action( 'wp_stream_before_db_update_' . $db_version, $current_version ); - $tables = array( 'stream', 'stream_context', 'stream_meta' ); - $collate = ( $wpdb->collate ) ? " COLLATE {$wpdb->collate}" : null; - foreach ( $tables as $table ) { - $wpdb->query( "ALTER TABLE {$prefix}{$table} CONVERT TO CHARACTER SET {$wpdb->charset}{$collate};" ); - } - if ( $wpdb->last_error ) { - return __( 'Database Update Error', 'stream ' ); + $args = array( + 'connector' => 'installer', + 'context' => 'themes', + 'action' => 'edited', + ); + $records = stream_query( $args ); + + foreach ( $records as $record ) { + $file_name = get_stream_meta( $record->ID, 'file', true ); + $theme_name = get_stream_meta( $record->ID, 'name', true ); + + if ( '' !== $theme_name ) { + $matched_themes = array_filter( + wp_get_themes(), + function ( $theme ) use ( $theme_name ) { + return (string)$theme === $theme_name; + } + ); + $theme = array_shift( $matched_themes ); + + // `stream` + $wpdb->update( + $wpdb->stream, + array( + 'summary' => sprintf( WP_Stream_Connector_Editor::get_message(), $file_name, $theme_name ), + ), + array( 'ID' => $record->ID ) + ); + + // `stream_context` + $wpdb->update( + $wpdb->streamcontext, + array( + 'connector' => 'editor', + 'context' => is_object( $theme ) ? $theme->get_template() : $theme_name, + 'action' => 'updated', + ), + array( 'record_id' => $record->ID ) + ); + + update_stream_meta( $record->ID, 'theme_name', $theme_name ); + + if ( is_object( $theme ) ) { + update_stream_meta( $record->ID, 'theme_slug', $theme->get_template() ); + } + } } do_action( 'wp_stream_after_db_update_' . $db_version, $current_version, $wpdb->last_error ); + if ( $wpdb->last_error ) { + return false; + } + return $current_version; } /** - * Update Database to current version from version 1.1.7 + * Update Database to current version from version 1.3.0 * * @param string $db_version Database version updating from * @param string $current_version Database version updating to * * @return bool true if no wpdb errors */ -function wp_stream_update_117( $db_version, $current_version ) { +function wp_stream_update_130( $db_version, $current_version ) { + do_action( 'wp_stream_before_db_update_' . $db_version, $current_version ); + + add_action( 'wp_stream_after_connectors_registration', 'migrate_old_options_to_exclude_tab' ); + + do_action( 'wp_stream_after_db_update_' . $db_version, $current_version, false ); + + return $current_version; +} + +/** + * Function will migrate old options from the General and Connectors tabs into the new Exclude tab + * + * @param $labels array connectors terms labels + * + * @action wp_stream_after_connectors_registration + * @return bool|int|string + */ +function migrate_old_options_to_exclude_tab( $labels ) { global $wpdb; - $prefix = WP_Stream_Install::$table_prefix; + + $prefix = WP_Stream_Install::$table_prefix; + $db_version = WP_Stream_Install::$db_version; + $current_version = WP_Stream_Install::$current; + do_action( 'wp_stream_before_db_update_' . $db_version, $current_version ); - if ( version_compare( $db_version, '1.1.7', '<' ) ) { - $wpdb->query( "ALTER TABLE {$prefix}stream MODIFY ip varchar(39) NULL AFTER created" ); + $old_options = get_option( WP_Stream_Settings::KEY, array() ); + + // Stream > Settings > General > Log Activity for + if ( isset( $old_options['general_log_activity_for'] ) ) { + WP_Stream_Settings::$options['exclude_authors_and_roles'] = array_diff( + array_keys( WP_Stream_Settings::get_roles() ), + $old_options['general_log_activity_for'] + ); + unset( WP_Stream_Settings::$options['general_log_activity_for'] ); + } + + // Stream > Settings > Connectors > Active Connectors + if ( isset( $old_options['connectors_active_connectors'] ) ) { + WP_Stream_Settings::$options['exclude_connectors'] = array_diff( + array_keys( $labels ), + $old_options['connectors_active_connectors'] + ); + unset( WP_Stream_Settings::$options['connectors_active_connectors'] ); } + update_option( WP_Stream_Settings::KEY, WP_Stream_Settings::$options ); + do_action( 'wp_stream_after_db_update_' . $db_version, $current_version, $wpdb->last_error ); + if ( $wpdb->last_error ) { - return __( 'Database Update Error', 'stream ' ); + return false; } return $current_version; } /** - * Update Database to current version from version 1.2.5 + * Update Database to current version from version 1.2.8 * * @param string $db_version Database version updating from * @param string $current_version Database version updating to * * @return bool true if no wpdb errors */ -function wp_stream_update_125( $db_version, $current_version ) { +function wp_stream_update_128( $db_version, $current_version ) { global $wpdb; + $prefix = WP_Stream_Install::$table_prefix; + do_action( 'wp_stream_before_db_update_' . $db_version, $current_version ); $sql = "SELECT r.ID id, r.object_id pid, c.meta_id mid @@ -92,23 +192,27 @@ function wp_stream_update_125( $db_version, $current_version ) { } do_action( 'wp_stream_after_db_update_' . $db_version, $current_version, $wpdb->last_error ); + if ( $wpdb->last_error ) { return __( 'Database Update Error', 'stream ' ); } + return $current_version; } /** - * Update Database to current version from version 1.2.8 + * Update Database to current version from version 1.2.5 * * @param string $db_version Database version updating from * @param string $current_version Database version updating to * * @return bool true if no wpdb errors */ -function wp_stream_update_128( $db_version, $current_version ) { +function wp_stream_update_125( $db_version, $current_version ) { global $wpdb; + $prefix = WP_Stream_Install::$table_prefix; + do_action( 'wp_stream_before_db_update_' . $db_version, $current_version ); $sql = "SELECT r.ID id, r.object_id pid, c.meta_id mid @@ -135,150 +239,73 @@ function wp_stream_update_128( $db_version, $current_version ) { } do_action( 'wp_stream_after_db_update_' . $db_version, $current_version, $wpdb->last_error ); + if ( $wpdb->last_error ) { return __( 'Database Update Error', 'stream ' ); } - return $current_version; -} - -/** - * Update Database to current version from version 1.3.0 - * - * @param string $db_version Database version updating from - * @param string $current_version Database version updating to - * - * @return bool true if no wpdb errors - */ -function wp_stream_update_130( $db_version, $current_version ) { - do_action( 'wp_stream_before_db_update_' . $db_version, $current_version ); - add_action( 'wp_stream_after_connectors_registration', 'migrate_old_options_to_exclude_tab' ); - do_action( 'wp_stream_after_db_update_' . $db_version, $current_version, false ); return $current_version; } /** - * Update Database to current version from version 1.3.1 + * Update Database to current version from version 1.1.7 * * @param string $db_version Database version updating from * @param string $current_version Database version updating to * * @return bool true if no wpdb errors */ -function wp_stream_update_131( $db_version, $current_version ) { - do_action( 'wp_stream_before_db_update_' . $db_version, $current_version ); - add_action( 'wp_stream_after_connectors_registration', 'migrate_installer_edits_to_theme_editor_connector' ); - do_action( 'wp_stream_after_db_update_' . $db_version, $current_version, false ); - - return $current_version; -} - -/** - * Function will migrate old options from the General and Connectors tabs into the new Exclude tab - * - * @param $labels array connectors terms labels - * - * @action wp_stream_after_connectors_registration - * @return bool|int|string - */ -function migrate_old_options_to_exclude_tab( $labels ) { +function wp_stream_update_117( $db_version, $current_version ) { global $wpdb; - $prefix = WP_Stream_Install::$table_prefix; - $db_version = WP_Stream_Install::$db_version; - $current_version = WP_Stream_Install::$current; - do_action( 'wp_stream_before_db_update_' . $db_version, $current_version ); - - $old_options = get_option( WP_Stream_Settings::KEY, array() ); + $prefix = WP_Stream_Install::$table_prefix; - // Stream > Settings > General > Log Activity for - if ( isset( $old_options['general_log_activity_for'] ) ) { - WP_Stream_Settings::$options['exclude_authors_and_roles'] = array_diff( - array_keys( WP_Stream_Settings::get_roles() ), - $old_options['general_log_activity_for'] - ); - unset( WP_Stream_Settings::$options['general_log_activity_for'] ); - } + do_action( 'wp_stream_before_db_update_' . $db_version, $current_version ); - // Stream > Settings > Connectors > Active Connectors - if ( isset( $old_options['connectors_active_connectors'] ) ) { - WP_Stream_Settings::$options['exclude_connectors'] = array_diff( - array_keys( $labels ), - $old_options['connectors_active_connectors'] - ); - unset( WP_Stream_Settings::$options['connectors_active_connectors'] ); + if ( version_compare( $db_version, '1.1.7', '<' ) ) { + $wpdb->query( "ALTER TABLE {$prefix}stream MODIFY ip varchar(39) NULL AFTER created" ); } - update_option( WP_Stream_Settings::KEY, WP_Stream_Settings::$options ); do_action( 'wp_stream_after_db_update_' . $db_version, $current_version, $wpdb->last_error ); + if ( $wpdb->last_error ) { - return false; + return __( 'Database Update Error', 'stream ' ); } return $current_version; } /** - * Function will migrate theme file edit records from Installer connector to the Theme Editor connector + * Update Database to current version from version 1.1.4 * - * @action wp_stream_after_connectors_registration + * @param string $db_version Database version updating from + * @param string $current_version Database version updating to + * + * @return bool true if no wpdb errors */ -function migrate_installer_edits_to_theme_editor_connector() { +function wp_stream_update_114( $db_version, $current_version ) { global $wpdb; - $prefix = WP_Stream_Install::$table_prefix; - $db_version = WP_Stream_Install::$db_version; - $current_version = WP_Stream_Install::$current; - - $args = array( - 'connector' => 'installer', - 'context' => 'themes', - 'action' => 'edited', - ); - $records = stream_query( $args ); - - foreach ( $records as $record ) { - $file_name = get_stream_meta( $record->ID, 'file', true ); - $theme_name = get_stream_meta( $record->ID, 'name', true ); - if ( '' !== $theme_name ) { - $matched_themes = array_filter( - wp_get_themes(), - function ( $theme ) use ( $theme_name ) { - return (string)$theme === $theme_name; - } - ); - $theme = array_shift( $matched_themes ); + $prefix = WP_Stream_Install::$table_prefix; - // `stream` - $wpdb->update( - $wpdb->stream, - array( - 'summary' => sprintf( WP_Stream_Connector_Editor::get_message(), $file_name, $theme_name ), - ), - array( 'ID' => $record->ID ) - ); + if ( ! empty( $wpdb->charset ) ) { + return true; + } - // `stream_context` - $wpdb->update( - $wpdb->streamcontext, - array( - 'connector' => 'editor', - 'context' => is_object( $theme ) ? $theme->get_template() : $theme_name, - 'action' => 'updated', - ), - array( 'record_id' => $record->ID ) - ); + do_action( 'wp_stream_before_db_update_' . $db_version, $current_version ); - update_stream_meta( $record->ID, 'theme_name', $theme_name ); + $tables = array( 'stream', 'stream_context', 'stream_meta' ); + $collate = ( $wpdb->collate ) ? " COLLATE {$wpdb->collate}" : null; - if ( is_object( $theme ) ) { - update_stream_meta( $record->ID, 'theme_slug', $theme->get_template() ); - } - } + foreach ( $tables as $table ) { + $wpdb->query( "ALTER TABLE {$prefix}{$table} CONVERT TO CHARACTER SET {$wpdb->charset}{$collate};" ); } - do_action( 'wp_stream_after_db_update_' . $db_version, $current_version, $wpdb->last_error ); + if ( $wpdb->last_error ) { - return false; + return __( 'Database Update Error', 'stream ' ); } + + do_action( 'wp_stream_after_db_update_' . $db_version, $current_version, $wpdb->last_error ); + return $current_version; -} \ No newline at end of file +} diff --git a/includes/install.php b/includes/install.php index 80823bd4b..467161e83 100755 --- a/includes/install.php +++ b/includes/install.php @@ -77,6 +77,7 @@ public static function get_instance() { */ function __construct() { global $wpdb; + self::$current = WP_Stream::VERSION; self::$db_version = self::get_db_version(); self::$stream_url = self_admin_url( WP_Stream_Admin::ADMIN_PARENT_PAGE . '&page=' . WP_Stream_Admin::SETTINGS_PAGE_SLUG ); @@ -104,6 +105,7 @@ private static function check() { if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { return; } + if ( empty( self::$db_version ) ) { $current = self::install( self::$current ); } elseif ( self::$db_version !== self::$current ) { @@ -156,7 +158,9 @@ public static function prompt_update() { */ public static function prompt_update_status() { global $wpdb; + check_admin_referer( 'wp_stream_update_db' ); + $success_db = self::update( self::$db_version, self::$current ); if ( $success_db ) { @@ -187,6 +191,7 @@ public static function update_notice_hook() { if ( ! current_user_can( WP_Stream_Admin::VIEW_CAP ) ) { return; } + if ( ! isset( $_REQUEST['wp_stream_update'] ) ) { self::prompt_update(); } elseif ( 'update_and_continue' === $_REQUEST['wp_stream_update'] ) { @@ -227,6 +232,7 @@ private static function db_update_versions() { */ public static function update( $db_version, $current ) { require_once WP_STREAM_INC_DIR . 'db-updates.php'; + $prefix = self::$table_prefix; $versions = apply_filters( 'wp_stream_db_update_versions', self::db_update_versions(), $current, $prefix ); @@ -338,4 +344,4 @@ public static function install( $current ) { return $current; } -} \ No newline at end of file +} diff --git a/includes/query.php b/includes/query.php index cf6ac0017..f42c23b6f 100755 --- a/includes/query.php +++ b/includes/query.php @@ -21,6 +21,7 @@ public static function get_instance() { */ public function query( $args ) { global $wpdb; + $defaults = array( // Pagination params 'records_per_page' => 10, @@ -120,8 +121,7 @@ public function query( $args ) { */ if ( $args['date'] ) { $where .= $wpdb->prepare( " AND DATE($wpdb->stream.created) = %s", $args['date'] ); - } - else { + } else { if ( $args['date_from'] ) { $where .= $wpdb->prepare( " AND DATE($wpdb->stream.created) >= %s", $args['date_from'] ); } @@ -245,17 +245,13 @@ public function query( $args ) { if ( in_array( $orderby, $orderable ) ) { $orderby = $wpdb->stream . '.' . $orderby; - } - elseif ( in_array( $orderby, array( 'connector', 'context', 'action' ) ) ) { + } elseif ( in_array( $orderby, array( 'connector', 'context', 'action' ) ) ) { $orderby = $wpdb->streamcontext . '.' . $orderby; - } - elseif ( 'meta_value_num' === $orderby && ! empty( $args['meta_key'] ) ) { + } elseif ( 'meta_value_num' === $orderby && ! empty( $args['meta_key'] ) ) { $orderby = "CAST($wpdb->streammeta.meta_value AS SIGNED)"; - } - elseif ( 'meta_value' === $orderby && ! empty( $args['meta_key'] ) ) { + } elseif ( 'meta_value' === $orderby && ! empty( $args['meta_key'] ) ) { $orderby = "$wpdb->streammeta.meta_value"; - } - else { + } else { $orderby = "$wpdb->stream.ID"; } $orderby = 'ORDER BY ' . $orderby . ' ' . $order; @@ -272,8 +268,7 @@ public function query( $args ) { if ( 'ID' === $fields ) { $select = "$wpdb->stream.ID"; - } - elseif ( 'summary' === $fields ) { + } elseif ( 'summary' === $fields ) { $select = "$wpdb->stream.summary, $wpdb->stream.ID"; } @@ -307,6 +302,7 @@ public function query( $args ) { $meta = $wpdb->get_results( $sql_meta ); $ids_f = array_flip( $ids ); + foreach ( $meta as $meta_record ) { $results[ $ids_f[ $meta_record->record_id ] ]->meta[ $meta_record->meta_key ][] = $meta_record->meta_value; } diff --git a/stream.php b/stream.php index e66b0b600..d4dd58cec 100755 --- a/stream.php +++ b/stream.php @@ -178,6 +178,7 @@ private function verify_database_present() { } global $wpdb; + $message = ''; // Check if all needed DB is present @@ -238,6 +239,7 @@ public static function get_instance() { $class = __CLASS__; self::$instance = new $class; } + return self::$instance; } From 9b36d0394e7560fbb425ad160e68c9fceda10f3a Mon Sep 17 00:00:00 2001 From: Chris Olbekson Date: Tue, 8 Apr 2014 14:30:30 -0500 Subject: [PATCH 32/47] Remove unused WP_STREAM_UPDATE_URL constant --- stream.php | 1 - 1 file changed, 1 deletion(-) diff --git a/stream.php b/stream.php index e66b0b600..cac81cfef 100755 --- a/stream.php +++ b/stream.php @@ -63,7 +63,6 @@ class WP_Stream { private function __construct() { define( 'WP_STREAM_DIR', plugin_dir_path( __FILE__ ) ); define( 'WP_STREAM_URL', plugin_dir_url( __FILE__ ) ); - define( 'WP_STREAM_UPDATE_URL', WP_STREAM_URL . DIRECTORY_SEPARATOR . 'includes/install.php' ); define( 'WP_STREAM_INC_DIR', WP_STREAM_DIR . 'includes/' ); define( 'WP_STREAM_CLASS_DIR', WP_STREAM_DIR . 'classes/' ); From 854418eae93665d48cf7fee4fcf335396232f174 Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Tue, 8 Apr 2014 14:38:04 -0500 Subject: [PATCH 33/47] Space police --- stream.php | 1 + 1 file changed, 1 insertion(+) diff --git a/stream.php b/stream.php index 5d6cb17a3..1dc4566fa 100755 --- a/stream.php +++ b/stream.php @@ -211,6 +211,7 @@ public static function is_valid_php_version() { '

%s

', __( 'Stream requires PHP version 5.3+, plugin is currently NOT ACTIVE.', 'stream' ) ); // xss ok + return false; } From 1f2b38fb289cc9c9973ea6099bf31a72ba76abe3 Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Thu, 10 Apr 2014 13:42:27 -0500 Subject: [PATCH 34/47] Two spaces between PRIMARY KEY and value, as per dbdelta guidelines --- includes/install.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/install.php b/includes/install.php index 467161e83..63b28744d 100755 --- a/includes/install.php +++ b/includes/install.php @@ -276,7 +276,7 @@ public static function install( $current ) { type varchar(20) NOT NULL DEFAULT 'stream', created datetime NOT NULL DEFAULT '0000-00-00 00:00:00', ip varchar(39) NULL, - PRIMARY KEY (ID), + PRIMARY KEY (ID), KEY site_id (site_id), KEY parent (parent), KEY author (author), @@ -301,7 +301,7 @@ public static function install( $current ) { context varchar(100) NOT NULL, action varchar(100) NOT NULL, connector varchar(100) NOT NULL, - PRIMARY KEY (meta_id), + PRIMARY KEY (meta_id), KEY context (context), KEY action (action), KEY connector (connector) @@ -324,7 +324,7 @@ public static function install( $current ) { record_id bigint(20) unsigned NOT NULL, meta_key varchar(200) NOT NULL, meta_value varchar(200) NOT NULL, - PRIMARY KEY (meta_id), + PRIMARY KEY (meta_id), KEY record_id (record_id), KEY meta_key (meta_key), KEY meta_value (meta_value) From 5470ec0fc7bf348f176b490db4966e124e037e70 Mon Sep 17 00:00:00 2001 From: Chris Olbekson Date: Fri, 11 Apr 2014 17:47:31 -0500 Subject: [PATCH 35/47] Change $wpdb query to find version from any previous directories - Changed version compare for updating db key to 1.3.2 or lower --- includes/install.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/install.php b/includes/install.php index 63b28744d..c2a0bad6e 100755 --- a/includes/install.php +++ b/includes/install.php @@ -117,8 +117,8 @@ public static function get_db_version() { global $wpdb; $version = get_option( self::KEY ); - if ( ! $version && version_compare( self::$current, '1.3.1', '<=' ) ) { - $old_key = $wpdb->get_col( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%wp-stream%_db'" ); + if ( ! $version && version_compare( self::$current, '1.3.2', '<=' ) ) { + $old_key = $wpdb->get_col( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%stream%db'" ); if ( ! empty( $old_key ) && is_array( $old_key ) ) { $version = get_option( $old_key[0] ); From 7ef69cf2a4d6905c1e9fa595b50b00c4395f68a6 Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Mon, 14 Apr 2014 14:29:45 -0500 Subject: [PATCH 36/47] Matching actual convention used by plugin_basename( WP_STREAM_DIR ) . '_db' --- includes/install.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/install.php b/includes/install.php index c2a0bad6e..60d8a6942 100755 --- a/includes/install.php +++ b/includes/install.php @@ -118,7 +118,7 @@ public static function get_db_version() { $version = get_option( self::KEY ); if ( ! $version && version_compare( self::$current, '1.3.2', '<=' ) ) { - $old_key = $wpdb->get_col( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%stream%db'" ); + $old_key = $wpdb->get_col( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%stream%_db'" ); if ( ! empty( $old_key ) && is_array( $old_key ) ) { $version = get_option( $old_key[0] ); From 231b36e3f4cf72d58e66c7448c94cdbff79128d4 Mon Sep 17 00:00:00 2001 From: Chris Olbekson Date: Tue, 15 Apr 2014 10:45:03 -0500 Subject: [PATCH 37/47] update method should only return false if error updating - Remove early return to allow multiple version updates to run - return false early only if update function fails - update functions should always return version string unless fail then they should return error object or false --- includes/db-updates.php | 2 +- includes/install.php | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/includes/db-updates.php b/includes/db-updates.php index 96c15cb57..0b60e7f4f 100644 --- a/includes/db-updates.php +++ b/includes/db-updates.php @@ -289,7 +289,7 @@ function wp_stream_update_114( $db_version, $current_version ) { $prefix = WP_Stream_Install::$table_prefix; if ( ! empty( $wpdb->charset ) ) { - return true; + return $current_version; } do_action( 'wp_stream_before_db_update_' . $db_version, $current_version ); diff --git a/includes/install.php b/includes/install.php index 60d8a6942..595957d5a 100755 --- a/includes/install.php +++ b/includes/install.php @@ -241,10 +241,9 @@ public static function update( $db_version, $current ) { if ( version_compare( $db_version, $version, '<' ) ) { $result = function_exists( $function ) ? call_user_func( $function, $db_version, $current ) : false; - if ( $current === $result ) { - return $current; + if ( $current !== $result ) { + return false; } - return false; } } From 4ade7025725a5583ab1a89b802cedea0aa36d793 Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Tue, 15 Apr 2014 23:09:10 -0500 Subject: [PATCH 38/47] Changing docblock descriptions that were misleading --- includes/db-updates.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/includes/db-updates.php b/includes/db-updates.php index 0b60e7f4f..8603f9825 100644 --- a/includes/db-updates.php +++ b/includes/db-updates.php @@ -1,7 +1,7 @@ Date: Wed, 16 Apr 2014 14:28:14 +1000 Subject: [PATCH 39/47] Merge branch 'issue-379' of https://github.com/x-team/wp-stream into issue-379 Conflicts: includes/db-updates.php --- includes/db-updates.php | 48 ++++++++++++++++++++++++++++++++--------- includes/install.php | 2 ++ 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/includes/db-updates.php b/includes/db-updates.php index 0b60e7f4f..becc7261b 100644 --- a/includes/db-updates.php +++ b/includes/db-updates.php @@ -1,7 +1,35 @@ query( "ALTER TABLE {$prefix}stream ADD author_role varchar(20) NOT NULL AFTER author" ); + } + + do_action( 'wp_stream_after_db_update_' . $db_version, $current_version, $wpdb->last_error ); + + if ( $wpdb->last_error ) { + return __( 'Database Update Error', 'stream' ); + } + + return $current_version; +} + +/** + * Update Database to version 1.3.1 * * @param string $db_version Database version updating from * @param string $current_version Database version updating to @@ -88,7 +116,7 @@ function ( $theme ) use ( $theme_name ) { } /** - * Update Database to current version from version 1.3.0 + * Update Database to version 1.3.0 * * @param string $db_version Database version updating from * @param string $current_version Database version updating to @@ -154,7 +182,7 @@ function migrate_old_options_to_exclude_tab( $labels ) { } /** - * Update Database to current version from version 1.2.8 + * Update Database to version 1.2.8 * * @param string $db_version Database version updating from * @param string $current_version Database version updating to @@ -194,14 +222,14 @@ function wp_stream_update_128( $db_version, $current_version ) { do_action( 'wp_stream_after_db_update_' . $db_version, $current_version, $wpdb->last_error ); if ( $wpdb->last_error ) { - return __( 'Database Update Error', 'stream ' ); + return __( 'Database Update Error', 'stream' ); } return $current_version; } /** - * Update Database to current version from version 1.2.5 + * Update Database to version 1.2.5 * * @param string $db_version Database version updating from * @param string $current_version Database version updating to @@ -241,14 +269,14 @@ function wp_stream_update_125( $db_version, $current_version ) { do_action( 'wp_stream_after_db_update_' . $db_version, $current_version, $wpdb->last_error ); if ( $wpdb->last_error ) { - return __( 'Database Update Error', 'stream ' ); + return __( 'Database Update Error', 'stream' ); } return $current_version; } /** - * Update Database to current version from version 1.1.7 + * Update Database to version 1.1.7 * * @param string $db_version Database version updating from * @param string $current_version Database version updating to @@ -269,14 +297,14 @@ function wp_stream_update_117( $db_version, $current_version ) { do_action( 'wp_stream_after_db_update_' . $db_version, $current_version, $wpdb->last_error ); if ( $wpdb->last_error ) { - return __( 'Database Update Error', 'stream ' ); + return __( 'Database Update Error', 'stream' ); } return $current_version; } /** - * Update Database to current version from version 1.1.4 + * Update Database to version 1.1.4 * * @param string $db_version Database version updating from * @param string $current_version Database version updating to @@ -302,7 +330,7 @@ function wp_stream_update_114( $db_version, $current_version ) { } if ( $wpdb->last_error ) { - return __( 'Database Update Error', 'stream ' ); + return __( 'Database Update Error', 'stream' ); } do_action( 'wp_stream_after_db_update_' . $db_version, $current_version, $wpdb->last_error ); diff --git a/includes/install.php b/includes/install.php index 595957d5a..c396da2f5 100755 --- a/includes/install.php +++ b/includes/install.php @@ -213,6 +213,7 @@ private static function db_update_versions() { '1.2.8'/** @version 1.2.8 Change the context for Media connectors to the attachment type */, '1.3.0'/** @version 1.3.0 Backward settings compatibility for old version plugins */, '1.3.1'/** @version 1.3.1 Update records of Installer to Theme Editor connector */, + '1.3.2'/** @version 1.3.2 Add the author_role column */, ); } @@ -269,6 +270,7 @@ public static function install( $current ) { site_id bigint(20) unsigned NOT NULL DEFAULT '1', object_id bigint(20) unsigned NULL, author bigint(20) unsigned NOT NULL DEFAULT '0', + author_role varchar(20) NOT NULL DEFAULT '', summary longtext NOT NULL, visibility varchar(20) NOT NULL DEFAULT 'publish', parent bigint(20) unsigned NOT NULL DEFAULT '0', From 56b8f74c085189e35e6c0d3444b4f45d5b5ea85c Mon Sep 17 00:00:00 2001 From: Chris Olbekson Date: Wed, 16 Apr 2014 17:48:40 -0500 Subject: [PATCH 40/47] Changed version compare to less than or equal to - Make sure db update function runs when updating from version that has update routine function --- includes/install.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/install.php b/includes/install.php index c396da2f5..7b5b9253d 100755 --- a/includes/install.php +++ b/includes/install.php @@ -240,7 +240,7 @@ public static function update( $db_version, $current ) { foreach ( $versions as $version ) { $function = 'wp_stream_update_' . str_ireplace( '.', '', $version ); - if ( version_compare( $db_version, $version, '<' ) ) { + if ( version_compare( $db_version, $version, '<=' ) ) { $result = function_exists( $function ) ? call_user_func( $function, $db_version, $current ) : false; if ( $current !== $result ) { return false; From 73d40113aabb8832254bf0b82bb736f579f13608 Mon Sep 17 00:00:00 2001 From: Chris Olbekson Date: Wed, 16 Apr 2014 18:38:36 -0500 Subject: [PATCH 41/47] Reload WP_Stream_Connectors to run db update action if needed --- includes/db-updates.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/includes/db-updates.php b/includes/db-updates.php index becc7261b..d04517385 100644 --- a/includes/db-updates.php +++ b/includes/db-updates.php @@ -41,6 +41,8 @@ function wp_stream_update_131( $db_version, $current_version ) { add_action( 'wp_stream_after_connectors_registration', 'migrate_installer_edits_to_theme_editor_connector' ); + WP_Stream_Connectors::load(); + do_action( 'wp_stream_after_db_update_' . $db_version, $current_version, false ); return $current_version; @@ -128,6 +130,8 @@ function wp_stream_update_130( $db_version, $current_version ) { add_action( 'wp_stream_after_connectors_registration', 'migrate_old_options_to_exclude_tab' ); + WP_Stream_Connectors::load(); + do_action( 'wp_stream_after_db_update_' . $db_version, $current_version, false ); return $current_version; From 712056a0fa82658737b2dd8621120123d8466145 Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Wed, 16 Apr 2014 19:01:06 -0500 Subject: [PATCH 42/47] Updating deprecated functions --- includes/db-updates.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/includes/db-updates.php b/includes/db-updates.php index d04517385..599485ded 100644 --- a/includes/db-updates.php +++ b/includes/db-updates.php @@ -65,11 +65,11 @@ function migrate_installer_edits_to_theme_editor_connector() { 'context' => 'themes', 'action' => 'edited', ); - $records = stream_query( $args ); + $records = wp_stream_query( $args ); foreach ( $records as $record ) { - $file_name = get_stream_meta( $record->ID, 'file', true ); - $theme_name = get_stream_meta( $record->ID, 'name', true ); + $file_name = wp_stream_get_meta( $record->ID, 'file', true ); + $theme_name = wp_stream_get_meta( $record->ID, 'name', true ); if ( '' !== $theme_name ) { $matched_themes = array_filter( @@ -100,10 +100,10 @@ function ( $theme ) use ( $theme_name ) { array( 'record_id' => $record->ID ) ); - update_stream_meta( $record->ID, 'theme_name', $theme_name ); + wp_stream_update_meta( $record->ID, 'theme_name', $theme_name ); if ( is_object( $theme ) ) { - update_stream_meta( $record->ID, 'theme_slug', $theme->get_template() ); + wp_stream_update_meta( $record->ID, 'theme_slug', $theme->get_template() ); } } } @@ -210,7 +210,7 @@ function wp_stream_update_128( $db_version, $current_version ) { foreach ( $media_records as $record ) { $post = get_post( $record->pid ); $guid = isset( $post->guid ) ? $post->guid : null; - $url = $guid ? $guid : get_stream_meta( $record->id, 'url', true ); + $url = $guid ? $guid : wp_stream_get_meta( $record->id, 'url', true ); if ( ! empty( $url ) ) { $wpdb->update( @@ -257,7 +257,7 @@ function wp_stream_update_125( $db_version, $current_version ) { foreach ( $media_records as $record ) { $post = get_post( $record->pid ); $guid = isset( $post->guid ) ? $post->guid : null; - $url = $guid ? $guid : get_stream_meta( $record->id, 'url', true ); + $url = $guid ? $guid : wp_stream_get_meta( $record->id, 'url', true ); if ( ! empty( $url ) ) { $wpdb->update( From f72869de962c60aebf14079cabccdd8d7ac9fda3 Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Wed, 16 Apr 2014 19:02:28 -0500 Subject: [PATCH 43/47] Code formatting --- includes/admin.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/includes/admin.php b/includes/admin.php index 3ae6fe41b..290abccec 100644 --- a/includes/admin.php +++ b/includes/admin.php @@ -323,8 +323,7 @@ public static function register_update_hook( $file, $callback, $version ) { if ( $network ) { update_site_option( WP_Stream_Install::KEY . '_registered_connectors', $current_versions ); - } - else { + } else { update_option( WP_Stream_Install::KEY . '_registered_connectors', $current_versions ); } From 03630f873d34c301239442e7749d2aaa616cac51 Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Wed, 16 Apr 2014 19:03:37 -0500 Subject: [PATCH 44/47] Change version compare operator back to lessthan only --- includes/install.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/install.php b/includes/install.php index 7b5b9253d..c396da2f5 100755 --- a/includes/install.php +++ b/includes/install.php @@ -240,7 +240,7 @@ public static function update( $db_version, $current ) { foreach ( $versions as $version ) { $function = 'wp_stream_update_' . str_ireplace( '.', '', $version ); - if ( version_compare( $db_version, $version, '<=' ) ) { + if ( version_compare( $db_version, $version, '<' ) ) { $result = function_exists( $function ) ? call_user_func( $function, $db_version, $current ) : false; if ( $current !== $result ) { return false; From 57ef26e530e4852365b96b3a13fb264fd7fdc447 Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Wed, 16 Apr 2014 19:06:40 -0500 Subject: [PATCH 45/47] Tweak update prompt message --- includes/install.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/install.php b/includes/install.php index c396da2f5..e96cfe158 100755 --- a/includes/install.php +++ b/includes/install.php @@ -143,8 +143,8 @@ public static function prompt_update() {

-

-

+

+

From ba8fcf0beb19707e1da670dbcf464febe9469fff Mon Sep 17 00:00:00 2001 From: Luke Carbis Date: Thu, 17 Apr 2014 12:11:06 +1000 Subject: [PATCH 46/47] Remove version compare MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … but add a check to see if the column exists --- includes/db-updates.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/db-updates.php b/includes/db-updates.php index 599485ded..34c4a9a48 100644 --- a/includes/db-updates.php +++ b/includes/db-updates.php @@ -15,7 +15,9 @@ function wp_stream_update_132( $db_version, $current_version ) { do_action( 'wp_stream_before_db_update_' . $db_version, $current_version ); - if ( version_compare( $db_version, '1.3.2', '<' ) ) { + $wpdb->get_results( "SELECT * FROM information_schema.COLUMNS WHERE TABLE_NAME = '{$prefix}stream' AND COLUMN_NAME = 'author_role'" ); + + if ( 0 === $wpdb->num_rows ) { $wpdb->query( "ALTER TABLE {$prefix}stream ADD author_role varchar(20) NOT NULL AFTER author" ); } @@ -294,9 +296,7 @@ function wp_stream_update_117( $db_version, $current_version ) { do_action( 'wp_stream_before_db_update_' . $db_version, $current_version ); - if ( version_compare( $db_version, '1.1.7', '<' ) ) { - $wpdb->query( "ALTER TABLE {$prefix}stream MODIFY ip varchar(39) NULL AFTER created" ); - } + $wpdb->query( "ALTER TABLE {$prefix}stream MODIFY ip varchar(39) NULL AFTER created" ); do_action( 'wp_stream_after_db_update_' . $db_version, $current_version, $wpdb->last_error ); From 4fef0843fe81800010705bd850846a0047598512 Mon Sep 17 00:00:00 2001 From: Luke Carbis Date: Thu, 17 Apr 2014 12:11:22 +1000 Subject: [PATCH 47/47] Store the database version in the network options --- includes/install.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/install.php b/includes/install.php index e96cfe158..f463563bf 100755 --- a/includes/install.php +++ b/includes/install.php @@ -116,13 +116,13 @@ private static function check() { public static function get_db_version() { global $wpdb; - $version = get_option( self::KEY ); + $version = get_site_option( self::KEY ); if ( ! $version && version_compare( self::$current, '1.3.2', '<=' ) ) { $old_key = $wpdb->get_col( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%stream%_db'" ); if ( ! empty( $old_key ) && is_array( $old_key ) ) { $version = get_option( $old_key[0] ); - update_option( self::KEY, $version ); + update_site_option( self::KEY, $version ); delete_option( $old_key[0] ); } } @@ -164,7 +164,7 @@ public static function prompt_update_status() { $success_db = self::update( self::$db_version, self::$current ); if ( $success_db ) { - $success_op = update_option( self::KEY, self::$current ); + $success_op = update_site_option( self::KEY, self::$current ); } if ( empty( $success_db ) || empty( $success_op ) ) {