Added Management "Crons" tab to display a sorted lsit of GLM Cron requests
authorChuck Scott <cscott@gaslightmedia.com>
Thu, 26 Apr 2018 14:27:23 +0000 (10:27 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Thu, 26 Apr 2018 14:27:23 +0000 (10:27 -0400)
index.php
models/admin/ajax/glmCron.php
models/admin/management/cron.php [new file with mode: 0644]
setup/validActions.php
views/admin/management/cron.html [new file with mode: 0644]
views/admin/management/header.html

index c3b8928..68b6092 100644 (file)
--- a/index.php
+++ b/index.php
@@ -222,8 +222,9 @@ require_once 'defines.php';
 // Get configuration
 require_once 'config.php';
 
-if (GLM_MEMBERS_PLUGIN_DEBUG_VERBOSE) {
-    trigger_error(glmAssociateMemoryUsage()." - Start glm-member-db setup",E_USER_NOTICE);
+if (GLM_MEMBERS_PLUGIN_DEBUG) {
+    ini_set('log_errors_max_len', 4096);
+    trigger_error("GLM Associate Index Start: ".glmAssociateMemoryUsage()." - Start glm-member-db setup",E_USER_NOTICE);
 }
 
 /*
@@ -839,4 +840,7 @@ if (!$timestamp) {
     wp_schedule_event( $t, 'hourly', 'glm_associate_cron' );
 }
 
+if (GLM_MEMBERS_PLUGIN_DEBUG) {
+    trigger_error("GLM Associate Index End: ".glmAssociateMemoryUsage()." - Start glm-member-db setup",E_USER_NOTICE);
+}
 
index 52babfb..d370fb4 100644 (file)
@@ -83,8 +83,8 @@ class GlmMembersAdmin_ajax_glmCron extends glmMembersAdmin
 
                 foreach ($cronActions as $act) {
 
-                    // Check if this action should be run now
-                    if (in_array($thisDay, $act['daysOfWeek']) && in_array($thisHour, $act['times'])) {
+                    // Check if this action should be run now - If daysOfWeek or times are false they they always match.
+                    if ((!$act['daysOfWeek'] || in_array($thisDay, $act['daysOfWeek'])) && (!$act['times'] || in_array($thisHour, $act['times']))) {
 
                         // Run the action by calling the controller - force controller to use supplied action (no REQUEST override)
                         $this->controller($act['menu'], $act['action'], $act['params'], false, true);
diff --git a/models/admin/management/cron.php b/models/admin/management/cron.php
new file mode 100644 (file)
index 0000000..18b83dd
--- /dev/null
@@ -0,0 +1,141 @@
+<?php
+/**
+ * Gaslight Media Members Database
+ * Admin Management - Cron
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @version  1.0.43
+ */
+
+/*
+ * This class performs the work for the default action of the "Members" menu
+ * option, which is to display the members dashboard.
+ *
+ */
+class GlmMembersAdmin_management_cron
+{
+
+    /**
+     * WordPress Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * Plugin Configuration Data
+     *
+     * @var $config
+     * @access public
+     */
+    public $config;
+
+    /*
+     * Constructor
+     *
+     * This contructor sets up this model. At this time that only includes
+     * storing away the WordPress data object.
+     *
+     * @return object Class object
+     *
+     */
+    public function __construct ($wpdb, $config)
+    {
+
+        // Save WordPress Database object
+        $this->wpdb = $wpdb;
+
+        // Save plugin configuration object
+        $this->config = $config;
+
+    }
+
+    /*
+     * Perform Model Action
+     *
+     * This method does the work for this model and returns any resulting data
+     *
+     * @return array Status and data array
+     *
+     * 'status'
+     *
+     * True if successfull and false if there was a fatal failure.
+     *
+     * 'menuItemRedirect'
+     *
+     * If not false, provides a menu item the controller should
+     * execute after this one. Normally if this is used, there would also be a
+     * modelRedirect value supplied as well.
+     *
+     * 'modelRedirect'
+     *
+     * If not false, provides an action the controller should execute after
+     * this one.
+     *
+     * 'view'
+     *
+     * A suggested view name that the contoller should use instead of the
+     * default view for this model or false to indicate that the default view
+     * should be used.
+     *
+     * 'data'
+     *
+     * Data that the model is returning for use in merging with the view to
+     * produce output.
+     *
+     */
+    public function modelAction ($actionData = false)
+    {
+
+        $haveCronActions = false;
+
+        // Get requested cron actions
+        $cronActions = apply_filters('glm_associate_cron_request', array());
+
+
+        // Loop through these actions and call what's appropriate for the current time
+        if (is_array($cronActions)) {
+            if (count($cronActions) > 0) {
+                $haveCronActions = true;
+
+                function sortCrons($a, $b) {
+                    if ($a['menu'] < $b['menu']) { return -1; }
+                    if ($a['menu'] > $b['menu']) { return 1; }
+                    if ($a['action'] < $b['action']) { return -1; }
+                    if ($a['action'] > $b['action']) { return 1; }
+                    return 0;
+                }
+
+                usort($cronActions, 'sortCrons');
+
+            }
+        } else {
+            trigger_error('GLM Associate Cron: Bad request array!', E_USER_WARNING);
+        }
+
+        $viewData = array(
+            'haveCronActions'   => $haveCronActions,
+            'cronActions'       => $cronActions
+        );
+
+        // echo "<pre>".print_r($viewData,1)."</pre>";
+
+        // Return status, suggested view, and data to controller
+        return array(
+            'status' => true,
+            'menuItemRedirect' => false,
+            'modelRedirect' => false,
+            'view' => 'admin/management/cron.html',
+            'data' => $viewData
+        );
+
+    }
+
+}
+
+?>
\ No newline at end of file
index cde1cd4..c9d93a0 100644 (file)
@@ -84,7 +84,8 @@ $glmMembersValidActions = array(
             'theme'       => 'glm-member-db',
             'import'      => 'glm-member-db',
             'addons'      => 'glm-member-db',
-            'hooks'       => 'glm-member-db'
+            'hooks'       => 'glm-member-db',
+            'cron'        => 'glm-member-db'
         ),
         'shortcodes' => array(
             'index' => 'glm-member-db'
diff --git a/views/admin/management/cron.html b/views/admin/management/cron.html
new file mode 100644 (file)
index 0000000..7d30ad5
--- /dev/null
@@ -0,0 +1,51 @@
+{include file='admin/management/header.html'}
+
+   <h2>Current Cron Action Requests</h2>
+   <div>&nbsp;</div>
+    
+    <table width="90%">
+        <thead>
+            <tr>
+                <th align="left">Menu</th>
+                <th align="left">Action</th>
+                <th align="left">Days</th>
+                <th align="left">Times</th>
+                <th align="left">Parameters</th>
+            </tr>
+        </thead>        
+        <tbody>
+{$m = ''}        
+{foreach $cronActions as $ca}
+            <tr>        
+                <td>
+    {if $ca.menu != $m}                
+        {$m = $ca.menu}        
+                    {$ca.menu}
+    {/if}
+                </td>
+                <td>{$ca.action}</td>
+                <td>
+                    {if $ca.daysOfWeek}
+                        {', '|implode:$ca.daysOfWeek}
+                    {else}
+                        All
+                    {/if}
+                </td>
+                <td>
+                    {if $ca.times}
+                        {', '|implode:$ca.times}
+                    {else}
+                        All
+                    {/if}
+                </td>
+                <td>
+                    {if $ca.params}Yes{else}&nbsp;{/if}
+                </td>
+            </tr>  
+{/foreach}            
+        </tbody>    
+    </table>
+    
+    
+        
+{include file='admin/footer.html'}
index b1080ca..5e95734 100644 (file)
@@ -10,6 +10,7 @@
         <a href="{$thisUrl}?page={$thisPage}&glm_action=import" class="nav-tab{if $thisAction==import} nav-tab-active{/if}">Members</a>
         <a href="{$thisUrl}?page={$thisPage}&glm_action=addons" class="nav-tab{if $thisAction==addons} nav-tab-active{/if}">Add-Ons</a>
         <a href="{$thisUrl}?page={$thisPage}&glm_action=hooks" class="nav-tab{if $thisAction==hooks} nav-tab-active{/if}">Hooks</a>
+        <a href="{$thisUrl}?page={$thisPage}&glm_action=cron" class="nav-tab{if $thisAction==cron} nav-tab-active{/if}">Crons</a>
         <a href="{$thisUrl}?page={$thisPage}&glm_action=videos" class="nav-tab{if $thisAction==videos} nav-tab-active{/if}">Videos</a>
 {foreach $addOnTabs as $a}
         <a href="{$thisUrl}?page={$thisPage}&glm_action={$a.action}" class="nav-tab{if $thisAction==$a.action} nav-tab-active{/if}">{$a.text}</a>