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