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
stream / includes / db-updates.php

db-updates.php in Stream – Activity Log & Audit Trail 3.8.2, at includes/db-updates.php

125 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
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 /**
67 * Version 3.0.0
68 *
69 * Update from 1.4.9
70 *
71 * @param string $db_version New database version.
72 * @param string $current_version Current database version.
73 *
74 * @return string
75 */
76 function wp_stream_update_auto_300( $db_version, $current_version ) {
77 global $wpdb;
78
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
82 $plugin = wp_stream_get_instance();
83 $plugin->install->install( $current_version );
84
85 $starting_row = 0;
86 $rows_per_round = 5000;
87
88 $stream_entries = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->base_prefix}stream_tmp LIMIT %d, %d", $starting_row, $rows_per_round ) );
89
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 );
95
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 );
114 }
115
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 ) );
119 }
120
121 $wpdb->query( "DROP TABLE {$wpdb->base_prefix}stream_tmp, {$wpdb->base_prefix}stream_context_tmp" );
122
123 return $current_version;
124 }
125