Skip to content

Small fixes: 5.5 support without warning and relative paths for sql file #2

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ How to use:

sh replace.sh


Licensed under the GPL version 3 or later:
http://www.gnu.org/licenses/gpl.txt

Regards,
Pau Iglesias

Blogestudio
http://blogestudio.com/
===========

Fixes by rysi3k:
- preg_replace modifier "e" is deprecated since PHP 5.5, so replaced with preg_replace_callback
- removed dirname(__FILE__) in file path allows to use relative paths for script and sql file
10 changes: 6 additions & 4 deletions fix-serialization.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/php
<?php

/*
* Blogestudio Fix Serialization 1.2
* Fixer script of length attributes for serialized strings (e.g. Wordpress databases)
Expand Down Expand Up @@ -65,7 +64,7 @@ function unescape_quotes($value) {
} else {

// Compose path from argument
$path = dirname(__FILE__).'/'.$argv[1];
$path = $argv[1]; // removed dirname allows to use relative paths when script called from other working directory
if (!file_exists($path)) {

// Error
Expand Down Expand Up @@ -109,7 +108,10 @@ function unescape_quotes($value) {
$do_preg_replace = true;

// Replace serialized string values
$data = preg_replace('!s:(\d+):([\\\\]?"[\\\\]?"|[\\\\]?"((.*?)[^\\\\])[\\\\]?");!e', "'s:'.strlen(unescape_mysql('$3')).':\"'.unescape_quotes('$3').'\";'", $data);
$data = preg_replace_callback('!s:(\d+):([\\\\]?"[\\\\]?"|[\\\\]?"((.*?)[^\\\\])[\\\\]?");!', function($m) {
if(empty($m[3])) return $m[0]; //dont change anything when no string has 0 chars
return 's:'.strlen(unescape_mysql($m[3])).':"'.unescape_quotes($m[3]).'";';
}, $data);
}

// Close file
Expand Down Expand Up @@ -158,4 +160,4 @@ function unescape_quotes($value) {



?>
?>