| 1 |
<?php |
| 2 |
/** |
| 3 |
* Version 3.0.2 |
| 4 |
* |
| 5 |
* @param string $db_version |
| 6 |
* @param string $current_version |
| 7 |
* |
| 8 |
* @return string |
| 9 |
*/ |
| 10 |
function wp_stream_update_302( $db_version, $current_version ) { |
| 11 |
global $wpdb; |
| 12 |
|
| 13 |
$plugin = wp_stream_get_instance(); |
| 14 |
$prefix = $plugin->install->table_prefix; |
| 15 |
|
| 16 |
$stream_entries = $wpdb->get_results( "SELECT * FROM {$prefix}stream" ); |
| 17 |
foreach ( $stream_entries as $entry ) { |
| 18 |
$class = 'Connector_' . $entry->context; |
| 19 |
if ( class_exists( $class ) ) { |
| 20 |
$connector = new $class(); |
| 21 |
$wpdb->update( $prefix . 'stream', array( 'connector' => $connector->name ), array( 'ID' => $entry->ID ) ); |
| 22 |
} else { |
| 23 |
$wpdb->update( $prefix . 'stream', array( 'connector' => strtolower( $entry->connector ) ), array( 'ID' => $entry->ID ) ); |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
return $current_version; |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Version 3.0.0 |
| 32 |
* |
| 33 |
* Update from 1.4.9 |
| 34 |
* |
| 35 |
* @param string $db_version |
| 36 |
* @param string $current_version |
| 37 |
* |
| 38 |
* @return string |
| 39 |
*/ |
| 40 |
function wp_stream_update_auto_300( $db_version, $current_version ) { |
| 41 |
global $wpdb; |
| 42 |
|
| 43 |
// Get only the author_meta values that are double-serialized |
| 44 |
$plugin = wp_stream_get_instance(); |
| 45 |
$prefix = $plugin->install->table_prefix; |
| 46 |
|
| 47 |
$wpdb->query( "RENAME TABLE {$prefix}stream TO {$prefix}stream_tmp, {$prefix}stream_context TO {$prefix}stream_context_tmp" ); |
| 48 |
|
| 49 |
$plugin->install->install( $current_version ); |
| 50 |
|
| 51 |
$stream_entries = $wpdb->get_results( "SELECT * FROM {$prefix}stream_tmp" ); |
| 52 |
|
| 53 |
foreach ( $stream_entries as $entry ) { |
| 54 |
$context = $wpdb->get_row( "SELECT * FROM {$prefix}stream_context_tmp WHERE record_id = {$entry->ID} LIMIT 1" ); |
| 55 |
|
| 56 |
$new_entry = array( |
| 57 |
'site_id' => $entry->site_id, |
| 58 |
'blog_id' => $entry->blog_id, |
| 59 |
'user_id' => $entry->author, |
| 60 |
'user_role' => $entry->author_role, |
| 61 |
'summary' => $entry->summary, |
| 62 |
'created' => $entry->created, |
| 63 |
'connector' => $context->connector, |
| 64 |
'context' => $context->context, |
| 65 |
'action' => $context->action, |
| 66 |
'ip' => $entry->ip, |
| 67 |
); |
| 68 |
|
| 69 |
if ( $entry->object_id && 0 !== $entry->object_id ) { |
| 70 |
$new_entry['object_id'] = $entry->object_id; |
| 71 |
} |
| 72 |
|
| 73 |
$wpdb->insert( $prefix . 'stream', $new_entry ); |
| 74 |
} |
| 75 |
|
| 76 |
$wpdb->query( "DROP TABLE {$prefix}stream_tmp, {$prefix}stream_context_tmp" ); |
| 77 |
|
| 78 |
return $current_version; |
| 79 |
} |
| 80 |
|