Add now cron to delete old travel lead notes.
authorSteve Sutton <steve@gaslightmedia.com>
Mon, 28 Oct 2019 17:58:36 +0000 (13:58 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Mon, 28 Oct 2019 17:58:36 +0000 (13:58 -0400)
Delete old notes older than 2 years.

models/admin/ajax/travelContacts.php
models/admin/ajax/travelLeadsNotesCron.php [new file with mode: 0644]
models/admin/ajax/travelNotes.php
models/admin/ajax/travelReferredby.php
models/admin/ajax/travelSearch.php
models/admin/travel/index.php
setup/adminHooks.php
setup/validActions.php

index 7f6ddeb..e59bd74 100644 (file)
@@ -79,7 +79,7 @@ class GlmMembersAdmin_ajax_travelContacts extends GlmDataTravelContacts
         $success =  true;
 
         $option = isset( $_REQUEST['option'] ) ? filter_var( $_REQUEST['option'], FILTER_SANITIZE_STRING ) : '';
-        trigger_error( print_r( $_REQUEST, E_USER_NOTICE ) );
+        // trigger_error( print_r( $_REQUEST, E_USER_NOTICE ) );
 
         $lead_id  = filter_var( $_REQUEST['lead_id'], FILTER_VALIDATE_INT );
 
diff --git a/models/admin/ajax/travelLeadsNotesCron.php b/models/admin/ajax/travelLeadsNotesCron.php
new file mode 100644 (file)
index 0000000..46d9835
--- /dev/null
@@ -0,0 +1,100 @@
+<?php
+
+/**
+ * Gaslight Media Registrants Database
+ * Registrants List Export by AJAX
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmRegistrantsDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @version  0.1
+ */
+
+
+// Load Registrant Info data abstract
+require_once GLM_MEMBERS_TRAVEL_PLUGIN_CLASS_PATH.'/data/dataLeads.php';
+require_once GLM_MEMBERS_TRAVEL_PLUGIN_CLASS_PATH . '/data/dataContacts.php';
+require_once GLM_MEMBERS_TRAVEL_PLUGIN_CLASS_PATH . '/data/dataNotes.php';
+
+/**
+ *
+ * This class exports the currently selected registrants list
+ * to a printable HTML file, to a CSV file, or otherwise.
+ */
+class GlmMembersAdmin_ajax_travelLeadsNotesCron
+{
+
+    /**
+     * WordPress Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * Plugin Configuration Data
+     *
+     * @var $config
+     * @access public
+     */
+    public $config;
+
+    /**
+     * Constructor
+     *
+     * This constructor 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;
+
+        // parent::__construct(false, false);
+
+    }
+
+    /**
+     * Perform Model Action
+     *
+     * This modelAction takes an AJAX image upload and stores the image in the
+     * media/images directory of the plugin.
+     *
+     * This model action does not return, it simply does it's work then calls die();
+     *
+     * @param $actionData
+     *
+     * Echos JSON string as response and does not return
+     */
+    public function modelAction ( $actionData = false )
+    {
+
+        // Remove old notes that are older than 2 years.
+        $this->wpdb->query(
+            $this->wpdb->prepare(
+                "DELETE
+                   FROM " . GLM_MEMBERS_TRAVEL_PLUGIN_DB_PREFIX .  "lead_notes
+                  WHERE updated < %s",
+                date( 'Y-m-d', mktime( 0, 0, 0, date( 'n' ), date( 'j' ), date( 'Y' ) - 2 ) )
+            )
+        );
+
+        trigger_error( 'Delete old Notes', E_USER_NOTICE );
+
+        exit;
+
+
+    }
+
+
+}
index 27e817e..3959b2c 100644 (file)
@@ -79,7 +79,7 @@ class GlmMembersAdmin_ajax_travelNotes extends GlmDataTravelNotes
         $success =  true;
 
         $option = isset($_REQUEST['option']) ? filter_var( $_REQUEST['option'], FILTER_SANITIZE_STRING ) : '';
-        trigger_error( print_r( $_REQUEST, E_USER_NOTICE ) );
+        // trigger_error( print_r( $_REQUEST, E_USER_NOTICE ) );
 
         switch ( $option ) {
         case 'update':
index a4392e5..6c94fc3 100644 (file)
@@ -82,7 +82,7 @@ class GlmMembersAdmin_ajax_travelReferredBy extends GlmDataReferredBy
         $referredby = false;
 
         $option = isset($_REQUEST['option']) ? filter_var( $_REQUEST['option'], FILTER_SANITIZE_STRING ) : '';
-        trigger_error( print_r( $_REQUEST, E_USER_NOTICE ) );
+        // trigger_error( print_r( $_REQUEST, E_USER_NOTICE ) );
 
         switch ( $option ) {
         case 'update':
index fad50bf..a9cd61c 100644 (file)
@@ -81,7 +81,7 @@ class GlmMembersAdmin_ajax_travelSearch // extends GlmDataTravelContacts
 
         $option = isset( $_REQUEST['option'] ) ? filter_var( $_REQUEST['option'], FILTER_SANITIZE_STRING ) : '';
         $term   = isset( $_REQUEST['term'] ) ? filter_var( $_REQUEST['term'], FILTER_SANITIZE_STRING ) : '';
-        trigger_error( print_r( $_REQUEST, E_USER_NOTICE ) );
+        // trigger_error( print_r( $_REQUEST, E_USER_NOTICE ) );
 
         switch ( $option ) {
         case 'company':
index b21daad..5849975 100644 (file)
@@ -207,8 +207,6 @@ class GlmMembersAdmin_travel_index extends GlmDataTravelLeads
         // Initialize the grouped_interests array
         $grouped_interests = array();
 
-        // echo '<pre>$this->config: ' . print_r( $this->config, true ) . '</pre>';
-
         switch ( $option ) {
         case 'delete':
             if ( $this->entryId ) {
@@ -241,8 +239,6 @@ class GlmMembersAdmin_travel_index extends GlmDataTravelLeads
             }
             $_REQUEST['updated'] = date( 'Y-m-d H:i:s' );
             $entry = $this->updateEntry( $this->entryId );
-            // echo '<pre>$entry: ' . print_r( $entry, true ) . '</pre>';
-            // $view = 'index.html';
             $entry = $this->editEntry( $this->entryId );
             $view = 'edit.html';
 
@@ -334,8 +330,6 @@ class GlmMembersAdmin_travel_index extends GlmDataTravelLeads
                 }
                 $order = "T.lname, T.fname";
             }
-            // echo '<pre>$where: ' . print_r( $where, true ) . '</pre>';
-            // echo '<pre>$order: ' . print_r( $order, true ) . '</pre>';
             // Check if we're doing paging
             if (isset($_REQUEST['pageSelect'])) {
                 // If request is for Next
@@ -362,10 +356,6 @@ class GlmMembersAdmin_travel_index extends GlmDataTravelLeads
             $alphaList = $this->getAlphaList(' AND '.$where, $alphaSelected);
 
 
-            // echo '<pre>$alphaWhere: ' . print_r( $alphaWhere, true ) . '</pre>';
-
-            // echo '<pre>$alphaList: ' . print_r( $alphaList, true ) . '</pre>';
-
             // Get paging results
             $params        = '';
             $numbDisplayed = $entryResults['returned'];
@@ -379,9 +369,6 @@ class GlmMembersAdmin_travel_index extends GlmDataTravelLeads
                     $start = 1;
                 }
             }
-            // if ( $entryResults['returned'] == $limit ) {
-            //     $nextStart = $start + $limit;
-            // }
             if ( $start + $limit <= $stats ) {
                 $nextStart = $start + $limit;
             }
index e25bdfd..a5c0fee 100644 (file)
@@ -42,3 +42,24 @@ add_filter('glm-member-db-admin-management-hooksHelp', function($content) {
     10,
     2
 );
+
+/**
+ * Setup cron task request to run travelLeadsNotesCron
+ *
+ * Run only once per week.
+ */
+add_filter(
+    'glm_associate_cron_request',
+    function( $cron_task ) {
+        $new_cron = array(
+            array(
+                'menu'       => 'ajax',
+                'action'     => 'travelLeadsNotesCron',
+                'daysOfWeek' => array( 1 ),
+                'times'      => array( 6 ),
+                'params'     => array()
+            )
+        );
+        return array_merge( $cron_task, $new_cron );
+    }
+);
index a25949b..e18122b 100644 (file)
 $glmMembersTravelAddOnValidActions = array(
     'adminActions' => array(
         'ajax' => array(
-            'travelContacts'   => GLM_MEMBERS_TRAVEL_PLUGIN_SLUG,
-            'travelReferredby' => GLM_MEMBERS_TRAVEL_PLUGIN_SLUG,
-            'travelSearch'     => GLM_MEMBERS_TRAVEL_PLUGIN_SLUG,
-            'travelNotes'      => GLM_MEMBERS_TRAVEL_PLUGIN_SLUG,
-            'leadCsvExport'    => GLM_MEMBERS_TRAVEL_PLUGIN_SLUG,
-            'leadPdfExport'    => GLM_MEMBERS_TRAVEL_PLUGIN_SLUG,
+            'travelContacts'       => GLM_MEMBERS_TRAVEL_PLUGIN_SLUG,
+            'travelReferredby'     => GLM_MEMBERS_TRAVEL_PLUGIN_SLUG,
+            'travelSearch'         => GLM_MEMBERS_TRAVEL_PLUGIN_SLUG,
+            'travelNotes'          => GLM_MEMBERS_TRAVEL_PLUGIN_SLUG,
+            'leadCsvExport'        => GLM_MEMBERS_TRAVEL_PLUGIN_SLUG,
+            'leadPdfExport'        => GLM_MEMBERS_TRAVEL_PLUGIN_SLUG,
+            'travelLeadsNotesCron' => GLM_MEMBERS_TRAVEL_PLUGIN_SLUG,
         ),
         'settings' => array(
             'referredBy' => GLM_MEMBERS_TRAVEL_PLUGIN_SLUG,