public function getFailedMessagesCount($start = false, $end = false)
 {
     $record = new Postmaster_TransportResponseRecord();
     $query = craft()->db->createCommand()->select('count(id) count')->from($record->getTableName())->andWhere('success = 0');
     if ($start) {
         $query->andWhere('dateCreated >= :date', array('date' => $start));
     }
     if ($end) {
         $query->andWhere('dateCreated <= :date', array('date' => $end));
     }
     $data = $query->queryRow();
     return (int) $data['count'];
 }
 public function delete($id)
 {
     if ($record = Postmaster_TransportResponseRecord::model()->findById($id)) {
         return $record->delete();
     }
     return false;
 }
 public function safeUp()
 {
     $table = new Postmaster_TransportResponseRecord();
     $this->addColumnAfter($table->getTableName(), 'code', ColumnType::Text, 'success');
     foreach (Postmaster_TransportResponseRecord::model()->findAll() as $row) {
         if (!isset($row->model['service']['__class__'])) {
             $obj = craft()->postmaster->getRegisteredService($row->model['service']['id']);
             $model = $row->model;
             $service = $model['service'];
             $service['__class__'] = $obj->__class__;
             $model['service'] = $service;
             $row->model = $model;
             $row->save();
         }
     }
     return true;
 }