DataObjects/core.sql
[Pman.Core] / UpdateDatabase.php
index 898ddd1..91c3fad 100644 (file)
@@ -44,7 +44,7 @@ class Pman_Core_UpdateDatabase extends Pman
         'add-company-with-type' => array(
             'desc' => 'the type of company (default OWNER)',
             'short' => 't',
-            'default' => '',
+            'default' => 'OWNER',
             'min' => 1,
             'max' => 1,
         ),
@@ -125,7 +125,7 @@ class Pman_Core_UpdateDatabase extends Pman
         PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'onPearError'));
    
         
-        $this->fixSequencesPgsql();exit;
+        //$this->fixSequencesPgsql();exit;
         $this->opts = $opts;
         
         // ask all the modules to verify the opts
@@ -145,6 +145,8 @@ class Pman_Core_UpdateDatabase extends Pman
         
         
         if (!empty($opts['add-company'])) {
+            // make sure we have a good cache...?
+           
             DB_DataObject::factory('companies')->initCompanies($this, $opts);
         }
          
@@ -509,9 +511,11 @@ class Pman_Core_UpdateDatabase extends Pman
             if (!preg_match('/^json-/', $o) || empty($v)) {
                 continue;
             }
-            $type = str_replace('_', '-', substr($o,6));
-            $data= json_decode(file_get_contents($file),true);
-            DB_DataObject::factory($type)->importFromArray($this,$data,$opts);
+            $type = str_replace('_', '-', substr($o,5));
+            
+            $data= json_decode(file_get_contents($v),true);
+            $pg = HTML_FlexyFramework::get()->page;
+            DB_DataObject::factory($type)->importFromArray($pg ,$data,$opts);
             
         }
         
@@ -557,7 +561,9 @@ class Pman_Core_UpdateDatabase extends Pman
     
     function updateDataEnums()
     {
+        
         $enum = DB_DataObject::Factory('core_enum');
+        //DB_DAtaObject::debugLevel(1);
         $enum->initEnums(
             array(
                 array(
@@ -674,7 +680,7 @@ class Pman_Core_UpdateDatabase extends Pman
     function updateData()
     {
         // fill i18n data..
-        
+        HTML_FlexyFramework::get()->generateDataobjectsCache(true);
         $this->updateDataEnums();
         $this->updateDataGroups();
         $this->updateDataCompanies();
@@ -696,7 +702,7 @@ class Pman_Core_UpdateDatabase extends Pman
          SELECT
                     'ALTER SEQUENCE '||
                     CASE WHEN strpos(seq_name, '.') > 0 THEN
-                        quote_ident(min(seq_name))
+                        min(seq_name)
                     ELSE 
                         quote_ident(min(schema_name)) ||'.'|| quote_ident(min(seq_name))
                     END 
@@ -721,6 +727,13 @@ class Pman_Core_UpdateDatabase extends Pman
                    AND d.adsrc ~ '^nextval'
               
              ) seq
+             WHERE
+                 CASE WHEN strpos(seq_name, '.') > 0 THEN
+                     substring(seq_name, 1,strpos(seq_name,'.')-1)
+                ELSE
+                    schema_name
+                END = schema_name
+             
              GROUP BY seq_name HAVING count(*)=1
              ");
         $cmds = array();
@@ -736,7 +749,7 @@ class Pman_Core_UpdateDatabase extends Pman
          $cs->query("
                SELECT  'SELECT SETVAL(' ||
                          quote_literal(quote_ident(nspname) || '.' || quote_ident(S.relname)) ||
-                        ', MAX(' || quote_ident(C.attname)|| ') )  FROM ' || nspname || '.' || quote_ident(T.relname)|| ';' as cmd 
+                        ', MAX(' || quote_ident(C.attname)|| ')::integer )  FROM ' || nspname || '.' || quote_ident(T.relname)|| ';' as cmd 
                 FROM pg_class AS S,
                     pg_depend AS D,
                     pg_class AS T,