Setup cron task and new cron.
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 7 Sep 2018 19:32:28 +0000 (15:32 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 7 Sep 2018 19:32:28 +0000 (15:32 -0400)
Setup a new cron task to check for and reset any contact roles for
active members to own entity manager.

models/admin/ajax/billingFixActiveUsers.php
setup/adminHooks.php

index 4c7c613..32ab08e 100644 (file)
@@ -70,7 +70,7 @@ class GlmMembersAdmin_ajax_billingFixActiveUsers
 
     public function modelAction( $actionData = false )
     {
-
+        $rolesReset = 0;
         // echo '<pre>$actionData: ' . print_r( $actionData, true ) . '</pre>';
         $days_after_expired = $this->config['settings']['days_after_expired'];
         $current_date       = date( 'Y-m-d' );
@@ -89,7 +89,7 @@ class GlmMembersAdmin_ajax_billingFixActiveUsers
                    ARRAY_A
             );
             $total = count( $members );
-            echo '<pre>$total: ' . print_r( $total, true ) . '</pre>';
+            // echo '<pre>$total: ' . print_r( $total, true ) . '</pre>';
             if ( isset( $members ) && $members ) {
                 foreach ( $members as $member ) {
                     echo '<pre>$member: ' . print_r( $member, true ) . '</pre>';
@@ -98,9 +98,10 @@ class GlmMembersAdmin_ajax_billingFixActiveUsers
                     $user_id = $Contact->getWpUserId( $contact_id );
                     $wpUser  = get_user_by( 'id', $user_id );
                     if ( $wpUser ) {
-                        echo '<pre>$wpUser-role: ' . print_r( $wpUser->roles, true ) . '</pre>';
+                        // echo '<pre>$wpUser-role: ' . print_r( $wpUser->roles, true ) . '</pre>';
                         $roles = $wpUser->roles;
                         if ( $roles[0] != 'glm_members_own_entity_manager' ) {
+                            $rolesReset++;
                             apply_filters(
                                 'glm_contact_update_user_role_by_ref_dest',
                                 '',
@@ -113,6 +114,7 @@ class GlmMembersAdmin_ajax_billingFixActiveUsers
                 }
             }
 
+            echo '<pre>$rolesReset: ' . print_r( $rolesReset, true ) . '</pre>';
         }
 
     }
index 1b803f1..991d6a8 100644 (file)
@@ -46,7 +46,7 @@ add_filter(
             array(
                 'menu'       => 'ajax',
                 'action'     => 'billingFlagExpiredUsers',
-                'daysOfWeek' => range( 1, 7 ),
+                'daysOfWeek' => false,
                 'times'      => array( 5 ),
                 'params'     => array()
             )
@@ -55,6 +55,22 @@ add_filter(
     }
 );
 
+add_filter(
+    'glm_associate_cron_request',
+    function( $cron_task ){
+        $new_cron = array(
+            array(
+                'menu'       => 'ajax',
+                'action'     => 'billingFixActiveUsers',
+                'daysOfWeek' => false,
+                'times'      => array( 6 ),
+                'params'     => array()
+            )
+        );
+        return array_merge( $cron_task, $new_cron );
+    }
+);
+
 /**
  * Setup cron task request to run billingSetupQueue
  *
@@ -67,7 +83,7 @@ add_filter(
             array(
                 'menu'       => 'ajax',
                 'action'     => 'billingSetupQueue',
-                'daysOfWeek' => range( 1, 7 ),
+                'daysOfWeek' => false,
                 'times'      => array( 3 ),
                 'params'     => array()
             )
@@ -88,7 +104,7 @@ add_filter(
             array(
                 'menu'       => 'ajax',
                 'action'     => 'billingRunQueue',
-                'daysOfWeek' => range( 1, 7 ),
+                'daysOfWeek' => false,
                 'times'      => array( 4 ),
                 'params'     => array()
             )