more quote identeiifers fixessss
[Pman.Core] / Process / FixCode.php
1 <?php
2
3 /*
4  *
5  *
6 find . | grep php | awk '{ print "php admin.php Core/Process/FixCode -f " $1 }' | sh
7 */
8
9 require_once 'Pman.php';
10
11 class Pman_Core_Process_FixCode extends Pman 
12 {
13     static $cli_desc = "Coverts old code using replacements"; 
14     
15     static $cli_opts = array(
16         'file' => array(
17             'desc' => 'File to process',
18             'short' => 'f',
19             'min' => 1,
20             'max' => 1,
21             
22         ),
23         
24     );
25     
26     function getAuth() {
27         $ff = HTML_FlexyFramework::get();
28         
29         if (!$ff->cli) {
30             die("cli only");
31         }
32         
33     }
34     
35     
36     var $factory_map = array(
37     
38             'Person' =>'core_person' ,
39             'Companies'=>'core_company' ,
40             'group_members'=>'core_group_member' ,
41             'group_rights'=>'core_group_right' ,
42             'Groups'=>'core_group' ,
43             'Office'=>'core_office' ,
44             'Projects'=>'core_project' ,
45             
46             // timesheet project..
47             'STAFF' => 'core_person',
48             'timesheet' => 'timesheet_week',
49             'activity' => 'timesheet_activity',
50             'timesheetapprovals' => 'timesheet_week',
51             'projectleaders' => 'timesheet_project_leader',
52             'userprojects' => 'timesheet_user_project',
53             
54             
55             
56     );
57     
58     function get($p,$opts=array())
59     {
60         $file = realpath($opts['file']);
61         if (!file_exists($file) || !is_writable($file)) {
62             echo "$file: NOT readable or writable\n";
63             exit;
64         }
65         
66         $c = file_get_contents($file);
67         $old_c = $c;
68         if (strpos($c, '<?php') === false) {
69             echo "$file: NOT PHP\n";
70             exit;
71         }
72         foreach($this->factory_map as $from=>$to) {
73             
74             $c = preg_replace("/DB_DataObject::factory\((\s{0,}['\"]" . $from . "['\"]\s{0,})\)/i", "DB_DataObject::factory('{$to}')", $c);
75             
76 //            $c = str_ireplace("DB_DataObject::factory('$from')","DB_DataObject::factory('$to')", $c);
77 //            $c = str_ireplace("DB_DataObject::factory(\"$from\")","DB_DataObject::factory('$to')", $c);
78             
79         }
80         if ($old_c == $c) {
81             echo "$file: SKIP NO CHANGES\n";
82             exit;
83         }
84         echo "$file: WRITE NEW FILE\n";
85         file_put_contents($file,$c);
86         exit;
87         
88     }
89     
90 }