These aren't so much feature requests, as things I had to hack into Swift myself... I'm sharing them here in case they seem like they might be a good idea for ver4.
Enhanced Failure Logging
I was creating a custom Decorator class that would perform replacements. I wanted to force the sending of an email to fail if the requested substitution (say {mailing_address}) did not exist for the recipient. I did get this to work simply by throwing an exception. However, I wanted to log this error properly, with the REASON (like "Sending Failed: Substitution for mailing address not found"), so that the rest of my code could present this message to the user. But IIRC, throwing an exception (in BatchSend) doesn't allow you to log the reason, just that it failed.
What I ended up doing was instantiating my own custom Swift_Log class, and using that to log all these things. Then, if there were any Failed Recipients recorded, I'd have the ability to look up the address, the error message, etc.
The suggestion for this though is allowing plugins to trigger the failing of a recipient, and be able to log the reason why, which would then be accessible in the main error log, united for all plugins as well as core operations.
Progress Tracking
I have progress bars in my app for anything that typically takes more than 10 seconds. Uploading, generating large pdfs, etc... and sending emails. If using Swift in a command-line environment, that's fine, the web front-end could just go happily on it's way while the backend churns things out. In my case, I wanted to allow people to cancel the process, so had a progress bar with a cancel button. But progress bars mean you need to be able to see what's going on!
In my case, I update the progressbar by writing JavaScript to an iframe. So the email sending is done by the script that is loading in the iframe. Here's what I did:
Code: Select all
$swift->attachPlugin(new Swift_Plugin_Progress($num_recipients, $initial_offset), 'progress');
apache_setenv('no-gzip', '1');
Here's the custom plugin:
Code: Select all
class Swift_Plugin_Progress implements Swift_Events_SendListener
{
protected $total;
protected $progress;
protected $starttime;
public function __construct($total, $progress = 0)
{
$this->total = $total;
$this->progress = $progress;
$this->initial = $progress;
$this->starttime = time();
}
public function sendPerformed(Swift_Events_SendEvent $e)
{
$this->progress ++;
$recipients = $e->getRecipients();
$recipients = $recipients->getTo();
$recipient = reset($recipients);
$percent = round(100 * $this->progress / $this->total);
$timesofar = time() - $this->starttime;
$rate = $timesofar / ($this->progress - $this->initial);
$remaining = round($rate * ($this->total - $this->progress)); //seconds
$statustext = 'Sent to '.$recipient->getName().'<br/>'.
'<em>Sent '.($this->progress - 1).' of '.$this->total.'</em>';
echo '<script type="text/javascript">'.
"parent.progressbarUpdate('".$statustext."',".$percent.",".$remaining.",false);".
'</script>';
flush();
}
}
Easy and simple. Luckily the event-driven design of Swift allows for plugins like this to be easily written (I love finding libraries that are well-thought out!). I'm including this second one here just in case they can be useful to anyone else, but also to see if it helps to spark any new ideas for the upcoming release, in terms of a progress monitor

.
Dave
PS, can't wait to see the php4 compatibility crutches gone! Death to php4!