3 * Table Definition for builder
5 require_once 'DB/DataObject.php';
7 class Pman_Builder_DataObjects_Builder extends DB_DataObject
10 /* the code below is auto generated do not remove the above tag */
12 public $__table = 'builder'; // table name
13 public $id; // int(11) not_null primary_key auto_increment
14 public $name; // string(128) not_null
15 public $json; // blob(-1) not_null blob
16 public $btype; // string(16) not_null
17 public $app; // string(64) not_null
18 public $module; // string(128) not_null
21 /* the code above is auto generated do not remove the tag below */
23 function applySort($au, $sort, $dir, $cols)
25 // DB_DAtaObject::debugLevel(1);
26 $this->orderBy( 'builder.app asc, builder.module asc');
32 function onInsert($req,$roo)
34 if (!empty($req['gitpath']) && !empty($this->module)) {
35 $this->writeCopy($req['gitpath'],$roo);
38 function onUpdate($old , $req, $roo)
40 if (!empty($req['gitpath']) && !empty($this->module)) {
41 $file = $this->writeCopy($req['gitpath'], $roo);
42 $this->gitCommit($file );
47 function gitCommit($file )
50 $dir = dirname($file);
52 if ($this->_new_file) {
53 $cmd = "git add " . escapeshellarg($n);
57 $cmd = "git commit -m 'commit by builder' " . escapeshellarg($n);
64 function writeCopy($path,$roo)
67 if (!file_exists($path)) {
72 require_once 'Pman/Builder/Code.php';
73 $x = new Pman_Builder_Code();
74 $this->_new_file = false;
75 if (!file_exists($path.'/'. $this->module.'.js')) {
76 $this->_new_file = true;
78 if (!$this->_new_file && !is_writable($path.'/'. $this->module.'.js')) {
79 $roo->jerr("Can not write to " . $path.'/'. $this->module.'.js');
82 if ($this->_new_file && !is_writable($path)) {
83 $roo->jerr("Can not write to " . $path);
87 file_put_contents($path.'/'. $this->module.'.js',
88 $x->toJSFile(json_decode($this->json))) ;
89 return $path.'/'. $this->module.'.js';
93 $ret = $this->toArray();
94 // update return the code.!!!
95 if (isset($_SERVER["REQUEST_METHOD"]) && $_SERVER["REQUEST_METHOD"] == 'POST') {
96 require_once 'Pman/Builder/Code.php';
97 $x = new Pman_Builder_Code();
98 $ret['code'] = $x->toJSFile(json_decode($this->json), $this->json);