PluginProbe
Stream – Activity Log & Audit Trail / 4.2.2
Stream – Activity Log & Audit Trail v4.2.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 4.2.2, at includes/db-updates.php

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