Skip to content

Commit

Permalink
Tweaked the CRON job to remove obsolete logic and to adjust the meta …
Browse files Browse the repository at this point in the history
…query to retrieve a single entry rather than array
  • Loading branch information
Olly Warren committed Sep 14, 2017
1 parent 02e2a4a commit 08dcdb5
Showing 1 changed file with 45 additions and 45 deletions.
90 changes: 45 additions & 45 deletions classes/class-wpcom-liveblog-cron.php
Expand Up @@ -10,59 +10,59 @@

class WPCOM_Liveblog_Cron {

/**
* Sets up the class.
*/
public static function load() {
self::configure_autoarchive_cron();
}
/**
* Sets up the class.
*/
public static function load() {
self::configure_autoarchive_cron();
}

/**
* Configures the CRON Entry to Check for the Auto Archive Expiry on all Live Blogs.
* @return mixed
*/
private static function configure_autoarchive_cron() {
/**
* Configures the CRON Entry to Check for the Auto Archive Expiry on all Live Blogs.
* @return mixed
*/
private static function configure_autoarchive_cron() {

if ( ! wp_next_scheduled( 'auto_archive_check_hook' ) ) {
wp_schedule_event( strtotime('today midnight'), 'daily', 'auto_archive_check_hook');
}
if ( ! wp_next_scheduled( 'auto_archive_check_hook' ) ) {
wp_schedule_event( strtotime( 'today midnight' ), 'daily', 'auto_archive_check_hook' );
}

add_action( 'auto_archive_check_hook', array( __CLASS__, 'execute_auto_archive_housekeeping' ) );
}
add_action( 'auto_archive_check_hook', array( __CLASS__, 'execute_auto_archive_housekeeping' ) );
}

/**
* The method that details the housekeepng to undertake during the execution of the CRON
* task.
* @return mixed
*/
public static function execute_auto_archive_housekeeping() {
/**
* The method that details the housekeepng to undertake during the execution of the CRON
* task.
* @return mixed
*/
public static function execute_auto_archive_housekeeping() {

//If Auto Archive is enabled,
if ( null !== WPCOM_Liveblog::$auto_archive_days ) {
//If Auto Archive is enabled,
if ( null !== WPCOM_Liveblog::$auto_archive_days ) {

$posts = new WP_Query( array(
'order' => 'ASC',
'orderby' => 'ID',
'meta_key' => 'liveblog',
) );
$posts = new WP_Query( array(
'order' => 'ASC',
'orderby' => 'ID',
'meta_key' => 'liveblog',
) );

foreach ( $posts->posts as $post ) {
foreach ( $posts->posts as $post ) {

$post_id = $post->ID;
$post_id = $post->ID;

//Lets grab todays day, convert it to a timestamp and look for any set auto archive date.
$today = strtotime( date('Y-m-d H:i:s' ) );
$expiry = get_post_meta( $post_id, WPCOM_Liveblog::$auto_archive_expiry_key );
//Lets grab todays day, convert it to a timestamp and look for any set auto archive date.
$today = strtotime( date( 'Y-m-d H:i:s' ) );
$expiry = get_post_meta( $post_id, WPCOM_Liveblog::$auto_archive_expiry_key, true );

//if we have an expiry date lets compare them and if the
// expiry is less than today i.e. its in the past lets archive the liveblog.
if ( $expiry ) {
if ( (int)$expiry[0] < $today ) {
WPCOM_Liveblog::set_liveblog_state( $post_id, 'archive' );
$state = get_post_meta( $post_id, WPCOM_Liveblog::key, true );
}
}
}
}
}
//if we have an expiry date lets compare them and if the
// expiry is less than today i.e. its in the past lets archive the liveblog.
if ( $expiry ) {

if ( (int) $expiry < $today ) {
WPCOM_Liveblog::set_liveblog_state( $post_id, 'archive' );
}
}
}
}
}
}

0 comments on commit 08dcdb5

Please sign in to comment.