DataObjects/core.sql
[Pman.Core] / UpdateDatabase.php
index 82afb01..d956b81 100644 (file)
@@ -152,7 +152,7 @@ class Pman_Core_UpdateDatabase extends Pman
         $this->runUpdateModulesData();
         
         
-        if (!empty($opts['add-company'])) {
+        if (!empty($opts['add-company']) && !in_array('Core', $this->disabled)) {
             // make sure we have a good cache...?
            
             DB_DataObject::factory('companies')->initCompanies($this, $opts);
@@ -239,6 +239,7 @@ class Pman_Core_UpdateDatabase extends Pman
             
             $this->{$dirmethod}($dburl, $fd);
             
+            
             // new -- sql directory..
             // new style will not support migrate ... they have to go into mysql-migrate.... directories..
             // new style will not support pg.sql etc.. naming - that's what the direcotries are for..
@@ -722,6 +723,68 @@ class Pman_Core_UpdateDatabase extends Pman
         
     }
     
+    
+    function initEmails($templateDir, $emails)
+    {
+      
+        $pg = HTML_FlexyFramework::get()->page;
+        foreach($emails as $name=>$data) {
+            $cm = DB_DataObject::factory('core_email');
+            $update = $cm->get('name', $name);
+            $old = clone($cm);
+            
+            if (empty($cm->bcc_group)) {
+                if (empty($data['bcc_group'])) {
+                    $this->jerr("missing bcc_group for template $name");
+                }
+                $g = DB_DataObject::Factory('Groups')->lookup($data['bcc_group']);
+                if (!$g) {
+                    $this->jerr("bcc_group {$data['bcc_group']} does not exist when importing template $name");
+                }
+                if (!$g->members('email')) {
+                      $this->jerr("bcc_group {$data['bcc_group']} does not have any members");
+                }
+                
+                
+                $cm->bcc_group = $g->id;
+            }
+            if (empty($cm->test_class)) {
+                if (empty($data['test_class'])) {
+                    $this->jerr("missing test_class for template $name");
+                }
+                $cm->test_class = $cm;
+            }
+            require_once $cm->test_class . '.php';
+            $clsname = str_replace('/','_', $cm->test_class);
+            $method = new ReflectionMethod($clsname , 'test_'. $name) ;
+            if (!$method->isStatic()) {
+                $this->jerr("template {$name} does not have a test method {$clsname}::test_{$name}");
+            }
+            if ($up) {
+                $cm->update($old);
+                continue; /// we do not import the body content of templates that exist...
+            } else {
+                $cm->insert();
+            }
+            
+            
+    //        $basedir = $this->bootLoader->rootDir . $mail_template_dir;
+            
+            $opts = array(
+                'update' => 1,
+                'file' => $mail_template_dir. $name .'.html'
+            );
+            
+            if (!empty($data['master'])) {
+                $opts['master'] = $mail_template_dir . $master .'.html';
+            }
+            require_once 'Pman/Core/Import/Core_email.php';
+            $x = new Pman_Core_Import_Core_email();
+            $x->get('', $opts);
+        }
+    }
+    
+    
     function updateData()
     {
         // fill i18n data..