Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions classes/class-install.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function check() {
}

if ( 'update_and_continue' === $update ) {
$this->$success_db = $this->update( $this->db_version, $this->plugin->get_version(), array( 'type' => 'user' ) );
$this->success_db = $this->update( $this->db_version, $this->plugin->get_version(), array( 'type' => 'user' ) );
}

$versions = $this->db_update_versions();
Expand Down Expand Up @@ -352,14 +352,7 @@ public function prompt_update_status() {
*/
public function db_update_versions() {
$db_update_versions = 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 */,
'1.4.0' /* @version 1.4.0 Add the author_role column and prepare tables for multisite support */,
'1.4.2' /* @version 1.4.2 Patch to fix rare multisite upgrade not triggering */,
'1.4.5' /* @version 1.4.5 Patch to fix author_meta broken values */,
'3.0.0' /* @version 3.0.0 Drop the stream_context table, changes to stream table */,
);

/**
Expand All @@ -383,6 +376,7 @@ public function db_update_versions() {
*/
public function update( $db_version, $current_version, $update_args ) {
$versions = $this->db_update_versions();
include_once( $this->plugin->locations['inc_dir'] . 'db-updates.php' );

foreach ( $versions as $version ) {
if ( ! isset( $update_args['type'] ) ) {
Expand Down Expand Up @@ -410,7 +404,7 @@ public function update( $db_version, $current_version, $update_args ) {
*
* @return string
*/
private function install( $current_version ) {
public function install( $current_version ) {
global $wpdb;

require_once ABSPATH . 'wp-admin/includes/upgrade.php';
Expand Down
33 changes: 32 additions & 1 deletion includes/db-updates.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,43 @@
*
* @return string
*/
function wp_stream_update_300( $db_version, $current_version ) {
function wp_stream_update_auto_300( $db_version, $current_version ) {
global $wpdb;

// Get only the author_meta values that are double-serialized
$plugin = wp_stream_get_instance();
$prefix = $plugin->install->table_prefix;

$wpdb->query( "RENAME TABLE {$prefix}stream TO {$prefix}stream_tmp, {$prefix}stream_context TO {$prefix}stream_context_tmp" );

$plugin->install->install( $current_version );

$stream_entries = $wpdb->get_results( "SELECT * FROM {$prefix}stream_tmp" );

foreach ( $stream_entries as $entry ) {
$context = $wpdb->get_row( "SELECT * FROM {$prefix}stream_context_tmp WHERE record_id = {$entry->ID} LIMIT 1" );

$new_entry = array(
'site_id' => $entry->site_id,
'blog_id' => $entry->blog_id,
'user_id' => $entry->author,
'user_role' => $entry->author_role,
'summary' => $entry->summary,
'created' => $entry->created,
'connector' => $context->connector,
'context' => $context->context,
'action' => $context->action,
'ip' => $entry->ip,
);

if ( $entry->object_id && 0 !== $entry->object_id ) {
$new_entry['object_id'] = $entry->object_id;
}

$wpdb->insert( $prefix . 'stream', $new_entry );
}

$wpdb->query( "DROP TABLE {$prefix}stream_tmp, {$prefix}stream_context_tmp" );

return $current_version;
}