check what is being written to our log files.
[Pman.Core] / Process / FixDataObjectCtor.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_FixDataObjectCtor 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     
37     function get($p,$opts=array())
38     {
39         $file = realpath($opts['file']);
40         if (!file_exists($file) || !is_writable($file)) {
41             echo "$file: NOT readable or writable\n";
42             exit;
43         }
44         
45         $c = file_get_contents($file);
46         $old_c = $c;
47         if (strpos($c, '<?php') === false) {
48             echo "$file: NOT PHP\n";
49             exit;
50         }
51         $c = preg_replace("/new DataObjects_([a-z_]+)/i", "DB_DataObject::factory('\\1')", $c);
52         
53         /// this one tends t hit a few odd comment examples..
54         //$c = preg_replace("/DataObjects_([a-z_]+)::/i", "DB_DataObject::factory('\\1')->", $c);
55         
56         $c = preg_replace("/DB_DataObject::staticGet\(\"DataObjects_([a-z_]+)\"\s*,/i", "DB_DataObject::factory('\\1')->load(", $c);
57         $c = preg_replace("/DB_DataObject::staticGet\('DataObjects_([a-z_]+)'\s*,/i", "DB_DataObject::factory('\\1')->load(", $c);
58
59       
60         $c = preg_replace("/DB_DataObject::factory\('([a-z_]+)'\)::/i", "DB_DataObject::factory('\\1')->", $c);
61         $c = preg_replace("/DB_DataObjects::factory/i", "DB_DataObject::factory", $c); // typo...
62
63         
64         
65         if ($old_c == $c) {
66             echo "$file: SKIP NO CHANGES\n";
67             exit;
68         }
69         echo "$file: WRITE NEW FILE\n";
70         file_put_contents($file,$c);
71         exit;
72         
73     }
74     
75 }