コード例 #1
0
ファイル: cron.classes.php プロジェクト: rmiddle/feg
 function ExportSnpp(Model_ExportType $export_type)
 {
     $logger = DevblocksPlatform::getConsoleLog();
     $db = DevblocksPlatform::getDatabaseService();
     @($snpp_current_hour = 0);
     @($snpp_sent_today = 0);
     $memory_limit = ini_get('memory_limit');
     if (substr($memory_limit, 0, -1) < 128) {
         @ini_set('memory_limit', '128M');
     }
     @set_time_limit(0);
     // Unlimited (if possible)
     $logger->info("[SNPP Exporter] Overloaded memory_limit to: " . ini_get('memory_limit'));
     $logger->info("[SNPP Exporter] Overloaded max_execution_time to: " . ini_get('max_execution_time'));
     $timeout = ini_get('max_execution_time');
     $runtime = microtime(true);
     $sql = sprintf("SELECT mr.id " . "FROM message_recipient mr " . "inner join customer_recipient cr on mr.recipient_id = cr.id " . "WHERE mr.send_status in (0,3,4) " . "AND cr.is_disabled = 0 " . "AND cr.export_type = %d " . "AND cr.type = 2 ", $export_type->id);
     $rs = $db->Execute($sql);
     // Loop though pending outbound emails.
     while ($row = mysql_fetch_assoc($rs)) {
         $id = $row['id'];
         $logger->info("[SNPP Exporter] Procing MR ID: " . $id);
         $message_recipient = DAO_MessageRecipient::get($id);
         $message = DAO_Message::get($message_recipient->message_id);
         $message_lines = explode('\\n', substr($message->message, 1, -1));
         $recipient = DAO_CustomerRecipient::get($message_recipient->recipient_id);
         $message_str = substr(implode("", $message_lines), 0, 160);
         // FIXME - Need to add in filter for now everything is unfiltered.
         // sendSnpp($phone_number, $message, $snpp_server="ann100sms01.answernet.com", $port=444)
         $send_status = FegSnpp::sendSnpp($recipient->address, $message_str);
         $logger->info("[SNPP Exporter] Send Status: " . ($send_status ? "Successful" : "Failure"));
         // Give plugins a chance to run export
         $eventMgr = DevblocksPlatform::getEventService();
         $eventMgr->trigger(new Model_DevblocksEvent('cron.send.snpp', array('recipient' => $recipient, 'message' => $message, 'message_lines' => $message_lines, 'message_recipient' => $message_recipient, 'send_status' => $send_status)));
         if ($send_status) {
             $snpp_current_hour++;
             $snpp_sent_today++;
         }
         $fields = array(DAO_MessageRecipient::SEND_STATUS => $send_status ? 2 : 1, DAO_MessageRecipient::CLOSED_DATE => $send_status ? time() : 0);
         DAO_MessageRecipient::update($id, $fields);
     }
     mysql_free_result($rs);
     if ($snpp_current_hour) {
         $current_fields = DAO_Stats::get(0);
         $fields = array(DAO_Stats::SNPP_CURRENT_HOUR => $current_fields->snpp_current_hour + $snpp_current_hour, DAO_Stats::SNPP_SENT_TODAY => $current_fields->snpp_sent_today + $snpp_sent_today);
         DAO_Stats::update(0, $fields);
     }
     return NULL;
 }
コード例 #2
0
ファイル: stats.php プロジェクト: rmiddle/feg
 function doBulkUpdate($filter, $do, $ids = array())
 {
     @set_time_limit(0);
     $change_fields = array();
     $custom_fields = array();
     // Make sure we have actions
     if (empty($do)) {
         return;
     }
     // Make sure we have checked items if we want a checked list
     if (0 == strcasecmp($filter, "checks") && empty($ids)) {
         return;
     }
     if (is_array($do)) {
         foreach ($do as $k => $v) {
             switch ($k) {
                 // [TODO] Implement actions
                 case 'example':
                     // [TODO] Used for bulk update
                     $change_fields[DAO_Stats::ID] = intval($v);
                     $change_fields[DAO_Stats::CURRENT_HOUR] = intval($v);
                     $change_fields[DAO_Stats::CURRENT_DAY] = intval($v);
                     $change_fields[DAO_Stats::FAX_CURRENT_HOUR] = intval($v);
                     $change_fields[DAO_Stats::FAX_LAST_HOUR] = intval($v);
                     $change_fields[DAO_Stats::FAX_SENT_TODAY] = intval($v);
                     $change_fields[DAO_Stats::FAX_SENT_YESTERDAY] = intval($v);
                     $change_fields[DAO_Stats::EMAIL_CURRENT_HOUR] = intval($v);
                     $change_fields[DAO_Stats::EMAIL_LAST_HOUR] = intval($v);
                     $change_fields[DAO_Stats::EMAIL_SENT_TODAY] = intval($v);
                     $change_fields[DAO_Stats::EMAIL_SENT_YESTERDAY] = intval($v);
                     $change_fields[DAO_Stats::SNPP_CURRENT_HOUR] = intval($v);
                     $change_fields[DAO_Stats::SNPP_LAST_HOUR] = intval($v);
                     $change_fields[DAO_Stats::SNPP_SENT_TODAY] = intval($v);
                     $change_fields[DAO_Stats::SNPP_SENT_YESTERDAY] = intval($v);
                     //$change_fields[DAO_Stats::EXAMPLE] = 'some value';
                     break;
                 default:
             }
         }
     }
     $pg = 0;
     if (empty($ids)) {
         do {
             list($objects, $null) = DAO_Stats::search($this->params, 100, $pg++, SearchFields_Stats::ID, true, false);
             $ids = array_merge($ids, array_keys($objects));
         } while (!empty($objects));
     }
     $batch_total = count($ids);
     for ($x = 0; $x <= $batch_total; $x += 100) {
         $batch_ids = array_slice($ids, $x, 100);
         DAO_Stats::update($batch_ids, $change_fields);
         // Custom Fields
         //self::_doBulkSetCustomFields(FegCustomFieldSource_Stats::ID, $custom_fields, $batch_ids);
         unset($batch_ids);
     }
     unset($ids);
 }