Import/Core_notify.php
[Pman.Core] / Import / Core_notify.php
1 <?php
2
3 require_once 'Pman/Roo.php';
4
5 class Pman_Core_Import_Core_notify extends Pman_Roo 
6 {
7     static $cli_desc = "Create Core.NotifyType from core notify"; 
8     
9     static $cli_opts = array(
10         
11     );
12     
13     function getAuth()
14     {
15         if (!HTML_FlexyFramework::get()->cli) {
16             return false;
17         }
18         
19         return true;
20         
21     }
22
23     var $defaults = array();
24     
25     function get()
26     {   
27         
28         $this->transObj = DB_DataObject::Factory('core_enum');
29         
30         $this->transObj->query('BEGIN');
31         
32         PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError'));
33         
34         $this->modules = $this->modulesList();
35         
36         $this->etype();
37         
38         $this->defaults();
39         
40         foreach ($this->defaults as $k => $v){
41             $enum = DB_DataObject::factory('core_enum');
42             $enum->setFrom(array(
43                 'etype' => $this->etype->name,
44                 'name' => $k,
45                 'active' => 1
46             ));
47             
48             if($enum->find(true)){
49                 continue;
50             }
51             
52             $enum->display_name = $v;
53             $enum->insert();
54         }
55         
56         
57         
58         
59         
60     }
61     
62     function etype()
63     {
64         $this->etype = DB_DataObject::factory('core_enum');
65         $this->etype->setFrom(array(
66             'etype' => '',
67             'name' => 'Core.NotifyType',
68             'display_name' => 'Core.NotifyType',
69             'active' => 1
70         ));
71         
72         if($this->etype->find(true)){
73             return;
74         }
75         
76         $this->etype->insert();
77     }
78     
79     function defaults()
80     {
81         foreach ($this->modules as $m){
82             $file = $this->rootDir. "/Pman/$m/Core.NotifyType.json";
83             
84             if(!file_exists($file)){
85                 continue;
86             }
87             
88             $this->defaults = array_merge($this->defaults, json_decode(file_get_contents($file), true)) ;
89         }
90         
91     }
92     
93     function log($str)
94     {
95         echo "$str \n";
96     }
97 }