-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not serialize already serialized values #515
Changes from 6 commits
be84467
e045e21
98d7b0d
8416dcd
741fe44
c0ab326
215e388
4164e81
9dfe61d
98ed116
acb80aa
a646c1b
f62ede3
6620d7e
bfc2170
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,32 @@ | ||
<?php | ||
|
||
/** | ||
* Version 1.4.5 | ||
* | ||
* Fix double serialized values in DB | ||
* | ||
* @param string $db_version Database version updating from | ||
* @param string $current_version Database version updating to | ||
* | ||
* @return string $current_version if updated correctly | ||
*/ | ||
function wp_stream_update_145( $db_version, $current_version ) { | ||
set_time_limit( 0 ); // This will probably take abit of time! | ||
global $wpdb; | ||
// Get all author_meta meta values, serialize them properly | ||
$sql = "SELECT record_id, meta_value WHERE meta_key = 'author_meta'"; | ||
$rows = $wpdb->get_results( $sql ); | ||
foreach ( $rows as $row ) { | ||
$row->meta_value = maybe_unserialize( $row->meta_value ); | ||
if ( is_serialized( $row->meta_value ) ) { | ||
$row->meta_value = maybe_unserialize( $meta_value ); | ||
} | ||
// update_metadata will serialize it back | ||
wp_stream_update_meta( $row->record_id, 'author_meta', $row->meta_value ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would adding another if ( is_serialized( $row->meta_value ) ) {
$row->meta_value = @unserialize( $row->meta_value );
if ( is_serialized( $row->meta_value ) ) {
$row->meta_value = @unserialize( $meta_value );
}
// update_metadata will serialize it back
wp_stream_update_meta( $row->record_id, 'author_meta', $row->meta_value );
} Reference: wp-includes/functions.php:252-256 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lukecarbis Yea, that makes perfect sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 215e388 |
||
} | ||
return $current_version; | ||
} | ||
|
||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @shadyvb from the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am so wrong. It is getting double-serialized, as @shady pointed out: |
||
* Version 1.4.2 | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,9 +80,6 @@ public function log( $connector, $message, $args, $object_id, $contexts, $user_i | |
'agent' => WP_Stream_Author::get_current_agent(), | ||
); | ||
} | ||
if ( isset( $args['author_meta'] ) ) { | ||
$args['author_meta'] = maybe_serialize( $args['author_meta'] ); | ||
} | ||
|
||
// Remove meta with null values from being logged | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without this serialization, I recall seeing that multiple stream meta records would get entered for each value in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @westonruter I fixed that in the PR i issued, now the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lukecarbis Sorry, not following. The PR i mentioned in my last comment is #515 ( this one ). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, sorry. Ignore my last. |
||
$meta = array_filter( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shadyvb we could speed this up a huge amount, and skip entries that aren't already malformed, by doing a
LIKE
query like so:Or a
SUBSTRING(meta_value…)
could be used.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@westonruter /five!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@westonruter Added in 4164e81, removed the redundant check ( since they'll all be double serialized )
/five!