From af0abc3b881134b04933e6efc1d090d9778d1d2b Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Mon, 28 Oct 2019 13:58:36 -0400 Subject: [PATCH] Add now cron to delete old travel lead notes. Delete old notes older than 2 years. --- models/admin/ajax/travelContacts.php | 2 +- models/admin/ajax/travelLeadsNotesCron.php | 100 +++++++++++++++++++++ models/admin/ajax/travelNotes.php | 2 +- models/admin/ajax/travelReferredby.php | 2 +- models/admin/ajax/travelSearch.php | 2 +- models/admin/travel/index.php | 13 --- setup/adminHooks.php | 21 +++++ setup/validActions.php | 13 +-- 8 files changed, 132 insertions(+), 23 deletions(-) create mode 100644 models/admin/ajax/travelLeadsNotesCron.php diff --git a/models/admin/ajax/travelContacts.php b/models/admin/ajax/travelContacts.php index 7f6ddeb..e59bd74 100644 --- a/models/admin/ajax/travelContacts.php +++ b/models/admin/ajax/travelContacts.php @@ -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 index 0000000..46d9835 --- /dev/null +++ b/models/admin/ajax/travelLeadsNotesCron.php @@ -0,0 +1,100 @@ + + * @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; + + + } + + +} diff --git a/models/admin/ajax/travelNotes.php b/models/admin/ajax/travelNotes.php index 27e817e..3959b2c 100644 --- a/models/admin/ajax/travelNotes.php +++ b/models/admin/ajax/travelNotes.php @@ -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': diff --git a/models/admin/ajax/travelReferredby.php b/models/admin/ajax/travelReferredby.php index a4392e5..6c94fc3 100644 --- a/models/admin/ajax/travelReferredby.php +++ b/models/admin/ajax/travelReferredby.php @@ -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': diff --git a/models/admin/ajax/travelSearch.php b/models/admin/ajax/travelSearch.php index fad50bf..a9cd61c 100644 --- a/models/admin/ajax/travelSearch.php +++ b/models/admin/ajax/travelSearch.php @@ -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': diff --git a/models/admin/travel/index.php b/models/admin/travel/index.php index b21daad..5849975 100644 --- a/models/admin/travel/index.php +++ b/models/admin/travel/index.php @@ -207,8 +207,6 @@ class GlmMembersAdmin_travel_index extends GlmDataTravelLeads // Initialize the grouped_interests array $grouped_interests = array(); - // echo '
$this->config: ' . print_r( $this->config, true ) . '
'; - 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 '
$entry: ' . print_r( $entry, true ) . '
'; - // $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 '
$where: ' . print_r( $where, true ) . '
'; - // echo '
$order: ' . print_r( $order, true ) . '
'; // 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 '
$alphaWhere: ' . print_r( $alphaWhere, true ) . '
'; - - // echo '
$alphaList: ' . print_r( $alphaList, true ) . '
'; - // 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; } diff --git a/setup/adminHooks.php b/setup/adminHooks.php index e25bdfd..a5c0fee 100644 --- a/setup/adminHooks.php +++ b/setup/adminHooks.php @@ -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 ); + } +); diff --git a/setup/validActions.php b/setup/validActions.php index a25949b..e18122b 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -60,12 +60,13 @@ $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, -- 2.17.1