| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
class Swift_PropelSpool extends Swift_ConfigurableSpool |
|---|
| 26 |
{ |
|---|
| 27 |
protected |
|---|
| 28 |
$model = null, |
|---|
| 29 |
$column = null, |
|---|
| 30 |
$method = null; |
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
* Constructor. |
|---|
| 34 |
* |
|---|
| 35 |
* @param string The Propel model to use to store the messages (MailMessage by default) |
|---|
| 36 |
* @param string The column name to use for message storage (message by default) |
|---|
| 37 |
* @param string The method to call to retrieve the messages to send (optional) |
|---|
| 38 |
*/ |
|---|
| 39 |
public function __construct($model = 'MailMessage', $column = 'message', $method = 'doSelect') |
|---|
| 40 |
{ |
|---|
| 41 |
$this->model = $model; |
|---|
| 42 |
$this->column = $column; |
|---|
| 43 |
$this->method = $method; |
|---|
| 44 |
} |
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
* Tests if this Transport mechanism has started. |
|---|
| 48 |
* |
|---|
| 49 |
* @return boolean |
|---|
| 50 |
*/ |
|---|
| 51 |
public function isStarted() |
|---|
| 52 |
{ |
|---|
| 53 |
return true; |
|---|
| 54 |
} |
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
* Starts this Transport mechanism. |
|---|
| 58 |
*/ |
|---|
| 59 |
public function start() |
|---|
| 60 |
{ |
|---|
| 61 |
} |
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
* Stops this Transport mechanism. |
|---|
| 65 |
*/ |
|---|
| 66 |
public function stop() |
|---|
| 67 |
{ |
|---|
| 68 |
} |
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
* Stores a message in the queue. |
|---|
| 72 |
* |
|---|
| 73 |
* @param Swift_Mime_Message $message The message to store |
|---|
| 74 |
*/ |
|---|
| 75 |
public function queueMessage(Swift_Mime_Message $message) |
|---|
| 76 |
{ |
|---|
| 77 |
$object = new $this->model; |
|---|
| 78 |
|
|---|
| 79 |
if (!$object instanceof BaseObject) |
|---|
| 80 |
{ |
|---|
| 81 |
throw new InvalidArgumentException('The mailer message object must be a BaseObject object.'); |
|---|
| 82 |
} |
|---|
| 83 |
|
|---|
| 84 |
$model = constant($this->model.'::PEER'); |
|---|
| 85 |
$method = 'set'.call_user_func(array($model, 'translateFieldName'), $this->column, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME); |
|---|
| 86 |
|
|---|
| 87 |
$object->$method(serialize($message)); |
|---|
| 88 |
$object->save(); |
|---|
| 89 |
} |
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
* Sends messages using the given transport instance. |
|---|
| 93 |
* |
|---|
| 94 |
* @param Swift_Transport $transport A transport instance |
|---|
| 95 |
* @param string[] &$failedRecipients An array of failures by-reference |
|---|
| 96 |
* |
|---|
| 97 |
* @return int The number of sent emails |
|---|
| 98 |
*/ |
|---|
| 99 |
public function flushQueue(Swift_Transport $transport, &$failedRecipients = null) |
|---|
| 100 |
{ |
|---|
| 101 |
$criteria = new Criteria(); |
|---|
| 102 |
$criteria->setLimit($this->getMessageLimit()); |
|---|
| 103 |
|
|---|
| 104 |
$model = constant($this->model.'::PEER'); |
|---|
| 105 |
$objects = call_user_func(array($model, $this->method), $criteria); |
|---|
| 106 |
|
|---|
| 107 |
if (!$transport->isStarted()) |
|---|
| 108 |
{ |
|---|
| 109 |
$transport->start(); |
|---|
| 110 |
} |
|---|
| 111 |
|
|---|
| 112 |
$method = 'get'.call_user_func(array($model, 'translateFieldName'), $this->column, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_PHPNAME); |
|---|
| 113 |
$count = 0; |
|---|
| 114 |
$time = time(); |
|---|
| 115 |
foreach ($objects as $object) |
|---|
| 116 |
{ |
|---|
| 117 |
if (is_resource($object->getMessage())) |
|---|
| 118 |
{ |
|---|
| 119 |
$message = unserialize(stream_get_contents($object->getMessage())); |
|---|
| 120 |
} |
|---|
| 121 |
else |
|---|
| 122 |
{ |
|---|
| 123 |
$message = unserialize($object->getMessage()); |
|---|
| 124 |
} |
|---|
| 125 |
|
|---|
| 126 |
$object->delete(); |
|---|
| 127 |
|
|---|
| 128 |
try |
|---|
| 129 |
{ |
|---|
| 130 |
$count += $transport->send($message, $failedRecipients); |
|---|
| 131 |
} |
|---|
| 132 |
catch (Exception $e) |
|---|
| 133 |
{ |
|---|
| 134 |
|
|---|
| 135 |
} |
|---|
| 136 |
|
|---|
| 137 |
if ($this->getTimeLimit() && (time() - $time) >= $this->getTimeLimit()) |
|---|
| 138 |
{ |
|---|
| 139 |
break; |
|---|
| 140 |
} |
|---|
| 141 |
} |
|---|
| 142 |
|
|---|
| 143 |
return $count; |
|---|
| 144 |
} |
|---|
| 145 |
} |
|---|
| 146 |
|
|---|