DataObjects/Core_person_signup.php
[Pman.Core] / 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_Core_UpdateDatabase extends Pman
16 {
17     
18     static $cli_desc = "Update SQL - Beta (it will run updateData of all modules)";
19  
20     static $cli_opts = array(
21       
22         'prefix' => array(
23             'desc' => 'prefix for the password (eg. fred > xxx4fred - prefix is xxx4)',
24             'short' => 'p',
25             'default' => '',
26             'min' => 1,
27             'max' => 1,
28         ),
29         'data-only' => array(
30             'desc' => 'only run the updateData - do not run import the tables and procedures.',
31             'short' => 'p',
32             'default' => '',
33             'min' => 1,
34             'max' => 1,
35             
36         ),
37         'add-company' => array(
38             'desc' => 'add a company name of the company',
39             'short' => 'n',
40             'default' => '',
41             'min' => 1,
42             'max' => 1,
43         ),
44         'add-company-with-type' => array(
45             'desc' => 'the type of company (default OWNER)',
46             'short' => 't',
47             'default' => 'OWNER',
48             'min' => 1,
49             'max' => 1,
50         ),
51         'init' => array(
52             'desc' => 'Initialize the database (pg only supported)',
53             'short' => 'i',
54             'default' => '',
55             'min' => 1,
56             'max' => 1,
57         ),
58         'only-module-sql' => array(
59             'desc' => 'Only run sql import on this modules - eg. Core',
60             'default' => '',
61             'min' => 1,
62             'max' => 1,
63         ),
64         'procedures-only' => array(
65             'desc' => 'Only import procedures (not supported by most modules yet) - ignores sql directory',
66             'default' => '',
67             'min' => 1,
68             'max' => 1,
69         ),
70         
71         
72         'json-person' => array(
73             'desc' => 'Person JSON file',
74             'default' => '',
75             'min' => 1,
76             'max' => 1,
77             
78         ),
79     );
80     
81     static function cli_opts()
82     {
83         
84         $ret = self::$cli_opts;
85         $ff = HTML_FlexyFramework::get();
86         $a = new Pman();
87         $mods = $a->modulesList();
88         foreach($mods as $m) {
89             
90             $fd = $ff->rootDir. "/Pman/$m/UpdateDatabase.php";
91             if (!file_exists($fd)) {
92                 continue;
93             }
94             
95             require_once $fd;
96             
97             $cls = new ReflectionClass('Pman_'. $m . '_UpdateDatabase');
98             
99             $ret = array_merge($ret, $cls->getStaticPropertyValue('cli_opts'));
100             
101             
102         }
103         
104         return $ret;
105     }
106     
107     var $opts = false;
108     
109     
110     var $cli = false;
111     function getAuth() {
112         
113         
114         $ff = HTML_FlexyFramework::get();
115         if (!empty($ff->cli)) {
116             $this->cli = true;
117             return true;
118         }
119         
120         parent::getAuth(); // load company!
121         $au = $this->getAuthUser();
122         if (!$au || $au->company()->comptype != 'OWNER') {
123             $this->jerr("Not authenticated", array('authFailure' => true));
124         }
125         $this->authUser = $au;
126         return true;
127     }
128      
129     function get($args, $opts)
130     {
131         PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError'));
132    
133         
134         //$this->fixSequencesPgsql();exit;
135         $this->opts = $opts;
136         
137         // ask all the modules to verify the opts
138         
139         $this->checkOpts($opts);
140         
141         
142      
143         if (empty($opts['data-only'])) {
144             $this->importSQL();
145         }
146         if (!empty($opts['only-module-sql'])) {
147             return;
148         }
149         
150         $this->runUpdateModulesData();
151         
152         
153         if (!empty($opts['add-company'])) {
154             // make sure we have a good cache...?
155            
156             DB_DataObject::factory('companies')->initCompanies($this, $opts);
157         }
158          
159     }
160     function output() {
161         return '';
162     }
163      /**
164      * imports SQL files from all DataObjects directories....
165      * 
166      * except any matching /migrate/
167      */
168     function importSQL()
169     {
170         
171         // loop through all the modules, and see if they have a importSQL method?
172         
173         
174         $ff = HTML_Flexyframework::get();
175         
176         $dburl = parse_url($ff->DB_DataObject['database']);
177         
178         //$this->{'import' . $url['scheme']}($url);
179         
180         $dbtype = $dburl['scheme'];
181         $dirmethod = 'import' . $dburl['scheme'] . 'dir';
182         
183         
184        
185         
186         $ar = $this->modulesList();
187        
188         
189         foreach($ar as $m) {
190              echo "Importing SQL from module $m\n";
191             if (!empty($this->opts['only-module-sql']) && $m != $this->opts['only-module-sql']) {
192                 continue;
193             }
194             
195             
196             // check to see if the class has
197             
198             
199             
200             $file = $this->rootDir. "/Pman/$m/UpdateDatabase.php";
201             if($m != 'Core' && file_exists($file)){
202                 
203                 require_once $file;
204                 $class = "Pman_{$m}_UpdateDatabase";
205                 $x = new $class;
206                 if(method_exists($x, 'importModuleSQL')){
207                     echo "Importing SQL from module $m using Module::importModuleSQL\n";
208                     $x->opts = $this->opts;
209                     $x->rootDir = $this->rootDir;
210                     $x->importModuleSQL($dburl);
211                     continue;
212                 }
213             };
214
215             echo "Importing SQL from module $m\n";
216             
217             
218             // if init has been called
219             // look in pgsql.ini
220             if (!empty($this->opts['init'])) {
221                 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}.init");
222                 
223             }
224             
225             
226             
227             $fd = $this->rootDir. "/Pman/$m/DataObjects";
228             
229             $this->{$dirmethod}($dburl, $fd);
230             
231             // new -- sql directory..
232             // new style will not support migrate ... they have to go into mysql-migrate.... directories..
233             // new style will not support pg.sql etc.. naming - that's what the direcotries are for..
234             
235             $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/sql");
236             $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}");
237             
238             
239             
240             if (!empty($this->opts['init']) && file_exists($this->rootDir. "/Pman/$m/{$dbtype}.initdata")) {
241                 HTML_FlexyFramework::get()->generateDataobjectsCache(true);
242                 
243                 $this->{$dirmethod}($dburl, $this->rootDir. "/Pman/$m/{$dbtype}.initdata");
244                 $this->{'fixSequences'. $dbtype}();
245                 
246             }
247               
248             
249         }
250         
251     }
252     
253     
254     
255      
256     /** -------------- code to handle importing a whole directory of files into the database  -------  **/
257     
258     
259     function importpgsqldir($url, $dir, $disable_triggers = false)
260     {
261         $ff = HTML_FlexyFramework::get();
262         
263         require_once 'System.php';
264         $cat = System::which('cat');
265         $psql = System::which('psql');
266         
267          
268         if (!empty($url['pass'])) { 
269             putenv("PGPASSWORD=". $url['pass']);
270         }
271            
272         $psql_cmd = $psql .
273             ' -h ' . $url['host'] .
274             ' -U' . escapeshellarg($url['user']) .
275              ' ' . basename($url['path']);
276         
277         
278         echo $psql_cmd . "\n" ;
279         echo "scan : $dir\n";
280         
281         if (is_file($dir)) {
282             $files = array($dir);
283
284         } else {
285         
286         
287             $files = glob($dir.'/*.sql');
288             uksort($files, 'strcasecmp');
289         }
290         //$lsort = create_function('$a,$b','return strlen($a) > strlen($b) ? 1 : -1;');
291         //usort($files, $lsort);
292         
293         
294         foreach($files as $bfn) {
295
296
297             if (preg_match('/migrate/i', basename($bfn))) { // skip migration scripts at present..
298                 continue;
299             }
300             if (preg_match('#\.[a-z]{2}\.sql#i', basename($bfn))
301                 && !preg_match('#\.pg\.sql#i', basename($bfn))
302             ) { // skip migration scripts at present..
303                 continue;
304             }
305             $fn = false;
306
307             if (!preg_match('/pgsql/', basename($dir) )) {
308                  if ( !preg_match('#\.pg\.sql$#', basename($bfn))) {
309                     $fn = $this->convertToPG($bfn);
310                 }
311             }
312
313             // files ending in .pg.sql are native postgres files.. ## depricated
314
315
316             $cmd = "$psql_cmd  < " . escapeshellarg($fn ? $fn : $bfn) . ' 2>&1' ;
317
318             echo "$bfn:   $cmd ". ($ff->cli ? "\n" : "<BR>\n");
319
320             passthru($cmd);
321
322             if ($fn) {
323                 unlink($fn);
324             }
325         }
326
327               
328              
329         
330     }
331     
332     
333     /**
334      * mysql - does not support conversions.
335      * 
336      *
337      */
338     
339     
340     function importmysqldir($dburl, $dir)
341     {
342         echo "Import MYSQL :: $dir\n";
343         
344         
345         require_once 'System.php';
346         $cat = System::which('cat');
347         $mysql = System::which('mysql');
348         
349        
350            
351         $mysql_cmd = $mysql .
352             ' -h ' . $dburl['host'] .
353             ' -u' . escapeshellarg($dburl['user']) .
354             (!empty($dburl['pass']) ? ' -p' . escapeshellarg($dburl['pass'])  :  '') .
355             ' ' . basename($dburl['path']);
356         //echo $mysql_cmd . "\n" ;
357         
358         $files = glob($dir.'/*.sql');
359         uksort($files, 'strcasecmp');
360         
361        
362         foreach($files as $fn) {
363                 
364                  
365                 if (preg_match('/migrate/i', basename($fn))) { // skip migration scripts at present..
366                     continue;
367                 }
368                 // .my.sql but not .pg.sql
369                 if (preg_match('#\.[a-z]{2}\.sql#i', basename($fn))
370                     && !preg_match('#\.my\.sql#i', basename($fn))
371                 ) { // skip migration scripts at present..
372                     continue;
373                 }
374                 if (!strlen(trim($fn))) {
375                     continue;
376                 }
377                 
378                 $cmd = "$mysql_cmd -f < " . escapeshellarg($fn) ;
379                 
380                 echo basename($dir).'/'. basename($fn) .    '::' .  $cmd. ($this->cli ? "\n" : "<BR>\n");
381                 
382                 passthru($cmd);
383             
384                 
385         }
386        
387         
388         
389     }
390     
391     
392     /**
393      * simple regex based convert mysql to pgsql...
394      */
395     function convertToPG($src)
396     {
397         //echo "Convert $src\n";
398                
399         $fn = $this->tempName('sql');
400         
401         $ret = array( ); // pad it a bit.
402         $extra = array("", "" );
403         
404         $tbl = false;
405         foreach(file($src) as $l) {
406             $l = trim($l);
407             
408             if (!strlen($l) || $l[0] == '#') {
409                 continue;
410             }
411             $m = array();
412             if (preg_match('#create\s+table\s+([a-z0-9_]+)#i',  $l, $m)) {
413                 $tbl = $m[1];
414              }
415             if (preg_match('#create\s+table\s+\`([a-z0-9_]+)\`#i',  $l, $m)) {
416                 $tbl = 'shop_' . strtolower($m[1]);
417                 $l = preg_replace('#create\s+table\s+\`([a-z0-9_]+)\`#i', "CREATE TABLE {$tbl}", $l);
418             }
419             if (preg_match('#\`([a-z0-9_]+)\`#i',  $l, $m) && !preg_match('#alter\s+table\s+#i',  $l)) {
420                 $l = preg_replace('#\`([a-z0-9_]+)\`#i', "{$m[1]}_name", $l);
421             }
422             // autoinc
423             if ($tbl && preg_match('#auto_increment#i',  $l, $m)) {
424                 $l = preg_replace('#auto_increment#i', "default nextval('{$tbl}_seq')", $l);
425                 $extra[]  =   "create sequence {$tbl}_seq;";
426               
427             }
428             
429             if (preg_match('#alter\s+table\s+(\`[a-z0-9_]+\`)#i',  $l, $m)){
430                 $l = preg_replace('#alter\s+table\s+(\`[a-z0-9_]+\`)#i', "ALTER TABLE {$tbl}", $l);
431             }
432             
433             // enum value -- use the text instead..
434             
435             if ($tbl && preg_match('#([\w]+)\s+(enum\([\w|\W]+\))#i',  $l, $m)) {
436                 $l = preg_replace('#enum\([\w|\W]+\)#i', "TEXT", $l);
437             }
438             // ignore the alter enum
439             if ($tbl && preg_match('#alter\s+table\s+([\w|\W]+)\s+enum\([\w|\W]+\)#i',  $l, $m)) {
440                 continue;
441             }
442             
443             // UNIQUE KEY .. ignore
444             if ($tbl && preg_match('#UNIQUE KEY#i',  $l, $m)) {
445                 $last = array_pop($ret);
446                 $ret[] = trim($last, ",");
447                 continue;
448             }
449             
450             if ($tbl && preg_match('#RENAME\s+TO#i',  $l, $m)) {
451                 continue;
452             }
453             
454             if ($tbl && preg_match('#change\s+column#i',  $l, $m)) {
455                 continue;
456             }
457             
458             // INDEX lookup ..ignore
459             if ($tbl && preg_match('#INDEX lookup+([\w|\W]+)#i',  $l, $m)) {
460                $last = array_pop($ret);
461                $ret[] = trim($last, ",");
462                continue;
463                
464             }
465             
466             // CREATE INDEX ..ignore
467             if (preg_match('#alter\s+table\s+([a-z0-9_]+)\s+add\s+index\s+#i',  $l, $m)) {
468 //               $l = "CREATE INDEX  {$m[1]}_{$m[2]} ON {$m[1]} {$m[3]}";
469                 continue;
470              }
471              
472             // basic types..
473             $l = preg_replace('#int\([0-9]+\)#i', 'INT', $l);
474             
475             $l = preg_replace('# datetime#i', ' TIMESTAMP WITHOUT TIME ZONE', $l);
476             $l = preg_replace('# blob#i', ' TEXT', $l);
477             $l = preg_replace('# longtext#i', ' TEXT', $l);
478             $l = preg_replace('# tinyint#i', ' INT', $l);
479             
480             $ret[] = $l;
481             
482         }
483         
484         $ret = array_merge($extra,$ret);
485 //        echo implode("\n", $ret); exit;
486         
487         file_put_contents($fn, implode("\n", $ret));
488         
489         return $fn;
490     }
491     
492     
493     function checkOpts($opts)
494     {
495         
496         
497         foreach($opts as $o=>$v) {
498             if (!preg_match('/^json-/', $o) || empty($v)) {
499                 continue;
500             }
501             if (!file_exists($v)) {
502                 die("File does not exist : OPTION --{$o} = {$v} \n");
503             }
504         }
505         
506         $modules = array_reverse($this->modulesList());
507         
508         // move 'project' one to the end...
509         
510         foreach ($modules as $module){
511             $file = $this->rootDir. "/Pman/$module/UpdateDatabase.php";
512             if($module == 'Core' || !file_exists($file)){
513                 continue;
514             }
515             require_once $file;
516             $class = "Pman_{$module}_UpdateDatabase";
517             $x = new $class;
518             if(!method_exists($x, 'checkOpts')){
519                 continue;
520             };
521             $x->checkOpts($opts);
522         }
523                 
524     }
525     static function jsonImportFromArray($opts)
526     {
527         foreach($opts as $o=>$v) {
528             if (!preg_match('/^json-/', $o) || empty($v)) {
529                 continue;
530             }
531             $type = str_replace('_', '-', substr($o,5));
532             
533             $data= json_decode(file_get_contents($v),true);
534             $pg = HTML_FlexyFramework::get()->page;
535             DB_DataObject::factory($type)->importFromArray($pg ,$data,$opts);
536             
537         }
538         
539         
540         
541     }
542     
543     
544     
545     function runUpdateModulesData()
546     {
547         
548         
549         HTML_FlexyFramework::get()->generateDataobjectsCache(true);
550         echo "Running jsonImportFromArray\n";
551         Pman_Core_UpdateDatabase::jsonImportFromArray($this->opts);
552         
553         
554         echo "Running updateData on modules\n";
555         // runs core...
556         echo "Core\n";
557         $this->updateData(); 
558         $modules = array_reverse($this->modulesList());
559         
560         // move 'project' one to the end...
561         
562         foreach ($modules as $module){
563             $file = $this->rootDir. "/Pman/$module/UpdateDatabase.php";
564             if($module == 'Core' || !file_exists($file)){
565                 continue;
566             }
567             
568             require_once $file;
569             $class = "Pman_{$module}_UpdateDatabase";
570             $x = new $class;
571             if(!method_exists($x, 'updateData')){
572                 continue;
573             };
574             echo "$module\n";
575             $x->updateData();
576         }
577                 
578     }
579     
580     
581     function updateDataEnums()
582     {
583         
584         $enum = DB_DataObject::Factory('core_enum');
585         //DB_DAtaObject::debugLevel(1);
586         $enum->initEnums(
587             array(
588                 array(
589                     'etype' => '',
590                     'name' => 'COMPTYPE',
591                     'display_name' =>  'Company Types',
592                     'is_system_enum' => 1,
593                     'cn' => array(
594                         array(
595                             'name' => 'OWNER',
596                             'display_name' => 'Owner',
597                             'seqid' => 999, // last...
598                             'is_system_enum' => 1,
599                         )
600                         
601                     )
602                 ),
603                 array(
604                     'etype' => '',
605                     'name' => 'HtmlEditor.font-family',
606                     'display_name' =>  'HTML Editor font families',
607                     'is_system_enum' => 1,
608                     'cn' => array(
609                         array(
610                             'name' => 'Helvetica,Arial,sans-serif',
611                             'display_name' => 'Helvetica',
612                             
613                         ),
614                         
615                         array(
616                             'name' => 'Courier New',
617                             'display_name' => 'Courier',
618                              
619                         ),
620                         array(
621                             'name' => 'Tahoma',
622                             'display_name' => 'Tahoma',
623                             
624                         ),
625                         array(
626                             'name' => 'Times New Roman,serif',
627                             'display_name' => 'Times',
628                            
629                         ),
630                         array(
631                             'name' => 'Verdana',
632                             'display_name' => 'Verdana',
633                             
634                         ),
635                         
636                             
637                         
638                     )
639                 ),
640             )
641         ); 
642         
643     }
644     function updateDataGroups()
645     {
646          
647         $groups = DB_DataObject::factory('groups');
648         $groups->initGroups();
649         
650         $groups->initDatabase($this,array(
651             array(
652                 'name' => 'bcc-email', // group who are bcc'ed on all requests.
653                 'type' => 0, // system
654             ),
655             array(
656                 'name' => 'system-email-from',
657                 'type' => 0, // system
658             ),
659         ));
660         
661     }
662     
663     function updateDataCompanies()
664     {
665          
666         // fix comptypes enums..
667         $c = DB_DataObject::Factory('Companies');
668         $c->selectAdd();
669         $c->selectAdd('distinct(comptype) as comptype');
670         $c->whereAdd("comptype != ''");
671         
672         $ctb = array();
673         foreach($c->fetchAll('comptype') as $cts) {
674             
675             
676             
677            $ctb[]= array( 'etype'=>'COMPTYPE', 'name' => $cts, 'display_name' => ucfirst(strtolower($cts)));
678         
679         }
680          $c = DB_DataObject::Factory('core_enum');
681          
682         $c->initEnums($ctb);
683         //DB_DataObject::debugLevel(1);
684         // fix comptypeid
685         $c = DB_DataObject::Factory('Companies');
686         $c->query("
687             UPDATE Companies 
688                 SET
689                     comptype_id = (SELECT id FROM core_enum where etype='comptype' and name=Companies.comptype LIMIT 1)
690                 WHERE
691                     comptype_id = 0
692                     AND
693                     LENGTH(comptype) > 0
694                   
695                   
696                   ");
697          
698         
699         
700     }
701     
702     function updateData()
703     {
704         // fill i18n data..
705         HTML_FlexyFramework::get()->generateDataobjectsCache(true);
706         $this->updateDataEnums();
707         $this->updateDataGroups();
708         $this->updateDataCompanies();
709         
710         $c = DB_DataObject::Factory('I18n');
711         $c->buildDB();
712          
713        
714         
715         
716     }
717     
718     function fixMysqlInnodb()
719     {
720         // innodb in single files is far more efficient that MYD or one big innodb file.
721         // first check if database is using this format.
722         $db = DB_DataObject::factory('core_enum');
723         $db->query("show variables like 'innodb_file_per_table'");
724         $db->fetch();
725         var_dump($db);
726         // Value should == ON
727         
728         // I think it needs to look in the mysql directory.... to see if the idb exists..
729         $db = DB_DataObject::factory('core_enum');
730         $db->query("SHOW TABLE STATUS");
731         // Engine should be InnoDB - and file XXX.idb should exist...
732         
733         
734
735  
736         
737         
738         
739         
740         
741     }
742     
743     
744     /** ------------- schema fixing ... there is an issue with data imported having the wrong sequence names... --- */
745     
746     function fixSequencesMysql()
747     {
748         // not required...
749     }
750     
751     function fixSequencesPgsql()
752     {
753      
754      
755         //DB_DataObject::debugLevel(1);
756         $cs = DB_DataObject::factory('core_enum');
757         $cs->query("
758          SELECT
759                     'ALTER SEQUENCE '||
760                     CASE WHEN strpos(seq_name, '.') > 0 THEN
761                         min(seq_name)
762                     ELSE 
763                         quote_ident(min(schema_name)) ||'.'|| quote_ident(min(seq_name))
764                     END 
765                     
766                     ||' OWNED BY '|| quote_ident(min(schema_name)) || '.' ||
767                     quote_ident(min(table_name)) ||'.'|| quote_ident(min(column_name)) ||';' as cmd
768              FROM (
769                       
770                        SELECT 
771                      n.nspname AS schema_name,
772                      c.relname AS table_name,
773                      a.attname AS column_name, 
774                      regexp_replace(regexp_replace(d.adsrc, E'nextval\\\\(+[''\\\"]*', ''),E'[''\\\"]*::.*\$','') AS seq_name 
775                  FROM pg_class c 
776                  JOIN pg_attribute a ON (c.oid=a.attrelid) 
777                  JOIN pg_attrdef d ON (a.attrelid=d.adrelid AND a.attnum=d.adnum) 
778                  JOIN pg_namespace n ON (c.relnamespace=n.oid)
779                  WHERE has_schema_privilege(n.oid,'USAGE')
780                    AND n.nspname NOT LIKE 'pg!_%' escape '!'
781                    AND has_table_privilege(c.oid,'SELECT')
782                    AND (NOT a.attisdropped)
783                    AND d.adsrc ~ '^nextval'
784               
785              ) seq
786              WHERE
787                  CASE WHEN strpos(seq_name, '.') > 0 THEN
788                      substring(seq_name, 1,strpos(seq_name,'.')-1)
789                 ELSE
790                     schema_name
791                 END = schema_name
792              
793              GROUP BY seq_name HAVING count(*)=1
794              ");
795         $cmds = array();
796         while ($cs->fetch()) {
797             $cmds[] = $cs->cmd;
798         }
799         foreach($cmds as $cmd) {
800             $cs = DB_DataObject::factory('core_enum');
801             echo "$cmd\n";
802             $cs->query($cmd);
803         }
804         $cs = DB_DataObject::factory('core_enum');
805          $cs->query("
806                SELECT  'SELECT SETVAL(' ||
807                          quote_literal(quote_ident(nspname) || '.' || quote_ident(S.relname)) ||
808                         ', MAX(' || quote_ident(C.attname)|| ')::integer )  FROM ' || nspname || '.' || quote_ident(T.relname)|| ';' as cmd 
809                 FROM pg_class AS S,
810                     pg_depend AS D,
811                     pg_class AS T,
812                     pg_attribute AS C,
813                     pg_namespace AS NS
814                 WHERE S.relkind = 'S'
815                     AND S.oid = D.objid
816                     AND D.refobjid = T.oid
817                     AND D.refobjid = C.attrelid
818                     AND D.refobjsubid = C.attnum
819                     AND NS.oid = T.relnamespace
820                 ORDER BY S.relname   
821         ");
822          $cmds = array();
823         while ($cs->fetch()) {
824             $cmds[] = $cs->cmd;
825         }
826         foreach($cmds as $cmd) {
827             $cs = DB_DataObject::factory('core_enum');
828             echo "$cmd\n";
829             $cs->query($cmd);
830         }
831        
832     }
833     
834 }