]> git.mxchange.org Git - mailer.git/blob - inc/purge/purge-coupon.php
Some fixes:
[mailer.git] / inc / purge / purge-coupon.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 07/05/2011 *
4  * ===================                          Last change: 07/05/2011 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : purge-coupon.php                                 *
8  * -------------------------------------------------------------------- *
9  * Short description : Purge expired coupons after some time            *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Nach einer Weile angelaufene Gutscheine entf.    *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2013 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
40         die();
41 } elseif (!isExtensionActive('coupon')) {
42         logDebugMessage(__FILE__, __LINE__, 'Not resetting, needed extension ext-coupon disabled.');
43         return;
44 }
45
46 // Search for all expired coupons that we can purge
47 $result = sqlQuery('SELECT
48         `id`,
49         UNIX_TIMESTAMP(`coupon_created`) AS `coupon_created`,
50         UNIX_TIMESTAMP(`coupon_expired`) AS `coupon_expired`,
51         `total_created`,
52         `total_cashed`,
53         `points`,
54         `coupon_description`
55 FROM
56         `{?_MYSQL_PREFIX?}_coupon_data`
57 WHERE
58         (UNIX_TIMESTAMP() - UNIX_TIMESTAMP(`coupon_expired`)) >= {?coupon_autopurge_time?}
59 ORDER BY
60         `id` ASC', __FILE__, __LINE__);
61
62 // Are there entries?
63 if (sqlNumRows($result) > 0) {
64         // Init variables
65         $out = '';
66         $ids = array();
67
68         // Start purging all
69         while ($content = sqlFetchArray($result)) {
70                 // Add id
71                 array_push($ids, $content['id']);
72
73                 // Translate some data
74                 $content['coupon_created'] = generateDateTime($content['coupon_created'], '2');
75                 $content['coupon_expired'] = generateDateTime($content['coupon_expired'], '2');
76
77                 // Load email row template
78                 $out .= loadEmailTemplate('admin_coupon_purge_row', $content);
79         } // END - while
80
81         // Purge all entries
82         sqlQuery('DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_coupon_data` WHERE (UNIX_TIMESTAMP() - UNIX_TIMESTAMP(`coupon_expired`)) >= {?coupon_autopurge_time?}', __FILE__, __LINE__);
83
84         // Purge also user entries
85         sqlQueryEscaped("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_coupons` WHERE `coupon_id` IN (%s) LIMIT %s",
86                 array(
87                         implode(',', $ids),
88                         count($ids)
89                 ), __FILE__, __LINE__);
90
91         // Send admin notification
92         sendAdminNotification('{--ADMIN_COUPON_PURGE_SUBJECT--}', 'admin_coupon_purge', $out);
93 } // END - if
94
95 // Free result
96 sqlFreeResult($result);
97
98 // [EOF]
99 ?>