PHP7 fix
[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($v, $opts=array())
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         $notify = DB_DataObject::factory('core_notify');
57         $notify->selectAdd();
58         $notify->selectAdd("
59             DISTINCT(evtype) AS evtype
60         ");
61         
62         $types = $notify->fetchAll();
63         
64         foreach ($types as $t){
65             $enum = DB_DataObject::factory('core_enum');
66             $enum->setFrom(array(
67                 'etype' => $this->etype->name,
68                 'name' => $t->evtype,
69                 'active' => 1
70             ));
71             
72             if($enum->find(true)){
73                 continue;
74             }
75             
76             $enum->display_name = $t->evtype;
77             $enum->insert();
78         }
79         
80         $this->jok('DONE');
81         
82         
83     }
84     
85     function etype()
86     {
87         $this->etype = DB_DataObject::factory('core_enum');
88         $this->etype->setFrom(array(
89             'etype' => '',
90             'name' => 'Core.NotifyType',
91             'display_name' => 'Core.NotifyType',
92             'active' => 1
93         ));
94         
95         if($this->etype->find(true)){
96             return;
97         }
98         
99         $this->etype->insert();
100     }
101     
102     function defaults()
103     {
104         foreach ($this->modules as $m){
105             $file = $this->rootDir. "/Pman/$m/Core.NotifyType.json";
106             
107             if(!file_exists($file)){
108                 continue;
109             }
110             
111             $this->log("Processing $file");
112                     
113             $this->defaults = array_merge($this->defaults, json_decode(file_get_contents($file), true)) ;
114         }
115         
116     }
117     
118     function log($str)
119     {
120         echo "$str \n";
121     }
122 }