Merge branch 'master' of http://git.roojs.com:8081/Pman.Core
authorAlan Knowles <alan@akbkhome.com>
Wed, 6 Apr 2011 06:10:11 +0000 (14:10 +0800)
committerAlan Knowles <alan@akbkhome.com>
Wed, 6 Apr 2011 06:10:11 +0000 (14:10 +0800)
DataObjects/Core_notify.php
DataObjects/Core_watch.php
DataObjects/core.sql

index 91a0c42..9f2f294 100644 (file)
@@ -13,7 +13,7 @@ CREATE TABLE  core_notify  (
   `person_id` int(11)  NOT NULL DEFAULT 0,
   `msgid` varchar(128)  NOT NULL  DEFAULT '',
   `sent` DATETIME  NOT NULL,
-  `bounced` int(4)  NOT NULL DEFAULT 0,
+  `event_id` int(11)  NOT NULL DEFAULT 0,
   PRIMARY KEY (`id`),
   INDEX `lookup`(`act_when`, `msgid`)
 );
@@ -47,5 +47,5 @@ class Pman_Core_DataObjects_Core_notify extends DB_DataObject
         return $c;
         
     }
-
+  
 }
\ No newline at end of file
index 0babeae..5b9615e 100644 (file)
@@ -30,7 +30,56 @@ class Pman_Core_DataObjects_Core_watch extends DB_DataObject
     
     /* the code above is auto generated do not remove the tag below */
     ###END_AUTOCODE
+    /** make sure there is a watch for this user.. */
     
+    function ensureNotify(  $ontable, $onid, $person_id, $whereAdd)
+    {
+        $w = DB_DataObject::factory('core_watch');
+        $w->ontable = $ontable;
+        $w->onid = $onid;
+        $w->person_id = $personid;
+        $nw = clone($w);
+        $w->whereAdd($whereAdd);
+        
+        
+        if ($w->count()) {
+            return;
+        }
+        $nw->medium = 'email';
+        $nw->active = 1;
+        $nw->insert();
+        
+        
+    }
+    
+    function notify($ontable , $onid, $whereAdd)
+    {
+        $w = DB_DataObject::factory('core_watch');
+        $w->whereAdd($whereAdd);
+        $w->selectAdd();
+        $w->selectAdd('distinct(person_id) as person_id');
+        $people = $w->fetchAll('person_id');
+        $nn = DB_DataObject::Factory('core_notify');
+        $nn->ontable = $ontable;
+        $nn->onid = $onid;
+        foreach($people as $p) {
+            $n = clone($nn);
+            $n->person_id = $p;
+            $nf = clone($n);
+            $nf->whereAdd('sent < act_when');
+            if ($nf->count()) {
+                // we have a item in the queue for that waiting to be sent..
+                continue;
+            }
+            $n->act_when = date("Y-m-d H:i:s");
+            $n->insert();
+            
+            
+        }
+        
+        
+        
+    }
     /***
      * The purpose of this is to gather all the events that have
      * occured in the system (where watches exist)
index 4ea894f..47d8fe7 100644 (file)
@@ -327,7 +327,7 @@ CREATE TABLE  core_notify  (
 ALTER TABLE core_notify CHANGE COLUMN bounced event_id INT(11) DEFAULT 0;
 
 
-
+ALTER TABLE core_notify CHANGE COLUMN bounced event_id INT(11) NOT NULL DEFAULT 0;
  
 
 # - used by email / tracker to handle alises - we have to be carefull adding to this table...