Skip to content

Instantly share code, notes, and snippets.

@karrikas
Last active September 21, 2015 12:43
Show Gist options
  • Save karrikas/970fd787e3e56b796831 to your computer and use it in GitHub Desktop.
Save karrikas/970fd787e3e56b796831 to your computer and use it in GitHub Desktop.
Custom task to clean wordpress serialized information in dump file
<project name="xxx" default="dist">
<target name="_init_wp_serialize">
<adhoc-task name="wp-serialize-clean"><![CDATA[
class Wp_Serialice_Update extends Task {
private $file;
function setFile($file) {
$this->file = $file;
}
function main() {
$file = file_get_contents($this->file);
if (preg_match_all('/s:([0-9]+):\\\"(http[^\"]+)\"/', $file, $res, PREG_SET_ORDER)) {
foreach($res as $r) {
$total = strlen($r[2])-1;
if ($total != $r[1]) {
$nstr = str_replace($r[1], $total, $r[0]);
$file = str_replace($r[0], $nstr, $file);
}
}
}
file_put_contents($this->file, $file);
}
}
]]></adhoc-task>
<echo message="Initialized Wp_Serialize_Update ad hoc task." />
</target>
<target name="wp:serialize:clean" depends="_init_wp_serialize">
<wp-serialize-clean file="build/db.sql"/>
</target>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment