|
| 1 | +<?php |
| 2 | +/* |
| 3 | + * This file is part of EC-CUBE |
| 4 | + * |
| 5 | + * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved. |
| 6 | + * |
| 7 | + * http://www.ec-cube.co.jp/ |
| 8 | + * |
| 9 | + * This program is free software; you can redistribute it and/or |
| 10 | + * modify it under the terms of the GNU General Public License |
| 11 | + * as published by the Free Software Foundation; either version 2 |
| 12 | + * of the License, or (at your option) any later version. |
| 13 | + * |
| 14 | + * This program is distributed in the hope that it will be useful, |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | + * GNU General Public License for more details. |
| 18 | + * |
| 19 | + * You should have received a copy of the GNU General Public License |
| 20 | + * along with this program; if not, write to the Free Software |
| 21 | + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 22 | + */ |
| 23 | + |
| 24 | +/** |
| 25 | + * メルマガ登録解除トークンクリーンアップバッチクラス |
| 26 | + * |
| 27 | + * Issue #819: メルマガワンクリック登録解除 |
| 28 | + * 期限切れ・使用済みのトークンを定期的にクリーンアップします。 |
| 29 | + * |
| 30 | + * @author EC-CUBE CO.,LTD. |
| 31 | + * |
| 32 | + * @version $Id$ |
| 33 | + */ |
| 34 | +class SC_Batch_CleanupMailmagaToken extends SC_Batch |
| 35 | +{ |
| 36 | + /** |
| 37 | + * バッチ処理を実行する |
| 38 | + * |
| 39 | + * 期限切れまたは使用済みのメルマガ登録解除トークンを削除します。 |
| 40 | + * |
| 41 | + * 推奨実行頻度: 1日1回(深夜のメンテナンス時間帯) |
| 42 | + * |
| 43 | + * @param array $args コマンドライン引数(未使用) |
| 44 | + * |
| 45 | + * @return void |
| 46 | + */ |
| 47 | + public function execute($args = []) |
| 48 | + { |
| 49 | + $this->start('メルマガ登録解除トークンクリーンアップバッチ'); |
| 50 | + |
| 51 | + try { |
| 52 | + $count = SC_Helper_Mailmaga_Ex::cleanupExpiredTokens(); |
| 53 | + |
| 54 | + if ($count > 0) { |
| 55 | + $msg = "期限切れ・使用済みトークン {$count} 件を削除しました。"; |
| 56 | + $this->printLog($msg); |
| 57 | + } else { |
| 58 | + $msg = 'クリーンアップ対象のトークンはありませんでした。'; |
| 59 | + $this->printLog($msg); |
| 60 | + } |
| 61 | + |
| 62 | + $this->end(); |
| 63 | + } catch (Exception $e) { |
| 64 | + $msg = 'エラーが発生しました: '.$e->getMessage(); |
| 65 | + $this->printLog($msg); |
| 66 | + GC_Utils_Ex::gfPrintLog($msg, ERROR_LOG_REALFILE); |
| 67 | + $this->end(true); |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * バッチ開始ログを出力する |
| 73 | + * |
| 74 | + * @param string $message バッチ名 |
| 75 | + * |
| 76 | + * @return void |
| 77 | + */ |
| 78 | + protected function start($message = '') |
| 79 | + { |
| 80 | + $msg = '========================================'; |
| 81 | + $this->printLog($msg); |
| 82 | + $msg = $message.' 開始: '.date('Y-m-d H:i:s'); |
| 83 | + $this->printLog($msg); |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * バッチ終了ログを出力する |
| 88 | + * |
| 89 | + * @param bool $error エラー終了フラグ |
| 90 | + * |
| 91 | + * @return void |
| 92 | + */ |
| 93 | + protected function end($error = false) |
| 94 | + { |
| 95 | + if ($error) { |
| 96 | + $msg = 'バッチ処理がエラーで終了しました: '.date('Y-m-d H:i:s'); |
| 97 | + } else { |
| 98 | + $msg = 'バッチ処理が正常に終了しました: '.date('Y-m-d H:i:s'); |
| 99 | + } |
| 100 | + $this->printLog($msg); |
| 101 | + $msg = '========================================'; |
| 102 | + $this->printLog($msg); |
| 103 | + } |
| 104 | + |
| 105 | + /** |
| 106 | + * ログメッセージを出力する |
| 107 | + * |
| 108 | + * @param string $message ログメッセージ |
| 109 | + * |
| 110 | + * @return void |
| 111 | + */ |
| 112 | + protected function printLog($message) |
| 113 | + { |
| 114 | + GC_Utils_Ex::gfPrintLog($message, LOG_REALFILE); |
| 115 | + echo $message.PHP_EOL; |
| 116 | + } |
| 117 | +} |
0 commit comments