Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
6a488035 TO |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | ||
29 | /* | |
30 | * This file updates the Reminder dates of all valid membership records. | |
31 | * | |
32 | */ | |
4e87860d EM |
33 | |
34 | /** | |
35 | * Class CRM_UpdateMembershipReminderDate | |
36 | */ | |
6a488035 | 37 | class CRM_UpdateMembershipReminderDate { |
4e87860d | 38 | /** |
4e87860d | 39 | */ |
389bcebf | 40 | public function __construct() { |
6a488035 TO |
41 | // you can run this program either from an apache command, or from the cli |
42 | if (php_sapi_name() == "cli") { | |
a9e80afc | 43 | require_once "cli.php"; |
6a488035 TO |
44 | $cli = new civicrm_cli(); |
45 | //if it doesn't die, it's authenticated | |
46 | } | |
47 | else { | |
48 | //from the webserver | |
49 | $this->initialize(); | |
50 | ||
51 | $config = CRM_Core_Config::singleton(); | |
52 | ||
53 | // this does not return on failure | |
54 | CRM_Utils_System::authenticateScript(TRUE); | |
55 | ||
56 | //log the execution time of script | |
57 | CRM_Core_Error::debug_log_message('UpdateMembershipReminderDate.php'); | |
58 | } | |
59 | } | |
60 | ||
389bcebf | 61 | public function initialize() { |
6a488035 TO |
62 | require_once '../civicrm.config.php'; |
63 | require_once 'CRM/Core/Config.php'; | |
64 | ||
65 | $config = CRM_Core_Config::singleton(); | |
66 | } | |
67 | ||
68 | public function updateMembershipReminderDate() { | |
69 | require_once 'CRM/Member/PseudoConstant.php'; | |
70 | ||
71 | //get all active statuses of membership. | |
72 | $allStatuses = CRM_Member_PseudoConstant::membershipStatus(); | |
73 | ||
74 | //set membership reminder date if membership | |
75 | //record has one of the following status. | |
76 | $validStatus = array('New', 'Current', 'Grace'); | |
77 | ||
78 | $statusIds = array(); | |
79 | foreach ($validStatus as $status) { | |
80 | $statusId = array_search($status, $allStatuses); | |
81 | if ($statusId) { | |
82 | $statusIds[$statusId] = $statusId; | |
83 | } | |
84 | } | |
85 | ||
86 | //we don't have valid status to check, | |
87 | //therefore no need to proceed further. | |
88 | if (empty($statusIds)) { | |
89 | return; | |
90 | } | |
91 | ||
92 | //set reminder date for all memberships, | |
93 | //in case reminder date is missing and | |
94 | //membership type has reminder day set. | |
95 | ||
96 | $query = ' | |
783f84c9 | 97 | UPDATE civicrm_membership membership |
98 | INNER JOIN civicrm_contact contact ON ( contact.id = membership.contact_id ) | |
6a488035 | 99 | INNER JOIN civicrm_membership_type type ON ( type.id = membership.membership_type_id ) |
783f84c9 | 100 | SET membership.reminder_date = DATE_SUB( membership.end_date, INTERVAL type.renewal_reminder_day + 1 DAY ) |
101 | WHERE membership.reminder_date IS NULL | |
6a488035 TO |
102 | AND contact.is_deleted = 0 |
103 | AND ( contact.is_deceased IS NULL OR contact.is_deceased = 0 ) | |
783f84c9 | 104 | AND type.renewal_reminder_day IS NOT NULL |
6a488035 TO |
105 | AND membership.status_id IN ( ' . implode(' , ', $statusIds) . ' )'; |
106 | ||
107 | CRM_Core_DAO::executeQuery($query); | |
108 | } | |
96025800 | 109 | |
6a488035 TO |
110 | } |
111 | ||
112 | $reminderDate = new CRM_UpdateMembershipReminderDate(); | |
113 | ||
114 | echo "\n Updating... "; | |
115 | $reminderDate->updateMembershipReminderDate(); | |
116 | echo "\n\n Membership(s) reminder date updated. (Done) \n"; |