Skip to content
Permalink
Browse files

Merge pull request #749 from xwp/bugfix/issue-733

Add a migration script for upgrading to Stream from 1.4.9
  • Loading branch information...
Luke Carbis
Luke Carbis committed Sep 2, 2015
2 parents 58bb85d + 340ab6a commit 55d7679998148aa9332f476afbc168cca2d0895e
Showing with 36 additions and 11 deletions.
  1. +4 −10 classes/class-install.php
  2. +32 −1 includes/db-updates.php
@@ -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();
@@ -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 */,
);
/**
@@ -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'] ) ) {
@@ -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';
@@ -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;
}

0 comments on commit 55d7679

Please sign in to comment.
You can’t perform that action at this time.