UpdateDatabase.php
[Pman.Cms] / UpdateDatabase.php
1 <?php
2
3 /**
4  *
5  * This applies database files from
6  * a) OLD - {MODULE}/DataObjects/XXXX.{dbtype}.sql
7  *
8  * b) NEW - {MODULE}/sql/XXX.sql (SHARED or translable)
9  *  and {MODULE}/{dbtype}/XXX.sql (SHARED or translable)
10  *
11  *
12  */
13
14 require_once 'Pman.php';
15 class Pman_Cms_UpdateDatabase extends Pman
16 {
17     
18     static $cli_desc = "Update SQL - Beta";
19  
20     static $cli_opts = array(
21         'template' => array(
22             'desc' => 'Compile a specific template',
23             'default' => '',
24             'short' => 't',
25             'min' => 1,
26             'max' => 1,
27             
28         ),
29         'force-content-update' => array(
30             'desc' => 'Force updating of content from templates',
31             'default' => '',
32             'short' => 'f',
33             'min' => 1,
34             'max' => 1,
35             
36         ),
37         'debug' => array(
38             'desc' => 'Turn on debuggin',
39             'default' => '',
40             'short' => 'd',
41             'min' => 1,
42             'max' => 1,
43             
44         )
45     );
46     
47     var $cli = false;
48     
49     var $opts;
50     
51     function getAuth() {
52         
53         
54         $ff = HTML_FlexyFramework::get();
55         if (!empty($ff->cli)) {
56             $this->cli = true;
57             return true;
58         }
59         
60         parent::getAuth(); // load company!
61         $au = $this->getAuthUser();
62         if (!$au || $au->company()->comptype != 'OWNER') {
63             $this->jerr("Not authenticated", array('authFailure' => true));
64         }
65         $this->authUser = $au;
66         return true;
67     }
68      
69     function get($tbl, $opts)
70     {
71         if (!empty($opts['debug'])) {
72             DB_DataObject::debugLevel(1);
73             
74         }
75         if (!empty($opts['template'])) {
76              $tp = DB_DataObject::factory('cms_template');
77              //$opts = HTML_FlexyFramework::get()->Pman_Cms;
78              $tp->syncTemplate($opts['template'], true, '');
79              die("done");
80             
81         }
82         $this->opts = $opts;
83         
84         
85         $this->updateData();
86         if (!empty($tbl)) {
87             $d = DB_DataObject::factory($tbl);
88             $d->initDatabase($this);
89         }
90         
91     }
92     
93     function updateData()
94     {
95         $enum = DB_DataObject::Factory('core_enum');
96         $enum->initEnums(
97             array(
98                 array(
99                     'etype' => '',
100                     'name' => 'cms_page_type',
101                     'display_name' =>  'Cms Page Type',
102                     'cn' => array(
103                         array(
104                             'name' => 'page',
105                             'display_name' => 'Pages',
106                         ),
107                         array(
108                             'name' => 'element',
109                             'display_name' => 'Elements',
110                         ),
111                         array(
112                             'name' => 'blog',
113                             'display_name' => 'Blog Entries',
114                         ),
115                         array(
116                             'name' => 'menu',
117                             'display_name' => 'Menu Tree',
118                         ),
119                         array(
120                             'name' => 'category',
121                             'display_name' => 'Category',
122                         ),
123                     )
124                 )
125             )
126         );
127         /*
128         $p = DB_DataObject::Factory('cms_page');
129         $p->page_type_id = 0;
130         $all = $p->fetchAll();
131         foreach($all as $t) {
132             $t->convertOld();
133         }
134         $ff = $this->bootLoader;
135         $opts = isset($this->bootLoader->Pman_Cms) ? $this->bootLoader->Pman_Cms  : array();
136         echo "Calling syncTemplateDir from Cms/UpdateDatabase\n";
137         
138         
139         if (empty($this->opts['force-content-update'])) {
140             return;
141         }
142         */
143        
144         
145         require_once 'Pman/Cms/UpdateTemplates.php';
146         $x = new Pman_Cms_UpdateDatabase();
147         $x->opts = $this->opts;
148         $x->updateData();
149          
150             //if (isset($q['lang'])) {
151             //    $this->syncLang($q['lang']);
152             //}
153         echo "Calling cms_page::initData from Cms/UpdateDatabase\n";
154         
155         
156        
157     }
158     
159 }