36aad25d9baca0a4868529afd6a5cce94adc5238
[Pman.Core] / Notify.php
1 <?php
2 require_once 'MTrackWeb.php';
3
4 /**
5  * notification script runner
6  *
7  * This does not actualy send stuf out, it only starts the NotifySend/{id}
8  * which does the actuall notifcations.
9  *
10  * It manages a pool of notifiers.
11  * 
12  * 
13  */
14
15 class Pman_Core_Notify extends Pman
16 {
17     
18     function getAuth()
19     {
20         $ff = HTML_FlexyFramework::get();
21         if (!$ff->cli) {
22             die("access denied");
23         }
24         HTML_FlexyFramework::ensureSingle(__FILE__, $this);
25         return true;
26         
27     }
28     
29     var $pool = array();
30     
31     function get()    
32     {
33         //DB_DataObject::debugLevel(1);
34         date_default_timezone_set('UTC');
35         
36         
37         $w = DB_DataObject::factory('core_notify');
38         $w->whereAdd('act_when < sent');
39         $w->orderBy('act_when ASC'); // oldest first.
40         $w->limit(1000); // we can run 1000 ...
41         $ar = $w->fetchAll('id');
42         
43         while (true) {
44             if (empty($ar)) {
45                 break;
46             }
47             if (!$this->poolfree()) {
48                 sleep(10);
49                 continue;
50             }
51             $p = array_shift($ar);
52             $this->run($p);
53         }
54         
55          
56     }
57     
58     function run($id) {
59         
60     }
61     
62 }