Exemplo n.º 1
0
 /**
  * Runs the required event
  * 1. The event type determines what function is to be called. 
  * 2. We can add arguments here to call different (custom) functions and more than one action.
  * 3. Global settings effect the event type selected, it is always cycled to ensure good admin
  * 
  * @param mixed $run_event_type, see event_decide() for list of event types 
  */
 public function event_action($run_event_type)
 {
     global $csv2post_settings, $CSV2POST;
     $c2p_schedule_array = CSV2POST::get_option_schedule_array();
     $c2p_schedule_array['history']['lasteventaction'] = $run_event_type . ' Requested';
     // we can override the $run_event_type
     // run specific script for the giving action
     switch ($run_event_type) {
         case "dataimport":
             // find a project with data still to import and return the project id (this includes new csv files with new rows)
             // enter project id into log
             // import data
             // enter result into log
             break;
         case "dataupdate":
             // find a project with a new csv file and return the id
             // import and update table where previously imported rows have now changed (do not import the new rows)
             break;
         case "postcreation":
             // find a project with unused rows
             // create posts based on global settings and project settings
             //csv2post_event_return( 'post creation procedure complete' );
             break;
         case "postupdate":
             /*
              * This has been designed to carry out one method of updating at a time.
              * 1st = Changed Records: search for records updated but not applied (post update function will update the csv2post_applied or at least the sql function called will)
              * 2nd = Meta Key: csv2post_outdated meta is searched, any meta value of 'yes' indicates posts needs to be updated 
              * 3rd = Changed Projected: project array includes a value ['updatecomplete'] which is set to true when no posts can be found with csv2post_updated dates older than ['modified']. This allows an update to all posts. 
              */
             $updating_carried_out = false;
             // change to true to avoid processing further methods after update performed
             ############################################################################
             #                                                                          #
             #                     UPDATED JOB TABLE RECORD METHOD                      #
             #                                                                          #
             ############################################################################
             // check which project was auto updated last and do the next, if none get the first project
             // does our project have updated rows not applied to their post
             if ($record) {
                 // determine number of rows to apply to posts based on settings
                 // ensure no further methods are processed if one or more rows are about to be updated
                 $updating_carried_out = true;
                 // query that number of applicable rows
                 // loop through those rows, updating their linked posts
                 // lasteventaction value needs a few words explaining what was done during schedule event
                 $c2p_schedule_array['history']['lasteventaction'] = 'post with ID ' . $r['csv2post_postid'] . ' was updated with a new record';
             }
             ############################################################################
             #                                                                          #
             #             csv2post_outdated META VALUE SET TO "yes" METHOD             #
             #                                                                          #
             ############################################################################
             if (!$updating_carried_out) {
                 // locate a post that have been marked as csv2post_outdated
                 //$post = csv2post_WP_SQL_get_posts_join_meta( 'csv2post_outdated', 'yes', $limit = 1, $select = 'ID' );
                 if ($post) {
                     // discontinue further post update methods
                     $updating_carried_out = true;
                     // loop through posts
                     foreach ($post as $key => $p) {
                         // continue foreach if no $project_code exists
                         $project_code = get_post_meta($p->ID, 'csv2post_project_code', true);
                         if (!$project_code) {
                             continue;
                         }
                         //csv2post_post_updatepost( $p->ID,get_post_meta( $p->ID, 'csv2post_record_id', true), $project_code);
                         //csv2post_log_schedule( 'Post with ID '.$p->ID.' was updated because it was marked as outdated', 'post updated',1, $run_event_type, __LINE__, __FILE__, __FUNCTION__, 'medium' );
                         // update the lasteventaction value - a very short sentence explaining the specific changes in blog
                         $c2p_schedule_array['history']['lasteventaction'] = 'post ' . $p->ID . ' was updated using csv2post_outdated method';
                     }
                 }
             }
             ############################################################################
             #                                                                          #
             #                  CHANGED PROJECT CONFIGURATION METHOD                    #
             #                                                                          #
             ############################################################################
             // this method checks $c2p_projectslist_array[PROJECTCODE]['updatecomplete']
             // if ['updatecomplete'] = false then it means we have yet to determine if some or no posts need updating
             // if we cannot locate just 1 post requiring updating, we change ['updatecomplete'] to true
             // we determine if a post requires updating by comparing $c2p_projectslist_array[PROJECTCODE]['modified']
             // against the csv2post_updated meta value
             if (!$updating_carried_out) {
                 // locate a project with ['updatecomplete'] set to false
                 // if we find an outdated project we will store the code
                 $outdated_project_code = false;
                 // get the projects full array
                 /*
                     now using the ['modified'] date not stored in $project_modified, we can search for a post not updated
                     1. if we find no posts then we change ['updatecomplete'] to true to avoid doing all this again
                     2. if we find a post we will update just one post due to the amount of processing involved in this                     
                 */
                 // run query for a post that has an older csv2post_last_updated date than the projects modified date
                 $post = csv2post_SQL_get_posts_oudated($project_modified, $project_code, $limit = 1, $select = 'ID');
                 if ($post) {
                     foreach ($post as $key => $p) {
                         // get record ID used to create post and ensure the value is numeric (precaution against user editing the value)
                         $record_id = get_post_meta($p->ID, 'csv2post_record_id', true);
                         if ($record_id && is_numeric($record_id)) {
                             // update the post, this function does not just use new records
                             //csv2post_post_updatepost( $p->ID, $record_id, $project_code);
                             // update the lasteventaction value - a very short sentence explaining the specific changes in blog
                             $c2p_schedule_array['history']['lasteventaction'] = 'post with ID ' . $p->ID . ' was updated because project configuration was changed';
                         }
                     }
                 } else {
                     // update the lasteventaction value - a very short sentence explaining the specific changes in blog
                     $c2p_schedule_array['history']['lasteventaction'] = 'schedule determine posts for project ' . $outdated_project_code . ' are all updated';
                     // set the ['updatecomplete'] value to true to indicate all posts have been updated
                 }
             }
             csv2post_event_return('data update procedure finished');
             break;
     }
     // end switch
     self::update_option_schedule_array($c2p_schedule_array);
 }