| @@ -1,6 +1,64 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | + * Version 3.0.8 | |
| 4 | + * | |
| 5 | + * Force update for older versions to call \dbdelta in install() method to fix column widths. | |
| 6 | + * | |
| 7 | + * @param string $db_version | |
| 8 | + * @param string $current_version | |
| 9 | + * | |
| 10 | + * @return string | |
| 11 | + */ | |
| 12 | +function wp_stream_update_auto_308( $db_version, $current_version ) { | |
| 13 | + $plugin = wp_stream_get_instance(); | |
| 14 | + $plugin->install->install( $current_version ); | |
| 15 | + | |
| 16 | + return $current_version; | |
| 17 | +} | |
| 18 | + | |
| 19 | +/** | |
| 20 | + * Version 3.0.2 | |
| 21 | + * | |
| 22 | + * @param string $db_version | |
| 23 | + * @param string $current_version | |
| 24 | + * | |
| 25 | + * @return string | |
| 26 | + */ | |
| 27 | +function wp_stream_update_302( $db_version, $current_version ) { | |
| 28 | + global $wpdb; | |
| 29 | + | |
| 30 | + $stream_entries = $wpdb->get_results( "SELECT * FROM {$wpdb->base_prefix}stream" ); | |
| 31 | + foreach ( $stream_entries as $entry ) { | |
| 32 | + $class = 'Connector_' . $entry->context; | |
| 33 | + if ( class_exists( $class ) ) { | |
| 34 | + $connector = new $class(); | |
| 35 | + $wpdb->update( | |
| 36 | + $wpdb->base_prefix . 'stream', | |
| 37 | + array( | |
| 38 | + 'connector' => $connector->name, | |
| 39 | + ), | |
| 40 | + array( | |
| 41 | + 'ID' => $entry->ID, | |
| 42 | + ) | |
| 43 | + ); | |
| 44 | + } else { | |
| 45 | + $wpdb->update( | |
| 46 | + $wpdb->base_prefix . 'stream', | |
| 47 | + array( | |
| 48 | + 'connector' => strtolower( $entry->connector ), | |
| 49 | + ), | |
| 50 | + array( | |
| 51 | + 'ID' => $entry->ID, | |
| 52 | + ) | |
| 53 | + ); | |
| 54 | + } | |
| 55 | + } | |
| 56 | + | |
| 57 | + return $current_version; | |
| 58 | +} | |
| 59 | + | |
| 60 | +/** | |
| 3 | 61 | * Version 3.0.0 |
| 4 | 62 | * |
| 5 | 63 | * Update from 1.4.9 |
| 6 | 64 | * |
| @@ -12,40 +70,49 @@ | ||
| 12 | 70 | function wp_stream_update_auto_300( $db_version, $current_version ) { |
| 13 | 71 | global $wpdb; |
| 14 | 72 | |
| 15 | 73 | // Get only the author_meta values that are double-serialized |
| 74 | + $wpdb->query( "RENAME TABLE {$wpdb->base_prefix}stream TO {$wpdb->base_prefix}stream_tmp, {$wpdb->base_prefix}stream_context TO {$wpdb->base_prefix}stream_context_tmp" ); | |
| 75 | + | |
| 16 | 76 | $plugin = wp_stream_get_instance(); |
| 17 | - $prefix = $plugin->install->table_prefix; | |
| 77 | + $plugin->install->install( $current_version ); | |
| 18 | 78 | |
| 19 | - $wpdb->query( "RENAME TABLE {$prefix}stream TO {$prefix}stream_tmp, {$prefix}stream_context TO {$prefix}stream_context_tmp" ); | |
| 79 | + $starting_row = 0; | |
| 80 | + $rows_per_round = 5000; | |
| 20 | 81 | |
| 21 | - $plugin->install->install( $current_version ); | |
| 82 | + $stream_entries = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->base_prefix}stream_tmp LIMIT %d, %d", $starting_row, $rows_per_round ) ); | |
| 22 | 83 | |
| 23 | - $stream_entries = $wpdb->get_results( "SELECT * FROM {$prefix}stream_tmp" ); | |
| 84 | + while ( ! empty( $stream_entries ) ) { | |
| 85 | + foreach ( $stream_entries as $entry ) { | |
| 86 | + $context = $wpdb->get_row( | |
| 87 | + $wpdb->prepare( "SELECT * FROM {$wpdb->base_prefix}stream_context_tmp WHERE record_id = %s LIMIT 1", $entry->ID ) | |
| 88 | + ); | |
| 24 | 89 | |
| 25 | - foreach ( $stream_entries as $entry ) { | |
| 26 | - $context = $wpdb->get_row( "SELECT * FROM {$prefix}stream_context_tmp WHERE record_id = {$entry->ID} LIMIT 1" ); | |
| 90 | + $new_entry = array( | |
| 91 | + 'site_id' => $entry->site_id, | |
| 92 | + 'blog_id' => $entry->blog_id, | |
| 93 | + 'user_id' => $entry->author, | |
| 94 | + 'user_role' => $entry->author_role, | |
| 95 | + 'summary' => $entry->summary, | |
| 96 | + 'created' => $entry->created, | |
| 97 | + 'connector' => $context->connector, | |
| 98 | + 'context' => $context->context, | |
| 99 | + 'action' => $context->action, | |
| 100 | + 'ip' => $entry->ip, | |
| 101 | + ); | |
| 27 | 102 | |
| 28 | - $new_entry = array( | |
| 29 | - 'site_id' => $entry->site_id, | |
| 30 | - 'blog_id' => $entry->blog_id, | |
| 31 | - 'user_id' => $entry->author, | |
| 32 | - 'user_role' => $entry->author_role, | |
| 33 | - 'summary' => $entry->summary, | |
| 34 | - 'created' => $entry->created, | |
| 35 | - 'connector' => $context->connector, | |
| 36 | - 'context' => $context->context, | |
| 37 | - 'action' => $context->action, | |
| 38 | - 'ip' => $entry->ip, | |
| 39 | - ); | |
| 103 | + if ( $entry->object_id && 0 !== $entry->object_id ) { | |
| 104 | + $new_entry['object_id'] = $entry->object_id; | |
| 105 | + } | |
| 40 | 106 | |
| 41 | - if ( $entry->object_id && 0 !== $entry->object_id ) { | |
| 42 | - $new_entry['object_id'] = $entry->object_id; | |
| 107 | + $wpdb->insert( $wpdb->base_prefix . 'stream', $new_entry ); | |
| 43 | 108 | } |
| 44 | 109 | |
| 45 | - $wpdb->insert( $prefix . 'stream', $new_entry ); | |
| 110 | + $starting_row += $rows_per_round; | |
| 111 | + | |
| 112 | + $stream_entries = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->base_prefix}stream_tmp LIMIT %d, %d", $starting_row, $rows_per_round ) ); | |
| 46 | 113 | } |
| 47 | 114 | |
| 48 | - $wpdb->query( "DROP TABLE {$prefix}stream_tmp, {$prefix}stream_context_tmp" ); | |
| 115 | + $wpdb->query( "DROP TABLE {$wpdb->base_prefix}stream_tmp, {$wpdb->base_prefix}stream_context_tmp" ); | |
| 49 | 116 | |
| 50 | 117 | return $current_version; |
| 51 | 118 | } |