2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 07/05/2011 *
4 * =================== Last change: 07/05/2011 *
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 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
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 *
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. *
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. *
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, *
36 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
41 } elseif (!isExtensionActive('coupon')) {
42 logDebugMessage(__FILE__, __LINE__, 'Not resetting, needed extension ext-coupon disabled.');
46 // Search for all expired coupons that we can purge
47 $result = sqlQuery('SELECT
49 UNIX_TIMESTAMP(`coupon_created`) AS `coupon_created`,
50 UNIX_TIMESTAMP(`coupon_expired`) AS `coupon_expired`,
56 `{?_MYSQL_PREFIX?}_coupon_data`
58 (UNIX_TIMESTAMP() - UNIX_TIMESTAMP(`coupon_expired`)) >= {?coupon_autopurge_time?}
60 `id` ASC', __FILE__, __LINE__);
63 if (sqlNumRows($result) > 0) {
69 while ($content = sqlFetchArray($result)) {
71 array_push($ids, $content['id']);
73 // Translate some data
74 $content['coupon_created'] = generateDateTime($content['coupon_created'], '2');
75 $content['coupon_expired'] = generateDateTime($content['coupon_expired'], '2');
77 // Load email row template
78 $out .= loadEmailTemplate('admin_coupon_purge_row', $content);
82 sqlQuery('DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_coupon_data` WHERE (UNIX_TIMESTAMP() - UNIX_TIMESTAMP(`coupon_expired`)) >= {?coupon_autopurge_time?}', __FILE__, __LINE__);
84 // Purge also user entries
85 sqlQueryEscaped("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_coupons` WHERE `coupon_id` IN (%s) LIMIT %s",
89 ), __FILE__, __LINE__);
91 // Send admin notification
92 sendAdminNotification('{--ADMIN_COUPON_PURGE_SUBJECT--}', 'admin_coupon_purge', $out);
96 sqlFreeResult($result);