PluginProbe
Stream – Activity Log & Audit Trail / 3.8.2
Stream – Activity Log & Audit Trail v3.8.2
4.4.0 4.3.0 4.2.2 4.2.1 trunk 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.1 3.1.1 3.10.0 3.2.0 3.2.1 3.2.2 3.2.3 All 50 releases
← All changes | includes/db-updates.php +98 -25 3.0.1 → 3.8.2 View file →
@@ -1,12 +1,76 @@
1 1 <?php
2 2 /**
3 + * Defines DB migrations.
4 + *
5 + * @package WP_Stream
6 + */
7 +
8 +/**
9 + * Version 3.0.8
10 + *
11 + * Force update for older versions to call \dbdelta in install() method to fix column widths.
12 + *
13 + * @param string $db_version New database version.
14 + * @param string $current_version Current database version.
15 + *
16 + * @return string
17 + */
18 +function wp_stream_update_auto_308( $db_version, $current_version ) {
19 + $plugin = wp_stream_get_instance();
20 + $plugin->install->install( $current_version );
21 +
22 + return $current_version;
23 +}
24 +
25 +/**
26 + * Version 3.0.2
27 + *
28 + * @param string $db_version New database version.
29 + * @param string $current_version Current database version.
30 + *
31 + * @return string
32 + */
33 +function wp_stream_update_302( $db_version, $current_version ) {
34 + global $wpdb;
35 +
36 + $stream_entries = $wpdb->get_results( "SELECT * FROM {$wpdb->base_prefix}stream" );
37 + foreach ( $stream_entries as $entry ) {
38 + $class = 'Connector_' . $entry->context;
39 + if ( class_exists( $class ) ) {
40 + $connector = new $class();
41 + $wpdb->update(
42 + $wpdb->base_prefix . 'stream',
43 + array(
44 + 'connector' => $connector->name,
45 + ),
46 + array(
47 + 'ID' => $entry->ID,
48 + )
49 + );
50 + } else {
51 + $wpdb->update(
52 + $wpdb->base_prefix . 'stream',
53 + array(
54 + 'connector' => strtolower( $entry->connector ),
55 + ),
56 + array(
57 + 'ID' => $entry->ID,
58 + )
59 + );
60 + }
61 + }
62 +
63 + return $current_version;
64 +}
65 +
66 +/**
3 67 * Version 3.0.0
4 68 *
5 69 * Update from 1.4.9
6 70 *
7 - * @param string $db_version
8 - * @param string $current_version
71 + * @param string $db_version New database version.
72 + * @param string $current_version Current database version.
9 73 *
10 74 * @return string
11 75 */
12 76 function wp_stream_update_auto_300( $db_version, $current_version ) {
@@ -11,41 +75,50 @@
11 75 */
12 76 function wp_stream_update_auto_300( $db_version, $current_version ) {
13 77 global $wpdb;
14 78
15 - // Get only the author_meta values that are double-serialized
79 + // Get only the author_meta values that are double-serialized.
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" );
81 +
16 82 $plugin = wp_stream_get_instance();
17 - $prefix = $plugin->install->table_prefix;
83 + $plugin->install->install( $current_version );
18 84
19 - $wpdb->query( "RENAME TABLE {$prefix}stream TO {$prefix}stream_tmp, {$prefix}stream_context TO {$prefix}stream_context_tmp" );
85 + $starting_row = 0;
86 + $rows_per_round = 5000;
20 87
21 - $plugin->install->install( $current_version );
88 + $stream_entries = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->base_prefix}stream_tmp LIMIT %d, %d", $starting_row, $rows_per_round ) );
22 89
23 - $stream_entries = $wpdb->get_results( "SELECT * FROM {$prefix}stream_tmp" );
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 + );
24 95
25 - foreach ( $stream_entries as $entry ) {
26 - $context = $wpdb->get_row( "SELECT * FROM {$prefix}stream_context_tmp WHERE record_id = {$entry->ID} LIMIT 1" );
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 + );
27 108
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 - );
109 + if ( $entry->object_id && 0 !== $entry->object_id ) {
110 + $new_entry['object_id'] = $entry->object_id;
111 + }
40 112
41 - if ( $entry->object_id && 0 !== $entry->object_id ) {
42 - $new_entry['object_id'] = $entry->object_id;
113 + $wpdb->insert( $wpdb->base_prefix . 'stream', $new_entry );
43 114 }
44 115
45 - $wpdb->insert( $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 ) );
46 119 }
47 120
48 - $wpdb->query( "DROP TABLE {$prefix}stream_tmp, {$prefix}stream_context_tmp" );
121 + $wpdb->query( "DROP TABLE {$wpdb->base_prefix}stream_tmp, {$wpdb->base_prefix}stream_context_tmp" );
49 122
50 123 return $current_version;
51 124 }