-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
172 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace Stem\MailTemplates\Logging; | ||
|
||
class MailTemplateLog { | ||
public static function LogSuccess($responseId, $response, $template, $to, $bcc, $data) { | ||
/** @var \WPDB */ | ||
global $wpdb; | ||
$wpdb->insert('stem_mail_template_log', [ | ||
'template' => $template, | ||
'email_to' => serialize($to), | ||
'email_bcc' => serialize($bcc), | ||
'status' => (int)1, | ||
'data' => serialize($data), | ||
'responseId' => $responseId, | ||
'response' => $response | ||
]); | ||
} | ||
|
||
public static function LogError($template, $to, $bcc, $data, $error) { | ||
/** @var \WPDB */ | ||
global $wpdb; | ||
$wpdb->insert('stem_mail_template_log', [ | ||
'template' => $template, | ||
'email_to' => serialize($to), | ||
'email_bcc' => serialize($bcc), | ||
'status' => (int)0, | ||
'data' => serialize($data), | ||
'error' => $error | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
namespace Stem\MailTemplates\UI; | ||
|
||
use Carbon\Carbon; | ||
use Stem\UI\ListTable; | ||
|
||
class MailLogList extends ListTable { | ||
|
||
public function __construct($args = []) { | ||
parent::__construct([ | ||
'singlur' => 'Mail Log', | ||
'plural' => 'Mail Logs', | ||
'ajax' => false, | ||
'screen' => (!empty($args['screen'])) ? $args['screen'] : null | ||
]); | ||
} | ||
|
||
public function get_columns() { | ||
return [ | ||
'date' => 'Date', | ||
'template' => 'Template', | ||
'to' => 'To', | ||
'error' => 'Error', | ||
'responseId' => 'Response ID', | ||
'response' => 'Response', | ||
]; | ||
} | ||
|
||
public function prepare_items() { | ||
/** @var \WPDB $wpdb */ | ||
global $wpdb; | ||
|
||
$offset = ($this->get_pagenum() - 1) * 100; | ||
$this->items = $wpdb->get_results("select * from stem_mail_template_log order by id desc limit 100 offset {$offset}"); | ||
$this->_column_headers = [$this->get_columns(), [], []]; | ||
$total = $wpdb->get_var("select count(id) from stem_mail_template_log"); | ||
$this->set_pagination_args([ | ||
'total_items' => $total, | ||
'per_page' => 100, | ||
'total_pages' => ceil($total / 100) | ||
]); | ||
} | ||
|
||
protected function column_date($item) { | ||
$date = Carbon::parse($item->created_at); | ||
return $date->format('n/j/Y g:i a'); | ||
} | ||
|
||
protected function column_template($item) { | ||
return $item->template; | ||
} | ||
|
||
protected function column_to($item) { | ||
$toData = unserialize($item->email_to); | ||
|
||
return implode(', ', $toData); | ||
} | ||
|
||
protected function column_error($item) { | ||
return $item->error; | ||
} | ||
|
||
protected function column_responseId($item) { | ||
return $item->responseId; | ||
} | ||
|
||
protected function column_response($item) { | ||
return $item->response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
|
||
use Phinx\Migration\AbstractMigration; | ||
|
||
class MailTemplateLogging extends AbstractMigration | ||
{ | ||
/** | ||
* Change Method. | ||
* | ||
* Write your reversible migrations using this method. | ||
* | ||
* More information on writing migrations is available here: | ||
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class | ||
* | ||
* The following commands can be used in this method and Phinx will | ||
* automatically reverse them when rolling back: | ||
* | ||
* createTable | ||
* renameTable | ||
* addColumn | ||
* addCustomColumn | ||
* renameColumn | ||
* addIndex | ||
* addForeignKey | ||
* | ||
* Any other destructive changes will result in an error when trying to | ||
* rollback the migration. | ||
* | ||
* Remember to call "create()" or "update()" and NOT "save()" when working | ||
* with the Table class. | ||
*/ | ||
public function change() | ||
{ | ||
$table = $this->table('stem_mail_template_log', ['id' => false, 'primary_key' => 'id', 'engine' => 'innodb', 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci']); | ||
$table | ||
->addColumn('id', 'biginteger', ['signed' => false, 'null' => false, 'identity' => true]) | ||
->addColumn('template', 'string', ['length' => 255, 'null' => false, 'collation' => 'utf8mb4_unicode_ci']) | ||
->addColumn('email_to', 'text', ['collation' => 'utf8mb4_unicode_ci']) | ||
->addColumn('email_bcc', 'text', ['collation' => 'utf8mb4_unicode_ci']) | ||
->addColumn('status', 'integer', ['signed' => true, 'null' => false, 'default' => (int)0]) | ||
->addColumn('data', 'text', ['collation' => 'utf8mb4_unicode_ci']) | ||
->addColumn('error', 'text', ['collation' => 'utf8mb4_unicode_ci']) | ||
->addColumn('responseId', 'string', ['length' => 255, 'collation' => 'utf8mb4_unicode_ci']) | ||
->addColumn('response', 'text', ['collation' => 'utf8mb4_unicode_ci']) | ||
->addTimestamps() | ||
->create(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters