Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

recreate missing schedule import #170

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions includes/class-wp-event-aggregator-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ function get_columns() {
'import_status' => __( 'Import Event Status', 'wp-event-aggregator' ),
'import_category' => __( 'Import Category', 'wp-event-aggregator' ),
'import_frequency' => __( 'Import Frequency', 'wp-event-aggregator' ),
'next_run' => __( 'Next Run', 'wp-event-aggregator' ),
'action' => __( 'Action', 'wp-event-aggregator' ),
);
return $columns;
Expand Down Expand Up @@ -293,6 +294,7 @@ function get_scheduled_import_data( $origin = '' ) {
}
$importdata_query = new WP_Query( $query_args );
$scheduled_import_data['total_records'] = ( $importdata_query->found_posts ) ? (int) $importdata_query->found_posts : 0;
$next_run_times = $this->get_wpea_next_run_times();
// The Loop.
if ( $importdata_query->have_posts() ) {
while ( $importdata_query->have_posts() ) {
Expand Down Expand Up @@ -374,12 +376,28 @@ function get_scheduled_import_data( $origin = '' ) {

$totalimport = $wpdb->get_var( $totalimport_query );

$next_run = '-';
if(isset($next_run_times[$import_id]) && !empty($next_run_times[$import_id])){
$next_time = $next_run_times[$import_id];
$next_run = sprintf( '%s (%s)',
esc_html( get_date_from_gmt( date( 'Y-m-d H:i:s', $next_time ), 'Y-m-d H:i:s' ) ),
esc_html( human_time_diff( current_time( 'timestamp', true ), $next_time ) )
);
}

if( $next_run == '-' ){
if ( function_exists( 'wpea_recreate_missng_scheduled_import' ) ) {
$importevents->common_pro->wpea_recreate_missng_scheduled_import($import_id);
}
}

$scheduled_import = array(
'ID' => $import_id,
'title' => $import_title,
'import_status' => ucfirst( $import_status ),
'import_category' => implode( ', ', $term_names ),
'import_frequency'=> isset( $import_data['import_frequency'] ) ? ucfirst( $import_data['import_frequency'] ) : '',
'next_run' => $next_run,
'import_origin' => $import_origin,
'import_into' => $import_plugin,
'last_import' => $last_import_history_date,
Expand All @@ -397,6 +415,47 @@ function get_scheduled_import_data( $origin = '' ) {
wp_reset_postdata();
return $scheduled_import_data;
}

/**
* Get WPEA crons.
*
* @return Array
*/
function get_wpea_crons(){
$crons = array();
if(function_exists('_get_cron_array') ){
$crons = _get_cron_array();
}
$wpea_scheduled = array_filter($crons, function($cron) {
$cron_name = array_keys($cron) ? array_keys($cron)[0] : '';
if (strpos($cron_name, 'xt_run_scheduled_import') !== false) {
return true;
}
return false;
});
return $wpea_scheduled;
}


/**
* Get Next run time array for schdeuled import.
*
* @return Array
*/
function get_wpea_next_run_times(){
$next_runs = array();
$crons = $this->get_wpea_crons();
foreach($crons as $time => $cron){
foreach($cron as $cron_name){
foreach($cron_name as $cron_post_id){
if( isset($cron_post_id['args']) && isset($cron_post_id['args']['post_id']) ){
$next_runs[$cron_post_id['args']['post_id']] = $time;
}
}
}
}
return $next_runs;
}
}

/**
Expand Down
62 changes: 33 additions & 29 deletions languages/wp-event-aggregator.pot
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2024-10-15T13:18:11+00:00\n"
"POT-Creation-Date: 2024-11-09T10:14:51+00:00\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"X-Generator: WP-CLI 2.11.0\n"
"X-Domain: wp-event-aggregator\n"
Expand Down Expand Up @@ -73,7 +73,7 @@ msgid "Settings"
msgstr ""

#: includes/class-wp-event-aggregator-admin.php:65
#: includes/class-wp-event-aggregator-list-table.php:726
#: includes/class-wp-event-aggregator-list-table.php:785
msgid "Shortcode"
msgstr ""

Expand Down Expand Up @@ -285,8 +285,8 @@ msgid "Created/Updated"
msgstr ""

#: includes/class-wp-event-aggregator-admin.php:502
#: includes/class-wp-event-aggregator-list-table.php:186
#: includes/class-wp-event-aggregator-list-table.php:552
#: includes/class-wp-event-aggregator-list-table.php:187
#: includes/class-wp-event-aggregator-list-table.php:611
msgid "Action"
msgstr ""

Expand Down Expand Up @@ -366,15 +366,15 @@ msgstr ""

#: includes/class-wp-event-aggregator-common.php:544
#: includes/class-wp-event-aggregator-list-table.php:132
#: includes/class-wp-event-aggregator-list-table.php:345
#: includes/class-wp-event-aggregator-list-table.php:480
#: includes/class-wp-event-aggregator-list-table.php:347
#: includes/class-wp-event-aggregator-list-table.php:539
msgid "%d Created"
msgstr ""

#: includes/class-wp-event-aggregator-common.php:547
#: includes/class-wp-event-aggregator-list-table.php:135
#: includes/class-wp-event-aggregator-list-table.php:348
#: includes/class-wp-event-aggregator-list-table.php:483
#: includes/class-wp-event-aggregator-list-table.php:350
#: includes/class-wp-event-aggregator-list-table.php:542
msgid "%d Updated"
msgstr ""

Expand All @@ -384,8 +384,8 @@ msgstr ""

#: includes/class-wp-event-aggregator-common.php:553
#: includes/class-wp-event-aggregator-list-table.php:141
#: includes/class-wp-event-aggregator-list-table.php:354
#: includes/class-wp-event-aggregator-list-table.php:489
#: includes/class-wp-event-aggregator-list-table.php:356
#: includes/class-wp-event-aggregator-list-table.php:548
msgid "%d Skipped (Already exists in Trash)"
msgstr ""

Expand Down Expand Up @@ -820,15 +820,15 @@ msgid "Please select end date bigger than start date."
msgstr ""

#: includes/class-wp-event-aggregator-list-table.php:76
#: includes/class-wp-event-aggregator-list-table.php:194
#: includes/class-wp-event-aggregator-list-table.php:451
#: includes/class-wp-event-aggregator-list-table.php:560
#: includes/class-wp-event-aggregator-list-table.php:195
#: includes/class-wp-event-aggregator-list-table.php:510
#: includes/class-wp-event-aggregator-list-table.php:619
msgid "Delete"
msgstr ""

#: includes/class-wp-event-aggregator-list-table.php:94
#: includes/class-wp-event-aggregator-list-table.php:106
#: includes/class-wp-event-aggregator-list-table.php:458
#: includes/class-wp-event-aggregator-list-table.php:517
msgid "Origin"
msgstr ""

Expand All @@ -845,8 +845,8 @@ msgid "Import is running in Background"
msgstr ""

#: includes/class-wp-event-aggregator-list-table.php:138
#: includes/class-wp-event-aggregator-list-table.php:351
#: includes/class-wp-event-aggregator-list-table.php:486
#: includes/class-wp-event-aggregator-list-table.php:353
#: includes/class-wp-event-aggregator-list-table.php:545
msgid "%d Skipped"
msgstr ""

Expand All @@ -867,59 +867,63 @@ msgid "Import Event Status"
msgstr ""

#: includes/class-wp-event-aggregator-list-table.php:184
#: includes/class-wp-event-aggregator-list-table.php:549
#: includes/class-wp-event-aggregator-list-table.php:608
msgid "Import Category"
msgstr ""

#: includes/class-wp-event-aggregator-list-table.php:185
msgid "Import Frequency"
msgstr ""

#: includes/class-wp-event-aggregator-list-table.php:338
#: includes/class-wp-event-aggregator-list-table.php:186
msgid "Next Run"
msgstr ""

#: includes/class-wp-event-aggregator-list-table.php:340
msgid "Last Import: %s ago"
msgstr ""

#: includes/class-wp-event-aggregator-list-table.php:357
#: includes/class-wp-event-aggregator-list-table.php:359
msgid "Last Import Stats: "
msgstr ""

#: includes/class-wp-event-aggregator-list-table.php:362
#: includes/class-wp-event-aggregator-list-table.php:364
msgid "<span style=\"color: red\"><strong>The Private token you provided was invalid.</strong></span>"
msgstr ""

#: includes/class-wp-event-aggregator-list-table.php:365
#: includes/class-wp-event-aggregator-list-table.php:367
msgid "No events are imported."
msgstr ""

#: includes/class-wp-event-aggregator-list-table.php:525
#: includes/class-wp-event-aggregator-list-table.php:584
msgid "View Imported Events"
msgstr ""

#: includes/class-wp-event-aggregator-list-table.php:548
#: includes/class-wp-event-aggregator-list-table.php:607
msgid "Import"
msgstr ""

#: includes/class-wp-event-aggregator-list-table.php:550
#: includes/class-wp-event-aggregator-list-table.php:609
msgid "Import Date"
msgstr ""

#: includes/class-wp-event-aggregator-list-table.php:551
#: includes/class-wp-event-aggregator-list-table.php:610
msgid "Import Stats"
msgstr ""

#: includes/class-wp-event-aggregator-list-table.php:585
#: includes/class-wp-event-aggregator-list-table.php:644
msgid "Warning! Import history will be permanatly deleted. Are you certain you want to delete the import history?"
msgstr ""

#: includes/class-wp-event-aggregator-list-table.php:588
#: includes/class-wp-event-aggregator-list-table.php:647
msgid "Clear Import History"
msgstr ""

#: includes/class-wp-event-aggregator-list-table.php:724
#: includes/class-wp-event-aggregator-list-table.php:783
msgid "ID"
msgstr ""

#: includes/class-wp-event-aggregator-list-table.php:725
#: includes/class-wp-event-aggregator-list-table.php:784
msgid "Title"
msgstr ""

Expand Down