3 * Table Definition for core_notify_server
5 class_exists('DB_DataObject') ? '' : require_once 'DB/DataObject.php';
7 class Pman_Core_DataObjects_Core_notify_server extends DB_DataObject
10 /* the code below is auto generated do not remove the above tag */
12 public $__table = 'core_notify_server'; // table name
13 public $id; // int(11) not_null primary_key auto_increment
20 // most services should call this first..
22 function getCurrent($notify)
24 static $current = false;;
26 if ($current !== false) {
30 $ns = DB_DataObject::factory('core_notify_server');
31 $ns->poolname = $notify->poolname;
33 $ns->hostname = gethostname();
35 $notify->jerr("Server not found for this server " . gethostname() . " in core_notify_server" );
42 // called on current server.
43 function assignQueues($notify)
47 $servers = $this->availableServers();
49 foreach($servers as $s) {
55 $notify->jerr("no configured servers in core_notify_server for poolname = {$notify->poolname}");
59 // only run this on the first server...
60 if ($this->id != $ids[0]) {
63 foreach($ids as $rn) {
67 $num_servers = count($ids);
69 if ($num_servers == 1) {
70 $p = DB_DataObject::factory($notify->table);
81 act_start < NOW() + INTERVAL 3 HOUR
88 // ((@row_number := CASE WHEN @row_number IS NULL THEN 0 ELSE @row_number END +1) % {$num_servers})
92 $p = DB_DataObject::factory($notify->table);
98 act_start < NOW() + INTERVAL 3 HOUR
103 if ($p->count() < 1) {
108 $p->selectAdd("id, ((@row_number := CASE WHEN @row_number IS NULL THEN 0 ELSE @row_number END +1) % {$num_servers}) as rn");
109 $kv = $p->fetchAll('id,rn');
110 foreach($kv as $id => $r) {
111 $up[ $ids[$r] ][] = $id;
113 foreach($up as $sid => $nids) {
114 $p = DB_DataObject::factory($notify->table);
121 id IN (". implode(",', $nids"). ')'
125 DB_DataObject::factory("core_notify_blacklist")->prune();
128 // called on current server.
130 function availableServers()
132 $ns = DB_DataObject::factory('core_notify_server');
133 $ns->poolname = $this->poolname;
135 $ns->orderBy('id ASC');
136 return $ns->fetchAll();
140 function updateNotifyToNextServer( $cn , $when = false, $allow_same = false)
142 // fixme - this should take into account blacklisted - and return false if no more servers are available
143 $email = empty($cn->to_email) ? ($cn->person() ? $cn->person()->email : $cn->to_email) : $cn->to_email;
145 $w = DB_DataObject::factory($cn->tableName());
148 $servers = $this->availableServerIds();
150 foreach($servers as $i => $s) {
151 if ($s->id == $this->id) {
156 $offset = ($start + 1) % count($ids);
158 while ($offset != $start) {
159 $s = $servers[$offset];
160 if (!$s->isBlacklisted($email)) {
165 if ($good == false && $allow_same) {
169 if ($good == false) {
176 $w->server_id = $good->id;
177 $w->act_when = $when === false ? $w->sqlValue('NOW() + INTERVAL 1 MINUTE') : $when;
183 function isBlacklisted($email)
185 // return current server id..
186 static $cache = array();
189 $ea = explode('@',$email);
190 $dom = strtolower(array_pop($ea));
191 if (isset($cache[$dom])) {
195 $cd = DB_DataObject::factory('core_domain')->loadOrCreate($dom);
197 $bl = DB_DataObject::factory('core_notify_blacklist');
198 $bl->server_id = $this->id;
199 $bl->domain_id = $cd->id;
210 $ff->Mail['helo'] = $this->helo;
213 function checkSmtpResponse($errmsg, $core_domain)
215 $bl = DB_DataObject::factory('core_notify_blacklist');
216 $bl->server_id = $this->id;
217 $bl->domain_id = $core_domain->id;
222 if (!$bl->messageIsBlacklisted($errmsg)) {
225 $bl->added_dt = $bl->sqlValue("NOW()");