From 9bba2b03ec32b78db817b700d80ec9c1471b4e11 Mon Sep 17 00:00:00 2001 From: Alan Knowles Date: Wed, 12 Oct 2016 18:24:05 +0800 Subject: [PATCH] Process/FixCode.php --- Process/FixCode.php | 86 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 Process/FixCode.php diff --git a/Process/FixCode.php b/Process/FixCode.php new file mode 100644 index 00000000..b0663775 --- /dev/null +++ b/Process/FixCode.php @@ -0,0 +1,86 @@ + array( + 'desc' => 'File to process', + 'short' => 'f', + 'min' => 1, + 'max' => 1, + + ), + + ); + + function getAuth() { + $ff = HTML_FlexyFramework::get(); + + if (!$ff->cli) { + die("cli only"); + } + + } + + + var $factory_map = array( + + 'Person' =>'core_person' , + 'Companies'=>'core_company' , + 'group_members'=>'core_group_member' , + 'group_rights'=>'core_group_right' , + 'Groups'=>'core_group' , + 'Office'=>'core_office' , + 'Projects'=>'core_project' , + + // timesheet project.. + 'STAFF' => 'core_person', + 'timesheet' => 'timesheet_week', + 'activity' => 'timesheet_activity', + 'timesheetapprovals' => 'timesheet_week', + 'projectleaders' => 'timesheet_project_leader', + 'userprojects' => 'timesheet_user_project', + + + + ); + + function get($p,$opts) + { + $file = realpath($opts['file']); + if (!file_exists($file) || !is_writable($file)) { + echo "$file: NOT readable or writable\n"; + exit; + } + + $c = file_get_contents($file); + $old_c = $c; + if (strpos($c, 'factory_map as $from=>$to) { + $c = str_ireplace("DB_DataObject::factory('$from')","DB_DataObject::factory('$to')", $c); + $c = str_ireplace("DB_DataObject::factory(\"$from\")","DB_DataObject::factory('$to')", $c); + } + if ($old_c == $c) { + echo "$file: SKIP NO CHANGES\n"; + exit; + } + echo "$file: WRITE NEW FILE\n"; + file_put_contents($file,$c); + exit; + + } + +} \ No newline at end of file -- 2.39.2