Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
232624b1 | 4 | | CiviCRM version 4.4 | |
6a488035 TO |
5 | +--------------------------------------------------------------------+ |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
7 | +--------------------------------------------------------------------+ | |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | ||
29 | /* | |
30 | * This file updates the Reminder dates of all valid membership records. | |
31 | * | |
32 | */ | |
33 | class CRM_UpdateMembershipReminderDate { | |
34 | function __construct() { | |
35 | // you can run this program either from an apache command, or from the cli | |
36 | if (php_sapi_name() == "cli") { | |
37 | require_once ("cli.php"); | |
38 | $cli = new civicrm_cli(); | |
39 | //if it doesn't die, it's authenticated | |
40 | } | |
41 | else { | |
42 | //from the webserver | |
43 | $this->initialize(); | |
44 | ||
45 | $config = CRM_Core_Config::singleton(); | |
46 | ||
47 | // this does not return on failure | |
48 | CRM_Utils_System::authenticateScript(TRUE); | |
49 | ||
50 | //log the execution time of script | |
51 | CRM_Core_Error::debug_log_message('UpdateMembershipReminderDate.php'); | |
52 | } | |
53 | } | |
54 | ||
55 | function initialize() { | |
56 | require_once '../civicrm.config.php'; | |
57 | require_once 'CRM/Core/Config.php'; | |
58 | ||
59 | $config = CRM_Core_Config::singleton(); | |
60 | } | |
61 | ||
62 | public function updateMembershipReminderDate() { | |
63 | require_once 'CRM/Member/PseudoConstant.php'; | |
64 | ||
65 | //get all active statuses of membership. | |
66 | $allStatuses = CRM_Member_PseudoConstant::membershipStatus(); | |
67 | ||
68 | //set membership reminder date if membership | |
69 | //record has one of the following status. | |
70 | $validStatus = array('New', 'Current', 'Grace'); | |
71 | ||
72 | $statusIds = array(); | |
73 | foreach ($validStatus as $status) { | |
74 | $statusId = array_search($status, $allStatuses); | |
75 | if ($statusId) { | |
76 | $statusIds[$statusId] = $statusId; | |
77 | } | |
78 | } | |
79 | ||
80 | //we don't have valid status to check, | |
81 | //therefore no need to proceed further. | |
82 | if (empty($statusIds)) { | |
83 | return; | |
84 | } | |
85 | ||
86 | //set reminder date for all memberships, | |
87 | //in case reminder date is missing and | |
88 | //membership type has reminder day set. | |
89 | ||
90 | $query = ' | |
783f84c9 | 91 | UPDATE civicrm_membership membership |
92 | INNER JOIN civicrm_contact contact ON ( contact.id = membership.contact_id ) | |
6a488035 | 93 | INNER JOIN civicrm_membership_type type ON ( type.id = membership.membership_type_id ) |
783f84c9 | 94 | SET membership.reminder_date = DATE_SUB( membership.end_date, INTERVAL type.renewal_reminder_day + 1 DAY ) |
95 | WHERE membership.reminder_date IS NULL | |
6a488035 TO |
96 | AND contact.is_deleted = 0 |
97 | AND ( contact.is_deceased IS NULL OR contact.is_deceased = 0 ) | |
783f84c9 | 98 | AND type.renewal_reminder_day IS NOT NULL |
6a488035 TO |
99 | AND membership.status_id IN ( ' . implode(' , ', $statusIds) . ' )'; |
100 | ||
101 | CRM_Core_DAO::executeQuery($query); | |
102 | } | |
103 | } | |
104 | ||
105 | $reminderDate = new CRM_UpdateMembershipReminderDate(); | |
106 | ||
107 | echo "\n Updating... "; | |
108 | $reminderDate->updateMembershipReminderDate(); | |
109 | echo "\n\n Membership(s) reminder date updated. (Done) \n"; | |
110 |