Merge remote-tracking branch 'upstream/4.4' into 4.4-master-2014-07-07-15-48-59
[civicrm-core.git] / bin / deprecated / UpdateMembershipRecord.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 checks and updates the status of all membership records for a given domain using the calc_membership_status and
31 * update_contact_membership APIs.
32 * It takes the first argument as the domain-id if specified, otherwise takes the domain-id as 1.
33 *
34 * IMPORTANT:
35 * We are using the default Domain FROM Name and FROM Email Address as the From email address for emails sent by this script.
36 * Verify that this value has been properly set from Administer > Configure > Domain Information
37 * If you want to use some other FROM email address, modify line 125 and set your valid email address.
38 *
39 * Save the file as UpdateMembershipRecord.php prior to running this script.
40 */
41
42 /**
43 * Class CRM_UpdateMembershipRecord
44 */
45 class CRM_UpdateMembershipRecord {
46 /**
47 *
48 */
49 function __construct() {
50 // you can run this program either from an apache command, or from the cli
51 if (php_sapi_name() == "cli") {
52 require_once ("cli.php");
53 $cli = new civicrm_cli();
54 //if it doesn't die, it's authenticated
55 }
56 else {
57 //from the webserver
58 $this->initialize();
59
60 $config = CRM_Core_Config::singleton();
61
62 // this does not return on failure
63 CRM_Utils_System::authenticateScript(TRUE);
64
65 //log the execution time of script
66 CRM_Core_Error::debug_log_message('UpdateMembershipRecord.php');
67 }
68 }
69
70 function initialize() {
71 require_once '../civicrm.config.php';
72 require_once 'CRM/Core/Config.php';
73
74 $config = CRM_Core_Config::singleton();
75 }
76
77 public function updateMembershipStatus() {
78 require_once 'CRM/Member/BAO/Membership.php';
79 CRM_Member_BAO_Membership::updateAllMembershipStatus();
80 }
81 }
82
83 $obj = new CRM_UpdateMembershipRecord();
84
85 echo "\n Updating ";
86 $obj->updateMembershipStatus();
87 echo "\n\n Membership records updated. (Done) \n";
88