eeffb055b46251f33b34fed44d3c7a21dc673b73
[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         $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         print_r($types);exit;
65         
66         
67         
68         
69     }
70     
71     function etype()
72     {
73         $this->etype = DB_DataObject::factory('core_enum');
74         $this->etype->setFrom(array(
75             'etype' => '',
76             'name' => 'Core.NotifyType',
77             'display_name' => 'Core.NotifyType',
78             'active' => 1
79         ));
80         
81         if($this->etype->find(true)){
82             return;
83         }
84         
85         $this->etype->insert();
86     }
87     
88     function defaults()
89     {
90         foreach ($this->modules as $m){
91             $file = $this->rootDir. "/Pman/$m/Core.NotifyType.json";
92             
93             if(!file_exists($file)){
94                 continue;
95             }
96             
97             $this->defaults = array_merge($this->defaults, json_decode(file_get_contents($file), true)) ;
98         }
99         
100     }
101     
102     function log($str)
103     {
104         echo "$str \n";
105     }
106 }