Skip to content

Instantly share code, notes, and snippets.

@detain
Created May 17, 2014 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save detain/0826d315d2a6096b2498 to your computer and use it in GitHub Desktop.
Save detain/0826d315d2a6096b2498 to your computer and use it in GitHub Desktop.
<?php
$files = explode(' ', './scripts/map_sql_to_api.php ./scripts/whmcs_import.php ./scripts/map_everything_to_my.php ./scripts/whmcs_import2.php ./phpunit/class_tests/db_mdb2Test.php ./phpunit/class_tests/db_PDOTest.php ./phpunit/class_tests/db_mysqlTest.php ./phpunit/class_tests/db_mysqliTest.php ./include/preconfig.functions.inc.php ./include/accounts/accounts.inc.php ./include/dns/pdns.functions.inc.php ./include/db/class.db_mdb2.functions.inc.php ./include/functions.inc.php ./monitord.php ./monitord_new.php');
foreach ($files as $file)
{
echo "Working on file $file\n";
$txt = file_get_contents($file);
$regex = '/([\s]+)(\$[\w\[\]\'_]+) = new db;\n[\s]+\$[\w\[\]\'_]+->Host = ([^;]+);\n[\s]+\$[\w\[\]\'_]+->Database = ([^;]+);\n[\s]+\$[\w\[\]\'_]+->User = ([^;]+);\n[\s]+\$[\w\[\]\'_]+->Password = ([^;]+);\n[\s]+\$[\w\[\]\'_]+->Type = ([^;]+);/m';
if (preg_match($regex, $txt))
{
$txt = preg_replace($regex, '\1\2 = new db(\4, \5, \6, \3);\1\2->Type = \7;', $txt);
}
$regex = '/([\s]+)(\$[\w\[\]\'_]+) = new db;\n[\s]+\$[\w\[\]\'_]+->Database = ([^;]+);\n[\s]+\$[\w\[\]\'_]+->User = ([^;]+);\n[\s]+\$[\w\[\]\'_]+->Password = ([^;]+);\n[\s]+\$[\w\[\]\'_]+->Host = ([^;]+);\n[\s]+\$[\w\[\]\'_]+->Type = ([^;]+);/m';
if (preg_match($regex, $txt))
{
$txt = preg_replace($regex, '\1\2 = new db(\3, \4, \5, \6);\1\2->Type = \7;', $txt);
}
file_put_contents($file, $txt);
//file_put_contents($file.'.new', $txt);
//echo `diff -wu $file $file.new;`;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment