Campustream 1.0
A social network MQP for WPI
application/tasks/email.php
Go to the documentation of this file.
00001 <?
00002 
00003 group('email');
00004 
00005 desc('Email queue');
00006 task('queue', function ($args) {
00007         
00008         $start = time();
00009         $runtime = 290;
00010         $queue_name = 'queue:email';
00011         
00012         $r = RedisManager::connection();
00013         
00014         while (($start + $runtime) > time()) {
00015                 if ($r->llen($queue_name) === 0) {
00016                         sleep(5);
00017                         continue;
00018                 }
00019                 
00020                 $data = $r->lpop($queue_name);
00021                 if (!$data) {
00022                         sleep(2);
00023                         continue;
00024                 }
00025                 
00026                 $data = unserialize($data);
00027                 email::send($data['to'], $data['subject'], $data['body']);
00028         }
00029 });
00030 
00031 desc('Resend confirmation email');
00032 task('resend_confirm', function ($args) {
00033 
00034         force_execution_on( any_web_server );
00035 
00036         $username = array_shift($args);
00037         $user = ActiveRecord::find('User_Model', "SELECT * FROM users WHERE username = '$username' LIMIT 1");
00038         if (!$user->is_loaded()) {
00039                 echo "ERROR: user not found\n";
00040                 return;
00041         }
00042         
00043         email::send_confirmation($user);
00044         echo "Confirmation email resent!\n";
00045 });
00046 
00047 desc('Print out all emails in a copy & pasteable format');
00048 task('print_all', function () {
00049         $users = ActiveRecord::find_all("User_Model", "SELECT * FROM users");
00050         foreach($users as $user) {
00051                 echo $user->email . "; ";
00052         }
00053 });