Skip to content

Commit

Permalink
Merge branch 'hotfix/1.3.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmilner committed May 15, 2019
2 parents 6bb84a4 + 5455e1c commit 2a4db10
Show file tree
Hide file tree
Showing 16 changed files with 1,014 additions and 788 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ build/
node_modules/
npm-debug.log
yarn-error.log
# composer
#
vendor/
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"phpcs.standard": "WordPress"
}
4 changes: 2 additions & 2 deletions ccbpress-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: CCBPress Core
* Plugin URI: https://ccbpress.com/
* Description: Display information from Church Community Builder on your WordPress site.
* Version: 1.3.4
* Version: 1.3.5
* Author: CCBPress <info@ccbpress.com>
* Author URI: https://ccbpress.com/
* Text Domain: ccbpress-core
Expand Down Expand Up @@ -66,7 +66,7 @@ class CCBPress_Core {
* @var string
* @since 1.0.0
*/
public $version = '1.3.4';
public $version = '1.3.5';

/**
* Main CCBPress_Core Instance
Expand Down
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require-dev": {
"squizlabs/php_codesniffer": "^3.4"
}
}
70 changes: 70 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

271 changes: 146 additions & 125 deletions includes/admin/admin-pages.php

Large diffs are not rendered by default.

24 changes: 22 additions & 2 deletions includes/admin/admin-purge-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,37 @@ public static function purge_transients() {

global $wpdb;

$cache = $wpdb->get_col( "SELECT option_name FROM $wpdb->options where option_name LIKE '_transient_timeout_ccbp_%'" );
// Find transients that contain expiration dates.
$cache = $wpdb->get_col(
$wpdb->prepare(
"SELECT option_name FROM $wpdb->options WHERE option_name LIKE %d",
$wpdb->esc_like( '_transient_timeout_ccbp_' ) . '%'
)
);

// Delete the transients.
if ( ! empty( $cache ) ) {
foreach ( $cache as $transient ) {
$name = str_replace( '_transient_timeout_', '', $transient );
delete_transient( $name );
if ( is_multisite() ) {
delete_site_transient( $name );
} else {
delete_transient( $name );
}
}
}

unset( $cache );

// Find and delete transients without expiration dates.
$wpdb->query(
$wpdb->prepare(
"DELETE FROM $wpdb->options WHERE option_name LIKE %s AND autoload = %s",
$wpdb->esc_like( '_transient_ccbp_' ) . '%',
'yes'
)
);

}

/**
Expand Down
2 changes: 1 addition & 1 deletion includes/class-ccbpress-background-get.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CCBPress_Background_Get extends WP_Background_Process {
*
* @var int
*/
protected $cron_interval = 10;
protected $cron_interval = 5;

/**
* The task
Expand Down
39 changes: 27 additions & 12 deletions includes/class-ccbpress-transients.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,21 +199,36 @@ public function cleanup() {

global $wpdb;

$expired = $wpdb->get_col( "SELECT option_name FROM " . $wpdb->options . " where option_name LIKE '_transient_timeout_" . $this->prefix . "%' AND option_value+0 < " . (string) time() );

if ( empty( $expired ) ) {
return false;
$expired = $wpdb->get_col(
$wpdb->prepare(
"SELECT option_name FROM $wpdb->options WHERE option_name LIKE %s AND option_value+0 < %s",
$wpdb->esc_like( '_transient_timeout_' . $this->prefix ) . '%',
(string) time()
)
);

if ( ! empty( $expired ) ) {
foreach ( $expired as $transient ) {

$name = str_replace( '_transient_timeout_', '', $transient );
if ( is_multisite() ) {
delete_site_transient( $name );
} else {
delete_transient( $name );
}
}
}

foreach ( $expired as $transient ) {
unset( $expired );

$name = str_replace( '_transient_timeout_', '', $transient );
if ( is_multisite() ) {
delete_site_transient( $name );
} else {
delete_transient( $name );
}
}
// Find and delete transients without expiration dates.
$wpdb->query(
$wpdb->prepare(
"DELETE FROM $wpdb->options WHERE option_name LIKE %s AND autoload = %s",
$wpdb->esc_like( '_transient_ccbp_' ) . '%',
'yes'
)
);

return true;

Expand Down
74 changes: 71 additions & 3 deletions includes/import.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ class CCBPress_Import {
* @return void
*/
public static function init() {
add_action( 'ccbpress_import', __CLASS__ . '::run' );
add_action( 'ccbpress_import_job_queued', __CLASS__ . '::import_job_queued' );
add_action( 'ccbpress_import_jobs_dispatched', __CLASS__ . '::import_jobs_dispatched' );
add_action( 'ccbpress_import', __CLASS__ . '::run' );
add_action( 'ccbpress_import_job_queued', __CLASS__ . '::import_job_queued' );
add_action( 'ccbpress_import_jobs_dispatched', __CLASS__ . '::import_jobs_dispatched' );
add_action( 'ccbpress_background_get_complete', __CLASS__ . '::import_complete' );
add_action( 'ccbpress_maintenance', __CLASS__ . '::find_stalled_imports' );
}

/**
Expand Down Expand Up @@ -187,5 +188,72 @@ public static function is_queue_empty() {

}

/**
* Find stalled imports
*
* @return void
*/
public static function find_stalled_imports() {
$is_stalled = false;
$in_progress = false;
$job_cron_exists = false;
$job_queue_exists = self::is_queue_empty();

if ( false !== get_option( 'ccbpress_import_in_progress', false ) ) {
$in_progress = true;
}

if ( false !== wp_next_scheduled( 'wp_ccbpress_get_cron' ) ) {
$job_cron_exists = true;
}

// Check if there are jobs in the queue, but the CRON to run them does not exist.
if ( true === $job_queue_exists && false === $job_cron_exists ) {
$is_stalled = true;
}

// Check if the "in_progress" option exists, but there are no jobs in the queue.
if ( true === $in_progress && false === $job_queue_exists ) {
$is_stalled = true;
}

// Check if the "in_progress" option exists, but the CRON to run it does not exist.
if ( true === $in_progress && false === $job_cron_exists ) {
$is_stalled = true;
}

// If the import is not stalled, then exit.
if ( false === $is_stalled ) {
return;
}

// Run the task to clean up the stalled import.
self::cleanup_stalled_import();
}

/**
* Cleanup the stalled import
*
* @return void
*/
private static function cleanup_stalled_import() {
global $wpdb;

$key = $wpdb->esc_like( 'wp_ccbpress_get_batch_' ) . '%';
$wpdb->query(
$wpdb->prepare(
"DELETE FROM $wpdb->options WHERE option_name LIKE %s",
$key
)
);

delete_option( 'ccbpress_import_in_progress' );
delete_option( 'ccbpress_current_import' );
delete_option( 'ccbpress_cancel_import' );
delete_site_transient( 'wp_ccbpress_get_process_lock' );

CCBPress_Core::schedule_cron();
}

}
CCBPress_Import::init();
Loading

0 comments on commit 2a4db10

Please sign in to comment.