Updating cron task for setting free memberships
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 10 Jan 2019 14:43:55 +0000 (09:43 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 10 Jan 2019 14:43:55 +0000 (09:43 -0500)
Free memberships should be reset to invoice_type of 0.

index.php
models/admin/ajax/billingFlagExpiredUsers.php

index 3ca41e7..52ffa5f 100644 (file)
--- a/index.php
+++ b/index.php
@@ -3,7 +3,7 @@
  * Plugin Name: GLM Members Billing
  * Plugin URI: http://www.gaslightmedia.com/
  * Description: This is glmAssociate Billing Module
- * Version: 1.0.20
+ * Version: 1.0.21
  * Author: Gaslight Media
  * Author URI: http://www.gaslightmedia.com/
  * License: GPL2
@@ -19,7 +19,7 @@
  * @package glmMembersBillingAddOn
  * @author Chuck Scott <cscott@gaslightmedia.com>
  * @license http://www.gaslightmedia.com Gaslightmedia
- * @version 1.0.20
+ * @version 1.0.21
  */
 
 /*
@@ -37,7 +37,7 @@
  *  so that we're sure the other add-ons see an up to date
  *  version from this plugin.
  */
-define('GLM_MEMBERS_BILLING_PLUGIN_VERSION', '1.0.20');
+define('GLM_MEMBERS_BILLING_PLUGIN_VERSION', '1.0.21');
 define('GLM_MEMBERS_BILLING_PLUGIN_DB_VERSION', '0.0.26');
 
 // This is the minimum version of the GLM Members DB plugin require for this plugin.
index e63f9fb..ed97f8a 100644 (file)
@@ -83,10 +83,20 @@ class GlmMembersAdmin_ajax_billingFlagExpiredUsers
             // Update any account that has invoice_type set to 0 and have an expired renewal_date
             // These would be memberships that are free so they don't pay.
             // They just get updated renewal dates.
+            $this->wpdb->query(
+                "UPDATE " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts
+                    SET invoice_type = 0
+                  WHERE invoice_type != 0
+                    AND ref_dest IN (
+                        SELECT id
+                          FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members
+                         WHERE member_type in ( 5, 7, 13))"
+            );
             $this->wpdb->query(
                 "UPDATE " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts
                     SET renewal_date = renewal_date + INTERVAL 1 YEAR
-                  WHERE renewal_date + INTERVAL 1 YEAR + INTERVAL $days_after_expired DAY <= '$current_date'
+                  WHERE renewal_date
+                    AND (renewal_date + INTERVAL 1 YEAR + INTERVAL $days_after_expired DAY <= '$current_date'
                     AND invoice_type = 0"
             );