| 1 |
<?php |
| 2 |
/** |
| 3 |
* Version 3.0.0 |
| 4 |
* |
| 5 |
* Update from 1.4.9 |
| 6 |
* |
| 7 |
* @param string $db_version |
| 8 |
* @param string $current_version |
| 9 |
* |
| 10 |
* @return string |
| 11 |
*/ |
| 12 |
function wp_stream_update_auto_300( $db_version, $current_version ) { |
| 13 |
global $wpdb; |
| 14 |
|
| 15 |
// Get only the author_meta values that are double-serialized |
| 16 |
$plugin = wp_stream_get_instance(); |
| 17 |
$prefix = $plugin->install->table_prefix; |
| 18 |
|
| 19 |
$wpdb->query( "RENAME TABLE {$prefix}stream TO {$prefix}stream_tmp, {$prefix}stream_context TO {$prefix}stream_context_tmp" ); |
| 20 |
|
| 21 |
$plugin->install->install( $current_version ); |
| 22 |
|
| 23 |
$stream_entries = $wpdb->get_results( "SELECT * FROM {$prefix}stream_tmp" ); |
| 24 |
|
| 25 |
foreach ( $stream_entries as $entry ) { |
| 26 |
$context = $wpdb->get_row( "SELECT * FROM {$prefix}stream_context_tmp WHERE record_id = {$entry->ID} LIMIT 1" ); |
| 27 |
|
| 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 |
); |
| 40 |
|
| 41 |
if ( $entry->object_id && 0 !== $entry->object_id ) { |
| 42 |
$new_entry['object_id'] = $entry->object_id; |
| 43 |
} |
| 44 |
|
| 45 |
$wpdb->insert( $prefix . 'stream', $new_entry ); |
| 46 |
} |
| 47 |
|
| 48 |
$wpdb->query( "DROP TABLE {$prefix}stream_tmp, {$prefix}stream_context_tmp" ); |
| 49 |
|
| 50 |
return $current_version; |
| 51 |
} |
| 52 |
|