Abandoned Cart Lite for WooCommerce - Version 5.9.0

Version Description

(26.07.2021) = * Enhancement - Introduced UTM tags to be added to reminder email links to help with Google Analytics. * Tweak - Added a filter to hide SKU in reminder emails. * Tweak - Removed the Action Scheduler library from the plugin. The plugin will now use the library from WooCommerce. * Tweak - The test email field will now be pre-populated with the email address of the logged-in user. * Fix - Made the plugin compatible with PHP 8.0 * Fix - No reminder emails were being sent to WC orders with the status Pending Payment and Failed. * Fix - Undefined was displayed for cart status when clicking on View Details in the Abandoned Orders page. This was later replaced by valid cart status.

Download this release

Release Info

Developer tychesoftwares
Plugin Icon 128x128 Abandoned Cart Lite for WooCommerce
Version 5.9.0
Comparing to
See all releases

Code changes from version 5.8.8 to 5.9.0

Files changed (96) hide show
  1. assets/js/admin/wcal_abandoned_cart_detail_modal.js +1 -1
  2. assets/js/admin/wcal_abandoned_cart_detail_modal.min.js +1 -1
  3. cron/class-wcal-cron.php +18 -15
  4. i18n/languages/woocommerce-abandoned-cart.pot +588 -442
  5. includes/admin/class-wcap-pro-settings-callbacks.php +0 -16
  6. includes/admin/class-wcap-pro-settings.php +0 -14
  7. includes/class-wcal-common.php +1 -1
  8. includes/libraries/action-scheduler/.editorconfig +0 -24
  9. includes/libraries/action-scheduler/README.md +0 -35
  10. includes/libraries/action-scheduler/action-scheduler.php +0 -53
  11. includes/libraries/action-scheduler/classes/ActionScheduler_ActionClaim.php +0 -23
  12. includes/libraries/action-scheduler/classes/ActionScheduler_ActionFactory.php +0 -179
  13. includes/libraries/action-scheduler/classes/ActionScheduler_AdminView.php +0 -137
  14. includes/libraries/action-scheduler/classes/ActionScheduler_AsyncRequest_QueueRunner.php +0 -96
  15. includes/libraries/action-scheduler/classes/ActionScheduler_Compatibility.php +0 -99
  16. includes/libraries/action-scheduler/classes/ActionScheduler_DataController.php +0 -177
  17. includes/libraries/action-scheduler/classes/ActionScheduler_DateTime.php +0 -76
  18. includes/libraries/action-scheduler/classes/ActionScheduler_Exception.php +0 -11
  19. includes/libraries/action-scheduler/classes/ActionScheduler_FatalErrorMonitor.php +0 -55
  20. includes/libraries/action-scheduler/classes/ActionScheduler_InvalidActionException.php +0 -47
  21. includes/libraries/action-scheduler/classes/ActionScheduler_ListTable.php +0 -559
  22. includes/libraries/action-scheduler/classes/ActionScheduler_LogEntry.php +0 -67
  23. includes/libraries/action-scheduler/classes/ActionScheduler_NullLogEntry.php +0 -11
  24. includes/libraries/action-scheduler/classes/ActionScheduler_OptionLock.php +0 -49
  25. includes/libraries/action-scheduler/classes/ActionScheduler_QueueCleaner.php +0 -155
  26. includes/libraries/action-scheduler/classes/ActionScheduler_QueueRunner.php +0 -185
  27. includes/libraries/action-scheduler/classes/ActionScheduler_Versions.php +0 -62
  28. includes/libraries/action-scheduler/classes/ActionScheduler_WPCommentCleaner.php +0 -108
  29. includes/libraries/action-scheduler/classes/ActionScheduler_wcSystemStatus.php +0 -147
  30. includes/libraries/action-scheduler/classes/WP_CLI/ActionScheduler_WPCLI_QueueRunner.php +0 -197
  31. includes/libraries/action-scheduler/classes/WP_CLI/ActionScheduler_WPCLI_Scheduler_command.php +0 -158
  32. includes/libraries/action-scheduler/classes/WP_CLI/Migration_Command.php +0 -148
  33. includes/libraries/action-scheduler/classes/WP_CLI/ProgressBar.php +0 -119
  34. includes/libraries/action-scheduler/classes/abstracts/ActionScheduler.php +0 -269
  35. includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_ListTable.php +0 -674
  36. includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_QueueRunner.php +0 -232
  37. includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_RecurringSchedule.php +0 -102
  38. includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_Schedule.php +0 -83
  39. includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_Schema.php +0 -133
  40. includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Lock.php +0 -62
  41. includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Logger.php +0 -176
  42. includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Store.php +0 -345
  43. includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_TimezoneHelper.php +0 -152
  44. includes/libraries/action-scheduler/classes/actions/ActionScheduler_Action.php +0 -75
  45. includes/libraries/action-scheduler/classes/actions/ActionScheduler_CanceledAction.php +0 -23
  46. includes/libraries/action-scheduler/classes/actions/ActionScheduler_FinishedAction.php +0 -16
  47. includes/libraries/action-scheduler/classes/actions/ActionScheduler_NullAction.php +0 -16
  48. includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_DBLogger.php +0 -146
  49. includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_DBStore.php +0 -803
  50. includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_HybridStore.php +0 -380
  51. includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpCommentLogger.php +0 -240
  52. includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore.php +0 -858
  53. includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore_PostStatusRegistrar.php +0 -58
  54. includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore_PostTypeRegistrar.php +0 -50
  55. includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore_TaxonomyRegistrar.php +0 -26
  56. includes/libraries/action-scheduler/classes/migration/ActionMigrator.php +0 -109
  57. includes/libraries/action-scheduler/classes/migration/ActionScheduler_DBStoreMigrator.php +0 -47
  58. includes/libraries/action-scheduler/classes/migration/BatchFetcher.php +0 -86
  59. includes/libraries/action-scheduler/classes/migration/Config.php +0 -168
  60. includes/libraries/action-scheduler/classes/migration/Controller.php +0 -206
  61. includes/libraries/action-scheduler/classes/migration/DryRun_ActionMigrator.php +0 -28
  62. includes/libraries/action-scheduler/classes/migration/DryRun_LogMigrator.php +0 -23
  63. includes/libraries/action-scheduler/classes/migration/LogMigrator.php +0 -49
  64. includes/libraries/action-scheduler/classes/migration/Runner.php +0 -136
  65. includes/libraries/action-scheduler/classes/migration/Scheduler.php +0 -128
  66. includes/libraries/action-scheduler/classes/schedules/ActionScheduler_CanceledSchedule.php +0 -57
  67. includes/libraries/action-scheduler/classes/schedules/ActionScheduler_CronSchedule.php +0 -102
  68. includes/libraries/action-scheduler/classes/schedules/ActionScheduler_IntervalSchedule.php +0 -81
  69. includes/libraries/action-scheduler/classes/schedules/ActionScheduler_NullSchedule.php +0 -28
  70. includes/libraries/action-scheduler/classes/schedules/ActionScheduler_Schedule.php +0 -18
  71. includes/libraries/action-scheduler/classes/schedules/ActionScheduler_SimpleSchedule.php +0 -71
  72. includes/libraries/action-scheduler/classes/schema/ActionScheduler_LoggerSchema.php +0 -48
  73. includes/libraries/action-scheduler/classes/schema/ActionScheduler_StoreSchema.php +0 -82
  74. includes/libraries/action-scheduler/deprecated/ActionScheduler_Abstract_QueueRunner_Deprecated.php +0 -27
  75. includes/libraries/action-scheduler/deprecated/ActionScheduler_AdminView_Deprecated.php +0 -147
  76. includes/libraries/action-scheduler/deprecated/ActionScheduler_Schedule_Deprecated.php +0 -29
  77. includes/libraries/action-scheduler/deprecated/ActionScheduler_Store_Deprecated.php +0 -49
  78. includes/libraries/action-scheduler/deprecated/functions.php +0 -126
  79. includes/libraries/action-scheduler/functions.php +0 -251
  80. includes/libraries/action-scheduler/lib/WP_Async_Request.php +0 -170
  81. includes/libraries/action-scheduler/lib/cron-expression/CronExpression.php +0 -318
  82. includes/libraries/action-scheduler/lib/cron-expression/CronExpression_AbstractField.php +0 -100
  83. includes/libraries/action-scheduler/lib/cron-expression/CronExpression_DayOfMonthField.php +0 -110
  84. includes/libraries/action-scheduler/lib/cron-expression/CronExpression_DayOfWeekField.php +0 -124
  85. includes/libraries/action-scheduler/lib/cron-expression/CronExpression_FieldFactory.php +0 -55
  86. includes/libraries/action-scheduler/lib/cron-expression/CronExpression_FieldInterface.php +0 -39
  87. includes/libraries/action-scheduler/lib/cron-expression/CronExpression_HoursField.php +0 -47
  88. includes/libraries/action-scheduler/lib/cron-expression/CronExpression_MinutesField.php +0 -39
  89. includes/libraries/action-scheduler/lib/cron-expression/CronExpression_MonthField.php +0 -55
  90. includes/libraries/action-scheduler/lib/cron-expression/CronExpression_YearField.php +0 -43
  91. includes/libraries/action-scheduler/lib/cron-expression/LICENSE +0 -19
  92. includes/libraries/action-scheduler/lib/cron-expression/README.md +0 -92
  93. includes/libraries/action-scheduler/license.txt +0 -674
  94. includes/templates/template_1.php +0 -9
  95. readme.txt +10 -1
  96. woocommerce-ac.php +67 -8
assets/js/admin/wcal_abandoned_cart_detail_modal.js CHANGED
@@ -120,7 +120,7 @@ jQuery(function($) {
120
  },
121
 
122
  open: function( classes ) {
123
-
124
  $(document.body).addClass('wcal-modal-open').append('<div class="wcal-modal-overlay"></div>');
125
  var modal_body = '<div class="wcal-modal ' + classes + '"><div class="wcal-modal__contents"> <div class="wcal-modal__header"><h1>Cart #'+wcal_clicked_cart_id+'</h1>'+$wcal_cart_status+'</div>'+ email_body +' <div class = "wcal-modal-cart-content-hide" id ="wcal_remove_class"> </div> </div> <div class="wcal-icon-close wcal-js-close-modal"></div> </div>';
126
 
120
  },
121
 
122
  open: function( classes ) {
123
+ $wcal_cart_status = '';
124
  $(document.body).addClass('wcal-modal-open').append('<div class="wcal-modal-overlay"></div>');
125
  var modal_body = '<div class="wcal-modal ' + classes + '"><div class="wcal-modal__contents"> <div class="wcal-modal__header"><h1>Cart #'+wcal_clicked_cart_id+'</h1>'+$wcal_cart_status+'</div>'+ email_body +' <div class = "wcal-modal-cart-content-hide" id ="wcal_remove_class"> </div> </div> <div class="wcal-icon-close wcal-js-close-modal"></div> </div>';
126
 
assets/js/admin/wcal_abandoned_cart_detail_modal.min.js CHANGED
@@ -1 +1 @@
1
- var Modal,wcal_clicked_cart_id,$wcal_get_email_address,$wcal_customer_details,$wcal_cart_total,$wcal_abandoned_date,$wcal_abandoned_status,email_body,$wcal_cart_status,$wcal_show_customer_detail;jQuery(function(a){(Modal={init:function(){a(document.body).on("click",".wcal-js-close-modal",this.close),a(document.body).on("click",".wcal-modal-overlay",this.close),a(document.body).on("click",".wcal-js-open-modal",this.handle_link),a(document.body).on("click",".wcal_customer_detail_modal",this.handle_customer_details),a(document.body).on("mousedown",".wcal-js-open-modal",this.handle_link_mouse_middle_click),a(window).resize(function(){Modal.position()}),a(document).keydown(function(a){27==a.keyCode&&Modal.close()})},handle_customer_details:function(t){t.preventDefault(),-1==a(t.target).text().indexOf("Hide")?(a(".wcal_modal_customer_all_details").fadeIn(),Modal.position(),a(t.target).text("Hide Details")):(a(".wcal_modal_customer_all_details").fadeOut(),Modal.position(),a(t.target).text("Show Details"))},handle_link_mouse_middle_click:function(a){if(2==a.which){var t=window.location.href;return this.href=t,a.preventDefault(),!1}},handle_link:function(t){t.preventDefault();var l,e,d=a(this),o="";if(-1==window.location.href.indexOf("action=emailstats")?(l=(e=d.closest("tr")[0]).getElementsByTagName("td")[1].innerHTML.split("<div")[0],$wcal_customer_details=e.getElementsByTagName("td")[2].innerHTML,$wcal_cart_total=e.getElementsByTagName("td")[3].innerHTML,$wcal_abandoned_date=e.getElementsByTagName("td")[4].innerHTML,$wcal_abandoned_status=e.getElementsByClassName("status")[0].firstChild.innerText,$wcal_cart_status=$wcal_abandoned_status):(o="send_email",l="",$wcal_customer_details="",$wcal_cart_total="",$wcal_abandoned_date="",$wcal_cart_status=""),email_body='<div class="wcal-modal__body"> <div class="wcal-modal__body-inner"> <table cellspacing="0" cellpadding="6" border="1" class="wcal-cart-table"> <thead><th>Email Address</th><th>Customer Details</th><th>Order Total</th><th> Abandoned Date</th></tr></thead><tbody><tr><td>'+l+"</td><td>"+$wcal_customer_details+($wcal_show_customer_detail='<br><a href="#" id "wcal_customer_detail_modal"> Show Details </a>')+"</td><td>"+$wcal_cart_total+" </td><td>"+$wcal_abandoned_date+" </td></tr></tbody></table></div> </div>","ajax"==d.data("modal-type")){wcal_clicked_cart_id=d.data("wcal-cart-id"),Modal.open("type-ajax"),Modal.loading();var c={action:"wcal_abandoned_cart_info",wcal_cart_id:wcal_clicked_cart_id,wcal_email_address:l,wcal_customer_details:$wcal_customer_details,wcal_cart_total:$wcal_cart_total,wcal_abandoned_date:$wcal_abandoned_date,wcal_abandoned_status:$wcal_cart_status,wcal_current_page:o};a.post(ajaxurl,c,function(a){Modal.contents(a)})}},open:function(t){a(document.body).addClass("wcal-modal-open").append('<div class="wcal-modal-overlay"></div>');var l='<div class="wcal-modal '+t+'"><div class="wcal-modal__contents"> <div class="wcal-modal__header"><h1>Cart #'+wcal_clicked_cart_id+"</h1>"+$wcal_cart_status+"</div>"+email_body+' <div class = "wcal-modal-cart-content-hide" id ="wcal_remove_class"> </div> </div> <div class="wcal-icon-close wcal-js-close-modal"></div> </div>';a(document.body).append(l),this.position()},loading:function(){a(document.body).addClass("wcal-modal-loading")},contents:function(t){a(document.body).removeClass("wcal-modal-loading"),t=t.replace(/\\(.)/gm,"$1"),a(".wcal-modal__contents").html(t),this.position()},close:function(){a(document.body).removeClass("wcal-modal-open wcal-modal-loading"),a(".wcal-modal, .wcal-modal-overlay").remove()},position:function(){a(".wcal-modal__body").removeProp("style");var t=a(".wcal-modal__header").outerHeight(),l=a(".wcal-modal").height(),e=a(".wcal-modal").width(),d=a(".wcal-modal__body").outerHeight()+t;a(".wcal-modal").css({"margin-left":-e/2,"margin-top":-l/2}),l<d-5&&a(".wcal-modal__body").height(l-t)}}).init()});
1
+ var Modal,wcal_clicked_cart_id,$wcal_get_email_address,$wcal_customer_details,$wcal_cart_total,$wcal_abandoned_date,$wcal_abandoned_status,email_body,$wcal_cart_status,$wcal_show_customer_detail;jQuery(function(a){(Modal={init:function(){a(document.body).on("click",".wcal-js-close-modal",this.close),a(document.body).on("click",".wcal-modal-overlay",this.close),a(document.body).on("click",".wcal-js-open-modal",this.handle_link),a(document.body).on("click",".wcal_customer_detail_modal",this.handle_customer_details),a(document.body).on("mousedown",".wcal-js-open-modal",this.handle_link_mouse_middle_click),a(window).resize(function(){Modal.position()}),a(document).keydown(function(a){27==a.keyCode&&Modal.close()})},handle_customer_details:function(t){t.preventDefault(),-1==a(t.target).text().indexOf("Hide")?(a(".wcal_modal_customer_all_details").fadeIn(),Modal.position(),a(t.target).text("Hide Details")):(a(".wcal_modal_customer_all_details").fadeOut(),Modal.position(),a(t.target).text("Show Details"))},handle_link_mouse_middle_click:function(a){if(2==a.which){var t=window.location.href;return this.href=t,a.preventDefault(),!1}},handle_link:function(t){t.preventDefault();var l,e,d=a(this),o="";if(-1==window.location.href.indexOf("action=emailstats")?(l=(e=d.closest("tr")[0]).getElementsByTagName("td")[1].innerHTML.split("<div")[0],$wcal_customer_details=e.getElementsByTagName("td")[2].innerHTML,$wcal_cart_total=e.getElementsByTagName("td")[3].innerHTML,$wcal_abandoned_date=e.getElementsByTagName("td")[4].innerHTML,$wcal_abandoned_status=e.getElementsByClassName("status")[0].firstChild.innerText,$wcal_cart_status=$wcal_abandoned_status):(o="send_email",l="",$wcal_customer_details="",$wcal_cart_total="",$wcal_abandoned_date="",$wcal_cart_status=""),email_body='<div class="wcal-modal__body"> <div class="wcal-modal__body-inner"> <table cellspacing="0" cellpadding="6" border="1" class="wcal-cart-table"> <thead><th>Email Address</th><th>Customer Details</th><th>Order Total</th><th> Abandoned Date</th></tr></thead><tbody><tr><td>'+l+"</td><td>"+$wcal_customer_details+($wcal_show_customer_detail='<br><a href="#" id "wcal_customer_detail_modal"> Show Details </a>')+"</td><td>"+$wcal_cart_total+" </td><td>"+$wcal_abandoned_date+" </td></tr></tbody></table></div> </div>","ajax"==d.data("modal-type")){wcal_clicked_cart_id=d.data("wcal-cart-id"),Modal.open("type-ajax"),Modal.loading();var c={action:"wcal_abandoned_cart_info",wcal_cart_id:wcal_clicked_cart_id,wcal_email_address:l,wcal_customer_details:$wcal_customer_details,wcal_cart_total:$wcal_cart_total,wcal_abandoned_date:$wcal_abandoned_date,wcal_abandoned_status:$wcal_cart_status,wcal_current_page:o};a.post(ajaxurl,c,function(a){Modal.contents(a)})}},open:function(t){$wcal_cart_status="",a(document.body).addClass("wcal-modal-open").append('<div class="wcal-modal-overlay"></div>');var l='<div class="wcal-modal '+t+'"><div class="wcal-modal__contents"> <div class="wcal-modal__header"><h1>Cart #'+wcal_clicked_cart_id+"</h1>"+$wcal_cart_status+"</div>"+email_body+' <div class = "wcal-modal-cart-content-hide" id ="wcal_remove_class"> </div> </div> <div class="wcal-icon-close wcal-js-close-modal"></div> </div>';a(document.body).append(l),this.position()},loading:function(){a(document.body).addClass("wcal-modal-loading")},contents:function(t){a(document.body).removeClass("wcal-modal-loading"),t=t.replace(/\\(.)/gm,"$1"),a(".wcal-modal__contents").html(t),this.position()},close:function(){a(document.body).removeClass("wcal-modal-open wcal-modal-loading"),a(".wcal-modal, .wcal-modal-overlay").remove()},position:function(){a(".wcal-modal__body").removeProp("style");var t=a(".wcal-modal__header").outerHeight(),l=a(".wcal-modal").height(),e=a(".wcal-modal").width(),d=a(".wcal-modal__body").outerHeight()+t;a(".wcal-modal").css({"margin-left":-e/2,"margin-top":-l/2}),l<d-5&&a(".wcal-modal__body").height(l-t)}}).init()});
cron/class-wcal-cron.php CHANGED
@@ -53,6 +53,11 @@ if ( ! class_exists( 'Wcal_Cron' ) ) {
53
  $last_template_id = 0;
54
  }
55
 
 
 
 
 
 
56
  foreach ( $results as $key => $value ) {
57
  if ( 'Days' === $value->day_or_hour ) {
58
  $time_to_send_template_after = intval( $value->frequency ) * $day_seconds;
@@ -270,7 +275,7 @@ if ( ! class_exists( 'Wcal_Cron' ) ) {
270
  $cart_page_link = $cart_page_id ? get_permalink( $cart_page_id ) : '';
271
  }
272
 
273
- $encoding_cart = $email_sent_id . '&url=' . $cart_page_link;
274
  $validate_cart = $this->wcal_encrypt_validate( $encoding_cart );
275
  $cart_link_track = get_option( 'siteurl' ) . '/?wcal_action=track_links&validate=' . $validate_cart;
276
  $email_body = str_ireplace( '{{cart.link}}', $cart_link_track, $email_body );
@@ -328,6 +333,11 @@ if ( ! class_exists( 'Wcal_Cron' ) ) {
328
  if ( '' === $sub_line_prod_name ) {
329
  $sub_line_prod_name = $product_name;
330
  }
 
 
 
 
 
331
  // Item subtotal is calculated as product total including taxes.
332
  if ( $v->line_tax > 0 ) {
333
  $item_subtotal = $item_subtotal + $v->line_total + $v->line_tax;
@@ -355,8 +365,9 @@ if ( ! class_exists( 'Wcal_Cron' ) ) {
355
  $explode_all = '' !== $name ? explode( '&ndash;', $name ) : array();
356
  if ( version_compare( $woocommerce->version, '3.0.0', '>=' ) ) {
357
  $wcap_sku = '';
358
- if ( false !== $variation ) {
359
- $wcap_sku = 'SKU: ' . $variation->get_sku() . '<br>';
 
360
  }
361
  $wcap_get_formatted_variation = false !== $variation ? wc_get_formatted_variation( $variation, true ) : '';
362
 
@@ -600,7 +611,10 @@ if ( ! class_exists( 'Wcal_Cron' ) ) {
600
  $order_date_with_time = $results_query_email[0]->post_date;
601
  $order_date = substr( $order_date_with_time, 0, 10 );
602
 
603
- if ( $order_date == $todays_date ) { // phpcs:ignore
 
 
 
604
 
605
  // In some cases the cart is recovered but it is not marked as the recovered. So here we check if any record is found for that cart id if yes then update the record respectively.
606
  $wcal_check_email_sent_to_cart = self::wcal_get_cart_sent_data( $cart_id );
@@ -642,17 +656,6 @@ if ( ! class_exists( 'Wcal_Cron' ) ) {
642
  );
643
  }
644
  return 1;
645
- } elseif ( strtotime( $order_date_with_time ) > $abandoned_cart_time ) {
646
- $wpdb->query( // phpcs:ignore
647
- $wpdb->prepare(
648
- "UPDATE `" . $wpdb->prefix . "ac_abandoned_cart_history_lite` SET cart_ignored = '1' WHERE id = %s ", // phpcs:ignore
649
- $cart_id
650
- )
651
- );
652
- return 1;
653
- } elseif ( 'wc-pending' === $results_query_email[0]->post_status || 'wc-failed' === $results_query_email[0]->post_status ) {
654
- // If the post status are pending or failed the send them for abandoned cart reminder emails.
655
- return 0;
656
  }
657
  }
658
  return 0;
53
  $last_template_id = 0;
54
  }
55
 
56
+ $utm = get_option( 'wcal_add_utm_to_links', '' );
57
+ if ( '' !== $utm && strlen( $utm ) > 0 && '?' !== substr( $utm, 0, 1 ) ) {
58
+ $utm = "?$utm";
59
+ }
60
+
61
  foreach ( $results as $key => $value ) {
62
  if ( 'Days' === $value->day_or_hour ) {
63
  $time_to_send_template_after = intval( $value->frequency ) * $day_seconds;
275
  $cart_page_link = $cart_page_id ? get_permalink( $cart_page_id ) : '';
276
  }
277
 
278
+ $encoding_cart = $email_sent_id . '&url=' . $cart_page_link . $utm;
279
  $validate_cart = $this->wcal_encrypt_validate( $encoding_cart );
280
  $cart_link_track = get_option( 'siteurl' ) . '/?wcal_action=track_links&validate=' . $validate_cart;
281
  $email_body = str_ireplace( '{{cart.link}}', $cart_link_track, $email_body );
333
  if ( '' === $sub_line_prod_name ) {
334
  $sub_line_prod_name = $product_name;
335
  }
336
+ if ( '' !== $product->get_sku() ) {
337
+ $wcap_sku = '<br>' . __( 'SKU: ', 'woocommerce-abandoned-cart' ) . $product->get_sku() . '<br>';
338
+ $wcap_sku = apply_filters( 'wcal_email_sku', $wcap_sku, $product_id );
339
+ $product_name .= $wcap_sku;
340
+ }
341
  // Item subtotal is calculated as product total including taxes.
342
  if ( $v->line_tax > 0 ) {
343
  $item_subtotal = $item_subtotal + $v->line_total + $v->line_tax;
365
  $explode_all = '' !== $name ? explode( '&ndash;', $name ) : array();
366
  if ( version_compare( $woocommerce->version, '3.0.0', '>=' ) ) {
367
  $wcap_sku = '';
368
+ if ( false !== $variation && '' !== $variation->get_sku() ) {
369
+ $wcap_sku = '<br>' . __( 'SKU: ', 'woocommerce-abandoned-cart' ) . $variation->get_sku() . '<br>';
370
+ $wcap_sku = apply_filters( 'wcal_email_sku', $wcap_sku, $variation_id );
371
  }
372
  $wcap_get_formatted_variation = false !== $variation ? wc_get_formatted_variation( $variation, true ) : '';
373
 
611
  $order_date_with_time = $results_query_email[0]->post_date;
612
  $order_date = substr( $order_date_with_time, 0, 10 );
613
 
614
+ if ( ( 'wc-pending' === $results_query_email[0]->post_status || 'wc-failed' === $results_query_email[0]->post_status ) && strtotime( $order_date_with_time ) > $abandoned_cart_time ) {
615
+ // If the post status are pending or failed the send them for abandoned cart reminder emails.
616
+ return 0;
617
+ } elseif ( strtotime( $order_date_with_time ) > $abandoned_cart_time ) {
618
 
619
  // In some cases the cart is recovered but it is not marked as the recovered. So here we check if any record is found for that cart id if yes then update the record respectively.
620
  $wcal_check_email_sent_to_cart = self::wcal_get_cart_sent_data( $cart_id );
656
  );
657
  }
658
  return 1;
 
 
 
 
 
 
 
 
 
 
 
659
  }
660
  }
661
  return 0;
i18n/languages/woocommerce-abandoned-cart.pot CHANGED
@@ -1,15 +1,15 @@
1
- # Copyright (C) 2020 Tyche Softwares
2
  # This file is distributed under the same license as the Abandoned Cart Lite for WooCommerce plugin.
3
  msgid ""
4
  msgstr ""
5
- "Project-Id-Version: Abandoned Cart Lite for WooCommerce 5.7.2\n"
6
- "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/woocommerce-abandoned-cart\n"
7
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
8
  "Language-Team: LANGUAGE <LL@li.org>\n"
9
  "MIME-Version: 1.0\n"
10
  "Content-Type: text/plain; charset=UTF-8\n"
11
  "Content-Transfer-Encoding: 8bit\n"
12
- "POT-Creation-Date: 2020-06-18T06:05:39+00:00\n"
13
  "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
14
  "X-Generator: WP-CLI 2.4.0\n"
15
  "X-Domain: woocommerce-abandoned-cart\n"
@@ -23,7 +23,7 @@ msgid "http://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned
23
  msgstr ""
24
 
25
  #. Description of the plugin
26
- msgid "This plugin captures abandoned carts by logged-in users & emails them about it."
27
  msgstr ""
28
 
29
  #. Author of the plugin
@@ -34,67 +34,72 @@ msgstr ""
34
  msgid "http://www.tychesoftwares.com/"
35
  msgstr ""
36
 
37
- #: cron/wcal_send_email.php:95
38
  msgid "Abandoned cart reminder"
39
  msgstr ""
40
 
41
- #: cron/wcal_send_email.php:277
42
- #: woocommerce-ac.php:2628
43
- #: woocommerce-ac.php:3347
44
- #: woocommerce-ac.php:3382
45
  msgid "Quantity"
46
  msgstr ""
47
 
48
- #: cron/wcal_send_email.php:278
49
- #: woocommerce-ac.php:3348
50
- #: woocommerce-ac.php:3383
51
  msgid "Price"
52
  msgstr ""
53
 
54
- #: cron/wcal_send_email.php:279
55
- #: woocommerce-ac.php:2629
56
- #: woocommerce-ac.php:3349
57
- #: woocommerce-ac.php:3384
58
  msgid "Line Subtotal"
59
  msgstr ""
60
 
61
- #: cron/wcal_send_email.php:283
62
- #: cron/wcal_send_email.php:293
63
- #: woocommerce-ac.php:3343
64
- #: woocommerce-ac.php:3377
65
  msgid "Your Shopping Cart"
66
  msgstr ""
67
 
68
- #: cron/wcal_send_email.php:285
69
- #: cron/wcal_send_email.php:295
70
- #: woocommerce-ac.php:2626
71
- #: woocommerce-ac.php:3345
72
- #: woocommerce-ac.php:3380
73
  msgid "Item"
74
  msgstr ""
75
 
76
- #: cron/wcal_send_email.php:286
77
- #: cron/wcal_send_email.php:296
78
- #: woocommerce-ac.php:2627
79
- #: woocommerce-ac.php:3346
80
- #: woocommerce-ac.php:3381
81
  msgid "Name"
82
  msgstr ""
83
 
84
- #: cron/wcal_send_email.php:387
85
- #: woocommerce-ac.php:3369
86
- #: woocommerce-ac.php:3404
 
 
 
 
 
87
  msgid "Cart Total:"
88
  msgstr ""
89
 
90
- #: cron/wcal_send_email.php:399
91
  msgid "Product no longer exists"
92
  msgstr ""
93
 
94
- #: cron/wcal_send_email.php:587
95
- #: cron/wcal_send_email.php:654
96
- #: includes/frontend/wcal_checkout_process.php:198
97
- #: includes/frontend/wcal_checkout_process.php:493
98
  msgid "This order was abandoned & subsequently recovered."
99
  msgstr ""
100
 
@@ -103,1102 +108,1243 @@ msgstr ""
103
  msgid "Cart #%s"
104
  msgstr ""
105
 
106
- #: includes/admin/wcal_privacy_erase.php:41
107
- #: includes/admin/wcal_privacy_export.php:41
108
  msgid "Abandoned & Recovered Carts"
109
  msgstr ""
110
 
111
- #: includes/admin/wcal_privacy_erase.php:90
112
  msgid "No personal data found for any abandoned carts."
113
  msgstr ""
114
 
115
  #. Translators: %s Abandoned Cart ID.
116
- #: includes/admin/wcal_privacy_erase.php:123
117
  msgid "Removed personal data from cart %s."
118
  msgstr ""
119
 
120
  #. Translators: %s Abandoned Cart ID.
121
- #: includes/admin/wcal_privacy_erase.php:127
122
  msgid "Personal data within cart %s has been retained."
123
  msgstr ""
124
 
125
- #: includes/admin/wcal_privacy_erase.php:204
126
  msgid "ANONYMIZED"
127
  msgstr ""
128
 
129
- #: includes/admin/wcal_privacy_export.php:123
130
- #: woocommerce-ac.php:1100
131
  msgid "Abandoned Carts"
132
  msgstr ""
133
 
134
- #: includes/admin/wcal_privacy_export.php:167
135
- #: includes/admin/wcal_privacy_export.php:179
136
  msgid "Abandoned Cart ID"
137
  msgstr ""
138
 
139
- #: includes/admin/wcal_privacy_export.php:168
140
- #: includes/admin/wcal_privacy_export.php:180
141
- #: includes/classes/class-wcal-abandoned-orders-table.php:100
142
  msgid "Abandoned Date"
143
  msgstr ""
144
 
145
- #: includes/admin/wcal_privacy_export.php:169
146
- #: includes/admin/wcal_privacy_export.php:181
147
  msgid "Abandoned Cart Status"
148
  msgstr ""
149
 
150
- #: includes/admin/wcal_privacy_export.php:170
151
- #: includes/admin/wcal_privacy_export.php:182
152
  msgid "Cart Total"
153
  msgstr ""
154
 
155
- #: includes/admin/wcal_privacy_export.php:171
156
- #: includes/admin/wcal_privacy_export.php:183
157
  msgid "Items Present"
158
  msgstr ""
159
 
160
- #: includes/admin/wcal_privacy_export.php:172
161
  msgid "Session ID"
162
  msgstr ""
163
 
164
- #: includes/admin/wcal_privacy_export.php:173
165
- #: includes/admin/wcal_privacy_export.php:184
166
  msgid "Billing Address"
167
  msgstr ""
168
 
169
- #: includes/admin/wcal_privacy_export.php:174
170
- #: includes/admin/wcal_privacy_export.php:185
171
- #: includes/classes/class-wcal-abandoned-orders-table.php:97
172
- #: includes/classes/class-wcal-recover-orders-table.php:125
173
  msgid "Email Address"
174
  msgstr ""
175
 
176
- #: includes/admin/wcal_privacy_export.php:215
177
- #: includes/admin/wcal_privacy_export.php:218
178
  msgid "Cart Recovered - Order #"
179
  msgstr ""
180
 
181
- #: includes/admin/wcal_privacy_export.php:215
182
- #: includes/classes/class-wcal-abandoned-orders-table.php:374
183
  msgid "Abandoned"
184
  msgstr ""
185
 
186
- #: includes/admin/wcal_privacy_export.php:218
187
  msgid "Abandoned but new cart created"
188
  msgstr ""
189
 
190
- #: includes/admin/wcal_privacy_export.php:221
191
  msgid "Abandoned - Unpaid Order #"
192
  msgstr ""
193
 
194
- #: includes/admin/wcap_add_cart_popup_modal.php:143
 
 
 
 
 
 
 
 
 
 
 
195
  msgid "Enable Add to cart popup modal"
196
  msgstr ""
197
 
198
- #: includes/admin/wcap_add_cart_popup_modal.php:200
199
- msgid "Custom pages to display the pop-up modal on"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
200
  msgstr ""
201
 
202
- #: includes/admin/wcap_add_cart_popup_modal.php:216
203
- #: includes/admin/wcap_add_cart_popup_modal.php:259
204
- msgid "Search for a Page&hellip;"
205
  msgstr ""
206
 
207
- #: includes/admin/wcap_add_cart_popup_modal.php:267
208
- msgid "Please add any custom pages (not created by WooCommerce) where you wish to display the Add to cart Pop-up Modal."
209
  msgstr ""
210
 
211
- #: includes/admin/wcap_add_cart_popup_modal.php:279
212
- msgid "<b>Note:</b> Please ensure that the Add to Cart button links on these pages are added with the correct classes and attributes to ensure the plugin can capture the cart data correctly. For further guidance, please check the documentation."
213
  msgstr ""
214
 
215
- #: includes/admin/wcap_add_cart_popup_modal.php:387
216
- msgid "Please enter your email address"
217
  msgstr ""
218
 
219
- #: includes/admin/wcap_add_cart_popup_modal.php:440
220
- #: includes/admin/wcap_add_cart_popup_modal.php:721
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
221
  msgid "To add this item to your cart, please enter your email address."
222
  msgstr ""
223
 
224
- #: includes/admin/wcap_add_cart_popup_modal.php:493
225
- #: includes/admin/wcap_add_cart_popup_modal.php:733
226
  msgid "Email address"
227
  msgstr ""
228
 
229
- #: includes/admin/wcap_add_cart_popup_modal.php:534
230
- #: includes/admin/wcap_add_cart_popup_modal.php:741
231
  msgid "Add to Cart"
232
  msgstr ""
233
 
234
- #: includes/admin/wcap_add_cart_popup_modal.php:660
235
- #: includes/admin/wcap_add_cart_popup_modal.php:749
236
  msgid "No Thanks"
237
  msgstr ""
238
 
239
- #: includes/admin/wcap_add_cart_popup_modal.php:719
240
- msgid "Please enter your email address."
241
  msgstr ""
242
 
243
- #. translators: %s Purchase Link
244
- #: includes/admin/wcap_pro_settings.php:66
245
  msgid "Upgrade to <a href='%s' target='_blank'>Abandoned Cart Pro for WooCommerce</a> to enable the feature."
246
  msgstr ""
247
 
248
- #: includes/admin/wcap_pro_settings.php:95
249
- #: includes/admin/wcap_pro_settings.php:395
250
- #: woocommerce-ac.php:3125
251
- msgid "Save Changes"
252
- msgstr ""
253
-
254
- #: includes/admin/wcap_pro_settings.php:118
255
  msgid "Cart abandoned cut-off time for guest users"
256
  msgstr ""
257
 
258
- #: includes/admin/wcap_pro_settings.php:126
259
  msgid "For guest users & visitors consider cart abandoned after X minutes of item being added to cart & order not placed."
260
  msgstr ""
261
 
262
- #: includes/admin/wcap_pro_settings.php:136
263
  msgid "Do not track carts of guest users"
264
  msgstr ""
265
 
266
- #: includes/admin/wcap_pro_settings.php:144
267
  msgid "Abandoned carts of guest users will not be tracked."
268
  msgstr ""
269
 
270
- #: includes/admin/wcap_pro_settings.php:154
271
  msgid "Do not track carts of logged-in users"
272
  msgstr ""
273
 
274
- #: includes/admin/wcap_pro_settings.php:162
275
  msgid "Abandoned carts of logged-in users will not be tracked."
276
  msgstr ""
277
 
278
- #: includes/admin/wcap_pro_settings.php:172
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
279
  msgid "Capture Email address from URL"
280
  msgstr ""
281
 
282
- #: includes/admin/wcap_pro_settings.php:180
283
  msgid "If your site URL contain the same key, then it will capture it as an email address of customer."
284
  msgstr ""
285
 
286
- #: includes/admin/wcap_pro_settings.php:238
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
287
  msgid "Product Image( H x W )"
288
  msgstr ""
289
 
290
- #: includes/admin/wcap_pro_settings.php:246
291
  msgid "This setting affects the dimension of the product image in the abandoned cart reminder email."
292
  msgstr ""
293
 
294
- #: includes/admin/wcap_pro_settings.php:266
295
  msgid "Setting for sending Emails & SMS using Action Scheduler"
296
  msgstr ""
297
 
298
- #: includes/admin/wcap_pro_settings.php:280
299
  msgid "Send Abandoned cart emails automatically using Action Scheduler"
300
  msgstr ""
301
 
302
- #: includes/admin/wcap_pro_settings.php:288
303
  msgid "Enabling this setting will send the abandoned cart reminder emails to the customer after the set time. If disabled, abandoned cart reminder emails will not be sent using the Action Scheduler. You will need to set cron job manually from cPanel. If you are unsure how to set the cron job, please <a href= mailto:support@tychesoftwares.com>contact us</a> for it."
304
  msgstr ""
305
 
306
- #: includes/admin/wcap_pro_settings.php:298
307
  msgid "Run automated Scheduler every X minutes"
308
  msgstr ""
309
 
310
- #: includes/admin/wcap_pro_settings.php:306
311
  msgid "The duration in minutes after which an action should be automatically scheduled to send email, SMS & FB reminders to customers."
312
  msgstr ""
313
 
314
- #: includes/admin/wcap_pro_settings.php:316
315
  msgid "Rules to exclude capturing abandoned carts"
316
  msgstr ""
317
 
318
- #: includes/admin/wcap_pro_settings.php:330
319
  msgid "Do not capture abandoned carts for these IP addresses"
320
  msgstr ""
321
 
322
- #: includes/admin/wcap_pro_settings.php:338
323
  msgid "The carts abandoned from these IP addresses will not be tracked by the plugin. Accepts wildcards, e.g <code>192.168.*</code> will block all IP addresses which starts from \"192.168\". <i>Separate IP addresses with commas.</i>"
324
  msgstr ""
325
 
326
- #: includes/admin/wcap_pro_settings.php:348
327
  msgid "Do not capture abandoned carts for these email addresses"
328
  msgstr ""
329
 
330
- #: includes/admin/wcap_pro_settings.php:356
331
  msgid "The carts abandoned using these email addresses will not be tracked by the plugin. <i>Separate email addresses with commas.</i>"
332
  msgstr ""
333
 
334
- #: includes/admin/wcap_pro_settings.php:366
335
  msgid "Do not capture abandoned carts for email addresses from these domains"
336
  msgstr ""
337
 
338
- #: includes/admin/wcap_pro_settings.php:374
339
  msgid "The carts abandoned from email addresses with these domains will not be tracked by the plugin. <i>Separate email address domains with commas.</i>"
340
  msgstr ""
341
 
342
- #: includes/admin/wcap_pro_settings.php:403
 
 
 
 
 
 
 
 
343
  msgid "Send Test SMS"
344
  msgstr ""
345
 
346
- #: includes/admin/wcap_pro_settings.php:411
347
  msgid "Recipient"
348
  msgstr ""
349
 
350
- #: includes/admin/wcap_pro_settings.php:417
351
  msgid "Must be a valid phone number in E.164 format."
352
  msgstr ""
353
 
354
- #: includes/admin/wcap_pro_settings.php:425
355
  msgid "Message"
356
  msgstr ""
357
 
358
- #: includes/admin/wcap_pro_settings.php:427
359
  msgid "Hello World!"
360
  msgstr ""
361
 
362
- #: includes/admin/wcap_pro_settings.php:463
363
  msgid "Twilio"
364
  msgstr ""
365
 
366
- #: includes/admin/wcap_pro_settings.php:477
367
  msgid "Enable SMS"
368
  msgstr ""
369
 
370
- #: includes/admin/wcap_pro_settings.php:485
371
  msgid "<i>Enable the ability to send reminder SMS for abandoned carts.</i>"
372
  msgstr ""
373
 
374
- #: includes/admin/wcap_pro_settings.php:495
375
  msgid "From"
376
  msgstr ""
377
 
378
- #: includes/admin/wcap_pro_settings.php:503
379
  msgid "<i>Must be a Twilio phone number (in E.164 format) or alphanumeric sender ID.</i>"
380
  msgstr ""
381
 
382
- #: includes/admin/wcap_pro_settings.php:513
383
  msgid "Account SID"
384
  msgstr ""
385
 
386
- #: includes/admin/wcap_pro_settings.php:531
387
  msgid "Auth Token"
388
  msgstr ""
389
 
390
- #: includes/admin/wcap_pro_settings.php:591
391
  msgid "Facebook Messenger Settings"
392
  msgstr ""
393
 
394
- #: includes/admin/wcap_pro_settings.php:605
395
  msgid "Enable Facebook Messenger Reminders"
396
  msgstr ""
397
 
398
- #: includes/admin/wcap_pro_settings.php:613
399
  msgid "<i>This option will display a checkbox after the Add to cart button for user consent to connect with Facebook.</i>"
400
  msgstr ""
401
 
402
- #: includes/admin/wcap_pro_settings.php:623
403
  msgid "Facebook Messenger on Add to Cart Pop-up modal"
404
  msgstr ""
405
 
406
- #: includes/admin/wcap_pro_settings.php:631
407
  msgid "<i>This option will display a checkbox on the pop-up modal to connect with Facebook.</i>"
408
  msgstr ""
409
 
410
- #: includes/admin/wcap_pro_settings.php:641
411
  msgid "Icon size of user"
412
  msgstr ""
413
 
414
- #: includes/admin/wcap_pro_settings.php:651
415
  msgid "<i>Select the size of user icon which shall be displayed below the checkbox in case the user is logged in.</i>"
416
  msgstr ""
417
 
418
- #: includes/admin/wcap_pro_settings.php:657
419
  msgid "Small"
420
  msgstr ""
421
 
422
- #: includes/admin/wcap_pro_settings.php:659
423
  msgid "Medium"
424
  msgstr ""
425
 
426
- #: includes/admin/wcap_pro_settings.php:661
427
  msgid "Large"
428
  msgstr ""
429
 
430
- #: includes/admin/wcap_pro_settings.php:663
431
  msgid "Standard"
432
  msgstr ""
433
 
434
- #: includes/admin/wcap_pro_settings.php:665
435
  msgid "Extra Large"
436
  msgstr ""
437
 
438
- #: includes/admin/wcap_pro_settings.php:679
439
  msgid "Consent text"
440
  msgstr ""
441
 
442
- #: includes/admin/wcap_pro_settings.php:687
443
  msgid "<i>Text that will appear above the consent checkbox. HTML tags are also allowed.</i>"
444
  msgstr ""
445
 
446
- #: includes/admin/wcap_pro_settings.php:697
447
  msgid "Facebook Page ID"
448
  msgstr ""
449
 
450
- #: includes/admin/wcap_pro_settings.php:705
451
  msgid "<i>Facebook Page ID in numberic format. You can find your page ID from <a href='https://www.tychesoftwares.com/docs/docs/abandoned-cart-pro-for-woocommerce/send-abandoned-cart-reminder-notifications-using-facebook-messenger#fbpageid' target='_blank'>here</a></i>"
452
  msgstr ""
453
 
454
- #: includes/admin/wcap_pro_settings.php:715
455
  msgid "Messenger App ID"
456
  msgstr ""
457
 
458
- #: includes/admin/wcap_pro_settings.php:723
459
  msgid "<i>Enter your Messenger App ID</i>"
460
  msgstr ""
461
 
462
- #: includes/admin/wcap_pro_settings.php:733
463
  msgid "Facebook Page Token"
464
  msgstr ""
465
 
466
- #: includes/admin/wcap_pro_settings.php:741
467
  msgid "<i>Enter your Facebook Page Token</i>"
468
  msgstr ""
469
 
470
- #: includes/admin/wcap_pro_settings.php:751
471
  msgid "Verify Token"
472
  msgstr ""
473
 
474
- #: includes/admin/wcap_pro_settings.php:759
475
  msgid "<i>Enter your Verify Token</i>"
476
  msgstr ""
477
 
478
- #: includes/admin/wcap_pro_settings_callbacks.php:45
479
- msgid "Configure your Twilio account settings below. Please note that due to some restrictions from Twilio, customers <i>may sometimes</i> receive delayed messages"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
480
  msgstr ""
481
 
482
- #: includes/admin/wcap_pro_settings_callbacks.php:183
483
- msgid "Configure the plugin to send notifications to Facebook Messenger using the settings below. Please refer the <a href=\"https://www.tychesoftwares.com/docs/docs/abandoned-cart-pro-for-woocommerce/send-abandoned-cart-reminder-notifications-using-facebook-messenger\" target=\"_blank\">following documentation</a> to complete the setup."
 
 
 
484
  msgstr ""
485
 
486
- #. translators: %s Link to Email Templates page
487
- #: includes/class-wcal-admin-notice.php:59
488
- msgid "<div id=\"wcal_update\" class=\"updated woocommerce-message\" style=\"padding:15px;\"><span>We need to update your email template database for some improvements. Please take a backup of your databases for your piece of mind</span><span class=\"submit\"><a href=\"%s\" class=\"button-primary\" style=\"float:right;\">Update</a></span></div>"
489
  msgstr ""
490
 
491
- #: includes/classes/class-wcal-abandoned-orders-table.php:52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
492
  msgid "abandoned_order_id"
493
  msgstr ""
494
 
495
- #: includes/classes/class-wcal-abandoned-orders-table.php:53
496
  msgid "abandoned_order_ids"
497
  msgstr ""
498
 
499
- #: includes/classes/class-wcal-abandoned-orders-table.php:96
500
  msgid "Id"
501
  msgstr ""
502
 
503
- #: includes/classes/class-wcal-abandoned-orders-table.php:98
504
  msgid "Customer"
505
  msgstr ""
506
 
507
- #: includes/classes/class-wcal-abandoned-orders-table.php:99
508
- #: includes/classes/class-wcal-recover-orders-table.php:128
509
  msgid "Order Total"
510
  msgstr ""
511
 
512
- #: includes/classes/class-wcal-abandoned-orders-table.php:101
513
  msgid "Status of Cart"
514
  msgstr ""
515
 
516
- #: includes/classes/class-wcal-abandoned-orders-table.php:159
517
- #: includes/classes/class-wcal-abandoned-orders-table.php:526
518
  msgid "View order"
519
  msgstr ""
520
 
521
- #: includes/classes/class-wcal-abandoned-orders-table.php:160
522
- #: includes/classes/class-wcal-abandoned-orders-table.php:566
523
- #: includes/classes/class-wcal-templates-table.php:145
524
- #: includes/classes/class-wcal-templates-table.php:332
525
  msgid "Delete"
526
  msgstr ""
527
 
528
- #: includes/classes/class-wcal-abandoned-orders-table.php:292
529
  msgid "User Deleted"
530
  msgstr ""
531
 
532
- #: includes/classes/class-wcal-abandoned-orders-table.php:366
533
- msgid "item"
534
  msgstr ""
535
 
536
- #: includes/classes/class-wcal-abandoned-orders-table.php:368
537
- msgid "items"
538
  msgstr ""
539
 
540
- #: includes/classes/class-wcal-abandoned-orders-table.php:372
541
  msgid "Unsubscribed"
542
  msgstr ""
543
 
544
- #: includes/classes/class-wcal-abandoned-orders-table.php:567
545
  msgid "Delete All Registered User Carts"
546
  msgstr ""
547
 
548
- #: includes/classes/class-wcal-abandoned-orders-table.php:568
549
  msgid "Delete All Guest User Carts"
550
  msgstr ""
551
 
552
- #: includes/classes/class-wcal-abandoned-orders-table.php:569
553
  msgid "Delete All Visitor Carts"
554
  msgstr ""
555
 
556
- #: includes/classes/class-wcal-abandoned-orders-table.php:570
557
  msgid "Delete All Carts"
558
  msgstr ""
559
 
560
- #: includes/classes/class-wcal-dashboard-report.php:102
561
  msgid "Recovered Amount"
562
  msgstr ""
563
 
564
- #: includes/classes/class-wcal-dashboard-report.php:107
565
- #: includes/classes/class-wcal-dashboard-report.php:156
566
- #: includes/classes/class-wcal-dashboard-report.php:191
567
- #: includes/classes/class-wcal-dashboard-report.php:226
568
- #: includes/classes/class-wcal-recover-orders-table.php:161
569
  msgid "View Details"
570
  msgstr ""
571
 
572
  #. translators: Count of carts recovered.
573
- #: includes/classes/class-wcal-dashboard-report.php:118
574
  msgid "<strong>%s</strong> Recovered Orders"
575
  msgstr ""
576
 
577
  #. translators: recovered percent of carts.
578
- #: includes/classes/class-wcal-dashboard-report.php:125
579
  msgid "<strong>%s%%</strong> of Abandoned Carts Recovered"
580
  msgstr ""
581
 
582
  #. translators: Percent of sales.
583
- #: includes/classes/class-wcal-dashboard-report.php:132
584
  msgid "<strong>%s%%</strong> of Total Revenue"
585
  msgstr ""
586
 
587
- #: includes/classes/class-wcal-dashboard-report.php:151
588
- #: woocommerce-ac.php:1806
589
  msgid "Abandoned Orders"
590
  msgstr ""
591
 
592
  #. translators: Abandoned Orders amount.
593
- #: includes/classes/class-wcal-dashboard-report.php:167
594
  msgid "%s amount of Abandoned Orders"
595
  msgstr ""
596
 
597
- #: includes/classes/class-wcal-dashboard-report.php:186
598
  msgid "Number of Emails Sent"
599
  msgstr ""
600
 
601
  #. translators: Link to Purchase the Pro version of the plugin.
602
- #: includes/classes/class-wcal-dashboard-report.php:202
603
  msgid "Upgrade to <a href='%s' target='_blank'>Abandoned Cart Pro for WooCommerce</a> to view the number of emails opened and links clicked."
604
  msgstr ""
605
 
606
- #: includes/classes/class-wcal-dashboard-report.php:221
607
  msgid "Emails Captured"
608
  msgstr ""
609
 
610
  #. translators: Number of guest emails captured.
611
- #: includes/classes/class-wcal-dashboard-report.php:237
612
  msgid "%s Guest emails captured."
613
  msgstr ""
614
 
615
  #. translators: Link to Purchase the Pro version.
616
- #: includes/classes/class-wcal-dashboard-report.php:243
617
  msgid "Upgrade to <a href='%s' target='_blank'>Abandoned Cart Pro for WooCommerce</a> to capture more guest carts."
618
  msgstr ""
619
 
620
- #: includes/classes/class-wcal-dashboard-report.php:270
621
  msgid "This Month"
622
  msgstr ""
623
 
624
- #: includes/classes/class-wcal-dashboard-report.php:271
625
  msgid "Last Month"
626
  msgstr ""
627
 
628
- #: includes/classes/class-wcal-dashboard-report.php:272
629
  msgid "This Quarter"
630
  msgstr ""
631
 
632
- #: includes/classes/class-wcal-dashboard-report.php:273
633
  msgid "Last Quarter"
634
  msgstr ""
635
 
636
- #: includes/classes/class-wcal-dashboard-report.php:274
637
  msgid "This Year"
638
  msgstr ""
639
 
640
- #: includes/classes/class-wcal-dashboard-report.php:275
641
  msgid "Last Year"
642
  msgstr ""
643
 
644
- #: includes/classes/class-wcal-dashboard-report.php:276
645
  msgid "Custom"
646
  msgstr ""
647
 
648
- #: includes/classes/class-wcal-dashboard-report.php:291
649
  msgid "Select date range:"
650
  msgstr ""
651
 
652
- #: includes/classes/class-wcal-dashboard-report.php:311
653
- #: woocommerce-ac.php:2589
654
  msgid "Go"
655
  msgstr ""
656
 
657
- #: includes/classes/class-wcal-product-report-table.php:58
658
  msgid "product_id"
659
  msgstr ""
660
 
661
- #: includes/classes/class-wcal-product-report-table.php:59
662
  msgid "product_ids"
663
  msgstr ""
664
 
665
- #: includes/classes/class-wcal-product-report-table.php:91
666
  msgid "Product Name"
667
  msgstr ""
668
 
669
- #: includes/classes/class-wcal-product-report-table.php:92
670
  msgid "Number of Times Abandoned"
671
  msgstr ""
672
 
673
- #: includes/classes/class-wcal-product-report-table.php:93
674
  msgid "Number of Times Recovered"
675
  msgstr ""
676
 
677
- #: includes/classes/class-wcal-recover-orders-table.php:86
678
  msgid "rec_abandoned_id"
679
  msgstr ""
680
 
681
- #: includes/classes/class-wcal-recover-orders-table.php:87
682
  msgid "rec_abandoned_ids"
683
  msgstr ""
684
 
685
- #: includes/classes/class-wcal-recover-orders-table.php:124
686
  msgid "Customer Name"
687
  msgstr ""
688
 
689
- #: includes/classes/class-wcal-recover-orders-table.php:126
690
  msgid "Cart Abandoned Date"
691
  msgstr ""
692
 
693
- #: includes/classes/class-wcal-recover-orders-table.php:127
694
  msgid "Cart Recovered Date"
695
  msgstr ""
696
 
697
- #: includes/classes/class-wcal-templates-table.php:53
698
  msgid "template_id"
699
  msgstr ""
700
 
701
- #: includes/classes/class-wcal-templates-table.php:54
702
  msgid "template_ids"
703
  msgstr ""
704
 
705
- #: includes/classes/class-wcal-templates-table.php:91
706
  msgid "Sr"
707
  msgstr ""
708
 
709
- #: includes/classes/class-wcal-templates-table.php:92
710
  msgid "Name Of Template"
711
  msgstr ""
712
 
713
- #: includes/classes/class-wcal-templates-table.php:93
714
  msgid "Sent After Set Time"
715
  msgstr ""
716
 
717
- #: includes/classes/class-wcal-templates-table.php:94
718
  msgid "Active ?"
719
  msgstr ""
720
 
721
- #: includes/classes/class-wcal-templates-table.php:144
722
  msgid "Edit"
723
  msgstr ""
724
 
725
- #: includes/classes/class-wcal-templates-table.php:306
726
- msgid "on"
727
- msgstr ""
728
-
729
- #: includes/classes/class-wcal-templates-table.php:309
730
- msgid "off"
731
- msgstr ""
732
-
733
- #: includes/component/welcome-page/templates/welcome/welcome-page.php:30
734
- msgid "Get Started with Abandoned Cart Lite"
735
- msgstr ""
736
-
737
- #: includes/component/welcome-page/templates/welcome/welcome-page.php:34
738
- #: includes/component/welcome-page/templates/welcome/welcome-page.php:59
739
- #: includes/component/welcome-page/templates/welcome/welcome-page.php:86
740
- #: includes/component/welcome-page/templates/welcome/welcome-page.php:93
741
- msgid "WooCommerce Abandoned Cart Lite"
742
- msgstr ""
743
-
744
- #: includes/component/welcome-page/templates/welcome/welcome-page.php:38
745
- msgid "Activate Email Template"
746
  msgstr ""
747
 
748
- #: includes/component/welcome-page/templates/welcome/welcome-page.php:40
749
- msgid "To start sending out abandoned cart notification emails, simply activate the email template from under WooCommerce -> Abandoned Carts -> Email Templates page."
750
- msgstr ""
751
-
752
- #: includes/component/welcome-page/templates/welcome/welcome-page.php:42
753
- msgid "Click Here to go to Email Templates page"
754
- msgstr ""
755
-
756
- #: includes/component/welcome-page/templates/welcome/welcome-page.php:52
757
- msgid "Know more about Abandoned Cart Pro"
758
- msgstr ""
759
-
760
- #: includes/component/welcome-page/templates/welcome/welcome-page.php:63
761
- msgid "Capture Visitor Emails on click of Add to Cart button"
762
- msgstr ""
763
-
764
- #: includes/component/welcome-page/templates/welcome/welcome-page.php:65
765
- msgid "The ability to capture the email address early in the order process is very important to reduce cart abandonment by unknown users as well as to be able to recover their carts if they abandon it. This ultimately leads to increase in your store sales."
766
- msgstr ""
767
-
768
- #: includes/component/welcome-page/templates/welcome/welcome-page.php:67
769
- #: includes/component/welcome-page/templates/welcome/welcome-page.php:80
770
- #: includes/component/welcome-page/templates/welcome/welcome-page.php:101
771
- msgid "Learn More"
772
- msgstr ""
773
-
774
- #: includes/component/welcome-page/templates/welcome/welcome-page.php:76
775
- msgid "Set different cut-off times for visitors & logged-in users"
776
- msgstr ""
777
-
778
- #: includes/component/welcome-page/templates/welcome/welcome-page.php:78
779
- msgid "The provision for setting two separate cut-off times for different roles is mainly because sometimes if the store admin wants the visitor carts to be captured earlier than the registered user carts, then these different settings can play an important role."
780
- msgstr ""
781
-
782
- #: includes/component/welcome-page/templates/welcome/welcome-page.php:97
783
- msgid "Send abandoned cart recovery email in minutes of cart being abandoned"
784
- msgstr ""
785
-
786
- #: includes/component/welcome-page/templates/welcome/welcome-page.php:99
787
- msgid "The ability to send the abandoned cart recovery email within first few minutes of cart being abandoned is a big advantage. In the Lite plugin, the earliest an email can be sent is after 1 hour. Whereas in the Pro version, the first recovery email gets sent 15 minutes after the cart is abandoned. This increases the recovery chances manifold."
788
- msgstr ""
789
-
790
- #: includes/wcal-common.php:674
791
- msgid "Database Updated Successfully"
792
- msgstr ""
793
-
794
- #: includes/wcal-common.php:689
795
- msgid "Database Update Failed. Please try again after sometime"
796
- msgstr ""
797
-
798
- #: includes/wcal-common.php:849
799
- msgid "This product no longer exists"
800
- msgstr ""
801
-
802
- #. translators: %1$s Link to Differences article, %2$s link to pro version
803
- #: includes/wcal_all_component.php:89
804
- msgid "Now that you are all set with the Lite version, you can upgrade to Pro version to take your abandoned cart recovery to the next level. You can capture customer’s email address when they click Add to Cart, get access to 11 unique, fully responsive email templates, send text messages for recovery & <strong><a target=\"_blank\" href= \"%1$s\">much more</a></strong>. <strong><a target=\"_blank\" href= \"%2$s\">Purchase now</a></strong>."
805
- msgstr ""
806
-
807
- #. translators: %s Link to Abandoned Cart Pro
808
- #: includes/wcal_all_component.php:93
809
- msgid "Boost your sales by recovering up to 60% of the abandoned carts with our Abandoned Cart Pro for WooCommerce plugin. You can capture customer email addresses right when they click the Add To Cart button. <strong><a target=\"_blank\" href= \"%s\"> Grab your copy of Abandon Cart Pro plugin now!</a></strong>"
810
- msgstr ""
811
-
812
- #. translators: %s Link to Abandoned Cart Pro
813
- #: includes/wcal_all_component.php:97
814
- msgid "Don't loose your sales to abandoned carts. Use our Abandon Cart Pro plugin & start recovering your lost sales in less then 60 seconds. <strong><a target=\"_blank\" href= \"%s\">Grab it now!</a></strong>."
815
- msgstr ""
816
-
817
- #. translators: %s Link to Abandoned Cart Pro
818
- #: includes/wcal_all_component.php:101
819
- msgid "Send Abandoned Cart reminders that actually convert. Take advantage of our fully responsive email templates designed specially with an intent to trigger conversion. <strong><a target=\"_blank\" href= \"%s\">Purchase now</a></strong>."
820
- msgstr ""
821
-
822
- #. translators: %s Link to Abandoned Cart Pro
823
- #: includes/wcal_all_component.php:105
824
- msgid ""
825
- "Increase your store sales by recovering your abandoned carts for just $119. No profit sharing, no monthly fees. Our Abandoned Cart Pro plugin comes with a 30 day money back guarantee as well. :) Use coupon code ACPRO20 & save $24!<br>\r\n"
826
- " <strong><a target=\"_blank\" href= \"%s\">Grab your copy now!</a></strong>"
827
- msgstr ""
828
-
829
- #. translators: %s Link to Order Delivery Date Pro
830
- #: includes/wcal_all_component.php:110
831
- msgid "Reduce cart abandonment rate by 57% with our Order Delivery Date Pro WooCommerce plugin. You can Create Delivery Settings by Shipping Zones & Shipping Classes. <br>Use discount code \"ORDPRO20\" and grab 20% discount on the purchase of the plugin. The discount code is valid only for the first 20 customers. <strong><a target=\"_blank\" href= \"%s\">Purchase now</a></strong>"
832
  msgstr ""
833
 
834
- #. translators: %s Link to Order Delivery Date Pro
835
- #: includes/wcal_all_component.php:114
836
- msgid ""
837
- "Allow your customers to select the Delivery Date on Single Product Page using our Product Delivery Date pro for WooCommerce Plugin. <br>\r\n"
838
- " <strong><a target=\"_blank\" href= \"%s\">Shop now</a></strong> & be one of the 20 customers to get 20% discount on the plugin price. Use the code \"PRDPRO20\". Hurry!!"
839
  msgstr ""
840
 
841
- #. translators: %s Link to WooCommerce Booking Plugin
842
- #: includes/wcal_all_component.php:119
843
- msgid "Allow your customers to book an appointment or rent an apartment with our Booking and Appointment for WooCommerce plugin. You can also sell your product as a resource or integrate with a few Vendor plugins. <br>Shop now & Save 20% on the plugin with the code \"BKAP20\". Only for first 20 customers. <strong><a target=\"_blank\" href= \"%s\">Have it now!</a></strong>"
844
  msgstr ""
845
 
846
- #. translators: %s Link to Deposits for WooCommerce
847
- #: includes/wcal_all_component.php:123
848
- msgid ""
849
- " Allow your customers to pay deposits on products using our Deposits for WooCommerce plugin. <br>\r\n"
850
- " <strong><a target=\"_blank\" href= \"%s\">Purchase now</a></strong> & Grab 20% discount with the code \"DFWP20\". The discount code is valid only for the first 20 customers."
851
  msgstr ""
852
 
853
- #: woocommerce-ac.php:222
854
- #: woocommerce-ac.php:635
855
- #: woocommerce-ac.php:1808
856
  msgid "Settings"
857
  msgstr ""
858
 
859
- #: woocommerce-ac.php:249
860
  msgid "Emails are not being sent to customers."
861
  msgstr ""
862
 
863
- #: woocommerce-ac.php:255
864
  msgid "Capturing of cart and other information was not satisfactory."
865
  msgstr ""
866
 
867
- #: woocommerce-ac.php:261
868
  msgid "I cannot see abandoned cart reminder emails records."
869
  msgstr ""
870
 
871
- #: woocommerce-ac.php:267
872
  msgid "I want to upgrade the plugin to the PRO version."
873
  msgstr ""
874
 
875
- #: woocommerce-ac.php:371
876
  msgid "HTML Email Template"
877
  msgstr ""
878
 
879
- #: woocommerce-ac.php:377
880
  msgid "Abandoned cart Email Template"
881
  msgstr ""
882
 
883
- #: woocommerce-ac.php:642
884
  msgid "Enable abandoned cart emails"
885
  msgstr ""
886
 
887
- #: woocommerce-ac.php:646
888
  msgid "Yes, enable the abandoned cart emails."
889
  msgstr ""
890
 
891
- #: woocommerce-ac.php:651
892
  msgid "Cart abandoned cut-off time"
893
  msgstr ""
894
 
895
- #: woocommerce-ac.php:655
896
  msgid "Consider cart abandoned after X minutes of item being added to cart & order not placed."
897
  msgstr ""
898
 
899
- #: woocommerce-ac.php:660
900
  msgid "Automatically Delete Abandoned Orders after X days"
901
  msgstr ""
902
 
903
- #: woocommerce-ac.php:664
904
  msgid "Automatically delete abandoned cart orders after X days."
905
  msgstr ""
906
 
907
- #: woocommerce-ac.php:670
908
  msgid "Email admin On Order Recovery"
909
  msgstr ""
910
 
911
- #: woocommerce-ac.php:674
912
  msgid "Sends email to Admin if an Abandoned Cart Order is recovered."
913
  msgstr ""
914
 
915
- #: woocommerce-ac.php:680
916
  msgid "Start tracking from Cart Page"
917
  msgstr ""
918
 
919
- #: woocommerce-ac.php:684
920
  msgid "Enable tracking of abandoned products & carts even if customer does not visit the checkout page or does not enter any details on the checkout page like Name or Email. Tracking will begin as soon as a visitor adds a product to their cart and visits the cart page."
921
  msgstr ""
922
 
923
- #: woocommerce-ac.php:689
924
  msgid "Message to be displayed for Guest users when tracking their carts"
925
  msgstr ""
926
 
927
- #: woocommerce-ac.php:693
928
  msgid "<br>In compliance with GDPR, add a message on the Checkout page to inform Guest users of how their data is being used.<br><i>For example: Your email address will help us support your shopping experience throughout the site. Please check our Privacy Policy to see how we use your personal data.</i>"
929
  msgstr ""
930
 
931
- #: woocommerce-ac.php:698
932
  msgid "Message to be displayed for registered users when tracking their carts."
933
  msgstr ""
934
 
935
- #: woocommerce-ac.php:702
936
  msgid "<br>In compliance with GDPR, add a message on the Shop & Product pages to inform Registered users of how their data is being used.<br><i>For example: Please check our Privacy Policy to see how we use your personal data.</i>"
937
  msgstr ""
938
 
939
- #: woocommerce-ac.php:707
940
  msgid "Allow the visitor to opt out of cart tracking."
941
  msgstr ""
942
 
943
- #: woocommerce-ac.php:711
944
  msgid "<br>In compliance with GDPR, allow the site visitor (guests & registered users) to opt out from cart tracking. This message will be displayed in conjunction with the GDPR message above.</i>"
945
  msgstr ""
946
 
947
- #: woocommerce-ac.php:716
948
  msgid "Message to be displayed when the user chooses to opt out of cart tracking."
949
  msgstr ""
950
 
951
- #: woocommerce-ac.php:720
952
  msgid "<br>Message to be displayed when the user chooses to opt out of cart tracking.</i>"
953
  msgstr ""
954
 
955
- #: woocommerce-ac.php:730
956
  msgid "Settings for abandoned cart recovery emails"
957
  msgstr ""
958
 
959
- #: woocommerce-ac.php:737
960
  msgid "\"From\" Name"
961
  msgstr ""
962
 
963
- #: woocommerce-ac.php:746
964
  msgid "\"From\" Address"
965
  msgstr ""
966
 
967
- #: woocommerce-ac.php:755
968
  msgid "Send Reply Emails to"
969
  msgstr ""
970
 
971
- #: woocommerce-ac.php:880
972
  msgid "Abandoned cart cut off time should be numeric and has to be greater than 0."
973
  msgstr ""
974
 
975
- #: woocommerce-ac.php:896
976
  msgid "Automatically Delete Abandoned Orders after X days has to be greater than 0."
977
  msgstr ""
978
 
979
- #: woocommerce-ac.php:1805
980
  msgid "Dashboard"
981
  msgstr ""
982
 
983
- #: woocommerce-ac.php:1807
984
  msgid "Email Templates"
985
  msgstr ""
986
 
987
- #: woocommerce-ac.php:1809
988
  msgid "Recovered Orders"
989
  msgstr ""
990
 
991
- #: woocommerce-ac.php:1810
992
  msgid "Product Report"
993
  msgstr ""
994
 
995
- #: woocommerce-ac.php:2020
996
  msgid "You do not have sufficient permissions to access this page."
997
  msgstr ""
998
 
999
- #: woocommerce-ac.php:2024
1000
  msgid "WooCommerce - Abandon Cart Lite"
1001
  msgstr ""
1002
 
1003
- #: woocommerce-ac.php:2105
1004
  msgid "The Abandoned cart has been successfully deleted."
1005
  msgstr ""
1006
 
1007
- #: woocommerce-ac.php:2107
1008
  msgid "All Abandoned Carts have been successfully deleted."
1009
  msgstr ""
1010
 
1011
- #: woocommerce-ac.php:2109
1012
  msgid "All Visitor carts have been successfully deleted."
1013
  msgstr ""
1014
 
1015
- #: woocommerce-ac.php:2111
1016
  msgid "All Guest carts have been successfully deleted."
1017
  msgstr ""
1018
 
1019
- #: woocommerce-ac.php:2113
1020
  msgid "All Registered carts have been deleted."
1021
  msgstr ""
1022
 
1023
- #: woocommerce-ac.php:2124
1024
  msgid "The Template has been successfully deleted."
1025
  msgstr ""
1026
 
1027
- #: woocommerce-ac.php:2130
1028
  msgid "Change settings for sending email notifications to Customers, to Admin etc."
1029
  msgstr ""
1030
 
1031
- #: woocommerce-ac.php:2168
1032
  msgid "General Settings"
1033
  msgstr ""
1034
 
1035
- #: woocommerce-ac.php:2171
1036
  msgid "Email Sending Settings"
1037
  msgstr ""
1038
 
1039
- #: woocommerce-ac.php:2221
1040
  msgid "The list below shows all Abandoned Carts which have remained in cart for a time higher than the \"Cart abandoned cut-off time\" setting."
1041
  msgstr ""
1042
 
1043
- #: woocommerce-ac.php:2263
1044
  msgid "All "
1045
  msgstr ""
1046
 
1047
- #: woocommerce-ac.php:2268
 
1048
  msgid "Registered %s"
1049
  msgstr ""
1050
 
1051
- #: woocommerce-ac.php:2274
 
1052
  msgid "Guest %s"
1053
  msgstr ""
1054
 
1055
- #: woocommerce-ac.php:2280
1056
  msgid "Carts without Customer Details"
1057
  msgstr ""
1058
 
1059
- #: woocommerce-ac.php:2301
1060
  msgid "Add email templates at different intervals to maximize the possibility of recovering your abandoned carts."
1061
  msgstr ""
1062
 
1063
- #: woocommerce-ac.php:2421
1064
  msgid "The Email Template has been successfully added. In order to start sending this email to your customers, please activate it."
1065
  msgstr ""
1066
 
1067
- #: woocommerce-ac.php:2430
1068
  msgid "There was a problem adding the email template. Please contact the plugin author via <a href= \"https://wordpress.org/support/plugin/woocommerce-abandoned-cart\">support forum</a>."
1069
  msgstr ""
1070
 
1071
- #: woocommerce-ac.php:2441
1072
  msgid "The Email Template has been successfully updated."
1073
  msgstr ""
1074
 
1075
- #: woocommerce-ac.php:2450
1076
  msgid "There was a problem updating the email template. Please contact the plugin author via <a href= \"https://wordpress.org/support/plugin/woocommerce-abandoned-cart\">support forum</a>."
1077
  msgstr ""
1078
 
1079
- #: woocommerce-ac.php:2459
1080
  msgid "Add New Template"
1081
  msgstr ""
1082
 
1083
- #: woocommerce-ac.php:2536
1084
  msgid "The Report below shows how many Abandoned Carts we were able to recover for you by sending automatic emails to encourage shoppers."
1085
  msgstr ""
1086
 
1087
- #: woocommerce-ac.php:2585
1088
  msgid "Start Date:"
1089
  msgstr ""
1090
 
1091
- #: woocommerce-ac.php:2587
1092
  msgid "End Date:"
1093
  msgstr ""
1094
 
1095
- #: woocommerce-ac.php:2603
1096
- msgid "During the selected range <strong>%d</strong> carts totaling <strong>%s</strong> were abandoned. We were able to recover <strong>%d</strong> of them, which led to an extra <strong>%s</strong>"
 
1097
  msgstr ""
1098
 
1099
- #: woocommerce-ac.php:2622
 
1100
  msgid "Abandoned Order #%s Details"
1101
  msgstr ""
1102
 
1103
- #: woocommerce-ac.php:2630
1104
  msgid "Line Total"
1105
  msgstr ""
1106
 
1107
- #: woocommerce-ac.php:2818
1108
  msgid "Customer Details"
1109
  msgstr ""
1110
 
1111
- #: woocommerce-ac.php:2822
1112
  msgid "Billing Details"
1113
  msgstr ""
1114
 
1115
- #: woocommerce-ac.php:2823
1116
  msgid "Name:"
1117
  msgstr ""
1118
 
1119
- #: woocommerce-ac.php:2826
1120
- #: woocommerce-ac.php:2846
1121
  msgid "Address:"
1122
  msgstr ""
1123
 
1124
- #: woocommerce-ac.php:2836
1125
  msgid "Email:"
1126
  msgstr ""
1127
 
1128
- #: woocommerce-ac.php:2840
1129
  msgid "Phone:"
1130
  msgstr ""
1131
 
1132
- #: woocommerce-ac.php:2845
1133
  msgid "Shipping Details"
1134
  msgstr ""
1135
 
1136
- #: woocommerce-ac.php:2934
 
 
 
 
 
 
 
 
1137
  msgid "Template Name:"
1138
  msgstr ""
1139
 
1140
- #: woocommerce-ac.php:2943
1141
  msgid "Enter a template name for reference"
1142
  msgstr ""
1143
 
1144
- #: woocommerce-ac.php:2949
1145
  msgid "Subject:"
1146
  msgstr ""
1147
 
1148
- #: woocommerce-ac.php:2958
1149
  msgid "Enter the subject that should appear in the email sent"
1150
  msgstr ""
1151
 
1152
- #: woocommerce-ac.php:2964
1153
  msgid "Email Body:"
1154
  msgstr ""
1155
 
1156
- #: woocommerce-ac.php:2991
1157
  msgid "Message to be sent in the reminder email."
1158
  msgstr ""
1159
 
1160
- #: woocommerce-ac.php:3018
1161
  msgid "Use WooCommerce Template Style:"
1162
  msgstr ""
1163
 
1164
- #: woocommerce-ac.php:3040
1165
  msgid "Email Template Header Text: "
1166
  msgstr ""
1167
 
1168
- #: woocommerce-ac.php:3054
1169
  msgid "Enter the header which will appear in the abandoned WooCommerce email sent. This is only applicable when only used when \"Use WooCommerce Template Style:\" is checked."
1170
  msgstr ""
1171
 
1172
- #: woocommerce-ac.php:3060
1173
  msgid "Send this email:"
1174
  msgstr ""
1175
 
1176
- #: woocommerce-ac.php:3101
1177
  msgid "after cart is abandoned."
1178
  msgstr ""
1179
 
1180
- #: woocommerce-ac.php:3108
1181
  msgid "Send a test email to:"
1182
  msgstr ""
1183
 
1184
- #: woocommerce-ac.php:3113
1185
  msgid "Enter the email id to which the test email needs to be sent."
1186
  msgstr ""
1187
 
1188
- #: woocommerce-ac.php:3127
1189
  msgid "Update Changes"
1190
  msgstr ""
1191
 
1192
- #: woocommerce-ac.php:3148
1193
  msgid "If you love <strong>Abandoned Cart Lite for WooCommerce</strong>, then please leave us a <a href=\"https://wordpress.org/support/plugin/woocommerce-abandoned-cart/reviews/?rate=5#new-post\" target=\"_blank\" class=\"ac-rating-link\" data-rated=\"Thanks :)\">★★★★★</a> rating. Thank you in advance. :)"
1194
  msgstr ""
1195
 
1196
- #: woocommerce-ac.php:3353
1197
- #: woocommerce-ac.php:3388
1198
  msgid "Men's Formal Shoes"
1199
  msgstr ""
1200
 
1201
- #: woocommerce-ac.php:3360
1202
- #: woocommerce-ac.php:3395
1203
  msgid "Woman's Hand Bags"
1204
  msgstr ""
1
+ # Copyright (C) 2021 Tyche Softwares
2
  # This file is distributed under the same license as the Abandoned Cart Lite for WooCommerce plugin.
3
  msgid ""
4
  msgstr ""
5
+ "Project-Id-Version: Abandoned Cart Lite for WooCommerce 5.9.0\n"
6
+ "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/Woocommerce-abandon-cart-lite\n"
7
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
8
  "Language-Team: LANGUAGE <LL@li.org>\n"
9
  "MIME-Version: 1.0\n"
10
  "Content-Type: text/plain; charset=UTF-8\n"
11
  "Content-Transfer-Encoding: 8bit\n"
12
+ "POT-Creation-Date: 2021-07-26T11:45:57+00:00\n"
13
  "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
14
  "X-Generator: WP-CLI 2.4.0\n"
15
  "X-Domain: woocommerce-abandoned-cart\n"
23
  msgstr ""
24
 
25
  #. Description of the plugin
26
+ msgid "This plugin captures abandoned carts by logged-in users & emails them about it. <strong><a href=\"http://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro\">Click here to get the PRO Version.</a></strong>"
27
  msgstr ""
28
 
29
  #. Author of the plugin
34
  msgid "http://www.tychesoftwares.com/"
35
  msgstr ""
36
 
37
+ #: cron/class-wcal-cron.php:88
38
  msgid "Abandoned cart reminder"
39
  msgstr ""
40
 
41
+ #: cron/class-wcal-cron.php:293
42
+ #: woocommerce-ac.php:2964
43
+ #: woocommerce-ac.php:3775
44
+ #: woocommerce-ac.php:3810
45
  msgid "Quantity"
46
  msgstr ""
47
 
48
+ #: cron/class-wcal-cron.php:294
49
+ #: woocommerce-ac.php:3776
50
+ #: woocommerce-ac.php:3811
51
  msgid "Price"
52
  msgstr ""
53
 
54
+ #: cron/class-wcal-cron.php:295
55
+ #: woocommerce-ac.php:2965
56
+ #: woocommerce-ac.php:3777
57
+ #: woocommerce-ac.php:3812
58
  msgid "Line Subtotal"
59
  msgstr ""
60
 
61
+ #: cron/class-wcal-cron.php:300
62
+ #: cron/class-wcal-cron.php:311
63
+ #: woocommerce-ac.php:3771
64
+ #: woocommerce-ac.php:3805
65
  msgid "Your Shopping Cart"
66
  msgstr ""
67
 
68
+ #: cron/class-wcal-cron.php:302
69
+ #: cron/class-wcal-cron.php:313
70
+ #: woocommerce-ac.php:2962
71
+ #: woocommerce-ac.php:3773
72
+ #: woocommerce-ac.php:3808
73
  msgid "Item"
74
  msgstr ""
75
 
76
+ #: cron/class-wcal-cron.php:303
77
+ #: cron/class-wcal-cron.php:314
78
+ #: woocommerce-ac.php:2963
79
+ #: woocommerce-ac.php:3774
80
+ #: woocommerce-ac.php:3809
81
  msgid "Name"
82
  msgstr ""
83
 
84
+ #: cron/class-wcal-cron.php:337
85
+ #: cron/class-wcal-cron.php:369
86
+ msgid "SKU: "
87
+ msgstr ""
88
+
89
+ #: cron/class-wcal-cron.php:420
90
+ #: woocommerce-ac.php:3797
91
+ #: woocommerce-ac.php:3832
92
  msgid "Cart Total:"
93
  msgstr ""
94
 
95
+ #: cron/class-wcal-cron.php:432
96
  msgid "Product no longer exists"
97
  msgstr ""
98
 
99
+ #: cron/class-wcal-cron.php:645
100
+ #: cron/class-wcal-cron.php:714
101
+ #: includes/frontend/class-wcal-checkout-process.php:220
102
+ #: includes/frontend/class-wcal-checkout-process.php:550
103
  msgid "This order was abandoned & subsequently recovered."
104
  msgstr ""
105
 
108
  msgid "Cart #%s"
109
  msgstr ""
110
 
111
+ #: includes/admin/class-wcal-personal-data-eraser.php:46
112
+ #: includes/admin/class-wcal-personal-data-export.php:45
113
  msgid "Abandoned & Recovered Carts"
114
  msgstr ""
115
 
116
+ #: includes/admin/class-wcal-personal-data-eraser.php:99
117
  msgid "No personal data found for any abandoned carts."
118
  msgstr ""
119
 
120
  #. Translators: %s Abandoned Cart ID.
121
+ #: includes/admin/class-wcal-personal-data-eraser.php:133
122
  msgid "Removed personal data from cart %s."
123
  msgstr ""
124
 
125
  #. Translators: %s Abandoned Cart ID.
126
+ #: includes/admin/class-wcal-personal-data-eraser.php:137
127
  msgid "Personal data within cart %s has been retained."
128
  msgstr ""
129
 
130
+ #: includes/admin/class-wcal-personal-data-eraser.php:222
131
  msgid "ANONYMIZED"
132
  msgstr ""
133
 
134
+ #: includes/admin/class-wcal-personal-data-export.php:137
135
+ #: woocommerce-ac.php:1255
136
  msgid "Abandoned Carts"
137
  msgstr ""
138
 
139
+ #: includes/admin/class-wcal-personal-data-export.php:186
140
+ #: includes/admin/class-wcal-personal-data-export.php:202
141
  msgid "Abandoned Cart ID"
142
  msgstr ""
143
 
144
+ #: includes/admin/class-wcal-personal-data-export.php:187
145
+ #: includes/admin/class-wcal-personal-data-export.php:203
146
+ #: includes/classes/class-wcal-abandoned-orders-table.php:110
147
  msgid "Abandoned Date"
148
  msgstr ""
149
 
150
+ #: includes/admin/class-wcal-personal-data-export.php:188
151
+ #: includes/admin/class-wcal-personal-data-export.php:204
152
  msgid "Abandoned Cart Status"
153
  msgstr ""
154
 
155
+ #: includes/admin/class-wcal-personal-data-export.php:189
156
+ #: includes/admin/class-wcal-personal-data-export.php:205
157
  msgid "Cart Total"
158
  msgstr ""
159
 
160
+ #: includes/admin/class-wcal-personal-data-export.php:190
161
+ #: includes/admin/class-wcal-personal-data-export.php:206
162
  msgid "Items Present"
163
  msgstr ""
164
 
165
+ #: includes/admin/class-wcal-personal-data-export.php:191
166
  msgid "Session ID"
167
  msgstr ""
168
 
169
+ #: includes/admin/class-wcal-personal-data-export.php:192
170
+ #: includes/admin/class-wcal-personal-data-export.php:207
171
  msgid "Billing Address"
172
  msgstr ""
173
 
174
+ #: includes/admin/class-wcal-personal-data-export.php:193
175
+ #: includes/admin/class-wcal-personal-data-export.php:208
176
+ #: includes/classes/class-wcal-abandoned-orders-table.php:107
177
+ #: includes/classes/class-wcal-recover-orders-table.php:133
178
  msgid "Email Address"
179
  msgstr ""
180
 
181
+ #: includes/admin/class-wcal-personal-data-export.php:239
182
+ #: includes/admin/class-wcal-personal-data-export.php:242
183
  msgid "Cart Recovered - Order #"
184
  msgstr ""
185
 
186
+ #: includes/admin/class-wcal-personal-data-export.php:239
187
+ #: includes/classes/class-wcal-abandoned-orders-table.php:604
188
  msgid "Abandoned"
189
  msgstr ""
190
 
191
+ #: includes/admin/class-wcal-personal-data-export.php:242
192
  msgid "Abandoned but new cart created"
193
  msgstr ""
194
 
195
+ #: includes/admin/class-wcal-personal-data-export.php:245
196
  msgid "Abandoned - Unpaid Order #"
197
  msgstr ""
198
 
199
+ #: includes/admin/class-wcap-add-cart-popup-modal.php:84
200
+ #: includes/admin/class-wcap-pro-settings.php:66
201
+ #: includes/admin/class-wcap-pro-settings.php:384
202
+ #: woocommerce-ac.php:3531
203
+ msgid "Save Changes"
204
+ msgstr ""
205
+
206
+ #: includes/admin/class-wcap-add-cart-popup-modal.php:85
207
+ msgid "Reset to default configuration"
208
+ msgstr ""
209
+
210
+ #: includes/admin/class-wcap-add-cart-popup-modal.php:104
211
  msgid "Enable Add to cart popup modal"
212
  msgstr ""
213
 
214
+ #: includes/admin/class-wcap-add-cart-popup-modal.php:122
215
+ msgid "Please enter your email."
216
+ msgstr ""
217
+
218
+ #: includes/admin/class-wcap-add-cart-popup-modal.php:126
219
+ msgid "Modal Heading"
220
+ msgstr ""
221
+
222
+ #: includes/admin/class-wcap-add-cart-popup-modal.php:152
223
+ msgid "Modal Text"
224
+ msgstr ""
225
+
226
+ #: includes/admin/class-wcap-add-cart-popup-modal.php:177
227
+ msgid "Email placeholder"
228
+ msgstr ""
229
+
230
+ #: includes/admin/class-wcap-add-cart-popup-modal.php:198
231
+ msgid "Add to cart button text"
232
+ msgstr ""
233
+
234
+ #: includes/admin/class-wcap-add-cart-popup-modal.php:228
235
+ msgid "Email address is mandatory?"
236
+ msgstr ""
237
+
238
+ #: includes/admin/class-wcap-add-cart-popup-modal.php:252
239
+ msgid "Not mandatory text"
240
+ msgstr ""
241
+
242
+ #: includes/admin/class-wcap-add-cart-popup-modal.php:272
243
+ msgid "Capture Phone"
244
+ msgstr ""
245
+
246
+ #: includes/admin/class-wcap-add-cart-popup-modal.php:295
247
+ msgid "Phone placeholder"
248
+ msgstr ""
249
+
250
+ #: includes/admin/class-wcap-add-cart-popup-modal.php:298
251
+ #: includes/admin/class-wcap-add-cart-popup-modal.php:483
252
+ msgid "Please enter your phone number in E.164 format"
253
+ msgstr ""
254
+
255
+ #: includes/admin/class-wcap-add-cart-popup-modal.php:338
256
+ msgid "Auto apply coupons on email address capture:"
257
+ msgstr ""
258
+
259
+ #: includes/admin/class-wcap-add-cart-popup-modal.php:347
260
+ msgid "Type of Coupon to apply:"
261
  msgstr ""
262
 
263
+ #: includes/admin/class-wcap-add-cart-popup-modal.php:351
264
+ msgid "Existing Coupons"
 
265
  msgstr ""
266
 
267
+ #: includes/admin/class-wcap-add-cart-popup-modal.php:352
268
+ msgid "Generate Unique Coupon code"
269
  msgstr ""
270
 
271
+ #: includes/admin/class-wcap-add-cart-popup-modal.php:356
272
+ msgid "Coupon code to apply:"
273
  msgstr ""
274
 
275
+ #: includes/admin/class-wcap-add-cart-popup-modal.php:393
276
+ msgid "Discount Type:"
277
  msgstr ""
278
 
279
+ #: includes/admin/class-wcap-add-cart-popup-modal.php:397
280
+ msgid "Percentage Discount"
281
+ msgstr ""
282
+
283
+ #: includes/admin/class-wcap-add-cart-popup-modal.php:398
284
+ msgid "Fixed Cart Amount"
285
+ msgstr ""
286
+
287
+ #: includes/admin/class-wcap-add-cart-popup-modal.php:402
288
+ msgid "Discount Amount:"
289
+ msgstr ""
290
+
291
+ #: includes/admin/class-wcap-add-cart-popup-modal.php:408
292
+ msgid "Allow Free Shipping?"
293
+ msgstr ""
294
+
295
+ #: includes/admin/class-wcap-add-cart-popup-modal.php:414
296
+ msgid "Coupon validity (in minutes):"
297
+ msgstr ""
298
+
299
+ #: includes/admin/class-wcap-add-cart-popup-modal.php:420
300
+ msgid "Display Urgency message on Cart page (If disabled it will display only on Checkout page)"
301
+ msgstr ""
302
+
303
+ #: includes/admin/class-wcap-add-cart-popup-modal.php:429
304
+ msgid "Urgency message to boost your conversions"
305
+ msgstr ""
306
+
307
+ #: includes/admin/class-wcap-add-cart-popup-modal.php:434
308
+ msgid "Merge tags available: <coupon_code>, <hh:mm:ss>"
309
+ msgstr ""
310
+
311
+ #: includes/admin/class-wcap-add-cart-popup-modal.php:437
312
+ msgid "Message to display after coupon validity is reached"
313
+ msgstr ""
314
+
315
+ #: includes/admin/class-wcap-add-cart-popup-modal.php:444
316
+ msgid "Note: For orders which use the coupon selected/generated by the ATC module will be marked as \"ATC Coupon Used\" in WooCommerce->Orders."
317
+ msgstr ""
318
+
319
+ #: includes/admin/class-wcap-add-cart-popup-modal.php:472
320
+ msgid "Please enter your email address."
321
+ msgstr ""
322
+
323
+ #: includes/admin/class-wcap-add-cart-popup-modal.php:473
324
  msgid "To add this item to your cart, please enter your email address."
325
  msgstr ""
326
 
327
+ #: includes/admin/class-wcap-add-cart-popup-modal.php:480
 
328
  msgid "Email address"
329
  msgstr ""
330
 
331
+ #: includes/admin/class-wcap-add-cart-popup-modal.php:485
 
332
  msgid "Add to Cart"
333
  msgstr ""
334
 
335
+ #: includes/admin/class-wcap-add-cart-popup-modal.php:489
 
336
  msgid "No Thanks"
337
  msgstr ""
338
 
339
+ #: includes/admin/class-wcap-pro-settings-callbacks.php:33
340
+ msgid "Configure your Twilio account settings below. Please note that due to some restrictions from Twilio, customers <i>may sometimes</i> receive delayed messages"
341
  msgstr ""
342
 
343
+ #. translators: %s Purchase Link.
344
+ #: includes/admin/class-wcap-pro-settings.php:45
345
  msgid "Upgrade to <a href='%s' target='_blank'>Abandoned Cart Pro for WooCommerce</a> to enable the feature."
346
  msgstr ""
347
 
348
+ #: includes/admin/class-wcap-pro-settings.php:82
 
 
 
 
 
 
349
  msgid "Cart abandoned cut-off time for guest users"
350
  msgstr ""
351
 
352
+ #: includes/admin/class-wcap-pro-settings.php:86
353
  msgid "For guest users & visitors consider cart abandoned after X minutes of item being added to cart & order not placed."
354
  msgstr ""
355
 
356
+ #: includes/admin/class-wcap-pro-settings.php:91
357
  msgid "Do not track carts of guest users"
358
  msgstr ""
359
 
360
+ #: includes/admin/class-wcap-pro-settings.php:95
361
  msgid "Abandoned carts of guest users will not be tracked."
362
  msgstr ""
363
 
364
+ #: includes/admin/class-wcap-pro-settings.php:100
365
  msgid "Do not track carts of logged-in users"
366
  msgstr ""
367
 
368
+ #: includes/admin/class-wcap-pro-settings.php:104
369
  msgid "Abandoned carts of logged-in users will not be tracked."
370
  msgstr ""
371
 
372
+ #: includes/admin/class-wcap-pro-settings.php:109
373
+ msgid "Send reminder emails for newly abandoned carts after X days of order placement"
374
+ msgstr ""
375
+
376
+ #: includes/admin/class-wcap-pro-settings.php:113
377
+ msgid "Reminder emails will be sent for newly abandoned carts only after X days of a previously placed order for a user with the same email address as that of the abandoned cart"
378
+ msgstr ""
379
+
380
+ #: includes/admin/class-wcap-pro-settings.php:118
381
+ msgid "Capture email address from custom fields."
382
+ msgstr ""
383
+
384
+ #: includes/admin/class-wcap-pro-settings.php:122
385
+ msgid "Enable this setting to capture email address from other form fields."
386
+ msgstr ""
387
+
388
+ #: includes/admin/class-wcap-pro-settings.php:127
389
+ msgid "Class names of the form fields."
390
+ msgstr ""
391
+
392
+ #: includes/admin/class-wcap-pro-settings.php:131
393
+ msgid "Enter class names of fields separated by commas from where email needs to be captured."
394
+ msgstr ""
395
+
396
+ #: includes/admin/class-wcap-pro-settings.php:136
397
  msgid "Capture Email address from URL"
398
  msgstr ""
399
 
400
+ #: includes/admin/class-wcap-pro-settings.php:140
401
  msgid "If your site URL contain the same key, then it will capture it as an email address of customer."
402
  msgstr ""
403
 
404
+ #: includes/admin/class-wcap-pro-settings.php:145
405
+ msgid "Remove Data on Uninstall?"
406
+ msgstr ""
407
+
408
+ #: includes/admin/class-wcap-pro-settings.php:149
409
+ msgid "Enable this setting if you want to completely remove Abandoned Cart data when plugin is deleted."
410
+ msgstr ""
411
+
412
+ #: includes/admin/class-wcap-pro-settings.php:154
413
+ msgid "Add Product to Cart when Close Icon is clicked?"
414
+ msgstr ""
415
+
416
+ #: includes/admin/class-wcap-pro-settings.php:158
417
+ msgid "Enable this setting if you want the product to the added to cart when the user clicks on the Close Icon in the Add to Cart Popup Modal."
418
+ msgstr ""
419
+
420
+ #: includes/admin/class-wcap-pro-settings.php:163
421
+ msgid "Enable Email Verification:"
422
+ msgstr ""
423
+
424
+ #: includes/admin/class-wcap-pro-settings.php:167
425
+ msgid "Enable this checkbox to allow email verification to be done via DeBounce API services."
426
+ msgstr ""
427
+
428
+ #: includes/admin/class-wcap-pro-settings.php:172
429
+ msgid "Enter DeBounce API Key"
430
+ msgstr ""
431
+
432
+ #: includes/admin/class-wcap-pro-settings.php:176
433
+ msgid "Enter DeBounce JS API Key."
434
+ msgstr ""
435
+
436
+ #: includes/admin/class-wcap-pro-settings.php:181
437
+ msgid "Coupon Settings"
438
+ msgstr ""
439
+
440
+ #: includes/admin/class-wcap-pro-settings.php:188
441
+ msgid "Delete Coupons Automatically"
442
+ msgstr ""
443
+
444
+ #: includes/admin/class-wcap-pro-settings.php:192
445
+ msgid "Enable this setting if you want to completely remove the expired and used coupon code automatically every 15 days."
446
+ msgstr ""
447
+
448
+ #: includes/admin/class-wcap-pro-settings.php:197
449
+ msgid "Delete Coupons Manually"
450
+ msgstr ""
451
+
452
+ #: includes/admin/class-wcap-pro-settings.php:201
453
+ msgid "If you want to completely remove the expired and used coupon code now then click on \"Delete\" button."
454
+ msgstr ""
455
+
456
+ #: includes/admin/class-wcap-pro-settings.php:266
457
  msgid "Product Image( H x W )"
458
  msgstr ""
459
 
460
+ #: includes/admin/class-wcap-pro-settings.php:270
461
  msgid "This setting affects the dimension of the product image in the abandoned cart reminder email."
462
  msgstr ""
463
 
464
+ #: includes/admin/class-wcap-pro-settings.php:294
465
  msgid "Setting for sending Emails & SMS using Action Scheduler"
466
  msgstr ""
467
 
468
+ #: includes/admin/class-wcap-pro-settings.php:301
469
  msgid "Send Abandoned cart emails automatically using Action Scheduler"
470
  msgstr ""
471
 
472
+ #: includes/admin/class-wcap-pro-settings.php:305
473
  msgid "Enabling this setting will send the abandoned cart reminder emails to the customer after the set time. If disabled, abandoned cart reminder emails will not be sent using the Action Scheduler. You will need to set cron job manually from cPanel. If you are unsure how to set the cron job, please <a href= mailto:support@tychesoftwares.com>contact us</a> for it."
474
  msgstr ""
475
 
476
+ #: includes/admin/class-wcap-pro-settings.php:310
477
  msgid "Run automated Scheduler every X minutes"
478
  msgstr ""
479
 
480
+ #: includes/admin/class-wcap-pro-settings.php:314
481
  msgid "The duration in minutes after which an action should be automatically scheduled to send email, SMS & FB reminders to customers."
482
  msgstr ""
483
 
484
+ #: includes/admin/class-wcap-pro-settings.php:319
485
  msgid "Rules to exclude capturing abandoned carts"
486
  msgstr ""
487
 
488
+ #: includes/admin/class-wcap-pro-settings.php:326
489
  msgid "Do not capture abandoned carts for these IP addresses"
490
  msgstr ""
491
 
492
+ #: includes/admin/class-wcap-pro-settings.php:330
493
  msgid "The carts abandoned from these IP addresses will not be tracked by the plugin. Accepts wildcards, e.g <code>192.168.*</code> will block all IP addresses which starts from \"192.168\". <i>Separate IP addresses with commas.</i>"
494
  msgstr ""
495
 
496
+ #: includes/admin/class-wcap-pro-settings.php:335
497
  msgid "Do not capture abandoned carts for these email addresses"
498
  msgstr ""
499
 
500
+ #: includes/admin/class-wcap-pro-settings.php:339
501
  msgid "The carts abandoned using these email addresses will not be tracked by the plugin. <i>Separate email addresses with commas.</i>"
502
  msgstr ""
503
 
504
+ #: includes/admin/class-wcap-pro-settings.php:344
505
  msgid "Do not capture abandoned carts for email addresses from these domains"
506
  msgstr ""
507
 
508
+ #: includes/admin/class-wcap-pro-settings.php:348
509
  msgid "The carts abandoned from email addresses with these domains will not be tracked by the plugin. <i>Separate email address domains with commas.</i>"
510
  msgstr ""
511
 
512
+ #: includes/admin/class-wcap-pro-settings.php:353
513
+ msgid "Unsubscribe Settings"
514
+ msgstr ""
515
+
516
+ #: includes/admin/class-wcap-pro-settings.php:361
517
+ msgid "Unsubscribe Landing Page"
518
+ msgstr ""
519
+
520
+ #: includes/admin/class-wcap-pro-settings.php:390
521
  msgid "Send Test SMS"
522
  msgstr ""
523
 
524
+ #: includes/admin/class-wcap-pro-settings.php:394
525
  msgid "Recipient"
526
  msgstr ""
527
 
528
+ #: includes/admin/class-wcap-pro-settings.php:397
529
  msgid "Must be a valid phone number in E.164 format."
530
  msgstr ""
531
 
532
+ #: includes/admin/class-wcap-pro-settings.php:402
533
  msgid "Message"
534
  msgstr ""
535
 
536
+ #: includes/admin/class-wcap-pro-settings.php:403
537
  msgid "Hello World!"
538
  msgstr ""
539
 
540
+ #: includes/admin/class-wcap-pro-settings.php:425
541
  msgid "Twilio"
542
  msgstr ""
543
 
544
+ #: includes/admin/class-wcap-pro-settings.php:432
545
  msgid "Enable SMS"
546
  msgstr ""
547
 
548
+ #: includes/admin/class-wcap-pro-settings.php:436
549
  msgid "<i>Enable the ability to send reminder SMS for abandoned carts.</i>"
550
  msgstr ""
551
 
552
+ #: includes/admin/class-wcap-pro-settings.php:441
553
  msgid "From"
554
  msgstr ""
555
 
556
+ #: includes/admin/class-wcap-pro-settings.php:445
557
  msgid "<i>Must be a Twilio phone number (in E.164 format) or alphanumeric sender ID.</i>"
558
  msgstr ""
559
 
560
+ #: includes/admin/class-wcap-pro-settings.php:450
561
  msgid "Account SID"
562
  msgstr ""
563
 
564
+ #: includes/admin/class-wcap-pro-settings.php:459
565
  msgid "Auth Token"
566
  msgstr ""
567
 
568
+ #: includes/admin/class-wcap-pro-settings.php:488
569
  msgid "Facebook Messenger Settings"
570
  msgstr ""
571
 
572
+ #: includes/admin/class-wcap-pro-settings.php:495
573
  msgid "Enable Facebook Messenger Reminders"
574
  msgstr ""
575
 
576
+ #: includes/admin/class-wcap-pro-settings.php:499
577
  msgid "<i>This option will display a checkbox after the Add to cart button for user consent to connect with Facebook.</i>"
578
  msgstr ""
579
 
580
+ #: includes/admin/class-wcap-pro-settings.php:504
581
  msgid "Facebook Messenger on Add to Cart Pop-up modal"
582
  msgstr ""
583
 
584
+ #: includes/admin/class-wcap-pro-settings.php:508
585
  msgid "<i>This option will display a checkbox on the pop-up modal to connect with Facebook.</i>"
586
  msgstr ""
587
 
588
+ #: includes/admin/class-wcap-pro-settings.php:513
589
  msgid "Icon size of user"
590
  msgstr ""
591
 
592
+ #: includes/admin/class-wcap-pro-settings.php:518
593
  msgid "<i>Select the size of user icon which shall be displayed below the checkbox in case the user is logged in.</i>"
594
  msgstr ""
595
 
596
+ #: includes/admin/class-wcap-pro-settings.php:521
597
  msgid "Small"
598
  msgstr ""
599
 
600
+ #: includes/admin/class-wcap-pro-settings.php:522
601
  msgid "Medium"
602
  msgstr ""
603
 
604
+ #: includes/admin/class-wcap-pro-settings.php:523
605
  msgid "Large"
606
  msgstr ""
607
 
608
+ #: includes/admin/class-wcap-pro-settings.php:524
609
  msgid "Standard"
610
  msgstr ""
611
 
612
+ #: includes/admin/class-wcap-pro-settings.php:525
613
  msgid "Extra Large"
614
  msgstr ""
615
 
616
+ #: includes/admin/class-wcap-pro-settings.php:532
617
  msgid "Consent text"
618
  msgstr ""
619
 
620
+ #: includes/admin/class-wcap-pro-settings.php:536
621
  msgid "<i>Text that will appear above the consent checkbox. HTML tags are also allowed.</i>"
622
  msgstr ""
623
 
624
+ #: includes/admin/class-wcap-pro-settings.php:541
625
  msgid "Facebook Page ID"
626
  msgstr ""
627
 
628
+ #: includes/admin/class-wcap-pro-settings.php:545
629
  msgid "<i>Facebook Page ID in numberic format. You can find your page ID from <a href='https://www.tychesoftwares.com/docs/docs/abandoned-cart-pro-for-woocommerce/send-abandoned-cart-reminder-notifications-using-facebook-messenger#fbpageid' target='_blank'>here</a></i>"
630
  msgstr ""
631
 
632
+ #: includes/admin/class-wcap-pro-settings.php:550
633
  msgid "Messenger App ID"
634
  msgstr ""
635
 
636
+ #: includes/admin/class-wcap-pro-settings.php:554
637
  msgid "<i>Enter your Messenger App ID</i>"
638
  msgstr ""
639
 
640
+ #: includes/admin/class-wcap-pro-settings.php:559
641
  msgid "Facebook Page Token"
642
  msgstr ""
643
 
644
+ #: includes/admin/class-wcap-pro-settings.php:563
645
  msgid "<i>Enter your Facebook Page Token</i>"
646
  msgstr ""
647
 
648
+ #: includes/admin/class-wcap-pro-settings.php:568
649
  msgid "Verify Token"
650
  msgstr ""
651
 
652
+ #: includes/admin/class-wcap-pro-settings.php:572
653
  msgid "<i>Enter your Verify Token</i>"
654
  msgstr ""
655
 
656
+ #. Translators: Plugin Name and URL.
657
+ #: includes/class-wcal-admin-notice.php:42
658
+ msgid "The %1$s now uses the Action Scheduler library to send reminders. For further details, please visit %2$s."
659
+ msgstr ""
660
+
661
+ #: includes/class-wcal-admin-notice.php:69
662
+ msgid "We need to update your email template database for some improvements. Please take a backup of your databases for your piece of mind."
663
+ msgstr ""
664
+
665
+ #: includes/class-wcal-admin-notice.php:72
666
+ msgid "Update"
667
+ msgstr ""
668
+
669
+ #. translators: %1$s Link to Differences article, %2$s link to pro version
670
+ #: includes/class-wcal-all-component.php:84
671
+ msgid "Now that you are all set with the Lite version, you can upgrade to Pro version to take your abandoned cart recovery to the next level. You can capture customer’s email address when they click Add to Cart, get access to 11 unique, fully responsive email templates, send text messages for recovery & <strong><a target=\"_blank\" href= \"%1$s\">much more</a></strong>. <strong><a target=\"_blank\" href= \"%2$s\">Purchase now</a></strong>."
672
+ msgstr ""
673
+
674
+ #. translators: %s Link to Abandoned Cart Pro
675
+ #: includes/class-wcal-all-component.php:88
676
+ msgid "Boost your sales by recovering up to 60% of the abandoned carts with our Abandoned Cart Pro for WooCommerce plugin. You can capture customer email addresses right when they click the Add To Cart button. <strong><a target=\"_blank\" href= \"%s\"> Grab your copy of Abandon Cart Pro plugin now!</a></strong>"
677
+ msgstr ""
678
+
679
+ #. translators: %s Link to Abandoned Cart Pro
680
+ #: includes/class-wcal-all-component.php:92
681
+ msgid "Don't loose your sales to abandoned carts. Use our Abandon Cart Pro plugin & start recovering your lost sales in less then 60 seconds. <strong><a target=\"_blank\" href= \"%s\">Grab it now!</a></strong>."
682
+ msgstr ""
683
+
684
+ #. translators: %s Link to Abandoned Cart Pro
685
+ #: includes/class-wcal-all-component.php:96
686
+ msgid "Send Abandoned Cart reminders that actually convert. Take advantage of our fully responsive email templates designed specially with an intent to trigger conversion. <strong><a target=\"_blank\" href= \"%s\">Purchase now</a></strong>."
687
+ msgstr ""
688
+
689
+ #. translators: Pro version link.
690
+ #: includes/class-wcal-all-component.php:103
691
+ msgid ""
692
+ "Increase your store sales by recovering your abandoned carts for just $119. No profit sharing, no monthly fees. Our Abandoned Cart Pro plugin comes with a 30 day money back guarantee as well. :) Use coupon code ACPRO20 & save $24!<br>\r\n"
693
+ " <strong><a target=\"_blank\" href= \"%s\">Grab your copy now!</a></strong>"
694
+ msgstr ""
695
+
696
+ #. translators: %s Link to Order Delivery Date Pro
697
+ #: includes/class-wcal-all-component.php:114
698
+ msgid "Reduce cart abandonment rate by 57% with our Order Delivery Date Pro WooCommerce plugin. You can Create Delivery Settings by Shipping Zones & Shipping Classes. <br>Use discount code \"ORDPRO20\" and grab 20% discount on the purchase of the plugin. The discount code is valid only for the first 20 customers. <strong><a target=\"_blank\" href= \"%s\">Purchase now</a></strong>"
699
  msgstr ""
700
 
701
+ #. translators: Order Delivery Date Pro link.
702
+ #: includes/class-wcal-all-component.php:121
703
+ msgid ""
704
+ "Allow your customers to select the Delivery Date on Single Product Page using our Product Delivery Date pro for WooCommerce Plugin. <br>\r\n"
705
+ " <strong><a target=\"_blank\" href= \"%s\">Shop now</a></strong> & be one of the 20 customers to get 20% discount on the plugin price. Use the code \"PRDPRO20\". Hurry!!"
706
  msgstr ""
707
 
708
+ #. translators: %s Link to WooCommerce Booking Plugin
709
+ #: includes/class-wcal-all-component.php:132
710
+ msgid "Allow your customers to book an appointment or rent an apartment with our Booking and Appointment for WooCommerce plugin. You can also sell your product as a resource or integrate with a few Vendor plugins. <br>Shop now & Save 20% on the plugin with the code \"BKAP20\". Only for first 20 customers. <strong><a target=\"_blank\" href= \"%s\">Have it now!</a></strong>"
711
  msgstr ""
712
 
713
+ #. translators: Deposits for WC pro plugin link.
714
+ #: includes/class-wcal-all-component.php:139
715
+ msgid ""
716
+ " Allow your customers to pay deposits on products using our Deposits for WooCommerce plugin. <br>\r\n"
717
+ " <strong><a target=\"_blank\" href= \"%s\">Purchase now</a></strong> & Grab 20% discount with the code \"DFWP20\". The discount code is valid only for the first 20 customers."
718
+ msgstr ""
719
+
720
+ #: includes/class-wcal-common.php:674
721
+ msgid "Database Updated Successfully"
722
+ msgstr ""
723
+
724
+ #: includes/class-wcal-common.php:689
725
+ msgid "Database Update Failed. Please try again after sometime"
726
+ msgstr ""
727
+
728
+ #: includes/class-wcal-common.php:849
729
+ msgid "This product no longer exists"
730
+ msgstr ""
731
+
732
+ #: includes/classes/class-wcal-abandoned-orders-table.php:59
733
  msgid "abandoned_order_id"
734
  msgstr ""
735
 
736
+ #: includes/classes/class-wcal-abandoned-orders-table.php:60
737
  msgid "abandoned_order_ids"
738
  msgstr ""
739
 
740
+ #: includes/classes/class-wcal-abandoned-orders-table.php:106
741
  msgid "Id"
742
  msgstr ""
743
 
744
+ #: includes/classes/class-wcal-abandoned-orders-table.php:108
745
  msgid "Customer"
746
  msgstr ""
747
 
748
+ #: includes/classes/class-wcal-abandoned-orders-table.php:109
749
+ #: includes/classes/class-wcal-recover-orders-table.php:136
750
  msgid "Order Total"
751
  msgstr ""
752
 
753
+ #: includes/classes/class-wcal-abandoned-orders-table.php:111
754
  msgid "Status of Cart"
755
  msgstr ""
756
 
757
+ #: includes/classes/class-wcal-abandoned-orders-table.php:173
758
+ #: includes/classes/class-wcal-abandoned-orders-table.php:745
759
  msgid "View order"
760
  msgstr ""
761
 
762
+ #: includes/classes/class-wcal-abandoned-orders-table.php:183
763
+ #: includes/classes/class-wcal-abandoned-orders-table.php:785
764
+ #: includes/classes/class-wcal-templates-table.php:175
765
+ #: includes/classes/class-wcal-templates-table.php:365
766
  msgid "Delete"
767
  msgstr ""
768
 
769
+ #: includes/classes/class-wcal-abandoned-orders-table.php:526
770
  msgid "User Deleted"
771
  msgstr ""
772
 
773
+ #: includes/classes/class-wcal-abandoned-orders-table.php:596
774
+ msgid "items"
775
  msgstr ""
776
 
777
+ #: includes/classes/class-wcal-abandoned-orders-table.php:598
778
+ msgid "item"
779
  msgstr ""
780
 
781
+ #: includes/classes/class-wcal-abandoned-orders-table.php:602
782
  msgid "Unsubscribed"
783
  msgstr ""
784
 
785
+ #: includes/classes/class-wcal-abandoned-orders-table.php:786
786
  msgid "Delete All Registered User Carts"
787
  msgstr ""
788
 
789
+ #: includes/classes/class-wcal-abandoned-orders-table.php:787
790
  msgid "Delete All Guest User Carts"
791
  msgstr ""
792
 
793
+ #: includes/classes/class-wcal-abandoned-orders-table.php:788
794
  msgid "Delete All Visitor Carts"
795
  msgstr ""
796
 
797
+ #: includes/classes/class-wcal-abandoned-orders-table.php:789
798
  msgid "Delete All Carts"
799
  msgstr ""
800
 
801
+ #: includes/classes/class-wcal-dashboard-report.php:112
802
  msgid "Recovered Amount"
803
  msgstr ""
804
 
805
+ #: includes/classes/class-wcal-dashboard-report.php:117
806
+ #: includes/classes/class-wcal-dashboard-report.php:166
807
+ #: includes/classes/class-wcal-dashboard-report.php:201
808
+ #: includes/classes/class-wcal-dashboard-report.php:236
809
+ #: includes/classes/class-wcal-recover-orders-table.php:170
810
  msgid "View Details"
811
  msgstr ""
812
 
813
  #. translators: Count of carts recovered.
814
+ #: includes/classes/class-wcal-dashboard-report.php:128
815
  msgid "<strong>%s</strong> Recovered Orders"
816
  msgstr ""
817
 
818
  #. translators: recovered percent of carts.
819
+ #: includes/classes/class-wcal-dashboard-report.php:135
820
  msgid "<strong>%s%%</strong> of Abandoned Carts Recovered"
821
  msgstr ""
822
 
823
  #. translators: Percent of sales.
824
+ #: includes/classes/class-wcal-dashboard-report.php:142
825
  msgid "<strong>%s%%</strong> of Total Revenue"
826
  msgstr ""
827
 
828
+ #: includes/classes/class-wcal-dashboard-report.php:161
829
+ #: woocommerce-ac.php:2086
830
  msgid "Abandoned Orders"
831
  msgstr ""
832
 
833
  #. translators: Abandoned Orders amount.
834
+ #: includes/classes/class-wcal-dashboard-report.php:177
835
  msgid "%s amount of Abandoned Orders"
836
  msgstr ""
837
 
838
+ #: includes/classes/class-wcal-dashboard-report.php:196
839
  msgid "Number of Emails Sent"
840
  msgstr ""
841
 
842
  #. translators: Link to Purchase the Pro version of the plugin.
843
+ #: includes/classes/class-wcal-dashboard-report.php:212
844
  msgid "Upgrade to <a href='%s' target='_blank'>Abandoned Cart Pro for WooCommerce</a> to view the number of emails opened and links clicked."
845
  msgstr ""
846
 
847
+ #: includes/classes/class-wcal-dashboard-report.php:231
848
  msgid "Emails Captured"
849
  msgstr ""
850
 
851
  #. translators: Number of guest emails captured.
852
+ #: includes/classes/class-wcal-dashboard-report.php:247
853
  msgid "%s Guest emails captured."
854
  msgstr ""
855
 
856
  #. translators: Link to Purchase the Pro version.
857
+ #: includes/classes/class-wcal-dashboard-report.php:253
858
  msgid "Upgrade to <a href='%s' target='_blank'>Abandoned Cart Pro for WooCommerce</a> to capture more guest carts."
859
  msgstr ""
860
 
861
+ #: includes/classes/class-wcal-dashboard-report.php:278
862
  msgid "This Month"
863
  msgstr ""
864
 
865
+ #: includes/classes/class-wcal-dashboard-report.php:279
866
  msgid "Last Month"
867
  msgstr ""
868
 
869
+ #: includes/classes/class-wcal-dashboard-report.php:280
870
  msgid "This Quarter"
871
  msgstr ""
872
 
873
+ #: includes/classes/class-wcal-dashboard-report.php:281
874
  msgid "Last Quarter"
875
  msgstr ""
876
 
877
+ #: includes/classes/class-wcal-dashboard-report.php:282
878
  msgid "This Year"
879
  msgstr ""
880
 
881
+ #: includes/classes/class-wcal-dashboard-report.php:283
882
  msgid "Last Year"
883
  msgstr ""
884
 
885
+ #: includes/classes/class-wcal-dashboard-report.php:284
886
  msgid "Custom"
887
  msgstr ""
888
 
889
+ #: includes/classes/class-wcal-dashboard-report.php:299
890
  msgid "Select date range:"
891
  msgstr ""
892
 
893
+ #: includes/classes/class-wcal-dashboard-report.php:319
894
+ #: woocommerce-ac.php:2915
895
  msgid "Go"
896
  msgstr ""
897
 
898
+ #: includes/classes/class-wcal-product-report-table.php:61
899
  msgid "product_id"
900
  msgstr ""
901
 
902
+ #: includes/classes/class-wcal-product-report-table.php:62
903
  msgid "product_ids"
904
  msgstr ""
905
 
906
+ #: includes/classes/class-wcal-product-report-table.php:98
907
  msgid "Product Name"
908
  msgstr ""
909
 
910
+ #: includes/classes/class-wcal-product-report-table.php:99
911
  msgid "Number of Times Abandoned"
912
  msgstr ""
913
 
914
+ #: includes/classes/class-wcal-product-report-table.php:100
915
  msgid "Number of Times Recovered"
916
  msgstr ""
917
 
918
+ #: includes/classes/class-wcal-recover-orders-table.php:90
919
  msgid "rec_abandoned_id"
920
  msgstr ""
921
 
922
+ #: includes/classes/class-wcal-recover-orders-table.php:91
923
  msgid "rec_abandoned_ids"
924
  msgstr ""
925
 
926
+ #: includes/classes/class-wcal-recover-orders-table.php:132
927
  msgid "Customer Name"
928
  msgstr ""
929
 
930
+ #: includes/classes/class-wcal-recover-orders-table.php:134
931
  msgid "Cart Abandoned Date"
932
  msgstr ""
933
 
934
+ #: includes/classes/class-wcal-recover-orders-table.php:135
935
  msgid "Cart Recovered Date"
936
  msgstr ""
937
 
938
+ #: includes/classes/class-wcal-templates-table.php:57
939
  msgid "template_id"
940
  msgstr ""
941
 
942
+ #: includes/classes/class-wcal-templates-table.php:58
943
  msgid "template_ids"
944
  msgstr ""
945
 
946
+ #: includes/classes/class-wcal-templates-table.php:99
947
  msgid "Sr"
948
  msgstr ""
949
 
950
+ #: includes/classes/class-wcal-templates-table.php:100
951
  msgid "Name Of Template"
952
  msgstr ""
953
 
954
+ #: includes/classes/class-wcal-templates-table.php:101
955
  msgid "Sent After Set Time"
956
  msgstr ""
957
 
958
+ #: includes/classes/class-wcal-templates-table.php:102
959
  msgid "Active ?"
960
  msgstr ""
961
 
962
+ #: includes/classes/class-wcal-templates-table.php:165
963
  msgid "Edit"
964
  msgstr ""
965
 
966
+ #: includes/classes/class-wcal-templates-table.php:215
967
+ msgid "After Abandonment"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
968
  msgstr ""
969
 
970
+ #: includes/classes/class-wcal-templates-table.php:338
971
+ msgid "on"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
972
  msgstr ""
973
 
974
+ #: includes/classes/class-wcal-templates-table.php:341
975
+ msgid "off"
 
 
 
976
  msgstr ""
977
 
978
+ #: includes/templates/rules/html-rules-engine.php:106
979
+ msgid "Add rules as needed to create different email templates for different user bases. "
 
980
  msgstr ""
981
 
982
+ #. Translators: Plugin purchase Link.
983
+ #: includes/templates/rules/html-rules-engine.php:108
984
+ msgid "<b><i>Upgrade to <a href='%s' target='_blank'>Abandoned Cart Pro for WooCommerce</a> to enable the feature.</i></b>"
 
 
985
  msgstr ""
986
 
987
+ #: woocommerce-ac.php:292
988
+ #: woocommerce-ac.php:731
989
+ #: woocommerce-ac.php:2100
990
  msgid "Settings"
991
  msgstr ""
992
 
993
+ #: woocommerce-ac.php:321
994
  msgid "Emails are not being sent to customers."
995
  msgstr ""
996
 
997
+ #: woocommerce-ac.php:327
998
  msgid "Capturing of cart and other information was not satisfactory."
999
  msgstr ""
1000
 
1001
+ #: woocommerce-ac.php:333
1002
  msgid "I cannot see abandoned cart reminder emails records."
1003
  msgstr ""
1004
 
1005
+ #: woocommerce-ac.php:339
1006
  msgid "I want to upgrade the plugin to the PRO version."
1007
  msgstr ""
1008
 
1009
+ #: woocommerce-ac.php:462
1010
  msgid "HTML Email Template"
1011
  msgstr ""
1012
 
1013
+ #: woocommerce-ac.php:468
1014
  msgid "Abandoned cart Email Template"
1015
  msgstr ""
1016
 
1017
+ #: woocommerce-ac.php:738
1018
  msgid "Enable abandoned cart emails"
1019
  msgstr ""
1020
 
1021
+ #: woocommerce-ac.php:742
1022
  msgid "Yes, enable the abandoned cart emails."
1023
  msgstr ""
1024
 
1025
+ #: woocommerce-ac.php:747
1026
  msgid "Cart abandoned cut-off time"
1027
  msgstr ""
1028
 
1029
+ #: woocommerce-ac.php:751
1030
  msgid "Consider cart abandoned after X minutes of item being added to cart & order not placed."
1031
  msgstr ""
1032
 
1033
+ #: woocommerce-ac.php:756
1034
  msgid "Automatically Delete Abandoned Orders after X days"
1035
  msgstr ""
1036
 
1037
+ #: woocommerce-ac.php:760
1038
  msgid "Automatically delete abandoned cart orders after X days."
1039
  msgstr ""
1040
 
1041
+ #: woocommerce-ac.php:765
1042
  msgid "Email admin On Order Recovery"
1043
  msgstr ""
1044
 
1045
+ #: woocommerce-ac.php:769
1046
  msgid "Sends email to Admin if an Abandoned Cart Order is recovered."
1047
  msgstr ""
1048
 
1049
+ #: woocommerce-ac.php:774
1050
  msgid "Start tracking from Cart Page"
1051
  msgstr ""
1052
 
1053
+ #: woocommerce-ac.php:778
1054
  msgid "Enable tracking of abandoned products & carts even if customer does not visit the checkout page or does not enter any details on the checkout page like Name or Email. Tracking will begin as soon as a visitor adds a product to their cart and visits the cart page."
1055
  msgstr ""
1056
 
1057
+ #: woocommerce-ac.php:783
1058
  msgid "Message to be displayed for Guest users when tracking their carts"
1059
  msgstr ""
1060
 
1061
+ #: woocommerce-ac.php:787
1062
  msgid "<br>In compliance with GDPR, add a message on the Checkout page to inform Guest users of how their data is being used.<br><i>For example: Your email address will help us support your shopping experience throughout the site. Please check our Privacy Policy to see how we use your personal data.</i>"
1063
  msgstr ""
1064
 
1065
+ #: woocommerce-ac.php:792
1066
  msgid "Message to be displayed for registered users when tracking their carts."
1067
  msgstr ""
1068
 
1069
+ #: woocommerce-ac.php:796
1070
  msgid "<br>In compliance with GDPR, add a message on the Shop & Product pages to inform Registered users of how their data is being used.<br><i>For example: Please check our Privacy Policy to see how we use your personal data.</i>"
1071
  msgstr ""
1072
 
1073
+ #: woocommerce-ac.php:801
1074
  msgid "Allow the visitor to opt out of cart tracking."
1075
  msgstr ""
1076
 
1077
+ #: woocommerce-ac.php:805
1078
  msgid "<br>In compliance with GDPR, allow the site visitor (guests & registered users) to opt out from cart tracking. This message will be displayed in conjunction with the GDPR message above.</i>"
1079
  msgstr ""
1080
 
1081
+ #: woocommerce-ac.php:810
1082
  msgid "Message to be displayed when the user chooses to opt out of cart tracking."
1083
  msgstr ""
1084
 
1085
+ #: woocommerce-ac.php:814
1086
  msgid "<br>Message to be displayed when the user chooses to opt out of cart tracking.</i>"
1087
  msgstr ""
1088
 
1089
+ #: woocommerce-ac.php:824
1090
  msgid "Settings for abandoned cart recovery emails"
1091
  msgstr ""
1092
 
1093
+ #: woocommerce-ac.php:831
1094
  msgid "\"From\" Name"
1095
  msgstr ""
1096
 
1097
+ #: woocommerce-ac.php:840
1098
  msgid "\"From\" Address"
1099
  msgstr ""
1100
 
1101
+ #: woocommerce-ac.php:849
1102
  msgid "Send Reply Emails to"
1103
  msgstr ""
1104
 
1105
+ #: woocommerce-ac.php:994
1106
  msgid "Abandoned cart cut off time should be numeric and has to be greater than 0."
1107
  msgstr ""
1108
 
1109
+ #: woocommerce-ac.php:1011
1110
  msgid "Automatically Delete Abandoned Orders after X days has to be greater than 0."
1111
  msgstr ""
1112
 
1113
+ #: woocommerce-ac.php:2079
1114
  msgid "Dashboard"
1115
  msgstr ""
1116
 
1117
+ #: woocommerce-ac.php:2093
1118
  msgid "Email Templates"
1119
  msgstr ""
1120
 
1121
+ #: woocommerce-ac.php:2107
1122
  msgid "Recovered Orders"
1123
  msgstr ""
1124
 
1125
+ #: woocommerce-ac.php:2114
1126
  msgid "Product Report"
1127
  msgstr ""
1128
 
1129
+ #: woocommerce-ac.php:2358
1130
  msgid "You do not have sufficient permissions to access this page."
1131
  msgstr ""
1132
 
1133
+ #: woocommerce-ac.php:2362
1134
  msgid "WooCommerce - Abandon Cart Lite"
1135
  msgstr ""
1136
 
1137
+ #: woocommerce-ac.php:2434
1138
  msgid "The Abandoned cart has been successfully deleted."
1139
  msgstr ""
1140
 
1141
+ #: woocommerce-ac.php:2436
1142
  msgid "All Abandoned Carts have been successfully deleted."
1143
  msgstr ""
1144
 
1145
+ #: woocommerce-ac.php:2438
1146
  msgid "All Visitor carts have been successfully deleted."
1147
  msgstr ""
1148
 
1149
+ #: woocommerce-ac.php:2440
1150
  msgid "All Guest carts have been successfully deleted."
1151
  msgstr ""
1152
 
1153
+ #: woocommerce-ac.php:2442
1154
  msgid "All Registered carts have been deleted."
1155
  msgstr ""
1156
 
1157
+ #: woocommerce-ac.php:2453
1158
  msgid "The Template has been successfully deleted."
1159
  msgstr ""
1160
 
1161
+ #: woocommerce-ac.php:2460
1162
  msgid "Change settings for sending email notifications to Customers, to Admin etc."
1163
  msgstr ""
1164
 
1165
+ #: woocommerce-ac.php:2494
1166
  msgid "General Settings"
1167
  msgstr ""
1168
 
1169
+ #: woocommerce-ac.php:2497
1170
  msgid "Email Sending Settings"
1171
  msgstr ""
1172
 
1173
+ #: woocommerce-ac.php:2547
1174
  msgid "The list below shows all Abandoned Carts which have remained in cart for a time higher than the \"Cart abandoned cut-off time\" setting."
1175
  msgstr ""
1176
 
1177
+ #: woocommerce-ac.php:2589
1178
  msgid "All "
1179
  msgstr ""
1180
 
1181
+ #. translators: Users.
1182
+ #: woocommerce-ac.php:2594
1183
  msgid "Registered %s"
1184
  msgstr ""
1185
 
1186
+ #. translators: Users.
1187
+ #: woocommerce-ac.php:2600
1188
  msgid "Guest %s"
1189
  msgstr ""
1190
 
1191
+ #: woocommerce-ac.php:2606
1192
  msgid "Carts without Customer Details"
1193
  msgstr ""
1194
 
1195
+ #: woocommerce-ac.php:2627
1196
  msgid "Add email templates at different intervals to maximize the possibility of recovering your abandoned carts."
1197
  msgstr ""
1198
 
1199
+ #: woocommerce-ac.php:2747
1200
  msgid "The Email Template has been successfully added. In order to start sending this email to your customers, please activate it."
1201
  msgstr ""
1202
 
1203
+ #: woocommerce-ac.php:2757
1204
  msgid "There was a problem adding the email template. Please contact the plugin author via <a href= \"https://wordpress.org/support/plugin/woocommerce-abandoned-cart\">support forum</a>."
1205
  msgstr ""
1206
 
1207
+ #: woocommerce-ac.php:2769
1208
  msgid "The Email Template has been successfully updated."
1209
  msgstr ""
1210
 
1211
+ #: woocommerce-ac.php:2779
1212
  msgid "There was a problem updating the email template. Please contact the plugin author via <a href= \"https://wordpress.org/support/plugin/woocommerce-abandoned-cart\">support forum</a>."
1213
  msgstr ""
1214
 
1215
+ #: woocommerce-ac.php:2788
1216
  msgid "Add New Template"
1217
  msgstr ""
1218
 
1219
+ #: woocommerce-ac.php:2860
1220
  msgid "The Report below shows how many Abandoned Carts we were able to recover for you by sending automatic emails to encourage shoppers."
1221
  msgstr ""
1222
 
1223
+ #: woocommerce-ac.php:2911
1224
  msgid "Start Date:"
1225
  msgstr ""
1226
 
1227
+ #: woocommerce-ac.php:2913
1228
  msgid "End Date:"
1229
  msgstr ""
1230
 
1231
+ #. translators: Abandoned & recovered numbers and order totals.
1232
+ #: woocommerce-ac.php:2933
1233
+ msgid "During the selected range <strong>%1$d</strong> carts totaling <strong>%2$s</strong> were abandoned. We were able to recover <strong>%3$d</strong> of them, which led to an extra <strong>%4$s</strong>"
1234
  msgstr ""
1235
 
1236
+ #. translators: Abandoned Order ID.
1237
+ #: woocommerce-ac.php:2958
1238
  msgid "Abandoned Order #%s Details"
1239
  msgstr ""
1240
 
1241
+ #: woocommerce-ac.php:2966
1242
  msgid "Line Total"
1243
  msgstr ""
1244
 
1245
+ #: woocommerce-ac.php:3191
1246
  msgid "Customer Details"
1247
  msgstr ""
1248
 
1249
+ #: woocommerce-ac.php:3195
1250
  msgid "Billing Details"
1251
  msgstr ""
1252
 
1253
+ #: woocommerce-ac.php:3196
1254
  msgid "Name:"
1255
  msgstr ""
1256
 
1257
+ #: woocommerce-ac.php:3199
1258
+ #: woocommerce-ac.php:3220
1259
  msgid "Address:"
1260
  msgstr ""
1261
 
1262
+ #: woocommerce-ac.php:3210
1263
  msgid "Email:"
1264
  msgstr ""
1265
 
1266
+ #: woocommerce-ac.php:3214
1267
  msgid "Phone:"
1268
  msgstr ""
1269
 
1270
+ #: woocommerce-ac.php:3219
1271
  msgid "Shipping Details"
1272
  msgstr ""
1273
 
1274
+ #: woocommerce-ac.php:3229
1275
+ msgid "Shipping Address same as Billing Address"
1276
+ msgstr ""
1277
+
1278
+ #: woocommerce-ac.php:3242
1279
+ msgid "Shipping Charges"
1280
+ msgstr ""
1281
+
1282
+ #: woocommerce-ac.php:3326
1283
  msgid "Template Name:"
1284
  msgstr ""
1285
 
1286
+ #: woocommerce-ac.php:3336
1287
  msgid "Enter a template name for reference"
1288
  msgstr ""
1289
 
1290
+ #: woocommerce-ac.php:3342
1291
  msgid "Subject:"
1292
  msgstr ""
1293
 
1294
+ #: woocommerce-ac.php:3352
1295
  msgid "Enter the subject that should appear in the email sent"
1296
  msgstr ""
1297
 
1298
+ #: woocommerce-ac.php:3358
1299
  msgid "Email Body:"
1300
  msgstr ""
1301
 
1302
+ #: woocommerce-ac.php:3385
1303
  msgid "Message to be sent in the reminder email."
1304
  msgstr ""
1305
 
1306
+ #: woocommerce-ac.php:3412
1307
  msgid "Use WooCommerce Template Style:"
1308
  msgstr ""
1309
 
1310
+ #: woocommerce-ac.php:3435
1311
  msgid "Email Template Header Text: "
1312
  msgstr ""
1313
 
1314
+ #: woocommerce-ac.php:3450
1315
  msgid "Enter the header which will appear in the abandoned WooCommerce email sent. This is only applicable when only used when \"Use WooCommerce Template Style:\" is checked."
1316
  msgstr ""
1317
 
1318
+ #: woocommerce-ac.php:3456
1319
  msgid "Send this email:"
1320
  msgstr ""
1321
 
1322
+ #: woocommerce-ac.php:3497
1323
  msgid "after cart is abandoned."
1324
  msgstr ""
1325
 
1326
+ #: woocommerce-ac.php:3504
1327
  msgid "Send a test email to:"
1328
  msgstr ""
1329
 
1330
+ #: woocommerce-ac.php:3513
1331
  msgid "Enter the email id to which the test email needs to be sent."
1332
  msgstr ""
1333
 
1334
+ #: woocommerce-ac.php:3527
1335
  msgid "Update Changes"
1336
  msgstr ""
1337
 
1338
+ #: woocommerce-ac.php:3553
1339
  msgid "If you love <strong>Abandoned Cart Lite for WooCommerce</strong>, then please leave us a <a href=\"https://wordpress.org/support/plugin/woocommerce-abandoned-cart/reviews/?rate=5#new-post\" target=\"_blank\" class=\"ac-rating-link\" data-rated=\"Thanks :)\">★★★★★</a> rating. Thank you in advance. :)"
1340
  msgstr ""
1341
 
1342
+ #: woocommerce-ac.php:3781
1343
+ #: woocommerce-ac.php:3816
1344
  msgid "Men's Formal Shoes"
1345
  msgstr ""
1346
 
1347
+ #: woocommerce-ac.php:3788
1348
+ #: woocommerce-ac.php:3823
1349
  msgid "Woman's Hand Bags"
1350
  msgstr ""
includes/admin/class-wcap-pro-settings-callbacks.php CHANGED
@@ -605,22 +605,6 @@ if ( ! class_exists( 'WCAP_Pro_Settings_Callbacks' ) ) {
605
  echo wp_kses_post( $html );
606
  }
607
 
608
- /**
609
- * Callback for UTM parameters.
610
- *
611
- * @param array $args - Arguments for the setting.
612
- */
613
- public static function wcap_add_utm_to_links_callback( $args ) {
614
-
615
- $wcap_add_utm_to_links = get_option( 'wcap_add_utm_to_links', '' );
616
-
617
- ?>
618
- <textarea id='wcap_add_utm_to_links' rows='4' cols='50' name='wcap_add_utm_to_links' readonly disabled ><?php echo esc_html( $wcap_add_utm_to_links ); ?></textarea>
619
- <?php
620
- $html = '<label for="wcap_add_utm_to_links">' . $args[0] . '</label>';
621
- echo wp_kses_post( $html );
622
- }
623
-
624
  /**
625
  * Unsubscribe settings section.
626
  */
605
  echo wp_kses_post( $html );
606
  }
607
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
608
  /**
609
  * Unsubscribe settings section.
610
  */
includes/admin/class-wcap-pro-settings.php CHANGED
@@ -279,15 +279,6 @@ if ( ! class_exists( 'WCAP_Pro_Settings' ) ) {
279
  array( __( 'Select the page where product name in reminder emails should redirect to.', 'woocommerce-ac' ) . $upgrade_pro_msg )
280
  );
281
 
282
- add_settings_field(
283
- 'wcap_add_utm_to_links',
284
- __( 'UTM parameters to be added to all the links in reminder emails', 'woocommerce-ac' ),
285
- array( 'WCAP_Pro_Settings_Callbacks', 'wcap_add_utm_to_links_callback' ),
286
- 'woocommerce_ac_email_page',
287
- 'ac_email_settings_section',
288
- array( __( 'UTM parameters that should be added to all the links in reminder emails.', 'woocommerce-ac' ) . $upgrade_pro_msg )
289
- );
290
-
291
  register_setting(
292
  'ac_email_settings_section',
293
  'wcap_product_image_size'
@@ -298,11 +289,6 @@ if ( ! class_exists( 'WCAP_Pro_Settings' ) ) {
298
  'wcap_product_name_redirect'
299
  );
300
 
301
- register_setting(
302
- 'woocommerce_ac_settings',
303
- 'wcap_add_utm_to_links'
304
- );
305
-
306
  add_settings_section(
307
  'ac_cron_job_settings_section', // ID used to identify this section and with which to register options.
308
  __( 'Setting for sending Emails & SMS using Action Scheduler', 'woocommerce-abandoned-cart' ), // Title to be displayed on the administration page.
279
  array( __( 'Select the page where product name in reminder emails should redirect to.', 'woocommerce-ac' ) . $upgrade_pro_msg )
280
  );
281
 
 
 
 
 
 
 
 
 
 
282
  register_setting(
283
  'ac_email_settings_section',
284
  'wcap_product_image_size'
289
  'wcap_product_name_redirect'
290
  );
291
 
 
 
 
 
 
292
  add_settings_section(
293
  'ac_cron_job_settings_section', // ID used to identify this section and with which to register options.
294
  __( 'Setting for sending Emails & SMS using Action Scheduler', 'woocommerce-abandoned-cart' ), // Title to be displayed on the administration page.
includes/class-wcal-common.php CHANGED
@@ -127,7 +127,7 @@ class wcal_common { // phpcs:ignore
127
  $cart_details = $cart_info->cart;
128
  }
129
 
130
- if ( count( $cart_details ) > 0 ) {
131
  foreach ( $cart_details as $k => $v ) {
132
  if ( 0 !== $v->line_subtotal_tax && $v->line_subtotal_tax > 0 ) {
133
  $wcal_abandoned_orders_amount = $wcal_abandoned_orders_amount + $v->line_total + $v->line_subtotal_tax;
127
  $cart_details = $cart_info->cart;
128
  }
129
 
130
+ if ( count( get_object_vars( $cart_details ) ) > 0 ) {
131
  foreach ( $cart_details as $k => $v ) {
132
  if ( 0 !== $v->line_subtotal_tax && $v->line_subtotal_tax > 0 ) {
133
  $wcal_abandoned_orders_amount = $wcal_abandoned_orders_amount + $v->line_total + $v->line_subtotal_tax;
includes/libraries/action-scheduler/.editorconfig DELETED
@@ -1,24 +0,0 @@
1
- # This file is for unifying the coding style for different editors and IDEs
2
- # editorconfig.org
3
-
4
- # WordPress Coding Standards
5
- # https://make.wordpress.org/core/handbook/coding-standards/
6
-
7
- root = true
8
-
9
- [*]
10
- charset = utf-8
11
- end_of_line = lf
12
- indent_size = 4
13
- tab_width = 4
14
- indent_style = tab
15
- insert_final_newline = true
16
- trim_trailing_whitespace = true
17
-
18
- [*.txt]
19
- trim_trailing_whitespace = false
20
-
21
- [*.{md,json,yml}]
22
- trim_trailing_whitespace = false
23
- indent_style = space
24
- indent_size = 2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/README.md DELETED
@@ -1,35 +0,0 @@
1
- # Action Scheduler - Job Queue for WordPress [![Build Status](https://travis-ci.org/woocommerce/action-scheduler.png?branch=master)](https://travis-ci.org/woocommerce/action-scheduler) [![codecov](https://codecov.io/gh/woocommerce/action-scheduler/branch/master/graph/badge.svg)](https://codecov.io/gh/woocommerce/action-scheduler)
2
-
3
- Action Scheduler is a scalable, traceable job queue for background processing large sets of actions in WordPress. It's specially designed to be distributed in WordPress plugins.
4
-
5
- Action Scheduler works by triggering an action hook to run at some time in the future. Each hook can be scheduled with unique data, to allow callbacks to perform operations on that data. The hook can also be scheduled to run on one or more occassions.
6
-
7
- Think of it like an extension to `do_action()` which adds the ability to delay and repeat a hook.
8
-
9
- ## Battle-Tested Background Processing
10
-
11
- Every month, Action Scheduler processes millions of payments for [Subscriptions](https://woocommerce.com/products/woocommerce-subscriptions/), webhooks for [WooCommerce](https://wordpress.org/plugins/woocommerce/), as well as emails and other events for a range of other plugins.
12
-
13
- It's been seen on live sites processing queues in excess of 50,000 jobs and doing resource intensive operations, like processing payments and creating orders, at a sustained rate of over 10,000 / hour without negatively impacting normal site operations.
14
-
15
- This is all on infrastructure and WordPress sites outside the control of the plugin author.
16
-
17
- If your plugin needs background processing, especially of large sets of tasks, Action Scheduler can help.
18
-
19
- ## Learn More
20
-
21
- To learn more about how to Action Scheduler works, and how to use it in your plugin, check out the docs on [ActionScheduler.org](https://actionscheduler.org).
22
-
23
- There you will find:
24
-
25
- * [Usage guide](https://actionscheduler.org/usage/): instructions on installing and using Action Scheduler
26
- * [WP CLI guide](https://actionscheduler.org/wp-cli/): instructions on running Action Scheduler at scale via WP CLI
27
- * [API Reference](https://actionscheduler.org/api/): complete reference guide for all API functions
28
- * [Administration Guide](https://actionscheduler.org/admin/): guide to managing scheduled actions via the administration screen
29
- * [Guide to Background Processing at Scale](https://actionscheduler.org/perf/): instructions for running Action Scheduler at scale via the default WP Cron queue runner
30
-
31
- ## Credits
32
-
33
- Action Scheduler is developed and maintained by [Automattic](http://automattic.com/) with significant early development completed by [Flightless](https://flightless.us/).
34
-
35
- Collaboration is cool. We'd love to work with you to improve Action Scheduler. [Pull Requests](https://github.com/woocommerce/action-scheduler/pulls) welcome.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/action-scheduler.php DELETED
@@ -1,53 +0,0 @@
1
- <?php
2
- /*
3
- * Plugin Name: Action Scheduler
4
- * Plugin URI: https://actionscheduler.org
5
- * Description: A robust scheduling library for use in WordPress plugins.
6
- * Author: Automattic
7
- * Author URI: https://automattic.com/
8
- * Version: 3.0.1
9
- * License: GPLv3
10
- *
11
- * Copyright 2019 Automattic, Inc. (https://automattic.com/contact/)
12
- *
13
- * This program is free software: you can redistribute it and/or modify
14
- * it under the terms of the GNU General Public License as published by
15
- * the Free Software Foundation, either version 3 of the License, or
16
- * (at your option) any later version.
17
- *
18
- * This program is distributed in the hope that it will be useful,
19
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
- * GNU General Public License for more details.
22
- *
23
- * You should have received a copy of the GNU General Public License
24
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
25
- *
26
- */
27
-
28
- if ( ! function_exists( 'action_scheduler_register_3_dot_0_dot_1' ) ) {
29
-
30
- if ( ! class_exists( 'ActionScheduler_Versions' ) ) {
31
- require_once( 'classes/ActionScheduler_Versions.php' );
32
- add_action( 'plugins_loaded', array( 'ActionScheduler_Versions', 'initialize_latest_version' ), 1, 0 );
33
- }
34
-
35
- add_action( 'plugins_loaded', 'action_scheduler_register_3_dot_0_dot_1', 0, 0 );
36
-
37
- function action_scheduler_register_3_dot_0_dot_1() {
38
- $versions = ActionScheduler_Versions::instance();
39
- $versions->register( '3.0.1', 'action_scheduler_initialize_3_dot_0_dot_1' );
40
- }
41
-
42
- function action_scheduler_initialize_3_dot_0_dot_1() {
43
- require_once( 'classes/abstracts/ActionScheduler.php' );
44
- ActionScheduler::init( __FILE__ );
45
- }
46
-
47
- // Support usage in themes - load this version if no plugin has loaded a version yet.
48
- if ( did_action( 'plugins_loaded' ) && ! class_exists( 'ActionScheduler' ) ) {
49
- action_scheduler_register_3_dot_0_dot_1();
50
- do_action( 'action_scheduler_pre_theme_init' );
51
- ActionScheduler_Versions::initialize_latest_version();
52
- }
53
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/ActionScheduler_ActionClaim.php DELETED
@@ -1,23 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_ActionClaim
5
- */
6
- class ActionScheduler_ActionClaim {
7
- private $id = '';
8
- private $action_ids = array();
9
-
10
- public function __construct( $id, array $action_ids ) {
11
- $this->id = $id;
12
- $this->action_ids = $action_ids;
13
- }
14
-
15
- public function get_id() {
16
- return $this->id;
17
- }
18
-
19
- public function get_actions() {
20
- return $this->action_ids;
21
- }
22
- }
23
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/ActionScheduler_ActionFactory.php DELETED
@@ -1,179 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_ActionFactory
5
- */
6
- class ActionScheduler_ActionFactory {
7
-
8
- /**
9
- * @param string $status The action's status in the data store
10
- * @param string $hook The hook to trigger when this action runs
11
- * @param array $args Args to pass to callbacks when the hook is triggered
12
- * @param ActionScheduler_Schedule $schedule The action's schedule
13
- * @param string $group A group to put the action in
14
- *
15
- * @return ActionScheduler_Action An instance of the stored action
16
- */
17
- public function get_stored_action( $status, $hook, array $args = array(), ActionScheduler_Schedule $schedule = null, $group = '' ) {
18
-
19
- switch ( $status ) {
20
- case ActionScheduler_Store::STATUS_PENDING :
21
- $action_class = 'ActionScheduler_Action';
22
- break;
23
- case ActionScheduler_Store::STATUS_CANCELED :
24
- $action_class = 'ActionScheduler_CanceledAction';
25
- if ( ! is_null( $schedule ) && ! is_a( $schedule, 'ActionScheduler_CanceledSchedule' ) ) {
26
- $schedule = new ActionScheduler_CanceledSchedule( $schedule->get_date() );
27
- }
28
- break;
29
- default :
30
- $action_class = 'ActionScheduler_FinishedAction';
31
- break;
32
- }
33
-
34
- $action_class = apply_filters( 'action_scheduler_stored_action_class', $action_class, $status, $hook, $args, $schedule, $group );
35
-
36
- $action = new $action_class( $hook, $args, $schedule, $group );
37
-
38
- /**
39
- * Allow 3rd party code to change the instantiated action for a given hook, args, schedule and group.
40
- *
41
- * @param ActionScheduler_Action $action The instantiated action.
42
- * @param string $hook The instantiated action's hook.
43
- * @param array $args The instantiated action's args.
44
- * @param ActionScheduler_Schedule $schedule The instantiated action's schedule.
45
- * @param string $group The instantiated action's group.
46
- */
47
- return apply_filters( 'action_scheduler_stored_action_instance', $action, $hook, $args, $schedule, $group );
48
- }
49
-
50
- /**
51
- * Enqueue an action to run one time, as soon as possible (rather a specific scheduled time).
52
- *
53
- * This method creates a new action with the NULLSchedule. This schedule maps to a MySQL datetime string of
54
- * 0000-00-00 00:00:00. This is done to create a psuedo "async action" type that is fully backward compatible.
55
- * Existing queries to claim actions claim by date, meaning actions scheduled for 0000-00-00 00:00:00 will
56
- * always be claimed prior to actions scheduled for a specific date. This makes sure that any async action is
57
- * given priority in queue processing. This has the added advantage of making sure async actions can be
58
- * claimed by both the existing WP Cron and WP CLI runners, as well as a new async request runner.
59
- *
60
- * @param string $hook The hook to trigger when this action runs
61
- * @param array $args Args to pass when the hook is triggered
62
- * @param string $group A group to put the action in
63
- *
64
- * @return string The ID of the stored action
65
- */
66
- public function async( $hook, $args = array(), $group = '' ) {
67
- $schedule = new ActionScheduler_NullSchedule();
68
- $action = new ActionScheduler_Action( $hook, $args, $schedule, $group );
69
- return $this->store( $action );
70
- }
71
-
72
- /**
73
- * @param string $hook The hook to trigger when this action runs
74
- * @param array $args Args to pass when the hook is triggered
75
- * @param int $when Unix timestamp when the action will run
76
- * @param string $group A group to put the action in
77
- *
78
- * @return string The ID of the stored action
79
- */
80
- public function single( $hook, $args = array(), $when = null, $group = '' ) {
81
- $date = as_get_datetime_object( $when );
82
- $schedule = new ActionScheduler_SimpleSchedule( $date );
83
- $action = new ActionScheduler_Action( $hook, $args, $schedule, $group );
84
- return $this->store( $action );
85
- }
86
-
87
- /**
88
- * Create the first instance of an action recurring on a given interval.
89
- *
90
- * @param string $hook The hook to trigger when this action runs
91
- * @param array $args Args to pass when the hook is triggered
92
- * @param int $first Unix timestamp for the first run
93
- * @param int $interval Seconds between runs
94
- * @param string $group A group to put the action in
95
- *
96
- * @return string The ID of the stored action
97
- */
98
- public function recurring( $hook, $args = array(), $first = null, $interval = null, $group = '' ) {
99
- if ( empty($interval) ) {
100
- return $this->single( $hook, $args, $first, $group );
101
- }
102
- $date = as_get_datetime_object( $first );
103
- $schedule = new ActionScheduler_IntervalSchedule( $date, $interval );
104
- $action = new ActionScheduler_Action( $hook, $args, $schedule, $group );
105
- return $this->store( $action );
106
- }
107
-
108
- /**
109
- * Create the first instance of an action recurring on a Cron schedule.
110
- *
111
- * @param string $hook The hook to trigger when this action runs
112
- * @param array $args Args to pass when the hook is triggered
113
- * @param int $base_timestamp The first instance of the action will be scheduled
114
- * to run at a time calculated after this timestamp matching the cron
115
- * expression. This can be used to delay the first instance of the action.
116
- * @param int $schedule A cron definition string
117
- * @param string $group A group to put the action in
118
- *
119
- * @return string The ID of the stored action
120
- */
121
- public function cron( $hook, $args = array(), $base_timestamp = null, $schedule = null, $group = '' ) {
122
- if ( empty($schedule) ) {
123
- return $this->single( $hook, $args, $base_timestamp, $group );
124
- }
125
- $date = as_get_datetime_object( $base_timestamp );
126
- $cron = CronExpression::factory( $schedule );
127
- $schedule = new ActionScheduler_CronSchedule( $date, $cron );
128
- $action = new ActionScheduler_Action( $hook, $args, $schedule, $group );
129
- return $this->store( $action );
130
- }
131
-
132
- /**
133
- * Create a successive instance of a recurring or cron action.
134
- *
135
- * Importantly, the action will be rescheduled to run based on the current date/time.
136
- * That means when the action is scheduled to run in the past, the next scheduled date
137
- * will be pushed forward. For example, if a recurring action set to run every hour
138
- * was scheduled to run 5 seconds ago, it will be next scheduled for 1 hour in the
139
- * future, which is 1 hour and 5 seconds from when it was last scheduled to run.
140
- *
141
- * Alternatively, if the action is scheduled to run in the future, and is run early,
142
- * likely via manual intervention, then its schedule will change based on the time now.
143
- * For example, if a recurring action set to run every day, and is run 12 hours early,
144
- * it will run again in 24 hours, not 36 hours.
145
- *
146
- * This slippage is less of an issue with Cron actions, as the specific run time can
147
- * be set for them to run, e.g. 1am each day. In those cases, and entire period would
148
- * need to be missed before there was any change is scheduled, e.g. in the case of an
149
- * action scheduled for 1am each day, the action would need to run an entire day late.
150
- *
151
- * @param ActionScheduler_Action $action The existing action.
152
- *
153
- * @return string The ID of the stored action
154
- * @throws InvalidArgumentException If $action is not a recurring action.
155
- */
156
- public function repeat( $action ) {
157
- $schedule = $action->get_schedule();
158
- $next = $schedule->get_next( as_get_datetime_object() );
159
-
160
- if ( is_null( $next ) || ! $schedule->is_recurring() ) {
161
- throw new InvalidArgumentException( __( 'Invalid action - must be a recurring action.', 'action-scheduler' ) );
162
- }
163
-
164
- $schedule_class = get_class( $schedule );
165
- $new_schedule = new $schedule( $next, $schedule->get_recurrence(), $schedule->get_first_date() );
166
- $new_action = new ActionScheduler_Action( $action->get_hook(), $action->get_args(), $new_schedule, $action->get_group() );
167
- return $this->store( $new_action );
168
- }
169
-
170
- /**
171
- * @param ActionScheduler_Action $action
172
- *
173
- * @return string The ID of the stored action
174
- */
175
- protected function store( ActionScheduler_Action $action ) {
176
- $store = ActionScheduler_Store::instance();
177
- return $store->save_action( $action );
178
- }
179
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/ActionScheduler_AdminView.php DELETED
@@ -1,137 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_AdminView
5
- * @codeCoverageIgnore
6
- */
7
- class ActionScheduler_AdminView extends ActionScheduler_AdminView_Deprecated {
8
-
9
- private static $admin_view = NULL;
10
-
11
- private static $screen_id = 'tools_page_action-scheduler';
12
-
13
- /**
14
- * @return ActionScheduler_AdminView
15
- * @codeCoverageIgnore
16
- */
17
- public static function instance() {
18
-
19
- if ( empty( self::$admin_view ) ) {
20
- $class = apply_filters('action_scheduler_admin_view_class', 'ActionScheduler_AdminView');
21
- self::$admin_view = new $class();
22
- }
23
-
24
- return self::$admin_view;
25
- }
26
-
27
- /**
28
- * @codeCoverageIgnore
29
- */
30
- public function init() {
31
- if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || false == DOING_AJAX ) ) {
32
-
33
- if ( class_exists( 'WooCommerce' ) ) {
34
- add_action( 'woocommerce_admin_status_content_action-scheduler', array( $this, 'render_admin_ui' ) );
35
- add_action( 'woocommerce_system_status_report', array( $this, 'system_status_report' ) );
36
- add_filter( 'woocommerce_admin_status_tabs', array( $this, 'register_system_status_tab' ) );
37
- }
38
-
39
- add_action( 'admin_menu', array( $this, 'register_menu' ) );
40
-
41
- add_action( 'current_screen', array( $this, 'add_help_tabs' ) );
42
- }
43
- }
44
-
45
- public function system_status_report() {
46
- $table = new ActionScheduler_wcSystemStatus( ActionScheduler::store() );
47
- $table->render();
48
- }
49
-
50
- /**
51
- * Registers action-scheduler into WooCommerce > System status.
52
- *
53
- * @param array $tabs An associative array of tab key => label.
54
- * @return array $tabs An associative array of tab key => label, including Action Scheduler's tabs
55
- */
56
- public function register_system_status_tab( array $tabs ) {
57
- $tabs['action-scheduler'] = __( 'Scheduled Actions', 'action-scheduler' );
58
-
59
- return $tabs;
60
- }
61
-
62
- /**
63
- * Include Action Scheduler's administration under the Tools menu.
64
- *
65
- * A menu under the Tools menu is important for backward compatibility (as that's
66
- * where it started), and also provides more convenient access than the WooCommerce
67
- * System Status page, and for sites where WooCommerce isn't active.
68
- */
69
- public function register_menu() {
70
- $hook_suffix = add_submenu_page(
71
- 'tools.php',
72
- __( 'Scheduled Actions', 'action-scheduler' ),
73
- __( 'Scheduled Actions', 'action-scheduler' ),
74
- 'manage_options',
75
- 'action-scheduler',
76
- array( $this, 'render_admin_ui' )
77
- );
78
- add_action( 'load-' . $hook_suffix , array( $this, 'process_admin_ui' ) );
79
- }
80
-
81
- /**
82
- * Triggers processing of any pending actions.
83
- */
84
- public function process_admin_ui() {
85
- $table = new ActionScheduler_ListTable( ActionScheduler::store(), ActionScheduler::logger(), ActionScheduler::runner() );
86
- $table->process_actions();
87
- }
88
-
89
- /**
90
- * Renders the Admin UI
91
- */
92
- public function render_admin_ui() {
93
- $table = new ActionScheduler_ListTable( ActionScheduler::store(), ActionScheduler::logger(), ActionScheduler::runner() );
94
- $table->display_page();
95
- }
96
-
97
- /**
98
- * Provide more information about the screen and its data in the help tab.
99
- */
100
- public function add_help_tabs() {
101
- $screen = get_current_screen();
102
-
103
- if ( ! $screen || self::$screen_id != $screen->id ) {
104
- return;
105
- }
106
-
107
- $screen->add_help_tab(
108
- array(
109
- 'id' => 'action_scheduler_about',
110
- 'title' => __( 'About', 'action-scheduler' ),
111
- 'content' =>
112
- '<h2>' . __( 'About Action Scheduler', 'action-scheduler' ) . '</h2>' .
113
- '<p>' .
114
- __( 'Action Scheduler is a scalable, traceable job queue for background processing large sets of actions. Action Scheduler works by triggering an action hook to run at some time in the future. Scheduled actions can also be scheduled to run on a recurring schedule.', 'action-scheduler' ) .
115
- '</p>',
116
- )
117
- );
118
-
119
- $screen->add_help_tab(
120
- array(
121
- 'id' => 'action_scheduler_columns',
122
- 'title' => __( 'Columns', 'action-scheduler' ),
123
- 'content' =>
124
- '<h2>' . __( 'Scheduled Action Columns', 'action-scheduler' ) . '</h2>' .
125
- '<ul>' .
126
- sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Hook', 'action-scheduler' ), __( 'Name of the action hook that will be triggered.', 'action-scheduler' ) ) .
127
- sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Status', 'action-scheduler' ), __( 'Action statuses are Pending, Complete, Canceled, Failed', 'action-scheduler' ) ) .
128
- sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Arguments', 'action-scheduler' ), __( 'Optional data array passed to the action hook.', 'action-scheduler' ) ) .
129
- sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Group', 'action-scheduler' ), __( 'Optional action group.', 'action-scheduler' ) ) .
130
- sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Recurrence', 'action-scheduler' ), __( 'The action\'s schedule frequency.', 'action-scheduler' ) ) .
131
- sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Scheduled', 'action-scheduler' ), __( 'The date/time the action is/was scheduled to run.', 'action-scheduler' ) ) .
132
- sprintf( '<li><strong>%1$s</strong>: %2$s</li>', __( 'Log', 'action-scheduler' ), __( 'Activity log for the action.', 'action-scheduler' ) ) .
133
- '</ul>',
134
- )
135
- );
136
- }
137
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/ActionScheduler_AsyncRequest_QueueRunner.php DELETED
@@ -1,96 +0,0 @@
1
- <?php
2
- /**
3
- * ActionScheduler_AsyncRequest_QueueRunner
4
- */
5
-
6
- defined( 'ABSPATH' ) || exit;
7
-
8
- /**
9
- * ActionScheduler_AsyncRequest_QueueRunner class.
10
- */
11
- class ActionScheduler_AsyncRequest_QueueRunner extends WP_Async_Request {
12
-
13
- /**
14
- * Data store for querying actions
15
- *
16
- * @var ActionScheduler_Store
17
- * @access protected
18
- */
19
- protected $store;
20
-
21
- /**
22
- * Prefix for ajax hooks
23
- *
24
- * @var string
25
- * @access protected
26
- */
27
- protected $prefix = 'as';
28
-
29
- /**
30
- * Action for ajax hooks
31
- *
32
- * @var string
33
- * @access protected
34
- */
35
- protected $action = 'async_request_queue_runner';
36
-
37
- /**
38
- * Initiate new async request
39
- */
40
- public function __construct( ActionScheduler_Store $store ) {
41
- parent::__construct();
42
- $this->store = $store;
43
- }
44
-
45
- /**
46
- * Handle async requests
47
- *
48
- * Run a queue, and maybe dispatch another async request to run another queue
49
- * if there are still pending actions after completing a queue in this request.
50
- */
51
- protected function handle() {
52
- do_action( 'action_scheduler_run_queue', 'Async Request' ); // run a queue in the same way as WP Cron, but declare the Async Request context
53
-
54
- $sleep_seconds = $this->get_sleep_seconds();
55
-
56
- if ( $sleep_seconds ) {
57
- sleep( $sleep_seconds );
58
- }
59
-
60
- $this->maybe_dispatch();
61
- }
62
-
63
- /**
64
- * If the async request runner is needed and allowed to run, dispatch a request.
65
- */
66
- public function maybe_dispatch() {
67
- if ( ! $this->allow() ) {
68
- return;
69
- }
70
-
71
- $this->dispatch();
72
- }
73
-
74
- /**
75
- * Only allow async requests when needed.
76
- *
77
- * Also allow 3rd party code to disable running actions via async requests.
78
- */
79
- protected function allow() {
80
-
81
- if ( ! has_action( 'action_scheduler_run_queue' ) || ActionScheduler::runner()->has_maximum_concurrent_batches() || ! $this->store->has_pending_actions_due() ) {
82
- $allow = false;
83
- } else {
84
- $allow = true;
85
- }
86
-
87
- return apply_filters( 'action_scheduler_allow_async_request_runner', $allow );
88
- }
89
-
90
- /**
91
- * Chaining async requests can crash MySQL. A brief sleep call in PHP prevents that.
92
- */
93
- protected function get_sleep_seconds() {
94
- return apply_filters( 'action_scheduler_async_request_sleep_seconds', 1, $this );
95
- }
96
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/ActionScheduler_Compatibility.php DELETED
@@ -1,99 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_Compatibility
5
- */
6
- class ActionScheduler_Compatibility {
7
-
8
- /**
9
- * Converts a shorthand byte value to an integer byte value.
10
- *
11
- * Wrapper for wp_convert_hr_to_bytes(), moved to load.php in WordPress 4.6 from media.php
12
- *
13
- * @link https://secure.php.net/manual/en/function.ini-get.php
14
- * @link https://secure.php.net/manual/en/faq.using.php#faq.using.shorthandbytes
15
- *
16
- * @param string $value A (PHP ini) byte value, either shorthand or ordinary.
17
- * @return int An integer byte value.
18
- */
19
- public static function convert_hr_to_bytes( $value ) {
20
- if ( function_exists( 'wp_convert_hr_to_bytes' ) ) {
21
- return wp_convert_hr_to_bytes( $value );
22
- }
23
-
24
- $value = strtolower( trim( $value ) );
25
- $bytes = (int) $value;
26
-
27
- if ( false !== strpos( $value, 'g' ) ) {
28
- $bytes *= GB_IN_BYTES;
29
- } elseif ( false !== strpos( $value, 'm' ) ) {
30
- $bytes *= MB_IN_BYTES;
31
- } elseif ( false !== strpos( $value, 'k' ) ) {
32
- $bytes *= KB_IN_BYTES;
33
- }
34
-
35
- // Deal with large (float) values which run into the maximum integer size.
36
- return min( $bytes, PHP_INT_MAX );
37
- }
38
-
39
- /**
40
- * Attempts to raise the PHP memory limit for memory intensive processes.
41
- *
42
- * Only allows raising the existing limit and prevents lowering it.
43
- *
44
- * Wrapper for wp_raise_memory_limit(), added in WordPress v4.6.0
45
- *
46
- * @return bool|int|string The limit that was set or false on failure.
47
- */
48
- public static function raise_memory_limit() {
49
- if ( function_exists( 'wp_raise_memory_limit' ) ) {
50
- return wp_raise_memory_limit( 'admin' );
51
- }
52
-
53
- $current_limit = @ini_get( 'memory_limit' );
54
- $current_limit_int = self::convert_hr_to_bytes( $current_limit );
55
-
56
- if ( -1 === $current_limit_int ) {
57
- return false;
58
- }
59
-
60
- $wp_max_limit = WP_MAX_MEMORY_LIMIT;
61
- $wp_max_limit_int = self::convert_hr_to_bytes( $wp_max_limit );
62
- $filtered_limit = apply_filters( 'admin_memory_limit', $wp_max_limit );
63
- $filtered_limit_int = self::convert_hr_to_bytes( $filtered_limit );
64
-
65
- if ( -1 === $filtered_limit_int || ( $filtered_limit_int > $wp_max_limit_int && $filtered_limit_int > $current_limit_int ) ) {
66
- if ( false !== @ini_set( 'memory_limit', $filtered_limit ) ) {
67
- return $filtered_limit;
68
- } else {
69
- return false;
70
- }
71
- } elseif ( -1 === $wp_max_limit_int || $wp_max_limit_int > $current_limit_int ) {
72
- if ( false !== @ini_set( 'memory_limit', $wp_max_limit ) ) {
73
- return $wp_max_limit;
74
- } else {
75
- return false;
76
- }
77
- }
78
- return false;
79
- }
80
-
81
- /**
82
- * Attempts to raise the PHP timeout for time intensive processes.
83
- *
84
- * Only allows raising the existing limit and prevents lowering it. Wrapper for wc_set_time_limit(), when available.
85
- *
86
- * @param int The time limit in seconds.
87
- */
88
- public static function raise_time_limit( $limit = 0 ) {
89
- if ( $limit < ini_get( 'max_execution_time' ) ) {
90
- return;
91
- }
92
-
93
- if ( function_exists( 'wc_set_time_limit' ) ) {
94
- wc_set_time_limit( $limit );
95
- } elseif ( function_exists( 'set_time_limit' ) && false === strpos( ini_get( 'disable_functions' ), 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) {
96
- @set_time_limit( $limit );
97
- }
98
- }
99
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/ActionScheduler_DataController.php DELETED
@@ -1,177 +0,0 @@
1
- <?php
2
-
3
- use Action_Scheduler\Migration\Controller;
4
-
5
- /**
6
- * Class ActionScheduler_DataController
7
- *
8
- * The main plugin/initialization class for the data stores.
9
- *
10
- * Responsible for hooking everything up with WordPress.
11
- *
12
- * @package Action_Scheduler
13
- *
14
- * @since 3.0.0
15
- */
16
- class ActionScheduler_DataController {
17
- /** Action data store class name. */
18
- const DATASTORE_CLASS = 'ActionScheduler_DBStore';
19
-
20
- /** Logger data store class name. */
21
- const LOGGER_CLASS = 'ActionScheduler_DBLogger';
22
-
23
- /** Migration status option name. */
24
- const STATUS_FLAG = 'action_scheduler_migration_status';
25
-
26
- /** Migration status option value. */
27
- const STATUS_COMPLETE = 'complete';
28
-
29
- /** Migration minimum required PHP version. */
30
- const MIN_PHP_VERSION = '5.5';
31
-
32
- /** @var ActionScheduler_DataController */
33
- private static $instance;
34
-
35
- /** @var int */
36
- private static $sleep_time = 0;
37
-
38
- /** @var int */
39
- private static $free_ticks = 50;
40
-
41
- /**
42
- * Get a flag indicating whether the migration environment dependencies are met.
43
- *
44
- * @return bool
45
- */
46
- public static function dependencies_met() {
47
- $php_support = version_compare( PHP_VERSION, self::MIN_PHP_VERSION, '>=' );
48
- return $php_support && apply_filters( 'action_scheduler_migration_dependencies_met', true );
49
- }
50
-
51
- /**
52
- * Get a flag indicating whether the migration is complete.
53
- *
54
- * @return bool Whether the flag has been set marking the migration as complete
55
- */
56
- public static function is_migration_complete() {
57
- return get_option( self::STATUS_FLAG ) === self::STATUS_COMPLETE;
58
- }
59
-
60
- /**
61
- * Mark the migration as complete.
62
- */
63
- public static function mark_migration_complete() {
64
- update_option( self::STATUS_FLAG, self::STATUS_COMPLETE );
65
- }
66
-
67
- /**
68
- * Set the action store class name.
69
- *
70
- * @param string $class Classname of the store class.
71
- *
72
- * @return string
73
- */
74
- public static function set_store_class( $class ) {
75
- return self::DATASTORE_CLASS;
76
- }
77
-
78
- /**
79
- * Set the action logger class name.
80
- *
81
- * @param string $class Classname of the logger class.
82
- *
83
- * @return string
84
- */
85
- public static function set_logger_class( $class ) {
86
- return self::LOGGER_CLASS;
87
- }
88
-
89
- /**
90
- * Set the sleep time in seconds.
91
- *
92
- * @param integer $sleep_time The number of seconds to pause before resuming operation.
93
- */
94
- public static function set_sleep_time( $sleep_time ) {
95
- self::$sleep_time = $sleep_time;
96
- }
97
-
98
- /**
99
- * Set the tick count required for freeing memory.
100
- *
101
- * @param integer $free_ticks The number of ticks to free memory on.
102
- */
103
- public static function set_free_ticks( $free_ticks ) {
104
- self::$free_ticks = $free_ticks;
105
- }
106
-
107
- /**
108
- * Free memory if conditions are met.
109
- *
110
- * @param int $ticks Current tick count.
111
- */
112
- public static function maybe_free_memory( $ticks ) {
113
- if ( self::$free_ticks && 0 === $ticks % self::$free_ticks ) {
114
- self::free_memory();
115
- }
116
- }
117
-
118
- /**
119
- * Reduce memory footprint by clearing the database query and object caches.
120
- */
121
- public static function free_memory() {
122
- if ( 0 < self::$sleep_time ) {
123
- /* translators: %d: amount of time */
124
- \WP_CLI::warning( sprintf( _n( 'Stopped the insanity for %d second', 'Stopped the insanity for %d seconds', self::$sleep_time, 'action-scheduler' ), self::$sleep_time ) );
125
- sleep( self::$sleep_time );
126
- }
127
-
128
- \WP_CLI::warning( __( 'Attempting to reduce used memory...', 'action-scheduler' ) );
129
-
130
- /**
131
- * @var $wpdb \wpdb
132
- * @var $wp_object_cache \WP_Object_Cache
133
- */
134
- global $wpdb, $wp_object_cache;
135
-
136
- $wpdb->queries = array();
137
-
138
- if ( ! is_a( $wp_object_cache, 'WP_Object_Cache' ) ) {
139
- return;
140
- }
141
-
142
- $wp_object_cache->group_ops = array();
143
- $wp_object_cache->stats = array();
144
- $wp_object_cache->memcache_debug = array();
145
- $wp_object_cache->cache = array();
146
-
147
- if ( is_callable( array( $wp_object_cache, '__remoteset' ) ) ) {
148
- call_user_func( array( $wp_object_cache, '__remoteset' ) ); // important
149
- }
150
- }
151
-
152
- /**
153
- * Connect to table datastores if migration is complete.
154
- * Otherwise, proceed with the migration if the dependencies have been met.
155
- */
156
- public static function init() {
157
- if ( self::is_migration_complete() ) {
158
- add_filter( 'action_scheduler_store_class', array( 'ActionScheduler_DataController', 'set_store_class' ), 100 );
159
- add_filter( 'action_scheduler_logger_class', array( 'ActionScheduler_DataController', 'set_logger_class' ), 100 );
160
- } elseif ( self::dependencies_met() ) {
161
- Controller::init();
162
- }
163
-
164
- add_action( 'action_scheduler/progress_tick', array( 'ActionScheduler_DataController', 'maybe_free_memory' ) );
165
- }
166
-
167
- /**
168
- * Singleton factory.
169
- */
170
- public static function instance() {
171
- if ( ! isset( self::$instance ) ) {
172
- self::$instance = new static();
173
- }
174
-
175
- return self::$instance;
176
- }
177
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/ActionScheduler_DateTime.php DELETED
@@ -1,76 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * ActionScheduler DateTime class.
5
- *
6
- * This is a custom extension to DateTime that
7
- */
8
- class ActionScheduler_DateTime extends DateTime {
9
-
10
- /**
11
- * UTC offset.
12
- *
13
- * Only used when a timezone is not set. When a timezone string is
14
- * used, this will be set to 0.
15
- *
16
- * @var int
17
- */
18
- protected $utcOffset = 0;
19
-
20
- /**
21
- * Get the unix timestamp of the current object.
22
- *
23
- * Missing in PHP 5.2 so just here so it can be supported consistently.
24
- *
25
- * @return int
26
- */
27
- public function getTimestamp() {
28
- return method_exists( 'DateTime', 'getTimestamp' ) ? parent::getTimestamp() : $this->format( 'U' );
29
- }
30
-
31
- /**
32
- * Set the UTC offset.
33
- *
34
- * This represents a fixed offset instead of a timezone setting.
35
- *
36
- * @param $offset
37
- */
38
- public function setUtcOffset( $offset ) {
39
- $this->utcOffset = intval( $offset );
40
- }
41
-
42
- /**
43
- * Returns the timezone offset.
44
- *
45
- * @return int
46
- * @link http://php.net/manual/en/datetime.getoffset.php
47
- */
48
- public function getOffset() {
49
- return $this->utcOffset ? $this->utcOffset : parent::getOffset();
50
- }
51
-
52
- /**
53
- * Set the TimeZone associated with the DateTime
54
- *
55
- * @param DateTimeZone $timezone
56
- *
57
- * @return static
58
- * @link http://php.net/manual/en/datetime.settimezone.php
59
- */
60
- public function setTimezone( $timezone ) {
61
- $this->utcOffset = 0;
62
- parent::setTimezone( $timezone );
63
-
64
- return $this;
65
- }
66
-
67
- /**
68
- * Get the timestamp with the WordPress timezone offset added or subtracted.
69
- *
70
- * @since 3.0.0
71
- * @return int
72
- */
73
- public function getOffsetTimestamp() {
74
- return $this->getTimestamp() + $this->getOffset();
75
- }
76
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/ActionScheduler_Exception.php DELETED
@@ -1,11 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * ActionScheduler Exception Interface.
5
- *
6
- * Facilitates catching Exceptions unique to Action Scheduler.
7
- *
8
- * @package ActionScheduler
9
- * @since %VERSION%
10
- */
11
- interface ActionScheduler_Exception {}
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/ActionScheduler_FatalErrorMonitor.php DELETED
@@ -1,55 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_FatalErrorMonitor
5
- */
6
- class ActionScheduler_FatalErrorMonitor {
7
- /** @var ActionScheduler_ActionClaim */
8
- private $claim = NULL;
9
- /** @var ActionScheduler_Store */
10
- private $store = NULL;
11
- private $action_id = 0;
12
-
13
- public function __construct( ActionScheduler_Store $store ) {
14
- $this->store = $store;
15
- }
16
-
17
- public function attach( ActionScheduler_ActionClaim $claim ) {
18
- $this->claim = $claim;
19
- add_action( 'shutdown', array( $this, 'handle_unexpected_shutdown' ) );
20
- add_action( 'action_scheduler_before_execute', array( $this, 'track_current_action' ), 0, 1 );
21
- add_action( 'action_scheduler_after_execute', array( $this, 'untrack_action' ), 0, 0 );
22
- add_action( 'action_scheduler_execution_ignored', array( $this, 'untrack_action' ), 0, 0 );
23
- add_action( 'action_scheduler_failed_execution', array( $this, 'untrack_action' ), 0, 0 );
24
- }
25
-
26
- public function detach() {
27
- $this->claim = NULL;
28
- $this->untrack_action();
29
- remove_action( 'shutdown', array( $this, 'handle_unexpected_shutdown' ) );
30
- remove_action( 'action_scheduler_before_execute', array( $this, 'track_current_action' ), 0 );
31
- remove_action( 'action_scheduler_after_execute', array( $this, 'untrack_action' ), 0 );
32
- remove_action( 'action_scheduler_execution_ignored', array( $this, 'untrack_action' ), 0 );
33
- remove_action( 'action_scheduler_failed_execution', array( $this, 'untrack_action' ), 0 );
34
- }
35
-
36
- public function track_current_action( $action_id ) {
37
- $this->action_id = $action_id;
38
- }
39
-
40
- public function untrack_action() {
41
- $this->action_id = 0;
42
- }
43
-
44
- public function handle_unexpected_shutdown() {
45
- if ( $error = error_get_last() ) {
46
- if ( in_array( $error['type'], array( E_ERROR, E_PARSE, E_COMPILE_ERROR, E_USER_ERROR, E_RECOVERABLE_ERROR ) ) ) {
47
- if ( !empty($this->action_id) ) {
48
- $this->store->mark_failure( $this->action_id );
49
- do_action( 'action_scheduler_unexpected_shutdown', $this->action_id, $error );
50
- }
51
- }
52
- $this->store->release_claim( $this->claim );
53
- }
54
- }
55
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/ActionScheduler_InvalidActionException.php DELETED
@@ -1,47 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * InvalidAction Exception.
5
- *
6
- * Used for identifying actions that are invalid in some way.
7
- *
8
- * @package ActionScheduler
9
- */
10
- class ActionScheduler_InvalidActionException extends \InvalidArgumentException implements ActionScheduler_Exception {
11
-
12
- /**
13
- * Create a new exception when the action's schedule cannot be fetched.
14
- *
15
- * @param string $action_id The action ID with bad args.
16
- * @return static
17
- */
18
- public static function from_schedule( $action_id, $schedule ) {
19
- $message = sprintf(
20
- /* translators: 1: action ID 2: schedule */
21
- __( 'Action [%1$s] has an invalid schedule: %2$s', 'action-scheduler' ),
22
- $action_id,
23
- var_export( $schedule, true )
24
- );
25
-
26
- return new static( $message );
27
- }
28
-
29
- /**
30
- * Create a new exception when the action's args cannot be decoded to an array.
31
- *
32
- * @author Jeremy Pry
33
- *
34
- * @param string $action_id The action ID with bad args.
35
- * @return static
36
- */
37
- public static function from_decoding_args( $action_id, $args = array() ) {
38
- $message = sprintf(
39
- /* translators: 1: action ID 2: arguments */
40
- __( 'Action [%1$s] has invalid arguments. It cannot be JSON decoded to an array. $args = %2$s', 'action-scheduler' ),
41
- $action_id,
42
- var_export( $args, true )
43
- );
44
-
45
- return new static( $message );
46
- }
47
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/ActionScheduler_ListTable.php DELETED
@@ -1,559 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Implements the admin view of the actions.
5
- * @codeCoverageIgnore
6
- */
7
- class ActionScheduler_ListTable extends ActionScheduler_Abstract_ListTable {
8
-
9
- /**
10
- * The package name.
11
- *
12
- * @var string
13
- */
14
- protected $package = 'action-scheduler';
15
-
16
- /**
17
- * Columns to show (name => label).
18
- *
19
- * @var array
20
- */
21
- protected $columns = array();
22
-
23
- /**
24
- * Actions (name => label).
25
- *
26
- * @var array
27
- */
28
- protected $row_actions = array();
29
-
30
- /**
31
- * The active data stores
32
- *
33
- * @var ActionScheduler_Store
34
- */
35
- protected $store;
36
-
37
- /**
38
- * A logger to use for getting action logs to display
39
- *
40
- * @var ActionScheduler_Logger
41
- */
42
- protected $logger;
43
-
44
- /**
45
- * A ActionScheduler_QueueRunner runner instance (or child class)
46
- *
47
- * @var ActionScheduler_QueueRunner
48
- */
49
- protected $runner;
50
-
51
- /**
52
- * Bulk actions. The key of the array is the method name of the implementation:
53
- *
54
- * bulk_<key>(array $ids, string $sql_in).
55
- *
56
- * See the comments in the parent class for further details
57
- *
58
- * @var array
59
- */
60
- protected $bulk_actions = array();
61
-
62
- /**
63
- * Flag variable to render our notifications, if any, once.
64
- *
65
- * @var bool
66
- */
67
- protected static $did_notification = false;
68
-
69
- /**
70
- * Array of seconds for common time periods, like week or month, alongside an internationalised string representation, i.e. "Day" or "Days"
71
- *
72
- * @var array
73
- */
74
- private static $time_periods;
75
-
76
- /**
77
- * Sets the current data store object into `store->action` and initialises the object.
78
- *
79
- * @param ActionScheduler_Store $store
80
- * @param ActionScheduler_Logger $logger
81
- * @param ActionScheduler_QueueRunner $runner
82
- */
83
- public function __construct( ActionScheduler_Store $store, ActionScheduler_Logger $logger, ActionScheduler_QueueRunner $runner ) {
84
-
85
- $this->store = $store;
86
- $this->logger = $logger;
87
- $this->runner = $runner;
88
-
89
- $this->table_header = __( 'Scheduled Actions', 'action-scheduler' );
90
-
91
- $this->bulk_actions = array(
92
- 'delete' => __( 'Delete', 'action-scheduler' ),
93
- );
94
-
95
- $this->columns = array(
96
- 'hook' => __( 'Hook', 'action-scheduler' ),
97
- 'status' => __( 'Status', 'action-scheduler' ),
98
- 'args' => __( 'Arguments', 'action-scheduler' ),
99
- 'group' => __( 'Group', 'action-scheduler' ),
100
- 'recurrence' => __( 'Recurrence', 'action-scheduler' ),
101
- 'schedule' => __( 'Scheduled Date', 'action-scheduler' ),
102
- 'log_entries' => __( 'Log', 'action-scheduler' ),
103
- );
104
-
105
- $this->sort_by = array(
106
- 'schedule',
107
- 'hook',
108
- 'group',
109
- );
110
-
111
- $this->search_by = array(
112
- 'hook',
113
- 'args',
114
- 'claim_id',
115
- );
116
-
117
- $request_status = $this->get_request_status();
118
-
119
- if ( empty( $request_status ) ) {
120
- $this->sort_by[] = 'status';
121
- } elseif ( in_array( $request_status, array( 'in-progress', 'failed' ) ) ) {
122
- $this->columns += array( 'claim_id' => __( 'Claim ID', 'action-scheduler' ) );
123
- $this->sort_by[] = 'claim_id';
124
- }
125
-
126
- $this->row_actions = array(
127
- 'hook' => array(
128
- 'run' => array(
129
- 'name' => __( 'Run', 'action-scheduler' ),
130
- 'desc' => __( 'Process the action now as if it were run as part of a queue', 'action-scheduler' ),
131
- ),
132
- 'cancel' => array(
133
- 'name' => __( 'Cancel', 'action-scheduler' ),
134
- 'desc' => __( 'Cancel the action now to avoid it being run in future', 'action-scheduler' ),
135
- 'class' => 'cancel trash',
136
- ),
137
- ),
138
- );
139
-
140
- self::$time_periods = array(
141
- array(
142
- 'seconds' => YEAR_IN_SECONDS,
143
- /* translators: %s: amount of time */
144
- 'names' => _n_noop( '%s year', '%s years', 'action-scheduler' ),
145
- ),
146
- array(
147
- 'seconds' => MONTH_IN_SECONDS,
148
- /* translators: %s: amount of time */
149
- 'names' => _n_noop( '%s month', '%s months', 'action-scheduler' ),
150
- ),
151
- array(
152
- 'seconds' => WEEK_IN_SECONDS,
153
- /* translators: %s: amount of time */
154
- 'names' => _n_noop( '%s week', '%s weeks', 'action-scheduler' ),
155
- ),
156
- array(
157
- 'seconds' => DAY_IN_SECONDS,
158
- /* translators: %s: amount of time */
159
- 'names' => _n_noop( '%s day', '%s days', 'action-scheduler' ),
160
- ),
161
- array(
162
- 'seconds' => HOUR_IN_SECONDS,
163
- /* translators: %s: amount of time */
164
- 'names' => _n_noop( '%s hour', '%s hours', 'action-scheduler' ),
165
- ),
166
- array(
167
- 'seconds' => MINUTE_IN_SECONDS,
168
- /* translators: %s: amount of time */
169
- 'names' => _n_noop( '%s minute', '%s minutes', 'action-scheduler' ),
170
- ),
171
- array(
172
- 'seconds' => 1,
173
- /* translators: %s: amount of time */
174
- 'names' => _n_noop( '%s second', '%s seconds', 'action-scheduler' ),
175
- ),
176
- );
177
-
178
- parent::__construct( array(
179
- 'singular' => 'action-scheduler',
180
- 'plural' => 'action-scheduler',
181
- 'ajax' => false,
182
- ) );
183
- }
184
-
185
- /**
186
- * Convert an interval of seconds into a two part human friendly string.
187
- *
188
- * The WordPress human_time_diff() function only calculates the time difference to one degree, meaning
189
- * even if an action is 1 day and 11 hours away, it will display "1 day". This function goes one step
190
- * further to display two degrees of accuracy.
191
- *
192
- * Inspired by the Crontrol::interval() function by Edward Dale: https://wordpress.org/plugins/wp-crontrol/
193
- *
194
- * @param int $interval A interval in seconds.
195
- * @param int $periods_to_include Depth of time periods to include, e.g. for an interval of 70, and $periods_to_include of 2, both minutes and seconds would be included. With a value of 1, only minutes would be included.
196
- * @return string A human friendly string representation of the interval.
197
- */
198
- private static function human_interval( $interval, $periods_to_include = 2 ) {
199
-
200
- if ( $interval <= 0 ) {
201
- return __( 'Now!', 'action-scheduler' );
202
- }
203
-
204
- $output = '';
205
-
206
- for ( $time_period_index = 0, $periods_included = 0, $seconds_remaining = $interval; $time_period_index < count( self::$time_periods ) && $seconds_remaining > 0 && $periods_included < $periods_to_include; $time_period_index++ ) {
207
-
208
- $periods_in_interval = floor( $seconds_remaining / self::$time_periods[ $time_period_index ]['seconds'] );
209
-
210
- if ( $periods_in_interval > 0 ) {
211
- if ( ! empty( $output ) ) {
212
- $output .= ' ';
213
- }
214
- $output .= sprintf( _n( self::$time_periods[ $time_period_index ]['names'][0], self::$time_periods[ $time_period_index ]['names'][1], $periods_in_interval, 'action-scheduler' ), $periods_in_interval );
215
- $seconds_remaining -= $periods_in_interval * self::$time_periods[ $time_period_index ]['seconds'];
216
- $periods_included++;
217
- }
218
- }
219
-
220
- return $output;
221
- }
222
-
223
- /**
224
- * Returns the recurrence of an action or 'Non-repeating'. The output is human readable.
225
- *
226
- * @param ActionScheduler_Action $action
227
- *
228
- * @return string
229
- */
230
- protected function get_recurrence( $action ) {
231
- $schedule = $action->get_schedule();
232
- if ( $schedule->is_recurring() ) {
233
- $recurrence = $schedule->get_recurrence();
234
-
235
- if ( is_numeric( $recurrence ) ) {
236
- /* translators: %s: time interval */
237
- return sprintf( __( 'Every %s', 'action-scheduler' ), self::human_interval( $recurrence ) );
238
- } else {
239
- return $recurrence;
240
- }
241
- }
242
-
243
- return __( 'Non-repeating', 'action-scheduler' );
244
- }
245
-
246
- /**
247
- * Serializes the argument of an action to render it in a human friendly format.
248
- *
249
- * @param array $row The array representation of the current row of the table
250
- *
251
- * @return string
252
- */
253
- public function column_args( array $row ) {
254
- if ( empty( $row['args'] ) ) {
255
- return '';
256
- }
257
-
258
- $row_html = '<ul>';
259
- foreach ( $row['args'] as $key => $value ) {
260
- $row_html .= sprintf( '<li><code>%s => %s</code></li>', esc_html( var_export( $key, true ) ), esc_html( var_export( $value, true ) ) );
261
- }
262
- $row_html .= '</ul>';
263
-
264
- return apply_filters( 'action_scheduler_list_table_column_args', $row_html, $row );
265
- }
266
-
267
- /**
268
- * Prints the logs entries inline. We do so to avoid loading Javascript and other hacks to show it in a modal.
269
- *
270
- * @param array $row Action array.
271
- * @return string
272
- */
273
- public function column_log_entries( array $row ) {
274
-
275
- $log_entries_html = '<ol>';
276
-
277
- $timezone = new DateTimezone( 'UTC' );
278
-
279
- foreach ( $row['log_entries'] as $log_entry ) {
280
- $log_entries_html .= $this->get_log_entry_html( $log_entry, $timezone );
281
- }
282
-
283
- $log_entries_html .= '</ol>';
284
-
285
- return $log_entries_html;
286
- }
287
-
288
- /**
289
- * Prints the logs entries inline. We do so to avoid loading Javascript and other hacks to show it in a modal.
290
- *
291
- * @param ActionScheduler_LogEntry $log_entry
292
- * @param DateTimezone $timezone
293
- * @return string
294
- */
295
- protected function get_log_entry_html( ActionScheduler_LogEntry $log_entry, DateTimezone $timezone ) {
296
- $date = $log_entry->get_date();
297
- $date->setTimezone( $timezone );
298
- return sprintf( '<li><strong>%s</strong><br/>%s</li>', esc_html( $date->format( 'Y-m-d H:i:s O' ) ), esc_html( $log_entry->get_message() ) );
299
- }
300
-
301
- /**
302
- * Only display row actions for pending actions.
303
- *
304
- * @param array $row Row to render
305
- * @param string $column_name Current row
306
- *
307
- * @return string
308
- */
309
- protected function maybe_render_actions( $row, $column_name ) {
310
- if ( 'pending' === strtolower( $row['status'] ) ) {
311
- return parent::maybe_render_actions( $row, $column_name );
312
- }
313
-
314
- return '';
315
- }
316
-
317
- /**
318
- * Renders admin notifications
319
- *
320
- * Notifications:
321
- * 1. When the maximum number of tasks are being executed simultaneously
322
- * 2. Notifications when a task us manually executed
323
- */
324
- public function display_admin_notices() {
325
-
326
- if ( $this->runner->has_maximum_concurrent_batches() ) {
327
- $this->admin_notices[] = array(
328
- 'class' => 'updated',
329
- 'message' => sprintf(
330
- /* translators: %s: amount of claims */
331
- __( 'Maximum simultaneous queues already in progress (%s queues). No additional queues will begin processing until the current queues are complete.', 'action-scheduler' ),
332
- $this->store->get_claim_count()
333
- ),
334
- );
335
- } elseif ( $this->store->has_pending_actions_due() ) {
336
-
337
- $async_request_lock_expiration = ActionScheduler::lock()->get_expiration( 'async-request-runner' );
338
-
339
- // No lock set or lock expired
340
- if ( false === $async_request_lock_expiration || $async_request_lock_expiration < time() ) {
341
- $in_progress_url = add_query_arg( 'status', 'in-progress', remove_query_arg( 'status' ) );
342
- /* translators: %s: process URL */
343
- $async_request_message = sprintf( __( 'A new queue has begun processing. <a href="%s">View actions in-progress &raquo;</a>', 'action-scheduler' ), esc_url( $in_progress_url ) );
344
- } else {
345
- /* translators: %d: seconds */
346
- $async_request_message = sprintf( __( 'The next queue will begin processing in approximately %d seconds.', 'action-scheduler' ), $async_request_lock_expiration - time() );
347
- }
348
-
349
- $this->admin_notices[] = array(
350
- 'class' => 'notice notice-info',
351
- 'message' => $async_request_message,
352
- );
353
- }
354
-
355
- $notification = get_transient( 'action_scheduler_admin_notice' );
356
-
357
- if ( is_array( $notification ) ) {
358
- delete_transient( 'action_scheduler_admin_notice' );
359
-
360
- $action = $this->store->fetch_action( $notification['action_id'] );
361
- $action_hook_html = '<strong><code>' . $action->get_hook() . '</code></strong>';
362
- if ( 1 == $notification['success'] ) {
363
- $class = 'updated';
364
- switch ( $notification['row_action_type'] ) {
365
- case 'run' :
366
- /* translators: %s: action HTML */
367
- $action_message_html = sprintf( __( 'Successfully executed action: %s', 'action-scheduler' ), $action_hook_html );
368
- break;
369
- case 'cancel' :
370
- /* translators: %s: action HTML */
371
- $action_message_html = sprintf( __( 'Successfully canceled action: %s', 'action-scheduler' ), $action_hook_html );
372
- break;
373
- default :
374
- /* translators: %s: action HTML */
375
- $action_message_html = sprintf( __( 'Successfully processed change for action: %s', 'action-scheduler' ), $action_hook_html );
376
- break;
377
- }
378
- } else {
379
- $class = 'error';
380
- /* translators: 1: action HTML 2: action ID 3: error message */
381
- $action_message_html = sprintf( __( 'Could not process change for action: "%1$s" (ID: %2$d). Error: %3$s', 'action-scheduler' ), $action_hook_html, esc_html( $notification['action_id'] ), esc_html( $notification['error_message'] ) );
382
- }
383
-
384
- $action_message_html = apply_filters( 'action_scheduler_admin_notice_html', $action_message_html, $action, $notification );
385
-
386
- $this->admin_notices[] = array(
387
- 'class' => $class,
388
- 'message' => $action_message_html,
389
- );
390
- }
391
-
392
- parent::display_admin_notices();
393
- }
394
-
395
- /**
396
- * Prints the scheduled date in a human friendly format.
397
- *
398
- * @param array $row The array representation of the current row of the table
399
- *
400
- * @return string
401
- */
402
- public function column_schedule( $row ) {
403
- return $this->get_schedule_display_string( $row['schedule'] );
404
- }
405
-
406
- /**
407
- * Get the scheduled date in a human friendly format.
408
- *
409
- * @param ActionScheduler_Schedule $schedule
410
- * @return string
411
- */
412
- protected function get_schedule_display_string( ActionScheduler_Schedule $schedule ) {
413
-
414
- $schedule_display_string = '';
415
-
416
- if ( ! $schedule->get_date() ) {
417
- return '0000-00-00 00:00:00';
418
- }
419
-
420
- $next_timestamp = $schedule->get_date()->getTimestamp();
421
-
422
- $schedule_display_string .= $schedule->get_date()->format( 'Y-m-d H:i:s O' );
423
- $schedule_display_string .= '<br/>';
424
-
425
- if ( gmdate( 'U' ) > $next_timestamp ) {
426
- /* translators: %s: date interval */
427
- $schedule_display_string .= sprintf( __( ' (%s ago)', 'action-scheduler' ), self::human_interval( gmdate( 'U' ) - $next_timestamp ) );
428
- } else {
429
- /* translators: %s: date interval */
430
- $schedule_display_string .= sprintf( __( ' (%s)', 'action-scheduler' ), self::human_interval( $next_timestamp - gmdate( 'U' ) ) );
431
- }
432
-
433
- return $schedule_display_string;
434
- }
435
-
436
- /**
437
- * Bulk delete
438
- *
439
- * Deletes actions based on their ID. This is the handler for the bulk delete. It assumes the data
440
- * properly validated by the callee and it will delete the actions without any extra validation.
441
- *
442
- * @param array $ids
443
- * @param string $ids_sql Inherited and unused
444
- */
445
- protected function bulk_delete( array $ids, $ids_sql ) {
446
- foreach ( $ids as $id ) {
447
- $this->store->delete_action( $id );
448
- }
449
- }
450
-
451
- /**
452
- * Implements the logic behind running an action. ActionScheduler_Abstract_ListTable validates the request and their
453
- * parameters are valid.
454
- *
455
- * @param int $action_id
456
- */
457
- protected function row_action_cancel( $action_id ) {
458
- $this->process_row_action( $action_id, 'cancel' );
459
- }
460
-
461
- /**
462
- * Implements the logic behind running an action. ActionScheduler_Abstract_ListTable validates the request and their
463
- * parameters are valid.
464
- *
465
- * @param int $action_id
466
- */
467
- protected function row_action_run( $action_id ) {
468
- $this->process_row_action( $action_id, 'run' );
469
- }
470
-
471
- /**
472
- * Implements the logic behind processing an action once an action link is clicked on the list table.
473
- *
474
- * @param int $action_id
475
- * @param string $row_action_type The type of action to perform on the action.
476
- */
477
- protected function process_row_action( $action_id, $row_action_type ) {
478
- try {
479
- switch ( $row_action_type ) {
480
- case 'run' :
481
- $this->runner->process_action( $action_id, 'Admin List Table' );
482
- break;
483
- case 'cancel' :
484
- $this->store->cancel_action( $action_id );
485
- break;
486
- }
487
- $success = 1;
488
- $error_message = '';
489
- } catch ( Exception $e ) {
490
- $success = 0;
491
- $error_message = $e->getMessage();
492
- }
493
-
494
- set_transient( 'action_scheduler_admin_notice', compact( 'action_id', 'success', 'error_message', 'row_action_type' ), 30 );
495
- }
496
-
497
- /**
498
- * {@inheritDoc}
499
- */
500
- public function prepare_items() {
501
- $this->prepare_column_headers();
502
-
503
- $per_page = $this->get_items_per_page( $this->package . '_items_per_page', $this->items_per_page );
504
- $query = array(
505
- 'per_page' => $per_page,
506
- 'offset' => $this->get_items_offset(),
507
- 'status' => $this->get_request_status(),
508
- 'orderby' => $this->get_request_orderby(),
509
- 'order' => $this->get_request_order(),
510
- 'search' => $this->get_request_search_query(),
511
- );
512
-
513
- $this->items = array();
514
-
515
- $total_items = $this->store->query_actions( $query, 'count' );
516
-
517
- $status_labels = $this->store->get_status_labels();
518
-
519
- foreach ( $this->store->query_actions( $query ) as $action_id ) {
520
- try {
521
- $action = $this->store->fetch_action( $action_id );
522
- } catch ( Exception $e ) {
523
- continue;
524
- }
525
- $this->items[ $action_id ] = array(
526
- 'ID' => $action_id,
527
- 'hook' => $action->get_hook(),
528
- 'status' => $status_labels[ $this->store->get_status( $action_id ) ],
529
- 'args' => $action->get_args(),
530
- 'group' => $action->get_group(),
531
- 'log_entries' => $this->logger->get_logs( $action_id ),
532
- 'claim_id' => $this->store->get_claim_id( $action_id ),
533
- 'recurrence' => $this->get_recurrence( $action ),
534
- 'schedule' => $action->get_schedule(),
535
- );
536
- }
537
-
538
- $this->set_pagination_args( array(
539
- 'total_items' => $total_items,
540
- 'per_page' => $per_page,
541
- 'total_pages' => ceil( $total_items / $per_page ),
542
- ) );
543
- }
544
-
545
- /**
546
- * Prints the available statuses so the user can click to filter.
547
- */
548
- protected function display_filter_by_status() {
549
- $this->status_counts = $this->store->action_counts();
550
- parent::display_filter_by_status();
551
- }
552
-
553
- /**
554
- * Get the text to display in the search box on the list table.
555
- */
556
- protected function get_search_box_button_text() {
557
- return __( 'Search hook, args and claim ID', 'action-scheduler' );
558
- }
559
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/ActionScheduler_LogEntry.php DELETED
@@ -1,67 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_LogEntry
5
- */
6
- class ActionScheduler_LogEntry {
7
-
8
- /**
9
- * @var int $action_id
10
- */
11
- protected $action_id = '';
12
-
13
- /**
14
- * @var string $message
15
- */
16
- protected $message = '';
17
-
18
- /**
19
- * @var Datetime $date
20
- */
21
- protected $date;
22
-
23
- /**
24
- * Constructor
25
- *
26
- * @param mixed $action_id Action ID
27
- * @param string $message Message
28
- * @param Datetime $date Datetime object with the time when this log entry was created. If this parameter is
29
- * not provided a new Datetime object (with current time) will be created.
30
- */
31
- public function __construct( $action_id, $message, $date = null ) {
32
-
33
- /*
34
- * ActionScheduler_wpCommentLogger::get_entry() previously passed a 3rd param of $comment->comment_type
35
- * to ActionScheduler_LogEntry::__construct(), goodness knows why, and the Follow-up Emails plugin
36
- * hard-codes loading its own version of ActionScheduler_wpCommentLogger with that out-dated method,
37
- * goodness knows why, so we need to guard against that here instead of using a DateTime type declaration
38
- * for the constructor's 3rd param of $date and causing a fatal error with older versions of FUE.
39
- */
40
- if ( null !== $date && ! is_a( $date, 'DateTime' ) ) {
41
- _doing_it_wrong( __METHOD__, 'The third parameter must be a valid DateTime instance, or null.', '2.0.0' );
42
- $date = null;
43
- }
44
-
45
- $this->action_id = $action_id;
46
- $this->message = $message;
47
- $this->date = $date ? $date : new Datetime;
48
- }
49
-
50
- /**
51
- * Returns the date when this log entry was created
52
- *
53
- * @return Datetime
54
- */
55
- public function get_date() {
56
- return $this->date;
57
- }
58
-
59
- public function get_action_id() {
60
- return $this->action_id;
61
- }
62
-
63
- public function get_message() {
64
- return $this->message;
65
- }
66
- }
67
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/ActionScheduler_NullLogEntry.php DELETED
@@ -1,11 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_NullLogEntry
5
- */
6
- class ActionScheduler_NullLogEntry extends ActionScheduler_LogEntry {
7
- public function __construct( $action_id = '', $message = '' ) {
8
- // nothing to see here
9
- }
10
- }
11
-
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/ActionScheduler_OptionLock.php DELETED
@@ -1,49 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Provide a way to set simple transient locks to block behaviour
5
- * for up-to a given duration.
6
- *
7
- * Class ActionScheduler_OptionLock
8
- * @since 3.0.0
9
- */
10
- class ActionScheduler_OptionLock extends ActionScheduler_Lock {
11
-
12
- /**
13
- * Set a lock using options for a given amount of time (60 seconds by default).
14
- *
15
- * Using an autoloaded option avoids running database queries or other resource intensive tasks
16
- * on frequently triggered hooks, like 'init' or 'shutdown'.
17
- *
18
- * For example, ActionScheduler_QueueRunner->maybe_dispatch_async_request() uses a lock to avoid
19
- * calling ActionScheduler_QueueRunner->has_maximum_concurrent_batches() every time the 'shutdown',
20
- * hook is triggered, because that method calls ActionScheduler_QueueRunner->store->get_claim_count()
21
- * to find the current number of claims in the database.
22
- *
23
- * @param string $lock_type A string to identify different lock types.
24
- * @bool True if lock value has changed, false if not or if set failed.
25
- */
26
- public function set( $lock_type ) {
27
- return update_option( $this->get_key( $lock_type ), time() + $this->get_duration( $lock_type ) );
28
- }
29
-
30
- /**
31
- * If a lock is set, return the timestamp it was set to expiry.
32
- *
33
- * @param string $lock_type A string to identify different lock types.
34
- * @return bool|int False if no lock is set, otherwise the timestamp for when the lock is set to expire.
35
- */
36
- public function get_expiration( $lock_type ) {
37
- return get_option( $this->get_key( $lock_type ) );
38
- }
39
-
40
- /**
41
- * Get the key to use for storing the lock in the transient
42
- *
43
- * @param string $lock_type A string to identify different lock types.
44
- * @return string
45
- */
46
- protected function get_key( $lock_type ) {
47
- return sprintf( 'action_scheduler_lock_%s', $lock_type );
48
- }
49
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/ActionScheduler_QueueCleaner.php DELETED
@@ -1,155 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_QueueCleaner
5
- */
6
- class ActionScheduler_QueueCleaner {
7
-
8
- /** @var int */
9
- protected $batch_size;
10
-
11
- /** @var ActionScheduler_Store */
12
- private $store = null;
13
-
14
- /**
15
- * 31 days in seconds.
16
- *
17
- * @var int
18
- */
19
- private $month_in_seconds = 2678400;
20
-
21
- /**
22
- * ActionScheduler_QueueCleaner constructor.
23
- *
24
- * @param ActionScheduler_Store $store The store instance.
25
- * @param int $batch_size The batch size.
26
- */
27
- public function __construct( ActionScheduler_Store $store = null, $batch_size = 20 ) {
28
- $this->store = $store ? $store : ActionScheduler_Store::instance();
29
- $this->batch_size = $batch_size;
30
- }
31
-
32
- public function delete_old_actions() {
33
- $lifespan = apply_filters( 'action_scheduler_retention_period', $this->month_in_seconds );
34
- $cutoff = as_get_datetime_object($lifespan.' seconds ago');
35
-
36
- $statuses_to_purge = array(
37
- ActionScheduler_Store::STATUS_COMPLETE,
38
- ActionScheduler_Store::STATUS_CANCELED,
39
- );
40
-
41
- foreach ( $statuses_to_purge as $status ) {
42
- $actions_to_delete = $this->store->query_actions( array(
43
- 'status' => $status,
44
- 'modified' => $cutoff,
45
- 'modified_compare' => '<=',
46
- 'per_page' => $this->get_batch_size(),
47
- ) );
48
-
49
- foreach ( $actions_to_delete as $action_id ) {
50
- try {
51
- $this->store->delete_action( $action_id );
52
- } catch ( Exception $e ) {
53
-
54
- /**
55
- * Notify 3rd party code of exceptions when deleting a completed action older than the retention period
56
- *
57
- * This hook provides a way for 3rd party code to log or otherwise handle exceptions relating to their
58
- * actions.
59
- *
60
- * @since 2.0.0
61
- *
62
- * @param int $action_id The scheduled actions ID in the data store
63
- * @param Exception $e The exception thrown when attempting to delete the action from the data store
64
- * @param int $lifespan The retention period, in seconds, for old actions
65
- * @param int $count_of_actions_to_delete The number of old actions being deleted in this batch
66
- */
67
- do_action( 'action_scheduler_failed_old_action_deletion', $action_id, $e, $lifespan, count( $actions_to_delete ) );
68
- }
69
- }
70
- }
71
- }
72
-
73
- /**
74
- * Unclaim pending actions that have not been run within a given time limit.
75
- *
76
- * When called by ActionScheduler_Abstract_QueueRunner::run_cleanup(), the time limit passed
77
- * as a parameter is 10x the time limit used for queue processing.
78
- *
79
- * @param int $time_limit The number of seconds to allow a queue to run before unclaiming its pending actions. Default 300 (5 minutes).
80
- */
81
- public function reset_timeouts( $time_limit = 300 ) {
82
- $timeout = apply_filters( 'action_scheduler_timeout_period', $time_limit );
83
- if ( $timeout < 0 ) {
84
- return;
85
- }
86
- $cutoff = as_get_datetime_object($timeout.' seconds ago');
87
- $actions_to_reset = $this->store->query_actions( array(
88
- 'status' => ActionScheduler_Store::STATUS_PENDING,
89
- 'modified' => $cutoff,
90
- 'modified_compare' => '<=',
91
- 'claimed' => true,
92
- 'per_page' => $this->get_batch_size(),
93
- ) );
94
-
95
- foreach ( $actions_to_reset as $action_id ) {
96
- $this->store->unclaim_action( $action_id );
97
- do_action( 'action_scheduler_reset_action', $action_id );
98
- }
99
- }
100
-
101
- /**
102
- * Mark actions that have been running for more than a given time limit as failed, based on
103
- * the assumption some uncatachable and unloggable fatal error occurred during processing.
104
- *
105
- * When called by ActionScheduler_Abstract_QueueRunner::run_cleanup(), the time limit passed
106
- * as a parameter is 10x the time limit used for queue processing.
107
- *
108
- * @param int $time_limit The number of seconds to allow an action to run before it is considered to have failed. Default 300 (5 minutes).
109
- */
110
- public function mark_failures( $time_limit = 300 ) {
111
- $timeout = apply_filters( 'action_scheduler_failure_period', $time_limit );
112
- if ( $timeout < 0 ) {
113
- return;
114
- }
115
- $cutoff = as_get_datetime_object($timeout.' seconds ago');
116
- $actions_to_reset = $this->store->query_actions( array(
117
- 'status' => ActionScheduler_Store::STATUS_RUNNING,
118
- 'modified' => $cutoff,
119
- 'modified_compare' => '<=',
120
- 'per_page' => $this->get_batch_size(),
121
- ) );
122
-
123
- foreach ( $actions_to_reset as $action_id ) {
124
- $this->store->mark_failure( $action_id );
125
- do_action( 'action_scheduler_failed_action', $action_id, $timeout );
126
- }
127
- }
128
-
129
- /**
130
- * Do all of the cleaning actions.
131
- *
132
- * @param int $time_limit The number of seconds to use as the timeout and failure period. Default 300 (5 minutes).
133
- * @author Jeremy Pry
134
- */
135
- public function clean( $time_limit = 300 ) {
136
- $this->delete_old_actions();
137
- $this->reset_timeouts( $time_limit );
138
- $this->mark_failures( $time_limit );
139
- }
140
-
141
- /**
142
- * Get the batch size for cleaning the queue.
143
- *
144
- * @author Jeremy Pry
145
- * @return int
146
- */
147
- protected function get_batch_size() {
148
- /**
149
- * Filter the batch size when cleaning the queue.
150
- *
151
- * @param int $batch_size The number of actions to clean in one batch.
152
- */
153
- return absint( apply_filters( 'action_scheduler_cleanup_batch_size', $this->batch_size ) );
154
- }
155
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/ActionScheduler_QueueRunner.php DELETED
@@ -1,185 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_QueueRunner
5
- */
6
- class ActionScheduler_QueueRunner extends ActionScheduler_Abstract_QueueRunner {
7
- const WP_CRON_HOOK = 'action_scheduler_run_queue';
8
-
9
- const WP_CRON_SCHEDULE = 'every_minute';
10
-
11
- /** @var ActionScheduler_AsyncRequest_QueueRunner */
12
- protected $async_request;
13
-
14
- /** @var ActionScheduler_QueueRunner */
15
- private static $runner = null;
16
-
17
- /**
18
- * @return ActionScheduler_QueueRunner
19
- * @codeCoverageIgnore
20
- */
21
- public static function instance() {
22
- if ( empty(self::$runner) ) {
23
- $class = apply_filters('action_scheduler_queue_runner_class', 'ActionScheduler_QueueRunner');
24
- self::$runner = new $class();
25
- }
26
- return self::$runner;
27
- }
28
-
29
- /**
30
- * ActionScheduler_QueueRunner constructor.
31
- *
32
- * @param ActionScheduler_Store $store
33
- * @param ActionScheduler_FatalErrorMonitor $monitor
34
- * @param ActionScheduler_QueueCleaner $cleaner
35
- */
36
- public function __construct( ActionScheduler_Store $store = null, ActionScheduler_FatalErrorMonitor $monitor = null, ActionScheduler_QueueCleaner $cleaner = null, ActionScheduler_AsyncRequest_QueueRunner $async_request = null ) {
37
- parent::__construct( $store, $monitor, $cleaner );
38
-
39
- if ( is_null( $async_request ) ) {
40
- $async_request = new ActionScheduler_AsyncRequest_QueueRunner( $this->store );
41
- }
42
-
43
- $this->async_request = $async_request;
44
- }
45
-
46
- /**
47
- * @codeCoverageIgnore
48
- */
49
- public function init() {
50
-
51
- add_filter( 'cron_schedules', array( self::instance(), 'add_wp_cron_schedule' ) );
52
-
53
- $cron_context = array( 'WP Cron' );
54
-
55
- if ( ! wp_next_scheduled( self::WP_CRON_HOOK, $cron_context ) ) {
56
-
57
- // Check for and remove any WP Cron hook scheduled by Action Scheduler < 3.0.0, which didn't include the $context param
58
- $next_timestamp = wp_next_scheduled( self::WP_CRON_HOOK );
59
- if ( $next_timestamp ) {
60
- wp_unschedule_event( $next_timestamp, self::WP_CRON_HOOK );
61
- }
62
-
63
- $schedule = apply_filters( 'action_scheduler_run_schedule', self::WP_CRON_SCHEDULE );
64
- wp_schedule_event( time(), $schedule, self::WP_CRON_HOOK, $cron_context );
65
- }
66
-
67
- add_action( self::WP_CRON_HOOK, array( self::instance(), 'run' ) );
68
-
69
- add_filter( 'shutdown', array( $this, 'maybe_dispatch_async_request' ) );
70
- }
71
-
72
- /**
73
- * Check if we should dispatch an async request to process actions.
74
- *
75
- * This method is attached to 'shutdown', so is called frequently. To avoid slowing down
76
- * the site, it mitigates the work performed in each request by:
77
- * 1. checking if it's in the admin context and then
78
- * 2. haven't run on the 'shutdown' hook within the lock time (60 seconds by default)
79
- * 3. haven't exceeded the number of allowed batches.
80
- *
81
- * The order of these checks is important, because they run from a check on a value:
82
- * 1. in memory - is_admin() maps to $GLOBALS or the WP_ADMIN constant
83
- * 2. in memory - transients use autoloaded options by default
84
- * 3. from a database query - has_maximum_concurrent_batches() run the query
85
- * $this->store->get_claim_count() to find the current number of claims in the DB.
86
- *
87
- * If all of these conditions are met, then we request an async runner check whether it
88
- * should dispatch a request to process pending actions.
89
- */
90
- public function maybe_dispatch_async_request() {
91
- if ( is_admin() && ! ActionScheduler::lock()->is_locked( 'async-request-runner' ) ) {
92
- // Only start an async queue at most once every 60 seconds
93
- ActionScheduler::lock()->set( 'async-request-runner' );
94
- $this->async_request->maybe_dispatch();
95
- }
96
- }
97
-
98
- /**
99
- * Process actions in the queue. Attached to self::WP_CRON_HOOK i.e. 'action_scheduler_run_queue'
100
- *
101
- * The $context param of this method defaults to 'WP Cron', because prior to Action Scheduler 3.0.0
102
- * that was the only context in which this method was run, and the self::WP_CRON_HOOK hook had no context
103
- * passed along with it. New code calling this method directly, or by triggering the self::WP_CRON_HOOK,
104
- * should set a context as the first parameter. For an example of this, refer to the code seen in
105
- * @see ActionScheduler_AsyncRequest_QueueRunner::handle()
106
- *
107
- * @param string $context Optional identifer for the context in which this action is being processed, e.g. 'WP CLI' or 'WP Cron'
108
- * Generally, this should be capitalised and not localised as it's a proper noun.
109
- * @return int The number of actions processed.
110
- */
111
- public function run( $context = 'WP Cron' ) {
112
- ActionScheduler_Compatibility::raise_memory_limit();
113
- ActionScheduler_Compatibility::raise_time_limit( $this->get_time_limit() );
114
- do_action( 'action_scheduler_before_process_queue' );
115
- $this->run_cleanup();
116
- $processed_actions = 0;
117
- if ( false === $this->has_maximum_concurrent_batches() ) {
118
- $batch_size = apply_filters( 'action_scheduler_queue_runner_batch_size', 25 );
119
- do {
120
- $processed_actions_in_batch = $this->do_batch( $batch_size, $context );
121
- $processed_actions += $processed_actions_in_batch;
122
- } while ( $processed_actions_in_batch > 0 && ! $this->batch_limits_exceeded( $processed_actions ) ); // keep going until we run out of actions, time, or memory
123
- }
124
-
125
- do_action( 'action_scheduler_after_process_queue' );
126
- return $processed_actions;
127
- }
128
-
129
- /**
130
- * Process a batch of actions pending in the queue.
131
- *
132
- * Actions are processed by claiming a set of pending actions then processing each one until either the batch
133
- * size is completed, or memory or time limits are reached, defined by @see $this->batch_limits_exceeded().
134
- *
135
- * @param int $size The maximum number of actions to process in the batch.
136
- * @param string $context Optional identifer for the context in which this action is being processed, e.g. 'WP CLI' or 'WP Cron'
137
- * Generally, this should be capitalised and not localised as it's a proper noun.
138
- * @return int The number of actions processed.
139
- */
140
- protected function do_batch( $size = 100, $context = '' ) {
141
- $claim = $this->store->stake_claim($size);
142
- $this->monitor->attach($claim);
143
- $processed_actions = 0;
144
-
145
- foreach ( $claim->get_actions() as $action_id ) {
146
- // bail if we lost the claim
147
- if ( ! in_array( $action_id, $this->store->find_actions_by_claim_id( $claim->get_id() ) ) ) {
148
- break;
149
- }
150
- $this->process_action( $action_id, $context );
151
- $processed_actions++;
152
-
153
- if ( $this->batch_limits_exceeded( $processed_actions ) ) {
154
- break;
155
- }
156
- }
157
- $this->store->release_claim($claim);
158
- $this->monitor->detach();
159
- $this->clear_caches();
160
- return $processed_actions;
161
- }
162
-
163
- /**
164
- * Running large batches can eat up memory, as WP adds data to its object cache.
165
- *
166
- * If using a persistent object store, this has the side effect of flushing that
167
- * as well, so this is disabled by default. To enable:
168
- *
169
- * add_filter( 'action_scheduler_queue_runner_flush_cache', '__return_true' );
170
- */
171
- protected function clear_caches() {
172
- if ( ! wp_using_ext_object_cache() || apply_filters( 'action_scheduler_queue_runner_flush_cache', false ) ) {
173
- wp_cache_flush();
174
- }
175
- }
176
-
177
- public function add_wp_cron_schedule( $schedules ) {
178
- $schedules['every_minute'] = array(
179
- 'interval' => 60, // in seconds
180
- 'display' => __( 'Every minute', 'action-scheduler' ),
181
- );
182
-
183
- return $schedules;
184
- }
185
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/ActionScheduler_Versions.php DELETED
@@ -1,62 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_Versions
5
- */
6
- class ActionScheduler_Versions {
7
- /**
8
- * @var ActionScheduler_Versions
9
- */
10
- private static $instance = NULL;
11
-
12
- private $versions = array();
13
-
14
- public function register( $version_string, $initialization_callback ) {
15
- if ( isset($this->versions[$version_string]) ) {
16
- return FALSE;
17
- }
18
- $this->versions[$version_string] = $initialization_callback;
19
- return TRUE;
20
- }
21
-
22
- public function get_versions() {
23
- return $this->versions;
24
- }
25
-
26
- public function latest_version() {
27
- $keys = array_keys($this->versions);
28
- if ( empty($keys) ) {
29
- return false;
30
- }
31
- uasort( $keys, 'version_compare' );
32
- return end($keys);
33
- }
34
-
35
- public function latest_version_callback() {
36
- $latest = $this->latest_version();
37
- if ( empty($latest) || !isset($this->versions[$latest]) ) {
38
- return '__return_null';
39
- }
40
- return $this->versions[$latest];
41
- }
42
-
43
- /**
44
- * @return ActionScheduler_Versions
45
- * @codeCoverageIgnore
46
- */
47
- public static function instance() {
48
- if ( empty(self::$instance) ) {
49
- self::$instance = new self();
50
- }
51
- return self::$instance;
52
- }
53
-
54
- /**
55
- * @codeCoverageIgnore
56
- */
57
- public static function initialize_latest_version() {
58
- $self = self::instance();
59
- call_user_func($self->latest_version_callback());
60
- }
61
- }
62
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/ActionScheduler_WPCommentCleaner.php DELETED
@@ -1,108 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_WPCommentCleaner
5
- *
6
- * @since 3.0.0
7
- */
8
- class ActionScheduler_WPCommentCleaner {
9
-
10
- /**
11
- * Post migration hook used to cleanup the WP comment table.
12
- *
13
- * @var string
14
- */
15
- protected static $cleanup_hook = 'action_scheduler/cleanup_wp_comment_logs';
16
-
17
- /**
18
- * An instance of the ActionScheduler_wpCommentLogger class to interact with the comments table.
19
- *
20
- * This instance should only be used as an interface. It should not be initialized.
21
- *
22
- * @var ActionScheduler_wpCommentLogger
23
- */
24
- protected static $wp_comment_logger = null;
25
-
26
- /**
27
- * The key used to store the cached value of whether there are logs in the WP comment table.
28
- *
29
- * @var string
30
- */
31
- protected static $has_logs_option_key = 'as_has_wp_comment_logs';
32
-
33
- /**
34
- * Initialize the class and attach callbacks.
35
- */
36
- public static function init() {
37
- if ( empty( self::$wp_comment_logger ) ) {
38
- self::$wp_comment_logger = new ActionScheduler_wpCommentLogger();
39
- }
40
-
41
- add_action( self::$cleanup_hook, array( __CLASS__, 'delete_all_action_comments' ) );
42
-
43
- // While there are orphaned logs left in the comments table, we need to attach the callbacks which filter comment counts.
44
- add_action( 'pre_get_comments', array( self::$wp_comment_logger, 'filter_comment_queries' ), 10, 1 );
45
- add_action( 'wp_count_comments', array( self::$wp_comment_logger, 'filter_comment_count' ), 20, 2 ); // run after WC_Comments::wp_count_comments() to make sure we exclude order notes and action logs
46
- add_action( 'comment_feed_where', array( self::$wp_comment_logger, 'filter_comment_feed' ), 10, 2 );
47
-
48
- // Action Scheduler may be displayed as a Tools screen or WooCommerce > Status administration screen
49
- add_action( 'load-tools_page_action-scheduler', array( __CLASS__, 'print_admin_notice' ) );
50
- add_action( 'load-woocommerce_page_wc-status', array( __CLASS__, 'print_admin_notice' ) );
51
- }
52
-
53
- /**
54
- * Determines if there are log entries in the wp comments table.
55
- *
56
- * Uses the flag set on migration completion set by @see self::maybe_schedule_cleanup().
57
- *
58
- * @return boolean Whether there are scheduled action comments in the comments table.
59
- */
60
- public static function has_logs() {
61
- return 'yes' === get_option( self::$has_logs_option_key );
62
- }
63
-
64
- /**
65
- * Schedules the WP Post comment table cleanup to run in 6 months if it's not already scheduled.
66
- * Attached to the migration complete hook 'action_scheduler/migration_complete'.
67
- */
68
- public static function maybe_schedule_cleanup() {
69
- if ( (bool) get_comments( array( 'type' => ActionScheduler_wpCommentLogger::TYPE, 'number' => 1, 'fields' => 'ids' ) ) ) {
70
- update_option( self::$has_logs_option_key, 'yes' );
71
-
72
- if ( ! as_next_scheduled_action( self::$cleanup_hook ) ) {
73
- as_schedule_single_action( gmdate( 'U' ) + ( 6 * MONTH_IN_SECONDS ), self::$cleanup_hook );
74
- }
75
- }
76
- }
77
-
78
- /**
79
- * Delete all action comments from the WP Comments table.
80
- */
81
- public static function delete_all_action_comments() {
82
- global $wpdb;
83
- $wpdb->delete( $wpdb->comments, array( 'comment_type' => ActionScheduler_wpCommentLogger::TYPE, 'comment_agent' => ActionScheduler_wpCommentLogger::AGENT ) );
84
- delete_option( self::$has_logs_option_key );
85
- }
86
-
87
- /**
88
- * Prints details about the orphaned action logs and includes information on where to learn more.
89
- */
90
- public static function print_admin_notice() {
91
- $next_cleanup_message = '';
92
- $next_scheduled_cleanup_hook = as_next_scheduled_action( self::$cleanup_hook );
93
-
94
- if ( $next_scheduled_cleanup_hook ) {
95
- /* translators: %s: date interval */
96
- $next_cleanup_message = sprintf( __( 'This data will be deleted in %s.', 'action-scheduler' ), human_time_diff( gmdate( 'U' ), $next_scheduled_cleanup_hook ) );
97
- }
98
-
99
- $notice = sprintf(
100
- /* translators: 1: next cleanup message 2: github issue URL */
101
- __( 'Action Scheduler has migrated data to custom tables; however, orphaned log entries exist in the WordPress Comments table. %1$s <a href="%2$s">Learn more &raquo;</a>', 'action-scheduler' ),
102
- $next_cleanup_message,
103
- 'https://github.com/woocommerce/action-scheduler/issues/368'
104
- );
105
-
106
- echo '<div class="notice notice-warning"><p>' . wp_kses_post( $notice ) . '</p></div>';
107
- }
108
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/ActionScheduler_wcSystemStatus.php DELETED
@@ -1,147 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_wcSystemStatus
5
- */
6
- class ActionScheduler_wcSystemStatus {
7
-
8
- /**
9
- * The active data stores
10
- *
11
- * @var ActionScheduler_Store
12
- */
13
- protected $store;
14
-
15
- function __construct( $store ) {
16
- $this->store = $store;
17
- }
18
-
19
- /**
20
- * Display action data, including number of actions grouped by status and the oldest & newest action in each status.
21
- *
22
- * Helpful to identify issues, like a clogged queue.
23
- */
24
- public function render() {
25
- $action_counts = $this->store->action_counts();
26
- $status_labels = $this->store->get_status_labels();
27
- $oldest_and_newest = $this->get_oldest_and_newest( array_keys( $status_labels ) );
28
-
29
- $this->get_template( $status_labels, $action_counts, $oldest_and_newest );
30
- }
31
-
32
- /**
33
- * Get oldest and newest scheduled dates for a given set of statuses.
34
- *
35
- * @param array $status_keys Set of statuses to find oldest & newest action for.
36
- * @return array
37
- */
38
- protected function get_oldest_and_newest( $status_keys ) {
39
-
40
- $oldest_and_newest = array();
41
-
42
- foreach ( $status_keys as $status ) {
43
- $oldest_and_newest[ $status ] = array(
44
- 'oldest' => '&ndash;',
45
- 'newest' => '&ndash;',
46
- );
47
-
48
- if ( 'in-progress' === $status ) {
49
- continue;
50
- }
51
-
52
- $oldest_and_newest[ $status ]['oldest'] = $this->get_action_status_date( $status, 'oldest' );
53
- $oldest_and_newest[ $status ]['newest'] = $this->get_action_status_date( $status, 'newest' );
54
- }
55
-
56
- return $oldest_and_newest;
57
- }
58
-
59
- /**
60
- * Get oldest or newest scheduled date for a given status.
61
- *
62
- * @param string $status Action status label/name string.
63
- * @param string $date_type Oldest or Newest.
64
- * @return DateTime
65
- */
66
- protected function get_action_status_date( $status, $date_type = 'oldest' ) {
67
-
68
- $order = 'oldest' === $date_type ? 'ASC' : 'DESC';
69
-
70
- $action = $this->store->query_actions( array(
71
- 'claimed' => false,
72
- 'status' => $status,
73
- 'per_page' => 1,
74
- 'order' => $order,
75
- ) );
76
-
77
- if ( ! empty( $action ) ) {
78
- $date_object = $this->store->get_date( $action[0] );
79
- $action_date = $date_object->format( 'Y-m-d H:i:s O' );
80
- } else {
81
- $action_date = '&ndash;';
82
- }
83
-
84
- return $action_date;
85
- }
86
-
87
- /**
88
- * Get oldest or newest scheduled date for a given status.
89
- *
90
- * @param array $status_labels Set of statuses to find oldest & newest action for.
91
- * @param array $action_counts Number of actions grouped by status.
92
- * @param array $oldest_and_newest Date of the oldest and newest action with each status.
93
- */
94
- protected function get_template( $status_labels, $action_counts, $oldest_and_newest ) {
95
- ?>
96
-
97
- <table class="wc_status_table widefat" cellspacing="0">
98
- <thead>
99
- <tr>
100
- <th colspan="5" data-export-label="Action Scheduler"><h2><?php esc_html_e( 'Action Scheduler', 'action-scheduler' ); ?><?php echo wc_help_tip( esc_html__( 'This section shows scheduled action counts.', 'action-scheduler' ) ); ?></h2></th>
101
- </tr>
102
- <tr>
103
- <td><strong><?php esc_html_e( 'Action Status', 'action-scheduler' ); ?></strong></td>
104
- <td class="help">&nbsp;</td>
105
- <td><strong><?php esc_html_e( 'Count', 'action-scheduler' ); ?></strong></td>
106
- <td><strong><?php esc_html_e( 'Oldest Scheduled Date', 'action-scheduler' ); ?></strong></td>
107
- <td><strong><?php esc_html_e( 'Newest Scheduled Date', 'action-scheduler' ); ?></strong></td>
108
- </tr>
109
- </thead>
110
- <tbody>
111
- <?php
112
- foreach ( $action_counts as $status => $count ) {
113
- // WC uses the 3rd column for export, so we need to display more data in that (hidden when viewed as part of the table) and add an empty 2nd column.
114
- printf(
115
- '<tr><td>%1$s</td><td>&nbsp;</td><td>%2$s<span style="display: none;">, Oldest: %3$s, Newest: %4$s</span></td><td>%3$s</td><td>%4$s</td></tr>',
116
- esc_html( $status_labels[ $status ] ),
117
- number_format_i18n( $count ),
118
- $oldest_and_newest[ $status ]['oldest'],
119
- $oldest_and_newest[ $status ]['newest']
120
- );
121
- }
122
- ?>
123
- </tbody>
124
- </table>
125
-
126
- <?php
127
- }
128
-
129
- /**
130
- * is triggered when invoking inaccessible methods in an object context.
131
- *
132
- * @param string $name
133
- * @param array $arguments
134
- *
135
- * @return mixed
136
- * @link https://php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.methods
137
- */
138
- public function __call( $name, $arguments ) {
139
- switch ( $name ) {
140
- case 'print':
141
- _deprecated_function( __CLASS__ . '::print()', '2.2.4', __CLASS__ . '::render()' );
142
- return call_user_func_array( array( $this, 'render' ), $arguments );
143
- }
144
-
145
- return null;
146
- }
147
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/WP_CLI/ActionScheduler_WPCLI_QueueRunner.php DELETED
@@ -1,197 +0,0 @@
1
- <?php
2
-
3
- use Action_Scheduler\WP_CLI\ProgressBar;
4
-
5
- /**
6
- * WP CLI Queue runner.
7
- *
8
- * This class can only be called from within a WP CLI instance.
9
- */
10
- class ActionScheduler_WPCLI_QueueRunner extends ActionScheduler_Abstract_QueueRunner {
11
-
12
- /** @var array */
13
- protected $actions;
14
-
15
- /** @var ActionScheduler_ActionClaim */
16
- protected $claim;
17
-
18
- /** @var \cli\progress\Bar */
19
- protected $progress_bar;
20
-
21
- /**
22
- * ActionScheduler_WPCLI_QueueRunner constructor.
23
- *
24
- * @param ActionScheduler_Store $store
25
- * @param ActionScheduler_FatalErrorMonitor $monitor
26
- * @param ActionScheduler_QueueCleaner $cleaner
27
- *
28
- * @throws Exception When this is not run within WP CLI
29
- */
30
- public function __construct( ActionScheduler_Store $store = null, ActionScheduler_FatalErrorMonitor $monitor = null, ActionScheduler_QueueCleaner $cleaner = null ) {
31
- if ( ! ( defined( 'WP_CLI' ) && WP_CLI ) ) {
32
- /* translators: %s php class name */
33
- throw new Exception( sprintf( __( 'The %s class can only be run within WP CLI.', 'action-scheduler' ), __CLASS__ ) );
34
- }
35
-
36
- parent::__construct( $store, $monitor, $cleaner );
37
- }
38
-
39
- /**
40
- * Set up the Queue before processing.
41
- *
42
- * @author Jeremy Pry
43
- *
44
- * @param int $batch_size The batch size to process.
45
- * @param array $hooks The hooks being used to filter the actions claimed in this batch.
46
- * @param string $group The group of actions to claim with this batch.
47
- * @param bool $force Whether to force running even with too many concurrent processes.
48
- *
49
- * @return int The number of actions that will be run.
50
- * @throws \WP_CLI\ExitException When there are too many concurrent batches.
51
- */
52
- public function setup( $batch_size, $hooks = array(), $group = '', $force = false ) {
53
- $this->run_cleanup();
54
- $this->add_hooks();
55
-
56
- // Check to make sure there aren't too many concurrent processes running.
57
- if ( $this->has_maximum_concurrent_batches() ) {
58
- if ( $force ) {
59
- WP_CLI::warning( __( 'There are too many concurrent batches, but the run is forced to continue.', 'action-scheduler' ) );
60
- } else {
61
- WP_CLI::error( __( 'There are too many concurrent batches.', 'action-scheduler' ) );
62
- }
63
- }
64
-
65
- // Stake a claim and store it.
66
- $this->claim = $this->store->stake_claim( $batch_size, null, $hooks, $group );
67
- $this->monitor->attach( $this->claim );
68
- $this->actions = $this->claim->get_actions();
69
-
70
- return count( $this->actions );
71
- }
72
-
73
- /**
74
- * Add our hooks to the appropriate actions.
75
- *
76
- * @author Jeremy Pry
77
- */
78
- protected function add_hooks() {
79
- add_action( 'action_scheduler_before_execute', array( $this, 'before_execute' ) );
80
- add_action( 'action_scheduler_after_execute', array( $this, 'after_execute' ), 10, 2 );
81
- add_action( 'action_scheduler_failed_execution', array( $this, 'action_failed' ), 10, 2 );
82
- }
83
-
84
- /**
85
- * Set up the WP CLI progress bar.
86
- *
87
- * @author Jeremy Pry
88
- */
89
- protected function setup_progress_bar() {
90
- $count = count( $this->actions );
91
- $this->progress_bar = new ProgressBar(
92
- /* translators: %d: amount of actions */
93
- sprintf( _n( 'Running %d action', 'Running %d actions', $count, 'action-scheduler' ), number_format_i18n( $count ) ),
94
- $count
95
- );
96
- }
97
-
98
- /**
99
- * Process actions in the queue.
100
- *
101
- * @author Jeremy Pry
102
- *
103
- * @param string $context Optional runner context. Default 'WP CLI'.
104
- *
105
- * @return int The number of actions processed.
106
- */
107
- public function run( $context = 'WP CLI' ) {
108
- do_action( 'action_scheduler_before_process_queue' );
109
- $this->setup_progress_bar();
110
- foreach ( $this->actions as $action_id ) {
111
- // Error if we lost the claim.
112
- if ( ! in_array( $action_id, $this->store->find_actions_by_claim_id( $this->claim->get_id() ) ) ) {
113
- WP_CLI::warning( __( 'The claim has been lost. Aborting current batch.', 'action-scheduler' ) );
114
- break;
115
- }
116
-
117
- $this->process_action( $action_id, $context );
118
- $this->progress_bar->tick();
119
- }
120
-
121
- $completed = $this->progress_bar->current();
122
- $this->progress_bar->finish();
123
- $this->store->release_claim( $this->claim );
124
- do_action( 'action_scheduler_after_process_queue' );
125
-
126
- return $completed;
127
- }
128
-
129
- /**
130
- * Handle WP CLI message when the action is starting.
131
- *
132
- * @author Jeremy Pry
133
- *
134
- * @param $action_id
135
- */
136
- public function before_execute( $action_id ) {
137
- /* translators: %s refers to the action ID */
138
- WP_CLI::log( sprintf( __( 'Started processing action %s', 'action-scheduler' ), $action_id ) );
139
- }
140
-
141
- /**
142
- * Handle WP CLI message when the action has completed.
143
- *
144
- * @author Jeremy Pry
145
- *
146
- * @param int $action_id
147
- * @param null|ActionScheduler_Action $action The instance of the action. Default to null for backward compatibility.
148
- */
149
- public function after_execute( $action_id, $action = null ) {
150
- // backward compatibility
151
- if ( null === $action ) {
152
- $action = $this->store->fetch_action( $action_id );
153
- }
154
- /* translators: 1: action ID 2: hook name */
155
- WP_CLI::log( sprintf( __( 'Completed processing action %1$s with hook: %2$s', 'action-scheduler' ), $action_id, $action->get_hook() ) );
156
- }
157
-
158
- /**
159
- * Handle WP CLI message when the action has failed.
160
- *
161
- * @author Jeremy Pry
162
- *
163
- * @param int $action_id
164
- * @param Exception $exception
165
- * @throws \WP_CLI\ExitException With failure message.
166
- */
167
- public function action_failed( $action_id, $exception ) {
168
- WP_CLI::error(
169
- /* translators: 1: action ID 2: exception message */
170
- sprintf( __( 'Error processing action %1$s: %2$s', 'action-scheduler' ), $action_id, $exception->getMessage() ),
171
- false
172
- );
173
- }
174
-
175
- /**
176
- * Sleep and help avoid hitting memory limit
177
- *
178
- * @param int $sleep_time Amount of seconds to sleep
179
- * @deprecated 3.0.0
180
- */
181
- protected function stop_the_insanity( $sleep_time = 0 ) {
182
- _deprecated_function( 'ActionScheduler_WPCLI_QueueRunner::stop_the_insanity', '3.0.0', 'ActionScheduler_DataController::free_memory' );
183
-
184
- ActionScheduler_DataController::free_memory();
185
- }
186
-
187
- /**
188
- * Maybe trigger the stop_the_insanity() method to free up memory.
189
- */
190
- protected function maybe_stop_the_insanity() {
191
- // The value returned by progress_bar->current() might be padded. Remove padding, and convert to int.
192
- $current_iteration = intval( trim( $this->progress_bar->current() ) );
193
- if ( 0 === $current_iteration % 50 ) {
194
- $this->stop_the_insanity();
195
- }
196
- }
197
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/WP_CLI/ActionScheduler_WPCLI_Scheduler_command.php DELETED
@@ -1,158 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Commands for Action Scheduler.
5
- */
6
- class ActionScheduler_WPCLI_Scheduler_command extends WP_CLI_Command {
7
-
8
- /**
9
- * Run the Action Scheduler
10
- *
11
- * ## OPTIONS
12
- *
13
- * [--batch-size=<size>]
14
- * : The maximum number of actions to run. Defaults to 100.
15
- *
16
- * [--batches=<size>]
17
- * : Limit execution to a number of batches. Defaults to 0, meaning batches will continue being executed until all actions are complete.
18
- *
19
- * [--cleanup-batch-size=<size>]
20
- * : The maximum number of actions to clean up. Defaults to the value of --batch-size.
21
- *
22
- * [--hooks=<hooks>]
23
- * : Only run actions with the specified hook. Omitting this option runs actions with any hook. Define multiple hooks as a comma separated string (without spaces), e.g. `--hooks=hook_one,hook_two,hook_three`
24
- *
25
- * [--group=<group>]
26
- * : Only run actions from the specified group. Omitting this option runs actions from all groups.
27
- *
28
- * [--free-memory-on=<count>]
29
- * : The number of actions to process between freeing memory. 0 disables freeing memory. Default 50.
30
- *
31
- * [--pause=<seconds>]
32
- * : The number of seconds to pause when freeing memory. Default no pause.
33
- *
34
- * [--force]
35
- * : Whether to force execution despite the maximum number of concurrent processes being exceeded.
36
- *
37
- * @param array $args Positional arguments.
38
- * @param array $assoc_args Keyed arguments.
39
- * @throws \WP_CLI\ExitException When an error occurs.
40
- *
41
- * @subcommand run
42
- */
43
- public function run( $args, $assoc_args ) {
44
- // Handle passed arguments.
45
- $batch = absint( \WP_CLI\Utils\get_flag_value( $assoc_args, 'batch-size', 100 ) );
46
- $batches = absint( \WP_CLI\Utils\get_flag_value( $assoc_args, 'batches', 0 ) );
47
- $clean = absint( \WP_CLI\Utils\get_flag_value( $assoc_args, 'cleanup-batch-size', $batch ) );
48
- $hooks = explode( ',', WP_CLI\Utils\get_flag_value( $assoc_args, 'hooks', '' ) );
49
- $hooks = array_filter( array_map( 'trim', $hooks ) );
50
- $group = \WP_CLI\Utils\get_flag_value( $assoc_args, 'group', '' );
51
- $free_on = \WP_CLI\Utils\get_flag_value( $assoc_args, 'free-memory-on', '' );
52
- $sleep = \WP_CLI\Utils\get_flag_value( $assoc_args, 'pause', '' );
53
- $force = \WP_CLI\Utils\get_flag_value( $assoc_args, 'force', false );
54
-
55
- ActionScheduler_DataController::set_free_ticks( $free_on );
56
- ActionScheduler_DataController::set_sleep_time( $sleep );
57
-
58
- $batches_completed = 0;
59
- $actions_completed = 0;
60
- $unlimited = $batches === 0;
61
-
62
- try {
63
- // Custom queue cleaner instance.
64
- $cleaner = new ActionScheduler_QueueCleaner( null, $clean );
65
-
66
- // Get the queue runner instance
67
- $runner = new ActionScheduler_WPCLI_QueueRunner( null, null, $cleaner );
68
-
69
- // Determine how many tasks will be run in the first batch.
70
- $total = $runner->setup( $batch, $hooks, $group, $force );
71
-
72
- // Run actions for as long as possible.
73
- while ( $total > 0 ) {
74
- $this->print_total_actions( $total );
75
- $actions_completed += $runner->run();
76
- $batches_completed++;
77
-
78
- // Maybe set up tasks for the next batch.
79
- $total = ( $unlimited || $batches_completed < $batches ) ? $runner->setup( $batch, $hooks, $group, $force ) : 0;
80
- }
81
- } catch ( Exception $e ) {
82
- $this->print_error( $e );
83
- }
84
-
85
- $this->print_total_batches( $batches_completed );
86
- $this->print_success( $actions_completed );
87
- }
88
-
89
- /**
90
- * Print WP CLI message about how many actions are about to be processed.
91
- *
92
- * @author Jeremy Pry
93
- *
94
- * @param int $total
95
- */
96
- protected function print_total_actions( $total ) {
97
- WP_CLI::log(
98
- sprintf(
99
- /* translators: %d refers to how many scheduled taks were found to run */
100
- _n( 'Found %d scheduled task', 'Found %d scheduled tasks', $total, 'action-scheduler' ),
101
- number_format_i18n( $total )
102
- )
103
- );
104
- }
105
-
106
- /**
107
- * Print WP CLI message about how many batches of actions were processed.
108
- *
109
- * @author Jeremy Pry
110
- *
111
- * @param int $batches_completed
112
- */
113
- protected function print_total_batches( $batches_completed ) {
114
- WP_CLI::log(
115
- sprintf(
116
- /* translators: %d refers to the total number of batches executed */
117
- _n( '%d batch executed.', '%d batches executed.', $batches_completed, 'action-scheduler' ),
118
- number_format_i18n( $batches_completed )
119
- )
120
- );
121
- }
122
-
123
- /**
124
- * Convert an exception into a WP CLI error.
125
- *
126
- * @author Jeremy Pry
127
- *
128
- * @param Exception $e The error object.
129
- *
130
- * @throws \WP_CLI\ExitException
131
- */
132
- protected function print_error( Exception $e ) {
133
- WP_CLI::error(
134
- sprintf(
135
- /* translators: %s refers to the exception error message */
136
- __( 'There was an error running the action scheduler: %s', 'action-scheduler' ),
137
- $e->getMessage()
138
- )
139
- );
140
- }
141
-
142
- /**
143
- * Print a success message with the number of completed actions.
144
- *
145
- * @author Jeremy Pry
146
- *
147
- * @param int $actions_completed
148
- */
149
- protected function print_success( $actions_completed ) {
150
- WP_CLI::success(
151
- sprintf(
152
- /* translators: %d refers to the total number of taskes completed */
153
- _n( '%d scheduled task completed.', '%d scheduled tasks completed.', $actions_completed, 'action-scheduler' ),
154
- number_format_i18n( $actions_completed )
155
- )
156
- );
157
- }
158
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/WP_CLI/Migration_Command.php DELETED
@@ -1,148 +0,0 @@
1
- <?php
2
-
3
-
4
- namespace Action_Scheduler\WP_CLI;
5
-
6
- use Action_Scheduler\Migration\Config;
7
- use Action_Scheduler\Migration\Runner;
8
- use Action_Scheduler\Migration\Scheduler;
9
- use Action_Scheduler\Migration\Controller;
10
- use WP_CLI;
11
- use WP_CLI_Command;
12
-
13
- /**
14
- * Class Migration_Command
15
- *
16
- * @package Action_Scheduler\WP_CLI
17
- *
18
- * @since 3.0.0
19
- *
20
- * @codeCoverageIgnore
21
- */
22
- class Migration_Command extends WP_CLI_Command {
23
-
24
- /** @var int */
25
- private $total_processed = 0;
26
-
27
- /**
28
- * Register the command with WP-CLI
29
- */
30
- public function register() {
31
- if ( ! defined( 'WP_CLI' ) || ! WP_CLI ) {
32
- return;
33
- }
34
-
35
- WP_CLI::add_command( 'action-scheduler migrate', [ $this, 'migrate' ], [
36
- 'shortdesc' => 'Migrates actions to the DB tables store',
37
- 'synopsis' => [
38
- [
39
- 'type' => 'assoc',
40
- 'name' => 'batch-size',
41
- 'optional' => true,
42
- 'default' => 100,
43
- 'description' => 'The number of actions to process in each batch',
44
- ],
45
- [
46
- 'type' => 'assoc',
47
- 'name' => 'free-memory-on',
48
- 'optional' => true,
49
- 'default' => 50,
50
- 'description' => 'The number of actions to process between freeing memory. 0 disables freeing memory',
51
- ],
52
- [
53
- 'type' => 'assoc',
54
- 'name' => 'pause',
55
- 'optional' => true,
56
- 'default' => 0,
57
- 'description' => 'The number of seconds to pause when freeing memory',
58
- ],
59
- [
60
- 'type' => 'flag',
61
- 'name' => 'dry-run',
62
- 'optional' => true,
63
- 'description' => 'Reports on the actions that would have been migrated, but does not change any data',
64
- ],
65
- ],
66
- ] );
67
- }
68
-
69
- /**
70
- * Process the data migration.
71
- *
72
- * @param array $positional_args Required for WP CLI. Not used in migration.
73
- * @param array $assoc_args Optional arguments.
74
- *
75
- * @return void
76
- */
77
- public function migrate( $positional_args, $assoc_args ) {
78
- $this->init_logging();
79
-
80
- $config = $this->get_migration_config( $assoc_args );
81
- $runner = new Runner( $config );
82
- $runner->init_destination();
83
-
84
- $batch_size = isset( $assoc_args[ 'batch-size' ] ) ? (int) $assoc_args[ 'batch-size' ] : 100;
85
- $free_on = isset( $assoc_args[ 'free-memory-on' ] ) ? (int) $assoc_args[ 'free-memory-on' ] : 50;
86
- $sleep = isset( $assoc_args[ 'pause' ] ) ? (int) $assoc_args[ 'pause' ] : 0;
87
- \ActionScheduler_DataController::set_free_ticks( $free_on );
88
- \ActionScheduler_DataController::set_sleep_time( $sleep );
89
-
90
- do {
91
- $actions_processed = $runner->run( $batch_size );
92
- $this->total_processed += $actions_processed;
93
- } while ( $actions_processed > 0 );
94
-
95
- if ( ! $config->get_dry_run() ) {
96
- // let the scheduler know that there's nothing left to do
97
- $scheduler = new Scheduler();
98
- $scheduler->mark_complete();
99
- }
100
-
101
- WP_CLI::success( sprintf( '%s complete. %d actions processed.', $config->get_dry_run() ? 'Dry run' : 'Migration', $this->total_processed ) );
102
- }
103
-
104
- /**
105
- * Build the config object used to create the Runner
106
- *
107
- * @param array $args Optional arguments.
108
- *
109
- * @return ActionScheduler\Migration\Config
110
- */
111
- private function get_migration_config( $args ) {
112
- $args = wp_parse_args( $args, [
113
- 'dry-run' => false,
114
- ] );
115
-
116
- $config = Controller::instance()->get_migration_config_object();
117
- $config->set_dry_run( ! empty( $args[ 'dry-run' ] ) );
118
-
119
- return $config;
120
- }
121
-
122
- /**
123
- * Hook command line logging into migration actions.
124
- */
125
- private function init_logging() {
126
- add_action( 'action_scheduler/migrate_action_dry_run', function ( $action_id ) {
127
- WP_CLI::debug( sprintf( 'Dry-run: migrated action %d', $action_id ) );
128
- }, 10, 1 );
129
- add_action( 'action_scheduler/no_action_to_migrate', function ( $action_id ) {
130
- WP_CLI::debug( sprintf( 'No action found to migrate for ID %d', $action_id ) );
131
- }, 10, 1 );
132
- add_action( 'action_scheduler/migrate_action_failed', function ( $action_id ) {
133
- WP_CLI::warning( sprintf( 'Failed migrating action with ID %d', $action_id ) );
134
- }, 10, 1 );
135
- add_action( 'action_scheduler/migrate_action_incomplete', function ( $source_id, $destination_id ) {
136
- WP_CLI::warning( sprintf( 'Unable to remove source action with ID %d after migrating to new ID %d', $source_id, $destination_id ) );
137
- }, 10, 2 );
138
- add_action( 'action_scheduler/migrated_action', function ( $source_id, $destination_id ) {
139
- WP_CLI::debug( sprintf( 'Migrated source action with ID %d to new store with ID %d', $source_id, $destination_id ) );
140
- }, 10, 2 );
141
- add_action( 'action_scheduler/migration_batch_starting', function ( $batch ) {
142
- WP_CLI::debug( 'Beginning migration of batch: ' . print_r( $batch, true ) );
143
- }, 10, 1 );
144
- add_action( 'action_scheduler/migration_batch_complete', function ( $batch ) {
145
- WP_CLI::log( sprintf( 'Completed migration of %d actions', count( $batch ) ) );
146
- }, 10, 1 );
147
- }
148
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/WP_CLI/ProgressBar.php DELETED
@@ -1,119 +0,0 @@
1
- <?php
2
-
3
- namespace Action_Scheduler\WP_CLI;
4
-
5
- /**
6
- * WP_CLI progress bar for Action Scheduler.
7
- */
8
-
9
- /**
10
- * Class ProgressBar
11
- *
12
- * @package Action_Scheduler\WP_CLI
13
- *
14
- * @since 3.0.0
15
- *
16
- * @codeCoverageIgnore
17
- */
18
- class ProgressBar {
19
-
20
- /** @var integer */
21
- protected $total_ticks;
22
-
23
- /** @var integer */
24
- protected $count;
25
-
26
- /** @var integer */
27
- protected $interval;
28
-
29
- /** @var string */
30
- protected $message;
31
-
32
- /** @var \cli\progress\Bar */
33
- protected $progress_bar;
34
-
35
- /**
36
- * ProgressBar constructor.
37
- *
38
- * @param string $message Text to display before the progress bar.
39
- * @param integer $count Total number of ticks to be performed.
40
- * @param integer $interval Optional. The interval in milliseconds between updates. Default 100.
41
- *
42
- * @throws Exception When this is not run within WP CLI
43
- */
44
- public function __construct( $message, $count, $interval = 100 ) {
45
- if ( ! ( defined( 'WP_CLI' ) && WP_CLI ) ) {
46
- /* translators: %s php class name */
47
- throw new \Exception( sprintf( __( 'The %s class can only be run within WP CLI.', 'action-scheduler' ), __CLASS__ ) );
48
- }
49
-
50
- $this->total_ticks = 0;
51
- $this->message = $message;
52
- $this->count = $count;
53
- $this->interval = $interval;
54
- }
55
-
56
- /**
57
- * Increment the progress bar ticks.
58
- */
59
- public function tick() {
60
- if ( null === $this->progress_bar ) {
61
- $this->setup_progress_bar();
62
- }
63
-
64
- $this->progress_bar->tick();
65
- $this->total_ticks++;
66
-
67
- do_action( 'action_scheduler/progress_tick', $this->total_ticks );
68
- }
69
-
70
- /**
71
- * Get the progress bar tick count.
72
- *
73
- * @return int
74
- */
75
- public function current() {
76
- return $this->progress_bar ? $this->progress_bar->current() : 0;
77
- }
78
-
79
- /**
80
- * Finish the current progress bar.
81
- */
82
- public function finish() {
83
- if ( null !== $this->progress_bar ) {
84
- $this->progress_bar->finish();
85
- }
86
-
87
- $this->progress_bar = null;
88
- }
89
-
90
- /**
91
- * Set the message used when creating the progress bar.
92
- *
93
- * @param string $message The message to be used when the next progress bar is created.
94
- */
95
- public function set_message( $message ) {
96
- $this->message = $message;
97
- }
98
-
99
- /**
100
- * Set the count for a new progress bar.
101
- *
102
- * @param integer $count The total number of ticks expected to complete.
103
- */
104
- public function set_count( $count ) {
105
- $this->count = $count;
106
- $this->finish();
107
- }
108
-
109
- /**
110
- * Set up the progress bar.
111
- */
112
- protected function setup_progress_bar() {
113
- $this->progress_bar = \WP_CLI\Utils\make_progress_bar(
114
- $this->message,
115
- $this->count,
116
- $this->interval
117
- );
118
- }
119
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/abstracts/ActionScheduler.php DELETED
@@ -1,269 +0,0 @@
1
- <?php
2
-
3
- use Action_Scheduler\WP_CLI\Migration_Command;
4
- use Action_Scheduler\Migration\Controller;
5
-
6
- /**
7
- * Class ActionScheduler
8
- * @codeCoverageIgnore
9
- */
10
- abstract class ActionScheduler {
11
- private static $plugin_file = '';
12
- /** @var ActionScheduler_ActionFactory */
13
- private static $factory = NULL;
14
-
15
- public static function factory() {
16
- if ( !isset(self::$factory) ) {
17
- self::$factory = new ActionScheduler_ActionFactory();
18
- }
19
- return self::$factory;
20
- }
21
-
22
- public static function store() {
23
- return ActionScheduler_Store::instance();
24
- }
25
-
26
- public static function lock() {
27
- return ActionScheduler_Lock::instance();
28
- }
29
-
30
- public static function logger() {
31
- return ActionScheduler_Logger::instance();
32
- }
33
-
34
- public static function runner() {
35
- return ActionScheduler_QueueRunner::instance();
36
- }
37
-
38
- public static function admin_view() {
39
- return ActionScheduler_AdminView::instance();
40
- }
41
-
42
- /**
43
- * Get the absolute system path to the plugin directory, or a file therein
44
- * @static
45
- * @param string $path
46
- * @return string
47
- */
48
- public static function plugin_path( $path ) {
49
- $base = dirname(self::$plugin_file);
50
- if ( $path ) {
51
- return trailingslashit($base).$path;
52
- } else {
53
- return untrailingslashit($base);
54
- }
55
- }
56
-
57
- /**
58
- * Get the absolute URL to the plugin directory, or a file therein
59
- * @static
60
- * @param string $path
61
- * @return string
62
- */
63
- public static function plugin_url( $path ) {
64
- return plugins_url($path, self::$plugin_file);
65
- }
66
-
67
- public static function autoload( $class ) {
68
- $d = DIRECTORY_SEPARATOR;
69
- $classes_dir = self::plugin_path( 'classes' . $d );
70
- $separator = strrpos( $class, '\\' );
71
- if ( false !== $separator ) {
72
- if ( 0 !== strpos( $class, 'Action_Scheduler' ) ) {
73
- return;
74
- }
75
- $class = substr( $class, $separator + 1 );
76
- }
77
-
78
- if ( 'Deprecated' === substr( $class, -10 ) ) {
79
- $dir = self::plugin_path( 'deprecated' . $d );
80
- } elseif ( self::is_class_abstract( $class ) ) {
81
- $dir = $classes_dir . 'abstracts' . $d;
82
- } elseif ( self::is_class_migration( $class ) ) {
83
- $dir = $classes_dir . 'migration' . $d;
84
- } elseif ( 'Schedule' === substr( $class, -8 ) ) {
85
- $dir = $classes_dir . 'schedules' . $d;
86
- } elseif ( 'Action' === substr( $class, -6 ) ) {
87
- $dir = $classes_dir . 'actions' . $d;
88
- } elseif ( 'Schema' === substr( $class, -6 ) ) {
89
- $dir = $classes_dir . 'schema' . $d;
90
- } elseif ( strpos( $class, 'ActionScheduler' ) === 0 ) {
91
- $segments = explode( '_', $class );
92
- $type = isset( $segments[ 1 ] ) ? $segments[ 1 ] : '';
93
-
94
- switch ( $type ) {
95
- case 'WPCLI':
96
- $dir = $classes_dir . 'WP_CLI' . $d;
97
- break;
98
- case 'DBLogger':
99
- case 'DBStore':
100
- case 'HybridStore':
101
- case 'wpPostStore':
102
- case 'wpCommentLogger':
103
- $dir = $classes_dir . 'data-stores' . $d;
104
- break;
105
- default:
106
- $dir = $classes_dir;
107
- break;
108
- }
109
- } elseif ( self::is_class_cli( $class ) ) {
110
- $dir = $classes_dir . 'WP_CLI' . $d;
111
- } elseif ( strpos( $class, 'CronExpression' ) === 0 ) {
112
- $dir = self::plugin_path( 'lib' . $d . 'cron-expression' . $d );
113
- } elseif ( strpos( $class, 'WP_Async_Request' ) === 0 ) {
114
- $dir = self::plugin_path( 'lib' . $d );
115
- } else {
116
- return;
117
- }
118
-
119
- if ( file_exists( "{$dir}{$class}.php" ) ) {
120
- include( "{$dir}{$class}.php" );
121
- return;
122
- }
123
- }
124
-
125
- /**
126
- * Initialize the plugin
127
- *
128
- * @static
129
- * @param string $plugin_file
130
- */
131
- public static function init( $plugin_file ) {
132
- self::$plugin_file = $plugin_file;
133
- spl_autoload_register( array( __CLASS__, 'autoload' ) );
134
-
135
- /**
136
- * Fires in the early stages of Action Scheduler init hook.
137
- */
138
- do_action( 'action_scheduler_pre_init' );
139
-
140
- require_once( self::plugin_path('functions.php') );
141
- ActionScheduler_DataController::init();
142
-
143
- $store = self::store();
144
- add_action( 'init', array( $store, 'init' ), 1, 0 );
145
-
146
- $logger = self::logger();
147
- add_action( 'init', array( $logger, 'init' ), 1, 0 );
148
-
149
- $runner = self::runner();
150
- add_action( 'init', array( $runner, 'init' ), 1, 0 );
151
-
152
- $admin_view = self::admin_view();
153
- add_action( 'init', array( $admin_view, 'init' ), 0, 0 ); // run before $store::init()
154
-
155
- if ( apply_filters( 'action_scheduler_load_deprecated_functions', true ) ) {
156
- require_once( self::plugin_path('deprecated/functions.php') );
157
- }
158
-
159
- if ( defined( 'WP_CLI' ) && WP_CLI ) {
160
- WP_CLI::add_command( 'action-scheduler', 'ActionScheduler_WPCLI_Scheduler_command' );
161
- if ( ! ActionScheduler_DataController::is_migration_complete() && Controller::instance()->allow_migration() ) {
162
- $command = new Migration_Command();
163
- $command->register();
164
- }
165
- }
166
-
167
- /**
168
- * Handle WP comment cleanup after migration.
169
- */
170
- if ( is_a( $logger, 'ActionScheduler_DBLogger' ) && ActionScheduler_DataController::is_migration_complete() && ActionScheduler_WPCommentCleaner::has_logs() ) {
171
- ActionScheduler_WPCommentCleaner::init();
172
- }
173
-
174
- add_action( 'action_scheduler/migration_complete', 'ActionScheduler_WPCommentCleaner::maybe_schedule_cleanup' );
175
- }
176
-
177
- /**
178
- * Determine if the class is one of our abstract classes.
179
- *
180
- * @since 3.0.0
181
- *
182
- * @param string $class The class name.
183
- *
184
- * @return bool
185
- */
186
- protected static function is_class_abstract( $class ) {
187
- static $abstracts = array(
188
- 'ActionScheduler' => true,
189
- 'ActionScheduler_Abstract_ListTable' => true,
190
- 'ActionScheduler_Abstract_QueueRunner' => true,
191
- 'ActionScheduler_Abstract_Schedule' => true,
192
- 'ActionScheduler_Abstract_RecurringSchedule' => true,
193
- 'ActionScheduler_Lock' => true,
194
- 'ActionScheduler_Logger' => true,
195
- 'ActionScheduler_Abstract_Schema' => true,
196
- 'ActionScheduler_Store' => true,
197
- 'ActionScheduler_TimezoneHelper' => true,
198
- );
199
-
200
- return isset( $abstracts[ $class ] ) && $abstracts[ $class ];
201
- }
202
-
203
- /**
204
- * Determine if the class is one of our migration classes.
205
- *
206
- * @since 3.0.0
207
- *
208
- * @param string $class The class name.
209
- *
210
- * @return bool
211
- */
212
- protected static function is_class_migration( $class ) {
213
- static $migration_segments = array(
214
- 'ActionMigrator' => true,
215
- 'BatchFetcher' => true,
216
- 'DBStoreMigrator' => true,
217
- 'DryRun' => true,
218
- 'LogMigrator' => true,
219
- 'Config' => true,
220
- 'Controller' => true,
221
- 'Runner' => true,
222
- 'Scheduler' => true,
223
- );
224
-
225
- $segments = explode( '_', $class );
226
- $segment = isset( $segments[ 1 ] ) ? $segments[ 1 ] : $class;
227
-
228
- return isset( $migration_segments[ $segment ] ) && $migration_segments[ $segment ];
229
- }
230
-
231
- /**
232
- * Determine if the class is one of our WP CLI classes.
233
- *
234
- * @since 3.0.0
235
- *
236
- * @param string $class The class name.
237
- *
238
- * @return bool
239
- */
240
- protected static function is_class_cli( $class ) {
241
- static $cli_segments = array(
242
- 'QueueRunner' => true,
243
- 'Command' => true,
244
- 'ProgressBar' => true,
245
- );
246
-
247
- $segments = explode( '_', $class );
248
- $segment = isset( $segments[ 1 ] ) ? $segments[ 1 ] : $class;
249
-
250
- return isset( $cli_segments[ $segment ] ) && $cli_segments[ $segment ];
251
- }
252
-
253
- final public function __clone() {
254
- trigger_error("Singleton. No cloning allowed!", E_USER_ERROR);
255
- }
256
-
257
- final public function __wakeup() {
258
- trigger_error("Singleton. No serialization allowed!", E_USER_ERROR);
259
- }
260
-
261
- final private function __construct() {}
262
-
263
- /** Deprecated **/
264
-
265
- public static function get_datetime_object( $when = null, $timezone = 'UTC' ) {
266
- _deprecated_function( __METHOD__, '2.0', 'wcs_add_months()' );
267
- return as_get_datetime_object( $when, $timezone );
268
- }
269
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_ListTable.php DELETED
@@ -1,674 +0,0 @@
1
- <?php
2
-
3
- if ( ! class_exists( 'WP_List_Table' ) ) {
4
- require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
5
- }
6
-
7
- /**
8
- * Action Scheduler Abstract List Table class
9
- *
10
- * This abstract class enhances WP_List_Table making it ready to use.
11
- *
12
- * By extending this class we can focus on describing how our table looks like,
13
- * which columns needs to be shown, filter, ordered by and more and forget about the details.
14
- *
15
- * This class supports:
16
- * - Bulk actions
17
- * - Search
18
- * - Sortable columns
19
- * - Automatic translations of the columns
20
- *
21
- * @codeCoverageIgnore
22
- * @since 2.0.0
23
- */
24
- abstract class ActionScheduler_Abstract_ListTable extends WP_List_Table {
25
-
26
- /**
27
- * The table name
28
- */
29
- protected $table_name;
30
-
31
- /**
32
- * Package name, used to get options from WP_List_Table::get_items_per_page.
33
- */
34
- protected $package;
35
-
36
- /**
37
- * How many items do we render per page?
38
- */
39
- protected $items_per_page = 10;
40
-
41
- /**
42
- * Enables search in this table listing. If this array
43
- * is empty it means the listing is not searchable.
44
- */
45
- protected $search_by = array();
46
-
47
- /**
48
- * Columns to show in the table listing. It is a key => value pair. The
49
- * key must much the table column name and the value is the label, which is
50
- * automatically translated.
51
- */
52
- protected $columns = array();
53
-
54
- /**
55
- * Defines the row-actions. It expects an array where the key
56
- * is the column name and the value is an array of actions.
57
- *
58
- * The array of actions are key => value, where key is the method name
59
- * (with the prefix row_action_<key>) and the value is the label
60
- * and title.
61
- */
62
- protected $row_actions = array();
63
-
64
- /**
65
- * The Primary key of our table
66
- */
67
- protected $ID = 'ID';
68
-
69
- /**
70
- * Enables sorting, it expects an array
71
- * of columns (the column names are the values)
72
- */
73
- protected $sort_by = array();
74
-
75
- protected $filter_by = array();
76
-
77
- /**
78
- * @var array The status name => count combinations for this table's items. Used to display status filters.
79
- */
80
- protected $status_counts = array();
81
-
82
- /**
83
- * @var array Notices to display when loading the table. Array of arrays of form array( 'class' => {updated|error}, 'message' => 'This is the notice text display.' ).
84
- */
85
- protected $admin_notices = array();
86
-
87
- /**
88
- * @var string Localised string displayed in the <h1> element above the able.
89
- */
90
- protected $table_header;
91
-
92
- /**
93
- * Enables bulk actions. It must be an array where the key is the action name
94
- * and the value is the label (which is translated automatically). It is important
95
- * to notice that it will check that the method exists (`bulk_$name`) and will throw
96
- * an exception if it does not exists.
97
- *
98
- * This class will automatically check if the current request has a bulk action, will do the
99
- * validations and afterwards will execute the bulk method, with two arguments. The first argument
100
- * is the array with primary keys, the second argument is a string with a list of the primary keys,
101
- * escaped and ready to use (with `IN`).
102
- */
103
- protected $bulk_actions = array();
104
-
105
- /**
106
- * Makes translation easier, it basically just wraps
107
- * `_x` with some default (the package name).
108
- *
109
- * @deprecated 3.0.0
110
- */
111
- protected function translate( $text, $context = '' ) {
112
- return $text;
113
- }
114
-
115
- /**
116
- * Reads `$this->bulk_actions` and returns an array that WP_List_Table understands. It
117
- * also validates that the bulk method handler exists. It throws an exception because
118
- * this is a library meant for developers and missing a bulk method is a development-time error.
119
- */
120
- protected function get_bulk_actions() {
121
- $actions = array();
122
-
123
- foreach ( $this->bulk_actions as $action => $label ) {
124
- if ( ! is_callable( array( $this, 'bulk_' . $action ) ) ) {
125
- throw new RuntimeException( "The bulk action $action does not have a callback method" );
126
- }
127
-
128
- $actions[ $action ] = $label;
129
- }
130
-
131
- return $actions;
132
- }
133
-
134
- /**
135
- * Checks if the current request has a bulk action. If that is the case it will validate and will
136
- * execute the bulk method handler. Regardless if the action is valid or not it will redirect to
137
- * the previous page removing the current arguments that makes this request a bulk action.
138
- */
139
- protected function process_bulk_action() {
140
- global $wpdb;
141
- // Detect when a bulk action is being triggered.
142
- $action = $this->current_action();
143
-
144
- if ( ! $action ) {
145
- return;
146
- }
147
-
148
- check_admin_referer( 'bulk-' . $this->_args['plural'] );
149
-
150
- $method = 'bulk_' . $action;
151
- if ( array_key_exists( $action, $this->bulk_actions ) && is_callable( array( $this, $method ) ) && ! empty( $_GET['ID'] ) && is_array( $_GET['ID'] ) ) {
152
- $ids_sql = '(' . implode( ',', array_fill( 0, count( $_GET['ID'] ), '%s' ) ) . ')';
153
- $this->$method( $_GET['ID'], $wpdb->prepare( $ids_sql, $_GET['ID'] ) );
154
- }
155
-
156
- wp_redirect( remove_query_arg(
157
- array( '_wp_http_referer', '_wpnonce', 'ID', 'action', 'action2' ),
158
- wp_unslash( $_SERVER['REQUEST_URI'] )
159
- ) );
160
- exit;
161
- }
162
-
163
- /**
164
- * Default code for deleting entries. We trust ids_sql because it is
165
- * validated already by process_bulk_action()
166
- */
167
- protected function bulk_delete( array $ids, $ids_sql ) {
168
- global $wpdb;
169
-
170
- $wpdb->query( "DELETE FROM {$this->table_name} WHERE {$this->ID} IN $ids_sql" );
171
- }
172
-
173
- /**
174
- * Prepares the _column_headers property which is used by WP_Table_List at rendering.
175
- * It merges the columns and the sortable columns.
176
- */
177
- protected function prepare_column_headers() {
178
- $this->_column_headers = array(
179
- $this->get_columns(),
180
- array(),
181
- $this->get_sortable_columns(),
182
- );
183
- }
184
-
185
- /**
186
- * Reads $this->sort_by and returns the columns name in a format that WP_Table_List
187
- * expects
188
- */
189
- public function get_sortable_columns() {
190
- $sort_by = array();
191
- foreach ( $this->sort_by as $column ) {
192
- $sort_by[ $column ] = array( $column, true );
193
- }
194
- return $sort_by;
195
- }
196
-
197
- /**
198
- * Returns the columns names for rendering. It adds a checkbox for selecting everything
199
- * as the first column
200
- */
201
- public function get_columns() {
202
- $columns = array_merge(
203
- array( 'cb' => '<input type="checkbox" />' ),
204
- $this->columns
205
- );
206
-
207
- return $columns;
208
- }
209
-
210
- /**
211
- * Get prepared LIMIT clause for items query
212
- *
213
- * @global wpdb $wpdb
214
- *
215
- * @return string Prepared LIMIT clause for items query.
216
- */
217
- protected function get_items_query_limit() {
218
- global $wpdb;
219
-
220
- $per_page = $this->get_items_per_page( $this->package . '_items_per_page', $this->items_per_page );
221
- return $wpdb->prepare( 'LIMIT %d', $per_page );
222
- }
223
-
224
- /**
225
- * Returns the number of items to offset/skip for this current view.
226
- *
227
- * @return int
228
- */
229
- protected function get_items_offset() {
230
- $per_page = $this->get_items_per_page( $this->package . '_items_per_page', $this->items_per_page );
231
- $current_page = $this->get_pagenum();
232
- if ( 1 < $current_page ) {
233
- $offset = $per_page * ( $current_page - 1 );
234
- } else {
235
- $offset = 0;
236
- }
237
-
238
- return $offset;
239
- }
240
-
241
- /**
242
- * Get prepared OFFSET clause for items query
243
- *
244
- * @global wpdb $wpdb
245
- *
246
- * @return string Prepared OFFSET clause for items query.
247
- */
248
- protected function get_items_query_offset() {
249
- global $wpdb;
250
-
251
- return $wpdb->prepare( 'OFFSET %d', $this->get_items_offset() );
252
- }
253
-
254
- /**
255
- * Prepares the ORDER BY sql statement. It uses `$this->sort_by` to know which
256
- * columns are sortable. This requests validates the orderby $_GET parameter is a valid
257
- * column and sortable. It will also use order (ASC|DESC) using DESC by default.
258
- */
259
- protected function get_items_query_order() {
260
- if ( empty( $this->sort_by ) ) {
261
- return '';
262
- }
263
-
264
- $orderby = esc_sql( $this->get_request_orderby() );
265
- $order = esc_sql( $this->get_request_order() );
266
-
267
- return "ORDER BY {$orderby} {$order}";
268
- }
269
-
270
- /**
271
- * Return the sortable column specified for this request to order the results by, if any.
272
- *
273
- * @return string
274
- */
275
- protected function get_request_orderby() {
276
-
277
- $valid_sortable_columns = array_values( $this->sort_by );
278
-
279
- if ( ! empty( $_GET['orderby'] ) && in_array( $_GET['orderby'], $valid_sortable_columns ) ) {
280
- $orderby = sanitize_text_field( $_GET['orderby'] );
281
- } else {
282
- $orderby = $valid_sortable_columns[0];
283
- }
284
-
285
- return $orderby;
286
- }
287
-
288
- /**
289
- * Return the sortable column order specified for this request.
290
- *
291
- * @return string
292
- */
293
- protected function get_request_order() {
294
-
295
- if ( ! empty( $_GET['order'] ) && 'desc' === strtolower( $_GET['order'] ) ) {
296
- $order = 'DESC';
297
- } else {
298
- $order = 'ASC';
299
- }
300
-
301
- return $order;
302
- }
303
-
304
- /**
305
- * Return the status filter for this request, if any.
306
- *
307
- * @return string
308
- */
309
- protected function get_request_status() {
310
- $status = ( ! empty( $_GET['status'] ) ) ? $_GET['status'] : '';
311
- return $status;
312
- }
313
-
314
- /**
315
- * Return the search filter for this request, if any.
316
- *
317
- * @return string
318
- */
319
- protected function get_request_search_query() {
320
- $search_query = ( ! empty( $_GET['s'] ) ) ? $_GET['s'] : '';
321
- return $search_query;
322
- }
323
-
324
- /**
325
- * Process and return the columns name. This is meant for using with SQL, this means it
326
- * always includes the primary key.
327
- *
328
- * @return array
329
- */
330
- protected function get_table_columns() {
331
- $columns = array_keys( $this->columns );
332
- if ( ! in_array( $this->ID, $columns ) ) {
333
- $columns[] = $this->ID;
334
- }
335
-
336
- return $columns;
337
- }
338
-
339
- /**
340
- * Check if the current request is doing a "full text" search. If that is the case
341
- * prepares the SQL to search texts using LIKE.
342
- *
343
- * If the current request does not have any search or if this list table does not support
344
- * that feature it will return an empty string.
345
- *
346
- * TODO:
347
- * - Improve search doing LIKE by word rather than by phrases.
348
- *
349
- * @return string
350
- */
351
- protected function get_items_query_search() {
352
- global $wpdb;
353
-
354
- if ( empty( $_GET['s'] ) || empty( $this->search_by ) ) {
355
- return '';
356
- }
357
-
358
- $filter = array();
359
- foreach ( $this->search_by as $column ) {
360
- $filter[] = $wpdb->prepare('`' . $column . '` like "%%s%"', $wpdb->esc_like( $_GET['s'] ));
361
- }
362
- return implode( ' OR ', $filter );
363
- }
364
-
365
- /**
366
- * Prepares the SQL to filter rows by the options defined at `$this->filter_by`. Before trusting
367
- * any data sent by the user it validates that it is a valid option.
368
- */
369
- protected function get_items_query_filters() {
370
- global $wpdb;
371
-
372
- if ( ! $this->filter_by || empty( $_GET['filter_by'] ) || ! is_array( $_GET['filter_by'] ) ) {
373
- return '';
374
- }
375
-
376
- $filter = array();
377
-
378
- foreach ( $this->filter_by as $column => $options ) {
379
- if ( empty( $_GET['filter_by'][ $column ] ) || empty( $options[ $_GET['filter_by'][ $column ] ] ) ) {
380
- continue;
381
- }
382
-
383
- $filter[] = $wpdb->prepare( "`$column` = %s", $_GET['filter_by'][ $column ] );
384
- }
385
-
386
- return implode( ' AND ', $filter );
387
-
388
- }
389
-
390
- /**
391
- * Prepares the data to feed WP_Table_List.
392
- *
393
- * This has the core for selecting, sorting and filting data. To keep the code simple
394
- * its logic is split among many methods (get_items_query_*).
395
- *
396
- * Beside populating the items this function will also count all the records that matches
397
- * the filtering criteria and will do fill the pagination variables.
398
- */
399
- public function prepare_items() {
400
- global $wpdb;
401
-
402
- $this->process_bulk_action();
403
-
404
- $this->process_row_actions();
405
-
406
- if ( ! empty( $_REQUEST['_wp_http_referer'] ) ) {
407
- // _wp_http_referer is used only on bulk actions, we remove it to keep the $_GET shorter
408
- wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
409
- exit;
410
- }
411
-
412
- $this->prepare_column_headers();
413
-
414
- $limit = $this->get_items_query_limit();
415
- $offset = $this->get_items_query_offset();
416
- $order = $this->get_items_query_order();
417
- $where = array_filter(array(
418
- $this->get_items_query_search(),
419
- $this->get_items_query_filters(),
420
- ));
421
- $columns = '`' . implode( '`, `', $this->get_table_columns() ) . '`';
422
-
423
- if ( ! empty( $where ) ) {
424
- $where = 'WHERE ('. implode( ') AND (', $where ) . ')';
425
- } else {
426
- $where = '';
427
- }
428
-
429
- $sql = "SELECT $columns FROM {$this->table_name} {$where} {$order} {$limit} {$offset}";
430
-
431
- $this->set_items( $wpdb->get_results( $sql, ARRAY_A ) );
432
-
433
- $query_count = "SELECT COUNT({$this->ID}) FROM {$this->table_name} {$where}";
434
- $total_items = $wpdb->get_var( $query_count );
435
- $per_page = $this->get_items_per_page( $this->package . '_items_per_page', $this->items_per_page );
436
- $this->set_pagination_args( array(
437
- 'total_items' => $total_items,
438
- 'per_page' => $per_page,
439
- 'total_pages' => ceil( $total_items / $per_page ),
440
- ) );
441
- }
442
-
443
- public function extra_tablenav( $which ) {
444
- if ( ! $this->filter_by || 'top' !== $which ) {
445
- return;
446
- }
447
-
448
- echo '<div class="alignleft actions">';
449
-
450
- foreach ( $this->filter_by as $id => $options ) {
451
- $default = ! empty( $_GET['filter_by'][ $id ] ) ? $_GET['filter_by'][ $id ] : '';
452
- if ( empty( $options[ $default ] ) ) {
453
- $default = '';
454
- }
455
-
456
- echo '<select name="filter_by[' . esc_attr( $id ) . ']" class="first" id="filter-by-' . esc_attr( $id ) . '">';
457
-
458
- foreach ( $options as $value => $label ) {
459
- echo '<option value="' . esc_attr( $value ) . '" ' . esc_html( $value == $default ? 'selected' : '' ) .'>'
460
- . esc_html( $label )
461
- . '</option>';
462
- }
463
-
464
- echo '</select>';
465
- }
466
-
467
- submit_button( esc_html__( 'Filter', 'action-scheduler' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
468
- echo '</div>';
469
- }
470
-
471
- /**
472
- * Set the data for displaying. It will attempt to unserialize (There is a chance that some columns
473
- * are serialized). This can be override in child classes for futher data transformation.
474
- */
475
- protected function set_items( array $items ) {
476
- $this->items = array();
477
- foreach ( $items as $item ) {
478
- $this->items[ $item[ $this->ID ] ] = array_map( 'maybe_unserialize', $item );
479
- }
480
- }
481
-
482
- /**
483
- * Renders the checkbox for each row, this is the first column and it is named ID regardless
484
- * of how the primary key is named (to keep the code simpler). The bulk actions will do the proper
485
- * name transformation though using `$this->ID`.
486
- */
487
- public function column_cb( $row ) {
488
- return '<input name="ID[]" type="checkbox" value="' . esc_attr( $row[ $this->ID ] ) .'" />';
489
- }
490
-
491
- /**
492
- * Renders the row-actions.
493
- *
494
- * This method renders the action menu, it reads the definition from the $row_actions property,
495
- * and it checks that the row action method exists before rendering it.
496
- *
497
- * @param array $row Row to render
498
- * @param $column_name Current row
499
- * @return
500
- */
501
- protected function maybe_render_actions( $row, $column_name ) {
502
- if ( empty( $this->row_actions[ $column_name ] ) ) {
503
- return;
504
- }
505
-
506
- $row_id = $row[ $this->ID ];
507
-
508
- $actions = '<div class="row-actions">';
509
- $action_count = 0;
510
- foreach ( $this->row_actions[ $column_name ] as $action_key => $action ) {
511
-
512
- $action_count++;
513
-
514
- if ( ! method_exists( $this, 'row_action_' . $action_key ) ) {
515
- continue;
516
- }
517
-
518
- $action_link = ! empty( $action['link'] ) ? $action['link'] : add_query_arg( array( 'row_action' => $action_key, 'row_id' => $row_id, 'nonce' => wp_create_nonce( $action_key . '::' . $row_id ) ) );
519
- $span_class = ! empty( $action['class'] ) ? $action['class'] : $action_key;
520
- $separator = ( $action_count < count( $this->row_actions[ $column_name ] ) ) ? ' | ' : '';
521
-
522
- $actions .= sprintf( '<span class="%s">', esc_attr( $span_class ) );
523
- $actions .= sprintf( '<a href="%1$s" title="%2$s">%3$s</a>', esc_url( $action_link ), esc_attr( $action['desc'] ), esc_html( $action['name'] ) );
524
- $actions .= sprintf( '%s</span>', $separator );
525
- }
526
- $actions .= '</div>';
527
- return $actions;
528
- }
529
-
530
- protected function process_row_actions() {
531
- $parameters = array( 'row_action', 'row_id', 'nonce' );
532
- foreach ( $parameters as $parameter ) {
533
- if ( empty( $_REQUEST[ $parameter ] ) ) {
534
- return;
535
- }
536
- }
537
-
538
- $method = 'row_action_' . $_REQUEST['row_action'];
539
-
540
- if ( $_REQUEST['nonce'] === wp_create_nonce( $_REQUEST[ 'row_action' ] . '::' . $_REQUEST[ 'row_id' ] ) && method_exists( $this, $method ) ) {
541
- $this->$method( $_REQUEST['row_id'] );
542
- }
543
-
544
- wp_redirect( remove_query_arg(
545
- array( 'row_id', 'row_action', 'nonce' ),
546
- wp_unslash( $_SERVER['REQUEST_URI'] )
547
- ) );
548
- exit;
549
- }
550
-
551
- /**
552
- * Default column formatting, it will escape everythig for security.
553
- */
554
- public function column_default( $item, $column_name ) {
555
- $column_html = esc_html( $item[ $column_name ] );
556
- $column_html .= $this->maybe_render_actions( $item, $column_name );
557
- return $column_html;
558
- }
559
-
560
- /**
561
- * Display the table heading and search query, if any
562
- */
563
- protected function display_header() {
564
- echo '<h1 class="wp-heading-inline">' . esc_attr( $this->table_header ) . '</h1>';
565
- if ( $this->get_request_search_query() ) {
566
- /* translators: %s: search query */
567
- echo '<span class="subtitle">' . esc_attr( sprintf( __( 'Search results for "%s"', 'action-scheduler' ), $this->get_request_search_query() ) ) . '</span>';
568
- }
569
- echo '<hr class="wp-header-end">';
570
- }
571
-
572
- /**
573
- * Display the table heading and search query, if any
574
- */
575
- protected function display_admin_notices() {
576
- foreach ( $this->admin_notices as $notice ) {
577
- echo '<div id="message" class="' . $notice['class'] . '">';
578
- echo ' <p>' . wp_kses_post( $notice['message'] ) . '</p>';
579
- echo '</div>';
580
- }
581
- }
582
-
583
- /**
584
- * Prints the available statuses so the user can click to filter.
585
- */
586
- protected function display_filter_by_status() {
587
-
588
- $status_list_items = array();
589
- $request_status = $this->get_request_status();
590
-
591
- // Helper to set 'all' filter when not set on status counts passed in
592
- if ( ! isset( $this->status_counts['all'] ) ) {
593
- $this->status_counts = array( 'all' => array_sum( $this->status_counts ) ) + $this->status_counts;
594
- }
595
-
596
- foreach ( $this->status_counts as $status_name => $count ) {
597
-
598
- if ( 0 === $count ) {
599
- continue;
600
- }
601
-
602
- if ( $status_name === $request_status || ( empty( $request_status ) && 'all' === $status_name ) ) {
603
- $status_list_item = '<li class="%1$s"><strong>%3$s</strong> (%4$d)</li>';
604
- } else {
605
- $status_list_item = '<li class="%1$s"><a href="%2$s">%3$s</a> (%4$d)</li>';
606
- }
607
-
608
- $status_filter_url = ( 'all' === $status_name ) ? remove_query_arg( 'status' ) : add_query_arg( 'status', $status_name );
609
- $status_list_items[] = sprintf( $status_list_item, esc_attr( $status_name ), esc_url( $status_filter_url ), esc_html( ucfirst( $status_name ) ), absint( $count ) );
610
- }
611
-
612
- if ( $status_list_items ) {
613
- echo '<ul class="subsubsub">';
614
- echo implode( " | \n", $status_list_items );
615
- echo '</ul>';
616
- }
617
- }
618
-
619
- /**
620
- * Renders the table list, we override the original class to render the table inside a form
621
- * and to render any needed HTML (like the search box). By doing so the callee of a function can simple
622
- * forget about any extra HTML.
623
- */
624
- protected function display_table() {
625
- echo '<form id="' . esc_attr( $this->_args['plural'] ) . '-filter" method="get">';
626
- foreach ( $_GET as $key => $value ) {
627
- if ( '_' === $key[0] || 'paged' === $key ) {
628
- continue;
629
- }
630
- echo '<input type="hidden" name="' . esc_attr( $key ) . '" value="' . esc_attr( $value ) . '" />';
631
- }
632
- if ( ! empty( $this->search_by ) ) {
633
- echo $this->search_box( $this->get_search_box_button_text(), 'plugin' ); // WPCS: XSS OK
634
- }
635
- parent::display();
636
- echo '</form>';
637
- }
638
-
639
- /**
640
- * Process any pending actions.
641
- */
642
- public function process_actions() {
643
- $this->process_bulk_action();
644
-
645
- $this->process_row_actions();
646
-
647
- if ( ! empty( $_REQUEST['_wp_http_referer'] ) ) {
648
- // _wp_http_referer is used only on bulk actions, we remove it to keep the $_GET shorter
649
- wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
650
- exit;
651
- }
652
- }
653
-
654
- /**
655
- * Render the list table page, including header, notices, status filters and table.
656
- */
657
- public function display_page() {
658
- $this->prepare_items();
659
-
660
- echo '<div class="wrap">';
661
- $this->display_header();
662
- $this->display_admin_notices();
663
- $this->display_filter_by_status();
664
- $this->display_table();
665
- echo '</div>';
666
- }
667
-
668
- /**
669
- * Get the text to display in the search box on the list table.
670
- */
671
- protected function get_search_box_placeholder() {
672
- return esc_html__( 'Search', 'action-scheduler' );
673
- }
674
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_QueueRunner.php DELETED
@@ -1,232 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Abstract class with common Queue Cleaner functionality.
5
- */
6
- abstract class ActionScheduler_Abstract_QueueRunner extends ActionScheduler_Abstract_QueueRunner_Deprecated {
7
-
8
- /** @var ActionScheduler_QueueCleaner */
9
- protected $cleaner;
10
-
11
- /** @var ActionScheduler_FatalErrorMonitor */
12
- protected $monitor;
13
-
14
- /** @var ActionScheduler_Store */
15
- protected $store;
16
-
17
- /**
18
- * The created time.
19
- *
20
- * Represents when the queue runner was constructed and used when calculating how long a PHP request has been running.
21
- * For this reason it should be as close as possible to the PHP request start time.
22
- *
23
- * @var int
24
- */
25
- private $created_time;
26
-
27
- /**
28
- * ActionScheduler_Abstract_QueueRunner constructor.
29
- *
30
- * @param ActionScheduler_Store $store
31
- * @param ActionScheduler_FatalErrorMonitor $monitor
32
- * @param ActionScheduler_QueueCleaner $cleaner
33
- */
34
- public function __construct( ActionScheduler_Store $store = null, ActionScheduler_FatalErrorMonitor $monitor = null, ActionScheduler_QueueCleaner $cleaner = null ) {
35
-
36
- $this->created_time = microtime( true );
37
-
38
- $this->store = $store ? $store : ActionScheduler_Store::instance();
39
- $this->monitor = $monitor ? $monitor : new ActionScheduler_FatalErrorMonitor( $this->store );
40
- $this->cleaner = $cleaner ? $cleaner : new ActionScheduler_QueueCleaner( $this->store );
41
- }
42
-
43
- /**
44
- * Process an individual action.
45
- *
46
- * @param int $action_id The action ID to process.
47
- * @param string $context Optional identifer for the context in which this action is being processed, e.g. 'WP CLI' or 'WP Cron'
48
- * Generally, this should be capitalised and not localised as it's a proper noun.
49
- */
50
- public function process_action( $action_id, $context = '' ) {
51
- try {
52
- do_action( 'action_scheduler_before_execute', $action_id, $context );
53
-
54
- if ( ActionScheduler_Store::STATUS_PENDING !== $this->store->get_status( $action_id ) ) {
55
- do_action( 'action_scheduler_execution_ignored', $action_id, $context );
56
- return;
57
- }
58
-
59
- $action = $this->store->fetch_action( $action_id );
60
- $this->store->log_execution( $action_id );
61
- $action->execute();
62
- do_action( 'action_scheduler_after_execute', $action_id, $action, $context );
63
- $this->store->mark_complete( $action_id );
64
- } catch ( Exception $e ) {
65
- $this->store->mark_failure( $action_id );
66
- do_action( 'action_scheduler_failed_execution', $action_id, $e, $context );
67
- }
68
-
69
- if ( isset( $action ) && is_a( $action, 'ActionScheduler_Action' ) && $action->get_schedule()->is_recurring() ) {
70
- $this->schedule_next_instance( $action, $action_id );
71
- }
72
- }
73
-
74
- /**
75
- * Schedule the next instance of the action if necessary.
76
- *
77
- * @param ActionScheduler_Action $action
78
- * @param int $action_id
79
- */
80
- protected function schedule_next_instance( ActionScheduler_Action $action, $action_id ) {
81
- try {
82
- ActionScheduler::factory()->repeat( $action );
83
- } catch ( Exception $e ) {
84
- do_action( 'action_scheduler_failed_to_schedule_next_instance', $action_id, $e, $action );
85
- }
86
- }
87
-
88
- /**
89
- * Run the queue cleaner.
90
- *
91
- * @author Jeremy Pry
92
- */
93
- protected function run_cleanup() {
94
- $this->cleaner->clean( 10 * $this->get_time_limit() );
95
- }
96
-
97
- /**
98
- * Get the number of concurrent batches a runner allows.
99
- *
100
- * @return int
101
- */
102
- public function get_allowed_concurrent_batches() {
103
- return apply_filters( 'action_scheduler_queue_runner_concurrent_batches', 1 );
104
- }
105
-
106
- /**
107
- * Check if the number of allowed concurrent batches is met or exceeded.
108
- *
109
- * @return bool
110
- */
111
- public function has_maximum_concurrent_batches() {
112
- return $this->store->get_claim_count() >= $this->get_allowed_concurrent_batches();
113
- }
114
-
115
- /**
116
- * Get the maximum number of seconds a batch can run for.
117
- *
118
- * @return int The number of seconds.
119
- */
120
- protected function get_time_limit() {
121
-
122
- $time_limit = 30;
123
-
124
- // Apply deprecated filter from deprecated get_maximum_execution_time() method
125
- if ( has_filter( 'action_scheduler_maximum_execution_time' ) ) {
126
- _deprecated_function( 'action_scheduler_maximum_execution_time', '2.1.1', 'action_scheduler_queue_runner_time_limit' );
127
- $time_limit = apply_filters( 'action_scheduler_maximum_execution_time', $time_limit );
128
- }
129
-
130
- return absint( apply_filters( 'action_scheduler_queue_runner_time_limit', $time_limit ) );
131
- }
132
-
133
- /**
134
- * Get the number of seconds the process has been running.
135
- *
136
- * @return int The number of seconds.
137
- */
138
- protected function get_execution_time() {
139
- $execution_time = microtime( true ) - $this->created_time;
140
-
141
- // Get the CPU time if the hosting environment uses it rather than wall-clock time to calculate a process's execution time.
142
- if ( function_exists( 'getrusage' ) && apply_filters( 'action_scheduler_use_cpu_execution_time', defined( 'PANTHEON_ENVIRONMENT' ) ) ) {
143
- $resource_usages = getrusage();
144
-
145
- if ( isset( $resource_usages['ru_stime.tv_usec'], $resource_usages['ru_stime.tv_usec'] ) ) {
146
- $execution_time = $resource_usages['ru_stime.tv_sec'] + ( $resource_usages['ru_stime.tv_usec'] / 1000000 );
147
- }
148
- }
149
-
150
- return $execution_time;
151
- }
152
-
153
- /**
154
- * Check if the host's max execution time is (likely) to be exceeded if processing more actions.
155
- *
156
- * @param int $processed_actions The number of actions processed so far - used to determine the likelihood of exceeding the time limit if processing another action
157
- * @return bool
158
- */
159
- protected function time_likely_to_be_exceeded( $processed_actions ) {
160
-
161
- $execution_time = $this->get_execution_time();
162
- $max_execution_time = $this->get_time_limit();
163
- $time_per_action = $execution_time / $processed_actions;
164
- $estimated_time = $execution_time + ( $time_per_action * 3 );
165
- $likely_to_be_exceeded = $estimated_time > $max_execution_time;
166
-
167
- return apply_filters( 'action_scheduler_maximum_execution_time_likely_to_be_exceeded', $likely_to_be_exceeded, $this, $processed_actions, $execution_time, $max_execution_time );
168
- }
169
-
170
- /**
171
- * Get memory limit
172
- *
173
- * Based on WP_Background_Process::get_memory_limit()
174
- *
175
- * @return int
176
- */
177
- protected function get_memory_limit() {
178
- if ( function_exists( 'ini_get' ) ) {
179
- $memory_limit = ini_get( 'memory_limit' );
180
- } else {
181
- $memory_limit = '128M'; // Sensible default, and minimum required by WooCommerce
182
- }
183
-
184
- if ( ! $memory_limit || -1 === $memory_limit || '-1' === $memory_limit ) {
185
- // Unlimited, set to 32GB.
186
- $memory_limit = '32G';
187
- }
188
-
189
- return ActionScheduler_Compatibility::convert_hr_to_bytes( $memory_limit );
190
- }
191
-
192
- /**
193
- * Memory exceeded
194
- *
195
- * Ensures the batch process never exceeds 90% of the maximum WordPress memory.
196
- *
197
- * Based on WP_Background_Process::memory_exceeded()
198
- *
199
- * @return bool
200
- */
201
- protected function memory_exceeded() {
202
-
203
- $memory_limit = $this->get_memory_limit() * 0.90;
204
- $current_memory = memory_get_usage( true );
205
- $memory_exceeded = $current_memory >= $memory_limit;
206
-
207
- return apply_filters( 'action_scheduler_memory_exceeded', $memory_exceeded, $this );
208
- }
209
-
210
- /**
211
- * See if the batch limits have been exceeded, which is when memory usage is almost at
212
- * the maximum limit, or the time to process more actions will exceed the max time limit.
213
- *
214
- * Based on WC_Background_Process::batch_limits_exceeded()
215
- *
216
- * @param int $processed_actions The number of actions processed so far - used to determine the likelihood of exceeding the time limit if processing another action
217
- * @return bool
218
- */
219
- protected function batch_limits_exceeded( $processed_actions ) {
220
- return $this->memory_exceeded() || $this->time_likely_to_be_exceeded( $processed_actions );
221
- }
222
-
223
- /**
224
- * Process actions in the queue.
225
- *
226
- * @author Jeremy Pry
227
- * @param string $context Optional identifer for the context in which this action is being processed, e.g. 'WP CLI' or 'WP Cron'
228
- * Generally, this should be capitalised and not localised as it's a proper noun.
229
- * @return int The number of actions processed.
230
- */
231
- abstract public function run( $context = '' );
232
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_RecurringSchedule.php DELETED
@@ -1,102 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_Abstract_RecurringSchedule
5
- */
6
- abstract class ActionScheduler_Abstract_RecurringSchedule extends ActionScheduler_Abstract_Schedule {
7
-
8
- /**
9
- * The date & time the first instance of this schedule was setup to run (which may not be this instance).
10
- *
11
- * Schedule objects are attached to an action object. Each schedule stores the run date for that
12
- * object as the start date - @see $this->start - and logic to calculate the next run date after
13
- * that - @see $this->calculate_next(). The $first_date property also keeps a record of when the very
14
- * first instance of this chain of schedules ran.
15
- *
16
- * @var DateTime
17
- */
18
- private $first_date = NULL;
19
-
20
- /**
21
- * Timestamp equivalent of @see $this->first_date
22
- *
23
- * @var int
24
- */
25
- protected $first_timestamp = NULL;
26
-
27
- /**
28
- * The recurrance between each time an action is run using this schedule.
29
- * Used to calculate the start date & time. Can be a number of seconds, in the
30
- * case of ActionScheduler_IntervalSchedule, or a cron expression, as in the
31
- * case of ActionScheduler_CronSchedule. Or something else.
32
- *
33
- * @var mixed
34
- */
35
- protected $recurrence;
36
-
37
- /**
38
- * @param DateTime $date The date & time to run the action.
39
- * @param mixed $recurrence The data used to determine the schedule's recurrance.
40
- * @param DateTime|null $first (Optional) The date & time the first instance of this interval schedule ran. Default null, meaning this is the first instance.
41
- */
42
- public function __construct( DateTime $date, $recurrence, DateTime $first = null ) {
43
- parent::__construct( $date );
44
- $this->first_date = empty( $first ) ? $date : $first;
45
- $this->recurrence = $recurrence;
46
- }
47
-
48
- /**
49
- * @return bool
50
- */
51
- public function is_recurring() {
52
- return true;
53
- }
54
-
55
- /**
56
- * Get the date & time of the first schedule in this recurring series.
57
- *
58
- * @return DateTime|null
59
- */
60
- public function get_first_date() {
61
- return clone $this->first_date;
62
- }
63
-
64
- /**
65
- * @return string
66
- */
67
- public function get_recurrence() {
68
- return $this->recurrence;
69
- }
70
-
71
- /**
72
- * For PHP 5.2 compat, since DateTime objects can't be serialized
73
- * @return array
74
- */
75
- public function __sleep() {
76
- $sleep_params = parent::__sleep();
77
- $this->first_timestamp = $this->first_date->getTimestamp();
78
- return array_merge( $sleep_params, array(
79
- 'first_timestamp',
80
- 'recurrence'
81
- ) );
82
- }
83
-
84
- /**
85
- * Unserialize recurring schedules serialized/stored prior to AS 3.0.0
86
- *
87
- * Prior to Action Scheduler 3.0.0, schedules used different property names to refer
88
- * to equivalent data. For example, ActionScheduler_IntervalSchedule::start_timestamp
89
- * was the same as ActionScheduler_SimpleSchedule::timestamp. This was addressed in
90
- * Action Scheduler 3.0.0, where properties and property names were aligned for better
91
- * inheritance. To maintain backward compatibility with scheduled serialized and stored
92
- * prior to 3.0, we need to correctly map the old property names.
93
- */
94
- public function __wakeup() {
95
- parent::__wakeup();
96
- if ( $this->first_timestamp > 0 ) {
97
- $this->first_date = as_get_datetime_object( $this->first_timestamp );
98
- } else {
99
- $this->first_date = $this->get_date();
100
- }
101
- }
102
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_Schedule.php DELETED
@@ -1,83 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_Abstract_Schedule
5
- */
6
- abstract class ActionScheduler_Abstract_Schedule extends ActionScheduler_Schedule_Deprecated {
7
-
8
- /**
9
- * The date & time the schedule is set to run.
10
- *
11
- * @var DateTime
12
- */
13
- private $scheduled_date = NULL;
14
-
15
- /**
16
- * Timestamp equivalent of @see $this->scheduled_date
17
- *
18
- * @var int
19
- */
20
- protected $scheduled_timestamp = NULL;
21
-
22
- /**
23
- * @param DateTime $date The date & time to run the action.
24
- */
25
- public function __construct( DateTime $date ) {
26
- $this->scheduled_date = $date;
27
- }
28
-
29
- /**
30
- * Check if a schedule should recur.
31
- *
32
- * @return bool
33
- */
34
- abstract public function is_recurring();
35
-
36
- /**
37
- * Calculate when the next instance of this schedule would run based on a given date & time.
38
- *
39
- * @param DateTime $after
40
- * @return DateTime
41
- */
42
- abstract protected function calculate_next( DateTime $after );
43
-
44
- /**
45
- * Get the next date & time when this schedule should run after a given date & time.
46
- *
47
- * @param DateTime $after
48
- * @return DateTime|null
49
- */
50
- public function get_next( DateTime $after ) {
51
- $after = clone $after;
52
- if ( $after > $this->scheduled_date ) {
53
- $after = $this->calculate_next( $after );
54
- return $after;
55
- }
56
- return clone $this->scheduled_date;
57
- }
58
-
59
- /**
60
- * Get the date & time the schedule is set to run.
61
- *
62
- * @return DateTime|null
63
- */
64
- public function get_date() {
65
- return $this->scheduled_date;
66
- }
67
-
68
- /**
69
- * For PHP 5.2 compat, since DateTime objects can't be serialized
70
- * @return array
71
- */
72
- public function __sleep() {
73
- $this->scheduled_timestamp = $this->scheduled_date->getTimestamp();
74
- return array(
75
- 'scheduled_timestamp',
76
- );
77
- }
78
-
79
- public function __wakeup() {
80
- $this->scheduled_date = as_get_datetime_object( $this->scheduled_timestamp );
81
- unset( $this->scheduled_timestamp );
82
- }
83
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_Schema.php DELETED
@@ -1,133 +0,0 @@
1
- <?php
2
-
3
-
4
- /**
5
- * Class ActionScheduler_Abstract_Schema
6
- *
7
- * @package Action_Scheduler
8
- *
9
- * @codeCoverageIgnore
10
- *
11
- * Utility class for creating/updating custom tables
12
- */
13
- abstract class ActionScheduler_Abstract_Schema {
14
-
15
- /**
16
- * @var int Increment this value in derived class to trigger a schema update.
17
- */
18
- protected $schema_version = 1;
19
-
20
- /**
21
- * @var array Names of tables that will be registered by this class.
22
- */
23
- protected $tables = [];
24
-
25
- /**
26
- * Register tables with WordPress, and create them if needed.
27
- *
28
- * @return void
29
- */
30
- public function register_tables() {
31
- global $wpdb;
32
-
33
- // make WP aware of our tables
34
- foreach ( $this->tables as $table ) {
35
- $wpdb->tables[] = $table;
36
- $name = $this->get_full_table_name( $table );
37
- $wpdb->$table = $name;
38
- }
39
-
40
- // create the tables
41
- if ( $this->schema_update_required() ) {
42
- foreach ( $this->tables as $table ) {
43
- $this->update_table( $table );
44
- }
45
- $this->mark_schema_update_complete();
46
- }
47
- }
48
-
49
- /**
50
- * @param string $table The name of the table
51
- *
52
- * @return string The CREATE TABLE statement, suitable for passing to dbDelta
53
- */
54
- abstract protected function get_table_definition( $table );
55
-
56
- /**
57
- * Determine if the database schema is out of date
58
- * by comparing the integer found in $this->schema_version
59
- * with the option set in the WordPress options table
60
- *
61
- * @return bool
62
- */
63
- private function schema_update_required() {
64
- $option_name = 'schema-' . static::class;
65
- $version_found_in_db = get_option( $option_name, 0 );
66
-
67
- // Check for schema option stored by the Action Scheduler Custom Tables plugin in case site has migrated from that plugin with an older schema
68
- if ( 0 === $version_found_in_db ) {
69
-
70
- $plugin_option_name = 'schema-';
71
-
72
- switch ( static::class ) {
73
- case 'ActionScheduler_StoreSchema' :
74
- $plugin_option_name .= 'Action_Scheduler\Custom_Tables\DB_Store_Table_Maker';
75
- break;
76
- case 'ActionScheduler_LoggerSchema' :
77
- $plugin_option_name .= 'Action_Scheduler\Custom_Tables\DB_Logger_Table_Maker';
78
- break;
79
- }
80
-
81
- $version_found_in_db = get_option( $plugin_option_name, 0 );
82
-
83
- delete_option( $plugin_option_name );
84
- }
85
-
86
- return version_compare( $version_found_in_db, $this->schema_version, '<' );
87
- }
88
-
89
- /**
90
- * Update the option in WordPress to indicate that
91
- * our schema is now up to date
92
- *
93
- * @return void
94
- */
95
- private function mark_schema_update_complete() {
96
- $option_name = 'schema-' . static::class;
97
-
98
- // work around race conditions and ensure that our option updates
99
- $value_to_save = (string) $this->schema_version . '.0.' . time();
100
-
101
- update_option( $option_name, $value_to_save );
102
- }
103
-
104
- /**
105
- * Update the schema for the given table
106
- *
107
- * @param string $table The name of the table to update
108
- *
109
- * @return void
110
- */
111
- private function update_table( $table ) {
112
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
113
- $definition = $this->get_table_definition( $table );
114
- if ( $definition ) {
115
- $updated = dbDelta( $definition );
116
- foreach ( $updated as $updated_table => $update_description ) {
117
- if ( strpos( $update_description, 'Created table' ) === 0 ) {
118
- do_action( 'action_scheduler/created_table', $updated_table, $table );
119
- }
120
- }
121
- }
122
- }
123
-
124
- /**
125
- * @param string $table
126
- *
127
- * @return string The full name of the table, including the
128
- * table prefix for the current blog
129
- */
130
- protected function get_full_table_name( $table ) {
131
- return $GLOBALS[ 'wpdb' ]->prefix . $table;
132
- }
133
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Lock.php DELETED
@@ -1,62 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Abstract class for setting a basic lock to throttle some action.
5
- *
6
- * Class ActionScheduler_Lock
7
- */
8
- abstract class ActionScheduler_Lock {
9
-
10
- /** @var ActionScheduler_Lock */
11
- private static $locker = NULL;
12
-
13
- /** @var int */
14
- protected static $lock_duration = MINUTE_IN_SECONDS;
15
-
16
- /**
17
- * Check if a lock is set for a given lock type.
18
- *
19
- * @param string $lock_type A string to identify different lock types.
20
- * @return bool
21
- */
22
- public function is_locked( $lock_type ) {
23
- return ( $this->get_expiration( $lock_type ) >= time() );
24
- }
25
-
26
- /**
27
- * Set a lock.
28
- *
29
- * @param string $lock_type A string to identify different lock types.
30
- * @return bool
31
- */
32
- abstract public function set( $lock_type );
33
-
34
- /**
35
- * If a lock is set, return the timestamp it was set to expiry.
36
- *
37
- * @param string $lock_type A string to identify different lock types.
38
- * @return bool|int False if no lock is set, otherwise the timestamp for when the lock is set to expire.
39
- */
40
- abstract public function get_expiration( $lock_type );
41
-
42
- /**
43
- * Get the amount of time to set for a given lock. 60 seconds by default.
44
- *
45
- * @param string $lock_type A string to identify different lock types.
46
- * @return int
47
- */
48
- protected function get_duration( $lock_type ) {
49
- return apply_filters( 'action_scheduler_lock_duration', self::$lock_duration, $lock_type );
50
- }
51
-
52
- /**
53
- * @return ActionScheduler_Lock
54
- */
55
- public static function instance() {
56
- if ( empty( self::$locker ) ) {
57
- $class = apply_filters( 'action_scheduler_lock_class', 'ActionScheduler_OptionLock' );
58
- self::$locker = new $class();
59
- }
60
- return self::$locker;
61
- }
62
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Logger.php DELETED
@@ -1,176 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_Logger
5
- * @codeCoverageIgnore
6
- */
7
- abstract class ActionScheduler_Logger {
8
- private static $logger = NULL;
9
-
10
- /**
11
- * @return ActionScheduler_Logger
12
- */
13
- public static function instance() {
14
- if ( empty(self::$logger) ) {
15
- $class = apply_filters('action_scheduler_logger_class', 'ActionScheduler_wpCommentLogger');
16
- self::$logger = new $class();
17
- }
18
- return self::$logger;
19
- }
20
-
21
- /**
22
- * @param string $action_id
23
- * @param string $message
24
- * @param DateTime $date
25
- *
26
- * @return string The log entry ID
27
- */
28
- abstract public function log( $action_id, $message, DateTime $date = NULL );
29
-
30
- /**
31
- * @param string $entry_id
32
- *
33
- * @return ActionScheduler_LogEntry
34
- */
35
- abstract public function get_entry( $entry_id );
36
-
37
- /**
38
- * @param string $action_id
39
- *
40
- * @return ActionScheduler_LogEntry[]
41
- */
42
- abstract public function get_logs( $action_id );
43
-
44
-
45
- /**
46
- * @codeCoverageIgnore
47
- */
48
- public function init() {
49
- $this->hook_stored_action();
50
- add_action( 'action_scheduler_canceled_action', array( $this, 'log_canceled_action' ), 10, 1 );
51
- add_action( 'action_scheduler_before_execute', array( $this, 'log_started_action' ), 10, 2 );
52
- add_action( 'action_scheduler_after_execute', array( $this, 'log_completed_action' ), 10, 3 );
53
- add_action( 'action_scheduler_failed_execution', array( $this, 'log_failed_action' ), 10, 3 );
54
- add_action( 'action_scheduler_failed_action', array( $this, 'log_timed_out_action' ), 10, 2 );
55
- add_action( 'action_scheduler_unexpected_shutdown', array( $this, 'log_unexpected_shutdown' ), 10, 2 );
56
- add_action( 'action_scheduler_reset_action', array( $this, 'log_reset_action' ), 10, 1 );
57
- add_action( 'action_scheduler_execution_ignored', array( $this, 'log_ignored_action' ), 10, 2 );
58
- add_action( 'action_scheduler_failed_fetch_action', array( $this, 'log_failed_fetch_action' ), 10, 2 );
59
- add_action( 'action_scheduler_failed_to_schedule_next_instance', array( $this, 'log_failed_schedule_next_instance' ), 10, 2 );
60
- add_action( 'action_scheduler_bulk_cancel_actions', array( $this, 'bulk_log_cancel_actions' ), 10, 1 );
61
- }
62
-
63
- public function hook_stored_action() {
64
- add_action( 'action_scheduler_stored_action', array( $this, 'log_stored_action' ) );
65
- }
66
-
67
- public function unhook_stored_action() {
68
- remove_action( 'action_scheduler_stored_action', array( $this, 'log_stored_action' ) );
69
- }
70
-
71
- public function log_stored_action( $action_id ) {
72
- $this->log( $action_id, __( 'action created', 'action-scheduler' ) );
73
- }
74
-
75
- public function log_canceled_action( $action_id ) {
76
- $this->log( $action_id, __( 'action canceled', 'action-scheduler' ) );
77
- }
78
-
79
- public function log_started_action( $action_id, $context = '' ) {
80
- if ( ! empty( $context ) ) {
81
- /* translators: %s: context */
82
- $message = sprintf( __( 'action started via %s', 'action-scheduler' ), $context );
83
- } else {
84
- $message = __( 'action started', 'action-scheduler' );
85
- }
86
- $this->log( $action_id, $message );
87
- }
88
-
89
- public function log_completed_action( $action_id, $action = NULL, $context = '' ) {
90
- if ( ! empty( $context ) ) {
91
- /* translators: %s: context */
92
- $message = sprintf( __( 'action complete via %s', 'action-scheduler' ), $context );
93
- } else {
94
- $message = __( 'action complete', 'action-scheduler' );
95
- }
96
- $this->log( $action_id, $message );
97
- }
98
-
99
- public function log_failed_action( $action_id, Exception $exception, $context = '' ) {
100
- if ( ! empty( $context ) ) {
101
- /* translators: 1: context 2: exception message */
102
- $message = sprintf( __( 'action failed via %1$s: %2$s', 'action-scheduler' ), $context, $exception->getMessage() );
103
- } else {
104
- /* translators: %s: exception message */
105
- $message = sprintf( __( 'action failed: %s', 'action-scheduler' ), $exception->getMessage() );
106
- }
107
- $this->log( $action_id, $message );
108
- }
109
-
110
- public function log_timed_out_action( $action_id, $timeout ) {
111
- /* translators: %s: amount of time */
112
- $this->log( $action_id, sprintf( __( 'action timed out after %s seconds', 'action-scheduler' ), $timeout ) );
113
- }
114
-
115
- public function log_unexpected_shutdown( $action_id, $error ) {
116
- if ( ! empty( $error ) ) {
117
- /* translators: 1: error message 2: filename 3: line */
118
- $this->log( $action_id, sprintf( __( 'unexpected shutdown: PHP Fatal error %1$s in %2$s on line %3$s', 'action-scheduler' ), $error['message'], $error['file'], $error['line'] ) );
119
- }
120
- }
121
-
122
- public function log_reset_action( $action_id ) {
123
- $this->log( $action_id, __( 'action reset', 'action-scheduler' ) );
124
- }
125
-
126
- public function log_ignored_action( $action_id, $context = '' ) {
127
- if ( ! empty( $context ) ) {
128
- /* translators: %s: context */
129
- $message = sprintf( __( 'action ignored via %s', 'action-scheduler' ), $context );
130
- } else {
131
- $message = __( 'action ignored', 'action-scheduler' );
132
- }
133
- $this->log( $action_id, __( 'action ignored', 'action-scheduler' ) );
134
- }
135
-
136
- /**
137
- * @param string $action_id
138
- * @param Exception|NULL $exception The exception which occured when fetching the action. NULL by default for backward compatibility.
139
- *
140
- * @return ActionScheduler_LogEntry[]
141
- */
142
- public function log_failed_fetch_action( $action_id, Exception $exception = NULL ) {
143
-
144
- if ( ! is_null( $exception ) ) {
145
- /* translators: %s: exception message */
146
- $log_message = sprintf( __( 'There was a failure fetching this action: %s', 'action-scheduler' ), $exception->getMessage() );
147
- } else {
148
- $log_message = __( 'There was a failure fetching this action', 'action-scheduler' );
149
- }
150
-
151
- $this->log( $action_id, $log_message );
152
- }
153
-
154
- public function log_failed_schedule_next_instance( $action_id, Exception $exception ) {
155
- /* translators: %s: exception message */
156
- $this->log( $action_id, sprintf( __( 'There was a failure scheduling the next instance of this action: %s', 'action-scheduler' ), $exception->getMessage() ) );
157
- }
158
-
159
- /**
160
- * Bulk add cancel action log entries.
161
- *
162
- * Implemented here for backward compatibility. Should be implemented in parent loggers
163
- * for more performant bulk logging.
164
- *
165
- * @param array $action_ids List of action ID.
166
- */
167
- public function bulk_log_cancel_actions( $action_ids ) {
168
- if ( empty( $action_ids ) ) {
169
- return;
170
- }
171
-
172
- foreach ( $action_ids as $action_id ) {
173
- $this->log_canceled_action( $action_id );
174
- }
175
- }
176
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Store.php DELETED
@@ -1,345 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_Store
5
- * @codeCoverageIgnore
6
- */
7
- abstract class ActionScheduler_Store extends ActionScheduler_Store_Deprecated {
8
- const STATUS_COMPLETE = 'complete';
9
- const STATUS_PENDING = 'pending';
10
- const STATUS_RUNNING = 'in-progress';
11
- const STATUS_FAILED = 'failed';
12
- const STATUS_CANCELED = 'canceled';
13
- const DEFAULT_CLASS = 'ActionScheduler_wpPostStore';
14
-
15
- /** @var ActionScheduler_Store */
16
- private static $store = NULL;
17
-
18
- /** @var int */
19
- private static $max_index_length = 191;
20
-
21
- /**
22
- * @param ActionScheduler_Action $action
23
- * @param DateTime $scheduled_date Optional Date of the first instance
24
- * to store. Otherwise uses the first date of the action's
25
- * schedule.
26
- *
27
- * @return string The action ID
28
- */
29
- abstract public function save_action( ActionScheduler_Action $action, DateTime $scheduled_date = NULL );
30
-
31
- /**
32
- * @param string $action_id
33
- *
34
- * @return ActionScheduler_Action
35
- */
36
- abstract public function fetch_action( $action_id );
37
-
38
- /**
39
- * @param string $hook Hook name/slug.
40
- * @param array $params Hook arguments.
41
- * @return string ID of the next action matching the criteria.
42
- */
43
- abstract public function find_action( $hook, $params = array() );
44
-
45
- /**
46
- * @param array $query Query parameters.
47
- * @param string $query_type Whether to select or count the results. Default, select.
48
- *
49
- * @return array|int The IDs of or count of actions matching the query.
50
- */
51
- abstract public function query_actions( $query = array(), $query_type = 'select' );
52
-
53
- /**
54
- * Get a count of all actions in the store, grouped by status
55
- *
56
- * @return array
57
- */
58
- abstract public function action_counts();
59
-
60
- /**
61
- * @param string $action_id
62
- */
63
- abstract public function cancel_action( $action_id );
64
-
65
- /**
66
- * @param string $action_id
67
- */
68
- abstract public function delete_action( $action_id );
69
-
70
- /**
71
- * @param string $action_id
72
- *
73
- * @return DateTime The date the action is schedule to run, or the date that it ran.
74
- */
75
- abstract public function get_date( $action_id );
76
-
77
-
78
- /**
79
- * @param int $max_actions
80
- * @param DateTime $before_date Claim only actions schedule before the given date. Defaults to now.
81
- * @param array $hooks Claim only actions with a hook or hooks.
82
- * @param string $group Claim only actions in the given group.
83
- *
84
- * @return ActionScheduler_ActionClaim
85
- */
86
- abstract public function stake_claim( $max_actions = 10, DateTime $before_date = null, $hooks = array(), $group = '' );
87
-
88
- /**
89
- * @return int
90
- */
91
- abstract public function get_claim_count();
92
-
93
- /**
94
- * @param ActionScheduler_ActionClaim $claim
95
- */
96
- abstract public function release_claim( ActionScheduler_ActionClaim $claim );
97
-
98
- /**
99
- * @param string $action_id
100
- */
101
- abstract public function unclaim_action( $action_id );
102
-
103
- /**
104
- * @param string $action_id
105
- */
106
- abstract public function mark_failure( $action_id );
107
-
108
- /**
109
- * @param string $action_id
110
- */
111
- abstract public function log_execution( $action_id );
112
-
113
- /**
114
- * @param string $action_id
115
- */
116
- abstract public function mark_complete( $action_id );
117
-
118
- /**
119
- * @param string $action_id
120
- *
121
- * @return string
122
- */
123
- abstract public function get_status( $action_id );
124
-
125
- /**
126
- * @param string $action_id
127
- * @return mixed
128
- */
129
- abstract public function get_claim_id( $action_id );
130
-
131
- /**
132
- * @param string $claim_id
133
- * @return array
134
- */
135
- abstract public function find_actions_by_claim_id( $claim_id );
136
-
137
- /**
138
- * @param string $comparison_operator
139
- * @return string
140
- */
141
- protected function validate_sql_comparator( $comparison_operator ) {
142
- if ( in_array( $comparison_operator, array('!=', '>', '>=', '<', '<=', '=') ) ) {
143
- return $comparison_operator;
144
- }
145
- return '=';
146
- }
147
-
148
- /**
149
- * Get the time MySQL formated date/time string for an action's (next) scheduled date.
150
- *
151
- * @param ActionScheduler_Action $action
152
- * @param DateTime $scheduled_date (optional)
153
- * @return string
154
- */
155
- protected function get_scheduled_date_string( ActionScheduler_Action $action, DateTime $scheduled_date = NULL ) {
156
- $next = null === $scheduled_date ? $action->get_schedule()->get_date() : $scheduled_date;
157
- if ( ! $next ) {
158
- return '0000-00-00 00:00:00';
159
- }
160
- $next->setTimezone( new DateTimeZone( 'UTC' ) );
161
-
162
- return $next->format( 'Y-m-d H:i:s' );
163
- }
164
-
165
- /**
166
- * Get the time MySQL formated date/time string for an action's (next) scheduled date.
167
- *
168
- * @param ActionScheduler_Action $action
169
- * @param DateTime $scheduled_date (optional)
170
- * @return string
171
- */
172
- protected function get_scheduled_date_string_local( ActionScheduler_Action $action, DateTime $scheduled_date = NULL ) {
173
- $next = null === $scheduled_date ? $action->get_schedule()->get_date() : $scheduled_date;
174
- if ( ! $next ) {
175
- return '0000-00-00 00:00:00';
176
- }
177
-
178
- ActionScheduler_TimezoneHelper::set_local_timezone( $next );
179
- return $next->format( 'Y-m-d H:i:s' );
180
- }
181
-
182
- /**
183
- * Validate that we could decode action arguments.
184
- *
185
- * @param mixed $args The decoded arguments.
186
- * @param int $action_id The action ID.
187
- *
188
- * @throws ActionScheduler_InvalidActionException When the decoded arguments are invalid.
189
- */
190
- protected function validate_args( $args, $action_id ) {
191
- // Ensure we have an array of args.
192
- if ( ! is_array( $args ) ) {
193
- throw ActionScheduler_InvalidActionException::from_decoding_args( $action_id );
194
- }
195
-
196
- // Validate JSON decoding if possible.
197
- if ( function_exists( 'json_last_error' ) && JSON_ERROR_NONE !== json_last_error() ) {
198
- throw ActionScheduler_InvalidActionException::from_decoding_args( $action_id, $args );
199
- }
200
- }
201
-
202
- /**
203
- * Validate a ActionScheduler_Schedule object.
204
- *
205
- * @param mixed $schedule The unserialized ActionScheduler_Schedule object.
206
- * @param int $action_id The action ID.
207
- *
208
- * @throws ActionScheduler_InvalidActionException When the schedule is invalid.
209
- */
210
- protected function validate_schedule( $schedule, $action_id ) {
211
- if ( empty( $schedule ) || ! is_a( $schedule, 'ActionScheduler_Schedule' ) ) {
212
- throw ActionScheduler_InvalidActionException::from_schedule( $action_id, $schedule );
213
- }
214
- }
215
-
216
- /**
217
- * InnoDB indexes have a maximum size of 767 bytes by default, which is only 191 characters with utf8mb4.
218
- *
219
- * Previously, AS wasn't concerned about args length, as we used the (unindex) post_content column. However,
220
- * as we prepare to move to custom tables, and can use an indexed VARCHAR column instead, we want to warn
221
- * developers of this impending requirement.
222
- *
223
- * @param ActionScheduler_Action $action
224
- */
225
- protected function validate_action( ActionScheduler_Action $action ) {
226
- if ( strlen( json_encode( $action->get_args() ) ) > self::$max_index_length ) {
227
- throw new InvalidArgumentException( __( 'ActionScheduler_Action::$args too long. To ensure the args column can be indexed, action args should not be more than 191 characters when encoded as JSON.', 'action-scheduler' ) );
228
- }
229
- }
230
-
231
- /**
232
- * Cancel pending actions by hook.
233
- *
234
- * @since 3.0.0
235
- *
236
- * @param string $hook Hook name.
237
- *
238
- * @return void
239
- */
240
- public function cancel_actions_by_hook( $hook ) {
241
- $action_ids = true;
242
- while ( ! empty( $action_ids ) ) {
243
- $action_ids = $this->query_actions(
244
- array(
245
- 'hook' => $hook,
246
- 'status' => self::STATUS_PENDING,
247
- 'per_page' => 1000,
248
- )
249
- );
250
-
251
- $this->bulk_cancel_actions( $action_ids );
252
- }
253
- }
254
-
255
- /**
256
- * Cancel pending actions by group.
257
- *
258
- * @since 3.0.0
259
- *
260
- * @param string $group Group slug.
261
- *
262
- * @return void
263
- */
264
- public function cancel_actions_by_group( $group ) {
265
- $action_ids = true;
266
- while ( ! empty( $action_ids ) ) {
267
- $action_ids = $this->query_actions(
268
- array(
269
- 'group' => $group,
270
- 'status' => self::STATUS_PENDING,
271
- 'per_page' => 1000,
272
- )
273
- );
274
-
275
- $this->bulk_cancel_actions( $action_ids );
276
- }
277
- }
278
-
279
- /**
280
- * Cancel a set of action IDs.
281
- *
282
- * @since 3.0.0
283
- *
284
- * @param array $action_ids List of action IDs.
285
- *
286
- * @return void
287
- */
288
- private function bulk_cancel_actions( $action_ids ) {
289
- foreach ( $action_ids as $action_id ) {
290
- $this->cancel_action( $action_id );
291
- }
292
-
293
- do_action( 'action_scheduler_bulk_cancel_actions', $action_ids );
294
- }
295
-
296
- /**
297
- * @return array
298
- */
299
- public function get_status_labels() {
300
- return array(
301
- self::STATUS_COMPLETE => __( 'Complete', 'action-scheduler' ),
302
- self::STATUS_PENDING => __( 'Pending', 'action-scheduler' ),
303
- self::STATUS_RUNNING => __( 'In-progress', 'action-scheduler' ),
304
- self::STATUS_FAILED => __( 'Failed', 'action-scheduler' ),
305
- self::STATUS_CANCELED => __( 'Canceled', 'action-scheduler' ),
306
- );
307
- }
308
-
309
- /**
310
- * Check if there are any pending scheduled actions due to run.
311
- *
312
- * @param ActionScheduler_Action $action
313
- * @param DateTime $scheduled_date (optional)
314
- * @return string
315
- */
316
- public function has_pending_actions_due() {
317
- $pending_actions = $this->query_actions( array(
318
- 'date' => as_get_datetime_object(),
319
- 'status' => ActionScheduler_Store::STATUS_PENDING,
320
- ) );
321
-
322
- return ! empty( $pending_actions );
323
- }
324
-
325
- /**
326
- * Callable initialization function optionally overridden in derived classes.
327
- */
328
- public function init() {}
329
-
330
- /**
331
- * Callable function to mark an action as migrated optionally overridden in derived classes.
332
- */
333
- public function mark_migrated( $action_id ) {}
334
-
335
- /**
336
- * @return ActionScheduler_Store
337
- */
338
- public static function instance() {
339
- if ( empty( self::$store ) ) {
340
- $class = apply_filters( 'action_scheduler_store_class', self::DEFAULT_CLASS );
341
- self::$store = new $class();
342
- }
343
- return self::$store;
344
- }
345
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_TimezoneHelper.php DELETED
@@ -1,152 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_TimezoneHelper
5
- */
6
- abstract class ActionScheduler_TimezoneHelper {
7
- private static $local_timezone = NULL;
8
-
9
- /**
10
- * Set a DateTime's timezone to the WordPress site's timezone, or a UTC offset
11
- * if no timezone string is available.
12
- *
13
- * @since 2.1.0
14
- *
15
- * @param DateTime $date
16
- * @return ActionScheduler_DateTime
17
- */
18
- public static function set_local_timezone( DateTime $date ) {
19
-
20
- // Accept a DateTime for easier backward compatibility, even though we require methods on ActionScheduler_DateTime
21
- if ( ! is_a( $date, 'ActionScheduler_DateTime' ) ) {
22
- $date = as_get_datetime_object( $date->format( 'U' ) );
23
- }
24
-
25
- if ( get_option( 'timezone_string' ) ) {
26
- $date->setTimezone( new DateTimeZone( self::get_local_timezone_string() ) );
27
- } else {
28
- $date->setUtcOffset( self::get_local_timezone_offset() );
29
- }
30
-
31
- return $date;
32
- }
33
-
34
- /**
35
- * Helper to retrieve the timezone string for a site until a WP core method exists
36
- * (see https://core.trac.wordpress.org/ticket/24730).
37
- *
38
- * Adapted from wc_timezone_string() and https://secure.php.net/manual/en/function.timezone-name-from-abbr.php#89155.
39
- *
40
- * If no timezone string is set, and its not possible to match the UTC offset set for the site to a timezone
41
- * string, then an empty string will be returned, and the UTC offset should be used to set a DateTime's
42
- * timezone.
43
- *
44
- * @since 2.1.0
45
- * @return string PHP timezone string for the site or empty if no timezone string is available.
46
- */
47
- protected static function get_local_timezone_string( $reset = false ) {
48
- // If site timezone string exists, return it.
49
- $timezone = get_option( 'timezone_string' );
50
- if ( $timezone ) {
51
- return $timezone;
52
- }
53
-
54
- // Get UTC offset, if it isn't set then return UTC.
55
- $utc_offset = intval( get_option( 'gmt_offset', 0 ) );
56
- if ( 0 === $utc_offset ) {
57
- return 'UTC';
58
- }
59
-
60
- // Adjust UTC offset from hours to seconds.
61
- $utc_offset *= 3600;
62
-
63
- // Attempt to guess the timezone string from the UTC offset.
64
- $timezone = timezone_name_from_abbr( '', $utc_offset );
65
- if ( $timezone ) {
66
- return $timezone;
67
- }
68
-
69
- // Last try, guess timezone string manually.
70
- foreach ( timezone_abbreviations_list() as $abbr ) {
71
- foreach ( $abbr as $city ) {
72
- if ( (bool) date( 'I' ) === (bool) $city['dst'] && $city['timezone_id'] && intval( $city['offset'] ) === $utc_offset ) {
73
- return $city['timezone_id'];
74
- }
75
- }
76
- }
77
-
78
- // No timezone string
79
- return '';
80
- }
81
-
82
- /**
83
- * Get timezone offset in seconds.
84
- *
85
- * @since 2.1.0
86
- * @return float
87
- */
88
- protected static function get_local_timezone_offset() {
89
- $timezone = get_option( 'timezone_string' );
90
-
91
- if ( $timezone ) {
92
- $timezone_object = new DateTimeZone( $timezone );
93
- return $timezone_object->getOffset( new DateTime( 'now' ) );
94
- } else {
95
- return floatval( get_option( 'gmt_offset', 0 ) ) * HOUR_IN_SECONDS;
96
- }
97
- }
98
-
99
- /**
100
- * @deprecated 2.1.0
101
- */
102
- public static function get_local_timezone( $reset = FALSE ) {
103
- _deprecated_function( __FUNCTION__, '2.1.0', 'ActionScheduler_TimezoneHelper::set_local_timezone()' );
104
- if ( $reset ) {
105
- self::$local_timezone = NULL;
106
- }
107
- if ( !isset(self::$local_timezone) ) {
108
- $tzstring = get_option('timezone_string');
109
-
110
- if ( empty($tzstring) ) {
111
- $gmt_offset = get_option('gmt_offset');
112
- if ( $gmt_offset == 0 ) {
113
- $tzstring = 'UTC';
114
- } else {
115
- $gmt_offset *= HOUR_IN_SECONDS;
116
- $tzstring = timezone_name_from_abbr( '', $gmt_offset, 1 );
117
-
118
- // If there's no timezone string, try again with no DST.
119
- if ( false === $tzstring ) {
120
- $tzstring = timezone_name_from_abbr( '', $gmt_offset, 0 );
121
- }
122
-
123
- // Try mapping to the first abbreviation we can find.
124
- if ( false === $tzstring ) {
125
- $is_dst = date( 'I' );
126
- foreach ( timezone_abbreviations_list() as $abbr ) {
127
- foreach ( $abbr as $city ) {
128
- if ( $city['dst'] == $is_dst && $city['offset'] == $gmt_offset ) {
129
- // If there's no valid timezone ID, keep looking.
130
- if ( null === $city['timezone_id'] ) {
131
- continue;
132
- }
133
-
134
- $tzstring = $city['timezone_id'];
135
- break 2;
136
- }
137
- }
138
- }
139
- }
140
-
141
- // If we still have no valid string, then fall back to UTC.
142
- if ( false === $tzstring ) {
143
- $tzstring = 'UTC';
144
- }
145
- }
146
- }
147
-
148
- self::$local_timezone = new DateTimeZone($tzstring);
149
- }
150
- return self::$local_timezone;
151
- }
152
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/actions/ActionScheduler_Action.php DELETED
@@ -1,75 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_Action
5
- */
6
- class ActionScheduler_Action {
7
- protected $hook = '';
8
- protected $args = array();
9
- /** @var ActionScheduler_Schedule */
10
- protected $schedule = NULL;
11
- protected $group = '';
12
-
13
- public function __construct( $hook, array $args = array(), ActionScheduler_Schedule $schedule = NULL, $group = '' ) {
14
- $schedule = empty( $schedule ) ? new ActionScheduler_NullSchedule() : $schedule;
15
- $this->set_hook($hook);
16
- $this->set_schedule($schedule);
17
- $this->set_args($args);
18
- $this->set_group($group);
19
- }
20
-
21
- public function execute() {
22
- return do_action_ref_array($this->get_hook(), $this->get_args());
23
- }
24
-
25
- /**
26
- * @param string $hook
27
- */
28
- protected function set_hook( $hook ) {
29
- $this->hook = $hook;
30
- }
31
-
32
- public function get_hook() {
33
- return $this->hook;
34
- }
35
-
36
- protected function set_schedule( ActionScheduler_Schedule $schedule ) {
37
- $this->schedule = $schedule;
38
- }
39
-
40
- /**
41
- * @return ActionScheduler_Schedule
42
- */
43
- public function get_schedule() {
44
- return $this->schedule;
45
- }
46
-
47
- protected function set_args( array $args ) {
48
- $this->args = $args;
49
- }
50
-
51
- public function get_args() {
52
- return $this->args;
53
- }
54
-
55
- /**
56
- * @param string $group
57
- */
58
- protected function set_group( $group ) {
59
- $this->group = $group;
60
- }
61
-
62
- /**
63
- * @return string
64
- */
65
- public function get_group() {
66
- return $this->group;
67
- }
68
-
69
- /**
70
- * @return bool If the action has been finished
71
- */
72
- public function is_finished() {
73
- return FALSE;
74
- }
75
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/actions/ActionScheduler_CanceledAction.php DELETED
@@ -1,23 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_CanceledAction
5
- *
6
- * Stored action which was canceled and therefore acts like a finished action but should always return a null schedule,
7
- * regardless of schedule passed to its constructor.
8
- */
9
- class ActionScheduler_CanceledAction extends ActionScheduler_FinishedAction {
10
-
11
- /**
12
- * @param string $hook
13
- * @param array $args
14
- * @param ActionScheduler_Schedule $schedule
15
- * @param string $group
16
- */
17
- public function __construct( $hook, array $args = array(), ActionScheduler_Schedule $schedule = null, $group = '' ) {
18
- parent::__construct( $hook, $args, $schedule, $group );
19
- if ( is_null( $schedule ) ) {
20
- $this->set_schedule( new ActionScheduler_NullSchedule() );
21
- }
22
- }
23
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/actions/ActionScheduler_FinishedAction.php DELETED
@@ -1,16 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_FinishedAction
5
- */
6
- class ActionScheduler_FinishedAction extends ActionScheduler_Action {
7
-
8
- public function execute() {
9
- // don't execute
10
- }
11
-
12
- public function is_finished() {
13
- return TRUE;
14
- }
15
- }
16
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/actions/ActionScheduler_NullAction.php DELETED
@@ -1,16 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_NullAction
5
- */
6
- class ActionScheduler_NullAction extends ActionScheduler_Action {
7
-
8
- public function __construct( $hook = '', array $args = array(), ActionScheduler_Schedule $schedule = NULL ) {
9
- $this->set_schedule( new ActionScheduler_NullSchedule() );
10
- }
11
-
12
- public function execute() {
13
- // don't execute
14
- }
15
- }
16
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_DBLogger.php DELETED
@@ -1,146 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_DBLogger
5
- *
6
- * Action logs data table data store.
7
- *
8
- * @since 3.0.0
9
- */
10
- class ActionScheduler_DBLogger extends ActionScheduler_Logger {
11
-
12
- /**
13
- * Add a record to an action log.
14
- *
15
- * @param int $action_id Action ID.
16
- * @param string $message Message to be saved in the log entry.
17
- * @param DateTime $date Timestamp of the log entry.
18
- *
19
- * @return int The log entry ID.
20
- */
21
- public function log( $action_id, $message, DateTime $date = null ) {
22
- if ( empty( $date ) ) {
23
- $date = as_get_datetime_object();
24
- } else {
25
- $date = clone $date;
26
- }
27
-
28
- $date_gmt = $date->format( 'Y-m-d H:i:s' );
29
- ActionScheduler_TimezoneHelper::set_local_timezone( $date );
30
- $date_local = $date->format( 'Y-m-d H:i:s' );
31
-
32
- /** @var \wpdb $wpdb */
33
- global $wpdb;
34
- $wpdb->insert( $wpdb->actionscheduler_logs, [
35
- 'action_id' => $action_id,
36
- 'message' => $message,
37
- 'log_date_gmt' => $date_gmt,
38
- 'log_date_local' => $date_local,
39
- ], [ '%d', '%s', '%s', '%s' ] );
40
-
41
- return $wpdb->insert_id;
42
- }
43
-
44
- /**
45
- * Retrieve an action log entry.
46
- *
47
- * @param int $entry_id Log entry ID.
48
- *
49
- * @return ActionScheduler_LogEntry
50
- */
51
- public function get_entry( $entry_id ) {
52
- /** @var \wpdb $wpdb */
53
- global $wpdb;
54
- $entry = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->actionscheduler_logs} WHERE log_id=%d", $entry_id ) );
55
-
56
- return $this->create_entry_from_db_record( $entry );
57
- }
58
-
59
- /**
60
- * Create an action log entry from a database record.
61
- *
62
- * @param object $record Log entry database record object.
63
- *
64
- * @return ActionScheduler_LogEntry
65
- */
66
- private function create_entry_from_db_record( $record ) {
67
- if ( empty( $record ) ) {
68
- return new ActionScheduler_NullLogEntry();
69
- }
70
-
71
- $date = as_get_datetime_object( $record->log_date_gmt );
72
-
73
- return new ActionScheduler_LogEntry( $record->action_id, $record->message, $date );
74
- }
75
-
76
- /**
77
- * Retrieve the an action's log entries from the database.
78
- *
79
- * @param int $action_id Action ID.
80
- *
81
- * @return ActionScheduler_LogEntry[]
82
- */
83
- public function get_logs( $action_id ) {
84
- /** @var \wpdb $wpdb */
85
- global $wpdb;
86
-
87
- $records = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->actionscheduler_logs} WHERE action_id=%d", $action_id ) );
88
-
89
- return array_map( [ $this, 'create_entry_from_db_record' ], $records );
90
- }
91
-
92
- /**
93
- * Initialize the data store.
94
- *
95
- * @codeCoverageIgnore
96
- */
97
- public function init() {
98
-
99
- $table_maker = new ActionScheduler_LoggerSchema();
100
- $table_maker->register_tables();
101
-
102
- parent::init();
103
-
104
- add_action( 'action_scheduler_deleted_action', [ $this, 'clear_deleted_action_logs' ], 10, 1 );
105
- }
106
-
107
- /**
108
- * Delete the action logs for an action.
109
- *
110
- * @param int $action_id Action ID.
111
- */
112
- public function clear_deleted_action_logs( $action_id ) {
113
- /** @var \wpdb $wpdb */
114
- global $wpdb;
115
- $wpdb->delete( $wpdb->actionscheduler_logs, [ 'action_id' => $action_id, ], [ '%d' ] );
116
- }
117
-
118
- /**
119
- * Bulk add cancel action log entries.
120
- *
121
- * @param array $action_ids List of action ID.
122
- */
123
- public function bulk_log_cancel_actions( $action_ids ) {
124
- if ( empty( $action_ids ) ) {
125
- return;
126
- }
127
-
128
- /** @var \wpdb $wpdb */
129
- global $wpdb;
130
- $date = as_get_datetime_object();
131
- $date_gmt = $date->format( 'Y-m-d H:i:s' );
132
- ActionScheduler_TimezoneHelper::set_local_timezone( $date );
133
- $date_local = $date->format( 'Y-m-d H:i:s' );
134
- $message = __( 'action canceled', 'action-scheduler' );
135
- $format = '(%d, ' . $wpdb->prepare( '%s, %s, %s', $message, $date_gmt, $date_local ) . ')';
136
- $sql_query = "INSERT {$wpdb->actionscheduler_logs} (action_id, message, log_date_gmt, log_date_local) VALUES ";
137
- $value_rows = [];
138
-
139
- foreach ( $action_ids as $action_id ) {
140
- $value_rows[] = $wpdb->prepare( $format, $action_id );
141
- }
142
- $sql_query .= implode( ',', $value_rows );
143
-
144
- $wpdb->query( $sql_query );
145
- }
146
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_DBStore.php DELETED
@@ -1,803 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_DBStore
5
- *
6
- * Action data table data store.
7
- *
8
- * @since 3.0.0
9
- */
10
- class ActionScheduler_DBStore extends ActionScheduler_Store {
11
-
12
- /**
13
- * Initialize the data store
14
- *
15
- * @codeCoverageIgnore
16
- */
17
- public function init() {
18
- $table_maker = new ActionScheduler_StoreSchema();
19
- $table_maker->register_tables();
20
- }
21
-
22
- /**
23
- * Save an action.
24
- *
25
- * @param ActionScheduler_Action $action Action object.
26
- * @param DateTime $date Optional schedule date. Default null.
27
- *
28
- * @return int Action ID.
29
- */
30
- public function save_action( ActionScheduler_Action $action, \DateTime $date = null ) {
31
- try {
32
-
33
- $this->validate_action( $action );
34
-
35
- /** @var \wpdb $wpdb */
36
- global $wpdb;
37
- $data = [
38
- 'hook' => $action->get_hook(),
39
- 'status' => ( $action->is_finished() ? self::STATUS_COMPLETE : self::STATUS_PENDING ),
40
- 'scheduled_date_gmt' => $this->get_scheduled_date_string( $action, $date ),
41
- 'scheduled_date_local' => $this->get_scheduled_date_string_local( $action, $date ),
42
- 'args' => json_encode( $action->get_args() ),
43
- 'schedule' => serialize( $action->get_schedule() ),
44
- 'group_id' => $this->get_group_id( $action->get_group() ),
45
- ];
46
- $wpdb->insert( $wpdb->actionscheduler_actions, $data );
47
- $action_id = $wpdb->insert_id;
48
-
49
- if ( is_wp_error( $action_id ) ) {
50
- throw new RuntimeException( $action_id->get_error_message() );
51
- }
52
- elseif ( empty( $action_id ) ) {
53
- throw new RuntimeException( $wpdb->last_error ? $wpdb->last_error : __( 'Database error.', 'action-scheduler' ) );
54
- }
55
-
56
- do_action( 'action_scheduler_stored_action', $action_id );
57
-
58
- return $action_id;
59
- } catch ( \Exception $e ) {
60
- /* translators: %s: error message */
61
- throw new \RuntimeException( sprintf( __( 'Error saving action: %s', 'action-scheduler' ), $e->getMessage() ), 0 );
62
- }
63
- }
64
-
65
- /**
66
- * Get a group's ID based on its name/slug.
67
- *
68
- * @param string $slug The string name of a group.
69
- * @param bool $create_if_not_exists Whether to create the group if it does not already exist. Default, true - create the group.
70
- *
71
- * @return int The group's ID, if it exists or is created, or 0 if it does not exist and is not created.
72
- */
73
- protected function get_group_id( $slug, $create_if_not_exists = true ) {
74
- if ( empty( $slug ) ) {
75
- return 0;
76
- }
77
- /** @var \wpdb $wpdb */
78
- global $wpdb;
79
- $group_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT group_id FROM {$wpdb->actionscheduler_groups} WHERE slug=%s", $slug ) );
80
- if ( empty( $group_id ) && $create_if_not_exists ) {
81
- $group_id = $this->create_group( $slug );
82
- }
83
-
84
- return $group_id;
85
- }
86
-
87
- /**
88
- * Create an action group.
89
- *
90
- * @param string $slug Group slug.
91
- *
92
- * @return int Group ID.
93
- */
94
- protected function create_group( $slug ) {
95
- /** @var \wpdb $wpdb */
96
- global $wpdb;
97
- $wpdb->insert( $wpdb->actionscheduler_groups, [ 'slug' => $slug ] );
98
-
99
- return (int) $wpdb->insert_id;
100
- }
101
-
102
- /**
103
- * Retrieve an action.
104
- *
105
- * @param int $action_id Action ID.
106
- *
107
- * @return ActionScheduler_Action
108
- */
109
- public function fetch_action( $action_id ) {
110
- /** @var \wpdb $wpdb */
111
- global $wpdb;
112
- $data = $wpdb->get_row( $wpdb->prepare(
113
- "SELECT a.*, g.slug AS `group` FROM {$wpdb->actionscheduler_actions} a LEFT JOIN {$wpdb->actionscheduler_groups} g ON a.group_id=g.group_id WHERE a.action_id=%d",
114
- $action_id
115
- ) );
116
-
117
- if ( empty( $data ) ) {
118
- return $this->get_null_action();
119
- }
120
-
121
- try {
122
- $action = $this->make_action_from_db_record( $data );
123
- } catch ( ActionScheduler_InvalidActionException $exception ) {
124
- do_action( 'action_scheduler_failed_fetch_action', $action_id, $exception );
125
- return $this->get_null_action();
126
- }
127
-
128
- return $action;
129
- }
130
-
131
- /**
132
- * Create a null action.
133
- *
134
- * @return ActionScheduler_NullAction
135
- */
136
- protected function get_null_action() {
137
- return new ActionScheduler_NullAction();
138
- }
139
-
140
- /**
141
- * Create an action from a database record.
142
- *
143
- * @param object $data Action database record.
144
- *
145
- * @return ActionScheduler_Action|ActionScheduler_CanceledAction|ActionScheduler_FinishedAction
146
- */
147
- protected function make_action_from_db_record( $data ) {
148
-
149
- $hook = $data->hook;
150
- $args = json_decode( $data->args, true );
151
- $schedule = unserialize( $data->schedule );
152
-
153
- $this->validate_args( $args, $data->action_id );
154
- $this->validate_schedule( $schedule, $data->action_id );
155
-
156
- if ( empty( $schedule ) ) {
157
- $schedule = new ActionScheduler_NullSchedule();
158
- }
159
- $group = $data->group ? $data->group : '';
160
-
161
- return ActionScheduler::factory()->get_stored_action( $data->status, $data->hook, $args, $schedule, $group );
162
- }
163
-
164
- /**
165
- * Find an action.
166
- *
167
- * @param string $hook Action hook.
168
- * @param array $params Parameters of the action to find.
169
- *
170
- * @return string|null ID of the next action matching the criteria or NULL if not found.
171
- */
172
- public function find_action( $hook, $params = [] ) {
173
- $params = wp_parse_args( $params, [
174
- 'args' => null,
175
- 'status' => self::STATUS_PENDING,
176
- 'group' => '',
177
- ] );
178
-
179
- /** @var wpdb $wpdb */
180
- global $wpdb;
181
- $query = "SELECT a.action_id FROM {$wpdb->actionscheduler_actions} a";
182
- $args = [];
183
- if ( ! empty( $params[ 'group' ] ) ) {
184
- $query .= " INNER JOIN {$wpdb->actionscheduler_groups} g ON g.group_id=a.group_id AND g.slug=%s";
185
- $args[] = $params[ 'group' ];
186
- }
187
- $query .= " WHERE a.hook=%s";
188
- $args[] = $hook;
189
- if ( ! is_null( $params[ 'args' ] ) ) {
190
- $query .= " AND a.args=%s";
191
- $args[] = json_encode( $params[ 'args' ] );
192
- }
193
-
194
- $order = 'ASC';
195
- if ( ! empty( $params[ 'status' ] ) ) {
196
- $query .= " AND a.status=%s";
197
- $args[] = $params[ 'status' ];
198
-
199
- if ( self::STATUS_PENDING == $params[ 'status' ] ) {
200
- $order = 'ASC'; // Find the next action that matches.
201
- } else {
202
- $order = 'DESC'; // Find the most recent action that matches.
203
- }
204
- }
205
-
206
- $query .= " ORDER BY scheduled_date_gmt $order LIMIT 1";
207
-
208
- $query = $wpdb->prepare( $query, $args );
209
-
210
- $id = $wpdb->get_var( $query );
211
-
212
- return $id;
213
- }
214
-
215
- /**
216
- * Returns the SQL statement to query (or count) actions.
217
- *
218
- * @param array $query Filtering options.
219
- * @param string $select_or_count Whether the SQL should select and return the IDs or just the row count.
220
- *
221
- * @return string SQL statement already properly escaped.
222
- */
223
- protected function get_query_actions_sql( array $query, $select_or_count = 'select' ) {
224
-
225
- if ( ! in_array( $select_or_count, array( 'select', 'count' ) ) ) {
226
- throw new InvalidArgumentException( __( 'Invalid value for select or count parameter. Cannot query actions.', 'action-scheduler' ) );
227
- }
228
-
229
- $query = wp_parse_args( $query, [
230
- 'hook' => '',
231
- 'args' => null,
232
- 'date' => null,
233
- 'date_compare' => '<=',
234
- 'modified' => null,
235
- 'modified_compare' => '<=',
236
- 'group' => '',
237
- 'status' => '',
238
- 'claimed' => null,
239
- 'per_page' => 5,
240
- 'offset' => 0,
241
- 'orderby' => 'date',
242
- 'order' => 'ASC',
243
- ] );
244
-
245
- /** @var \wpdb $wpdb */
246
- global $wpdb;
247
- $sql = ( 'count' === $select_or_count ) ? 'SELECT count(a.action_id)' : 'SELECT a.action_id';
248
- $sql .= " FROM {$wpdb->actionscheduler_actions} a";
249
- $sql_params = [];
250
-
251
- if ( ! empty( $query[ 'group' ] ) || 'group' === $query[ 'orderby' ] ) {
252
- $sql .= " LEFT JOIN {$wpdb->actionscheduler_groups} g ON g.group_id=a.group_id";
253
- }
254
-
255
- $sql .= " WHERE 1=1";
256
-
257
- if ( ! empty( $query[ 'group' ] ) ) {
258
- $sql .= " AND g.slug=%s";
259
- $sql_params[] = $query[ 'group' ];
260
- }
261
-
262
- if ( $query[ 'hook' ] ) {
263
- $sql .= " AND a.hook=%s";
264
- $sql_params[] = $query[ 'hook' ];
265
- }
266
- if ( ! is_null( $query[ 'args' ] ) ) {
267
- $sql .= " AND a.args=%s";
268
- $sql_params[] = json_encode( $query[ 'args' ] );
269
- }
270
-
271
- if ( $query[ 'status' ] ) {
272
- $sql .= " AND a.status=%s";
273
- $sql_params[] = $query[ 'status' ];
274
- }
275
-
276
- if ( $query[ 'date' ] instanceof \DateTime ) {
277
- $date = clone $query[ 'date' ];
278
- $date->setTimezone( new \DateTimeZone( 'UTC' ) );
279
- $date_string = $date->format( 'Y-m-d H:i:s' );
280
- $comparator = $this->validate_sql_comparator( $query[ 'date_compare' ] );
281
- $sql .= " AND a.scheduled_date_gmt $comparator %s";
282
- $sql_params[] = $date_string;
283
- }
284
-
285
- if ( $query[ 'modified' ] instanceof \DateTime ) {
286
- $modified = clone $query[ 'modified' ];
287
- $modified->setTimezone( new \DateTimeZone( 'UTC' ) );
288
- $date_string = $modified->format( 'Y-m-d H:i:s' );
289
- $comparator = $this->validate_sql_comparator( $query[ 'modified_compare' ] );
290
- $sql .= " AND a.last_attempt_gmt $comparator %s";
291
- $sql_params[] = $date_string;
292
- }
293
-
294
- if ( $query[ 'claimed' ] === true ) {
295
- $sql .= " AND a.claim_id != 0";
296
- } elseif ( $query[ 'claimed' ] === false ) {
297
- $sql .= " AND a.claim_id = 0";
298
- } elseif ( ! is_null( $query[ 'claimed' ] ) ) {
299
- $sql .= " AND a.claim_id = %d";
300
- $sql_params[] = $query[ 'claimed' ];
301
- }
302
-
303
- if ( ! empty( $query['search'] ) ) {
304
- $sql .= " AND (a.hook LIKE %s OR a.args LIKE %s";
305
- for( $i = 0; $i < 2; $i++ ) {
306
- $sql_params[] = sprintf( '%%%s%%', $query['search'] );
307
- }
308
-
309
- $search_claim_id = (int) $query['search'];
310
- if ( $search_claim_id ) {
311
- $sql .= ' OR a.claim_id = %d';
312
- $sql_params[] = $search_claim_id;
313
- }
314
-
315
- $sql .= ')';
316
- }
317
-
318
- if ( 'select' === $select_or_count ) {
319
- switch ( $query['orderby'] ) {
320
- case 'hook':
321
- $orderby = 'a.hook';
322
- break;
323
- case 'group':
324
- $orderby = 'g.slug';
325
- break;
326
- case 'modified':
327
- $orderby = 'a.last_attempt_gmt';
328
- break;
329
- case 'date':
330
- default:
331
- $orderby = 'a.scheduled_date_gmt';
332
- break;
333
- }
334
- if ( strtoupper( $query[ 'order' ] ) == 'ASC' ) {
335
- $order = 'ASC';
336
- } else {
337
- $order = 'DESC';
338
- }
339
- $sql .= " ORDER BY $orderby $order";
340
- if ( $query[ 'per_page' ] > 0 ) {
341
- $sql .= " LIMIT %d, %d";
342
- $sql_params[] = $query[ 'offset' ];
343
- $sql_params[] = $query[ 'per_page' ];
344
- }
345
- }
346
-
347
- if ( ! empty( $sql_params ) ) {
348
- $sql = $wpdb->prepare( $sql, $sql_params );
349
- }
350
-
351
- return $sql;
352
- }
353
-
354
- /**
355
- * Query for action count of list of action IDs.
356
- *
357
- * @param array $query Query parameters.
358
- * @param string $query_type Whether to select or count the results. Default, select.
359
- *
360
- * @return null|string|array The IDs of actions matching the query
361
- */
362
- public function query_actions( $query = [], $query_type = 'select' ) {
363
- /** @var wpdb $wpdb */
364
- global $wpdb;
365
-
366
- $sql = $this->get_query_actions_sql( $query, $query_type );
367
-
368
- return ( 'count' === $query_type ) ? $wpdb->get_var( $sql ) : $wpdb->get_col( $sql );
369
- }
370
-
371
- /**
372
- * Get a count of all actions in the store, grouped by status.
373
- *
374
- * @return array Set of 'status' => int $count pairs for statuses with 1 or more actions of that status.
375
- */
376
- public function action_counts() {
377
- global $wpdb;
378
-
379
- $sql = "SELECT a.status, count(a.status) as 'count'";
380
- $sql .= " FROM {$wpdb->actionscheduler_actions} a";
381
- $sql .= " GROUP BY a.status";
382
-
383
- $actions_count_by_status = array();
384
- $action_stati_and_labels = $this->get_status_labels();
385
-
386
- foreach ( $wpdb->get_results( $sql ) as $action_data ) {
387
- // Ignore any actions with invalid status
388
- if ( array_key_exists( $action_data->status, $action_stati_and_labels ) ) {
389
- $actions_count_by_status[ $action_data->status ] = $action_data->count;
390
- }
391
- }
392
-
393
- return $actions_count_by_status;
394
- }
395
-
396
- /**
397
- * Cancel an action.
398
- *
399
- * @param int $action_id Action ID.
400
- *
401
- * @return void
402
- */
403
- public function cancel_action( $action_id ) {
404
- /** @var \wpdb $wpdb */
405
- global $wpdb;
406
-
407
- $updated = $wpdb->update(
408
- $wpdb->actionscheduler_actions,
409
- [ 'status' => self::STATUS_CANCELED ],
410
- [ 'action_id' => $action_id ],
411
- [ '%s' ],
412
- [ '%d' ]
413
- );
414
- if ( empty( $updated ) ) {
415
- /* translators: %s: action ID */
416
- throw new \InvalidArgumentException( sprintf( __( 'Unidentified action %s', 'action-scheduler' ), $action_id ) );
417
- }
418
- do_action( 'action_scheduler_canceled_action', $action_id );
419
- }
420
-
421
- /**
422
- * Cancel pending actions by hook.
423
- *
424
- * @since 3.0.0
425
- *
426
- * @param string $hook Hook name.
427
- *
428
- * @return void
429
- */
430
- public function cancel_actions_by_hook( $hook ) {
431
- $this->bulk_cancel_actions( [ 'hook' => $hook ] );
432
- }
433
-
434
- /**
435
- * Cancel pending actions by group.
436
- *
437
- * @param string $group Group slug.
438
- *
439
- * @return void
440
- */
441
- public function cancel_actions_by_group( $group ) {
442
- $this->bulk_cancel_actions( [ 'group' => $group ] );
443
- }
444
-
445
- /**
446
- * Bulk cancel actions.
447
- *
448
- * @since 3.0.0
449
- *
450
- * @param array $query_args Query parameters.
451
- */
452
- protected function bulk_cancel_actions( $query_args ) {
453
- /** @var \wpdb $wpdb */
454
- global $wpdb;
455
-
456
- if ( ! is_array( $query_args ) ) {
457
- return;
458
- }
459
-
460
- // Don't cancel actions that are already canceled.
461
- if ( isset( $query_args['status'] ) && $query_args['status'] == self::STATUS_CANCELED ) {
462
- return;
463
- }
464
-
465
- $action_ids = true;
466
- $query_args = wp_parse_args(
467
- $query_args,
468
- [
469
- 'per_page' => 1000,
470
- 'status' => self::STATUS_PENDING,
471
- ]
472
- );
473
-
474
- while ( $action_ids ) {
475
- $action_ids = $this->query_actions( $query_args );
476
- if ( empty( $action_ids ) ) {
477
- break;
478
- }
479
-
480
- $format = array_fill( 0, count( $action_ids ), '%d' );
481
- $query_in = '(' . implode( ',', $format ) . ')';
482
- $parameters = $action_ids;
483
- array_unshift( $parameters, self::STATUS_CANCELED );
484
-
485
- $wpdb->query(
486
- $wpdb->prepare( // wpcs: PreparedSQLPlaceholders replacement count ok.
487
- "UPDATE {$wpdb->actionscheduler_actions} SET status = %s WHERE action_id IN {$query_in}",
488
- $parameters
489
- )
490
- );
491
-
492
- do_action( 'action_scheduler_bulk_cancel_actions', $action_ids );
493
- }
494
- }
495
-
496
- /**
497
- * Delete an action.
498
- *
499
- * @param int $action_id Action ID.
500
- */
501
- public function delete_action( $action_id ) {
502
- /** @var \wpdb $wpdb */
503
- global $wpdb;
504
- $deleted = $wpdb->delete( $wpdb->actionscheduler_actions, [ 'action_id' => $action_id ], [ '%d' ] );
505
- if ( empty( $deleted ) ) {
506
- throw new \InvalidArgumentException( sprintf( __( 'Unidentified action %s', 'action-scheduler' ), $action_id ) );
507
- }
508
- do_action( 'action_scheduler_deleted_action', $action_id );
509
- }
510
-
511
- /**
512
- * Get the schedule date for an action.
513
- *
514
- * @param string $action_id Action ID.
515
- *
516
- * @throws \InvalidArgumentException
517
- * @return \DateTime The local date the action is scheduled to run, or the date that it ran.
518
- */
519
- public function get_date( $action_id ) {
520
- $date = $this->get_date_gmt( $action_id );
521
- ActionScheduler_TimezoneHelper::set_local_timezone( $date );
522
- return $date;
523
- }
524
-
525
- /**
526
- * Get the GMT schedule date for an action.
527
- *
528
- * @param int $action_id Action ID.
529
- *
530
- * @throws \InvalidArgumentException
531
- * @return \DateTime The GMT date the action is scheduled to run, or the date that it ran.
532
- */
533
- protected function get_date_gmt( $action_id ) {
534
- /** @var \wpdb $wpdb */
535
- global $wpdb;
536
- $record = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->actionscheduler_actions} WHERE action_id=%d", $action_id ) );
537
- if ( empty( $record ) ) {
538
- throw new \InvalidArgumentException( sprintf( __( 'Unidentified action %s', 'action-scheduler' ), $action_id ) );
539
- }
540
- if ( $record->status == self::STATUS_PENDING ) {
541
- return as_get_datetime_object( $record->scheduled_date_gmt );
542
- } else {
543
- return as_get_datetime_object( $record->last_attempt_gmt );
544
- }
545
- }
546
-
547
- /**
548
- * Stake a claim on actions.
549
- *
550
- * @param int $max_actions Maximum number of action to include in claim.
551
- * @param \DateTime $before_date Jobs must be schedule before this date. Defaults to now.
552
- *
553
- * @return ActionScheduler_ActionClaim
554
- */
555
- public function stake_claim( $max_actions = 10, \DateTime $before_date = null, $hooks = array(), $group = '' ) {
556
- $claim_id = $this->generate_claim_id();
557
- $this->claim_actions( $claim_id, $max_actions, $before_date, $hooks, $group );
558
- $action_ids = $this->find_actions_by_claim_id( $claim_id );
559
-
560
- return new ActionScheduler_ActionClaim( $claim_id, $action_ids );
561
- }
562
-
563
- /**
564
- * Generate a new action claim.
565
- *
566
- * @return int Claim ID.
567
- */
568
- protected function generate_claim_id() {
569
- /** @var \wpdb $wpdb */
570
- global $wpdb;
571
- $now = as_get_datetime_object();
572
- $wpdb->insert( $wpdb->actionscheduler_claims, [ 'date_created_gmt' => $now->format( 'Y-m-d H:i:s' ) ] );
573
-
574
- return $wpdb->insert_id;
575
- }
576
-
577
- /**
578
- * Mark actions claimed.
579
- *
580
- * @param string $claim_id Claim Id.
581
- * @param int $limit Number of action to include in claim.
582
- * @param \DateTime $before_date Should use UTC timezone.
583
- *
584
- * @return int The number of actions that were claimed.
585
- * @throws \RuntimeException
586
- */
587
- protected function claim_actions( $claim_id, $limit, \DateTime $before_date = null, $hooks = array(), $group = '' ) {
588
- /** @var \wpdb $wpdb */
589
- global $wpdb;
590
-
591
- $now = as_get_datetime_object();
592
- $date = is_null( $before_date ) ? $now : clone $before_date;
593
-
594
- // can't use $wpdb->update() because of the <= condition
595
- $update = "UPDATE {$wpdb->actionscheduler_actions} SET claim_id=%d, last_attempt_gmt=%s, last_attempt_local=%s";
596
- $params = array(
597
- $claim_id,
598
- $now->format( 'Y-m-d H:i:s' ),
599
- current_time( 'mysql' ),
600
- );
601
-
602
- $where = "WHERE claim_id = 0 AND scheduled_date_gmt <= %s AND status=%s";
603
- $params[] = $date->format( 'Y-m-d H:i:s' );
604
- $params[] = self::STATUS_PENDING;
605
-
606
- if ( ! empty( $hooks ) ) {
607
- $placeholders = array_fill( 0, count( $hooks ), '%s' );
608
- $where .= ' AND hook IN (' . join( ', ', $placeholders ) . ')';
609
- $params = array_merge( $params, array_values( $hooks ) );
610
- }
611
-
612
- if ( ! empty( $group ) ) {
613
-
614
- $group_id = $this->get_group_id( $group, false );
615
-
616
- // throw exception if no matching group found, this matches ActionScheduler_wpPostStore's behaviour
617
- if ( empty( $group_id ) ) {
618
- /* translators: %s: group name */
619
- throw new InvalidArgumentException( sprintf( __( 'The group "%s" does not exist.', 'action-scheduler' ), $group ) );
620
- }
621
-
622
- $where .= ' AND group_id = %d';
623
- $params[] = $group_id;
624
- }
625
-
626
- $order = "ORDER BY attempts ASC, scheduled_date_gmt ASC, action_id ASC LIMIT %d";
627
- $params[] = $limit;
628
-
629
- $sql = $wpdb->prepare( "{$update} {$where} {$order}", $params );
630
-
631
- $rows_affected = $wpdb->query( $sql );
632
- if ( $rows_affected === false ) {
633
- throw new \RuntimeException( __( 'Unable to claim actions. Database error.', 'action-scheduler' ) );
634
- }
635
-
636
- return (int) $rows_affected;
637
- }
638
-
639
- /**
640
- * Get the number of active claims.
641
- *
642
- * @return int
643
- */
644
- public function get_claim_count() {
645
- global $wpdb;
646
-
647
- $sql = "SELECT COUNT(DISTINCT claim_id) FROM {$wpdb->actionscheduler_actions} WHERE claim_id != 0 AND status IN ( %s, %s)";
648
- $sql = $wpdb->prepare( $sql, [ self::STATUS_PENDING, self::STATUS_RUNNING ] );
649
-
650
- return (int) $wpdb->get_var( $sql );
651
- }
652
-
653
- /**
654
- * Return an action's claim ID, as stored in the claim_id column.
655
- *
656
- * @param string $action_id Action ID.
657
- * @return mixed
658
- */
659
- public function get_claim_id( $action_id ) {
660
- /** @var \wpdb $wpdb */
661
- global $wpdb;
662
-
663
- $sql = "SELECT claim_id FROM {$wpdb->actionscheduler_actions} WHERE action_id=%d";
664
- $sql = $wpdb->prepare( $sql, $action_id );
665
-
666
- return (int) $wpdb->get_var( $sql );
667
- }
668
-
669
- /**
670
- * Retrieve the action IDs of action in a claim.
671
- *
672
- * @param string $claim_id Claim ID.
673
- *
674
- * @return int[]
675
- */
676
- public function find_actions_by_claim_id( $claim_id ) {
677
- /** @var \wpdb $wpdb */
678
- global $wpdb;
679
-
680
- $sql = "SELECT action_id FROM {$wpdb->actionscheduler_actions} WHERE claim_id=%d";
681
- $sql = $wpdb->prepare( $sql, $claim_id );
682
-
683
- $action_ids = $wpdb->get_col( $sql );
684
-
685
- return array_map( 'intval', $action_ids );
686
- }
687
-
688
- /**
689
- * Release actions from a claim and delete the claim.
690
- *
691
- * @param ActionScheduler_ActionClaim $claim Claim object.
692
- */
693
- public function release_claim( ActionScheduler_ActionClaim $claim ) {
694
- /** @var \wpdb $wpdb */
695
- global $wpdb;
696
- $wpdb->update( $wpdb->actionscheduler_actions, [ 'claim_id' => 0 ], [ 'claim_id' => $claim->get_id() ], [ '%d' ], [ '%d' ] );
697
- $wpdb->delete( $wpdb->actionscheduler_claims, [ 'claim_id' => $claim->get_id() ], [ '%d' ] );
698
- }
699
-
700
- /**
701
- * Remove the claim from an action.
702
- *
703
- * @param int $action_id Action ID.
704
- *
705
- * @return void
706
- */
707
- public function unclaim_action( $action_id ) {
708
- /** @var \wpdb $wpdb */
709
- global $wpdb;
710
- $wpdb->update(
711
- $wpdb->actionscheduler_actions,
712
- [ 'claim_id' => 0 ],
713
- [ 'action_id' => $action_id ],
714
- [ '%s' ],
715
- [ '%d' ]
716
- );
717
- }
718
-
719
- /**
720
- * Mark an action as failed.
721
- *
722
- * @param int $action_id Action ID.
723
- */
724
- public function mark_failure( $action_id ) {
725
- /** @var \wpdb $wpdb */
726
- global $wpdb;
727
- $updated = $wpdb->update(
728
- $wpdb->actionscheduler_actions,
729
- [ 'status' => self::STATUS_FAILED ],
730
- [ 'action_id' => $action_id ],
731
- [ '%s' ],
732
- [ '%d' ]
733
- );
734
- if ( empty( $updated ) ) {
735
- throw new \InvalidArgumentException( sprintf( __( 'Unidentified action %s', 'action-scheduler' ), $action_id ) );
736
- }
737
- }
738
-
739
- /**
740
- * Add execution message to action log.
741
- *
742
- * @param int $action_id Action ID.
743
- *
744
- * @return void
745
- */
746
- public function log_execution( $action_id ) {
747
- /** @var \wpdb $wpdb */
748
- global $wpdb;
749
-
750
- $sql = "UPDATE {$wpdb->actionscheduler_actions} SET attempts = attempts+1, status=%s, last_attempt_gmt = %s, last_attempt_local = %s WHERE action_id = %d";
751
- $sql = $wpdb->prepare( $sql, self::STATUS_RUNNING, current_time( 'mysql', true ), current_time( 'mysql' ), $action_id );
752
- $wpdb->query( $sql );
753
- }
754
-
755
- /**
756
- * Mark an action as complete.
757
- *
758
- * @param int $action_id Action ID.
759
- *
760
- * @return void
761
- */
762
- public function mark_complete( $action_id ) {
763
- /** @var \wpdb $wpdb */
764
- global $wpdb;
765
- $updated = $wpdb->update(
766
- $wpdb->actionscheduler_actions,
767
- [
768
- 'status' => self::STATUS_COMPLETE,
769
- 'last_attempt_gmt' => current_time( 'mysql', true ),
770
- 'last_attempt_local' => current_time( 'mysql' ),
771
- ],
772
- [ 'action_id' => $action_id ],
773
- [ '%s' ],
774
- [ '%d' ]
775
- );
776
- if ( empty( $updated ) ) {
777
- throw new \InvalidArgumentException( sprintf( __( 'Unidentified action %s', 'action-scheduler' ), $action_id ) );
778
- }
779
- }
780
-
781
- /**
782
- * Get an action's status.
783
- *
784
- * @param int $action_id Action ID.
785
- *
786
- * @return string
787
- */
788
- public function get_status( $action_id ) {
789
- /** @var \wpdb $wpdb */
790
- global $wpdb;
791
- $sql = "SELECT status FROM {$wpdb->actionscheduler_actions} WHERE action_id=%d";
792
- $sql = $wpdb->prepare( $sql, $action_id );
793
- $status = $wpdb->get_var( $sql );
794
-
795
- if ( $status === null ) {
796
- throw new \InvalidArgumentException( __( 'Invalid action ID. No status found.', 'action-scheduler' ) );
797
- } elseif ( empty( $status ) ) {
798
- throw new \RuntimeException( __( 'Unknown status found for action.', 'action-scheduler' ) );
799
- } else {
800
- return $status;
801
- }
802
- }
803
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_HybridStore.php DELETED
@@ -1,380 +0,0 @@
1
- <?php
2
-
3
- use ActionScheduler_Store as Store;
4
- use Action_Scheduler\Migration\Runner;
5
- use Action_Scheduler\Migration\Config;
6
- use Action_Scheduler\Migration\Controller;
7
-
8
- /**
9
- * Class ActionScheduler_HybridStore
10
- *
11
- * A wrapper around multiple stores that fetches data from both.
12
- *
13
- * @since 3.0.0
14
- */
15
- class ActionScheduler_HybridStore extends Store {
16
- const DEMARKATION_OPTION = 'action_scheduler_hybrid_store_demarkation';
17
-
18
- private $primary_store;
19
- private $secondary_store;
20
- private $migration_runner;
21
-
22
- /**
23
- * @var int The dividing line between IDs of actions created
24
- * by the primary and secondary stores.
25
- *
26
- * Methods that accept an action ID will compare the ID against
27
- * this to determine which store will contain that ID. In almost
28
- * all cases, the ID should come from the primary store, but if
29
- * client code is bypassing the API functions and fetching IDs
30
- * from elsewhere, then there is a chance that an unmigrated ID
31
- * might be requested.
32
- */
33
- private $demarkation_id = 0;
34
-
35
- /**
36
- * ActionScheduler_HybridStore constructor.
37
- *
38
- * @param Config $config Migration config object.
39
- */
40
- public function __construct( Config $config = null ) {
41
- $this->demarkation_id = (int) get_option( self::DEMARKATION_OPTION, 0 );
42
- if ( empty( $config ) ) {
43
- $config = Controller::instance()->get_migration_config_object();
44
- }
45
- $this->primary_store = $config->get_destination_store();
46
- $this->secondary_store = $config->get_source_store();
47
- $this->migration_runner = new Runner( $config );
48
- }
49
-
50
- /**
51
- * Initialize the table data store tables.
52
- *
53
- * @codeCoverageIgnore
54
- */
55
- public function init() {
56
- add_action( 'action_scheduler/created_table', [ $this, 'set_autoincrement' ], 10, 2 );
57
- $this->primary_store->init();
58
- $this->secondary_store->init();
59
- remove_action( 'action_scheduler/created_table', [ $this, 'set_autoincrement' ], 10 );
60
- }
61
-
62
- /**
63
- * When the actions table is created, set its autoincrement
64
- * value to be one higher than the posts table to ensure that
65
- * there are no ID collisions.
66
- *
67
- * @param string $table_name
68
- * @param string $table_suffix
69
- *
70
- * @return void
71
- * @codeCoverageIgnore
72
- */
73
- public function set_autoincrement( $table_name, $table_suffix ) {
74
- if ( ActionScheduler_StoreSchema::ACTIONS_TABLE === $table_suffix ) {
75
- if ( empty( $this->demarkation_id ) ) {
76
- $this->demarkation_id = $this->set_demarkation_id();
77
- }
78
- /** @var \wpdb $wpdb */
79
- global $wpdb;
80
- $wpdb->insert(
81
- $wpdb->{ActionScheduler_StoreSchema::ACTIONS_TABLE},
82
- [
83
- 'action_id' => $this->demarkation_id,
84
- 'hook' => '',
85
- 'status' => '',
86
- ]
87
- );
88
- $wpdb->delete(
89
- $wpdb->{ActionScheduler_StoreSchema::ACTIONS_TABLE},
90
- [ 'action_id' => $this->demarkation_id ]
91
- );
92
- }
93
- }
94
-
95
- /**
96
- * Store the demarkation id in WP options.
97
- *
98
- * @param int $id The ID to set as the demarkation point between the two stores
99
- * Leave null to use the next ID from the WP posts table.
100
- *
101
- * @return int The new ID.
102
- *
103
- * @codeCoverageIgnore
104
- */
105
- private function set_demarkation_id( $id = null ) {
106
- if ( empty( $id ) ) {
107
- /** @var \wpdb $wpdb */
108
- global $wpdb;
109
- $id = (int) $wpdb->get_var( "SELECT MAX(ID) FROM $wpdb->posts" );
110
- $id ++;
111
- }
112
- update_option( self::DEMARKATION_OPTION, $id );
113
-
114
- return $id;
115
- }
116
-
117
- /**
118
- * Find the first matching action from the secondary store.
119
- * If it exists, migrate it to the primary store immediately.
120
- * After it migrates, the secondary store will logically contain
121
- * the next matching action, so return the result thence.
122
- *
123
- * @param string $hook
124
- * @param array $params
125
- *
126
- * @return string
127
- */
128
- public function find_action( $hook, $params = [] ) {
129
- $found_unmigrated_action = $this->secondary_store->find_action( $hook, $params );
130
- if ( ! empty( $found_unmigrated_action ) ) {
131
- $this->migrate( [ $found_unmigrated_action ] );
132
- }
133
-
134
- return $this->primary_store->find_action( $hook, $params );
135
- }
136
-
137
- /**
138
- * Find actions matching the query in the secondary source first.
139
- * If any are found, migrate them immediately. Then the secondary
140
- * store will contain the canonical results.
141
- *
142
- * @param array $query
143
- * @param string $query_type Whether to select or count the results. Default, select.
144
- *
145
- * @return int[]
146
- */
147
- public function query_actions( $query = [], $query_type = 'select' ) {
148
- $found_unmigrated_actions = $this->secondary_store->query_actions( $query, 'select' );
149
- if ( ! empty( $found_unmigrated_actions ) ) {
150
- $this->migrate( $found_unmigrated_actions );
151
- }
152
-
153
- return $this->primary_store->query_actions( $query, $query_type );
154
- }
155
-
156
- /**
157
- * Get a count of all actions in the store, grouped by status
158
- *
159
- * @return array Set of 'status' => int $count pairs for statuses with 1 or more actions of that status.
160
- */
161
- public function action_counts() {
162
- $unmigrated_actions_count = $this->secondary_store->action_counts();
163
- $migrated_actions_count = $this->primary_store->action_counts();
164
- $actions_count_by_status = array();
165
-
166
- foreach ( $this->get_status_labels() as $status_key => $status_label ) {
167
-
168
- $count = 0;
169
-
170
- if ( isset( $unmigrated_actions_count[ $status_key ] ) ) {
171
- $count += $unmigrated_actions_count[ $status_key ];
172
- }
173
-
174
- if ( isset( $migrated_actions_count[ $status_key ] ) ) {
175
- $count += $migrated_actions_count[ $status_key ];
176
- }
177
-
178
- $actions_count_by_status[ $status_key ] = $count;
179
- }
180
-
181
- $actions_count_by_status = array_filter( $actions_count_by_status );
182
-
183
- return $actions_count_by_status;
184
- }
185
-
186
- /**
187
- * If any actions would have been claimed by the secondary store,
188
- * migrate them immediately, then ask the primary store for the
189
- * canonical claim.
190
- *
191
- * @param int $max_actions
192
- * @param DateTime|null $before_date
193
- *
194
- * @return ActionScheduler_ActionClaim
195
- */
196
- public function stake_claim( $max_actions = 10, DateTime $before_date = null, $hooks = array(), $group = '' ) {
197
- $claim = $this->secondary_store->stake_claim( $max_actions, $before_date, $hooks, $group );
198
-
199
- $claimed_actions = $claim->get_actions();
200
- if ( ! empty( $claimed_actions ) ) {
201
- $this->migrate( $claimed_actions );
202
- }
203
-
204
- $this->secondary_store->release_claim( $claim );
205
-
206
- return $this->primary_store->stake_claim( $max_actions, $before_date, $hooks, $group );
207
- }
208
-
209
- /**
210
- * Migrate a list of actions to the table data store.
211
- *
212
- * @param array $action_ids List of action IDs.
213
- */
214
- private function migrate( $action_ids ) {
215
- $this->migration_runner->migrate_actions( $action_ids );
216
- }
217
-
218
- /**
219
- * Save an action to the primary store.
220
- *
221
- * @param ActionScheduler_Action $action Action object to be saved.
222
- * @param DateTime $date Optional. Schedule date. Default null.
223
- */
224
- public function save_action( ActionScheduler_Action $action, DateTime $date = null ) {
225
- return $this->primary_store->save_action( $action, $date );
226
- }
227
-
228
- /**
229
- * Retrieve an existing action whether migrated or not.
230
- *
231
- * @param int $action_id Action ID.
232
- */
233
- public function fetch_action( $action_id ) {
234
- if ( $action_id < $this->demarkation_id ) {
235
- return $this->secondary_store->fetch_action( $action_id );
236
- } else {
237
- return $this->primary_store->fetch_action( $action_id );
238
- }
239
- }
240
-
241
- /**
242
- * Cancel an existing action whether migrated or not.
243
- *
244
- * @param int $action_id Action ID.
245
- */
246
- public function cancel_action( $action_id ) {
247
- if ( $action_id < $this->demarkation_id ) {
248
- $this->secondary_store->cancel_action( $action_id );
249
- } else {
250
- $this->primary_store->cancel_action( $action_id );
251
- }
252
- }
253
-
254
- /**
255
- * Delete an existing action whether migrated or not.
256
- *
257
- * @param int $action_id Action ID.
258
- */
259
- public function delete_action( $action_id ) {
260
- if ( $action_id < $this->demarkation_id ) {
261
- $this->secondary_store->delete_action( $action_id );
262
- } else {
263
- $this->primary_store->delete_action( $action_id );
264
- }
265
- }
266
-
267
- /**
268
- * Get the schedule date an existing action whether migrated or not.
269
- *
270
- * @param int $action_id Action ID.
271
- */
272
- public function get_date( $action_id ) {
273
- if ( $action_id < $this->demarkation_id ) {
274
- return $this->secondary_store->get_date( $action_id );
275
- } else {
276
- return $this->primary_store->get_date( $action_id );
277
- }
278
- }
279
-
280
- /**
281
- * Mark an existing action as failed whether migrated or not.
282
- *
283
- * @param int $action_id Action ID.
284
- */
285
- public function mark_failure( $action_id ) {
286
- if ( $action_id < $this->demarkation_id ) {
287
- $this->secondary_store->mark_failure( $action_id );
288
- } else {
289
- $this->primary_store->mark_failure( $action_id );
290
- }
291
- }
292
-
293
- /**
294
- * Log the execution of an existing action whether migrated or not.
295
- *
296
- * @param int $action_id Action ID.
297
- */
298
- public function log_execution( $action_id ) {
299
- if ( $action_id < $this->demarkation_id ) {
300
- $this->secondary_store->log_execution( $action_id );
301
- } else {
302
- $this->primary_store->log_execution( $action_id );
303
- }
304
- }
305
-
306
- /**
307
- * Mark an existing action complete whether migrated or not.
308
- *
309
- * @param int $action_id Action ID.
310
- */
311
- public function mark_complete( $action_id ) {
312
- if ( $action_id < $this->demarkation_id ) {
313
- $this->secondary_store->mark_complete( $action_id );
314
- } else {
315
- $this->primary_store->mark_complete( $action_id );
316
- }
317
- }
318
-
319
- /**
320
- * Get an existing action status whether migrated or not.
321
- *
322
- * @param int $action_id Action ID.
323
- */
324
- public function get_status( $action_id ) {
325
- if ( $action_id < $this->demarkation_id ) {
326
- return $this->secondary_store->get_status( $action_id );
327
- } else {
328
- return $this->primary_store->get_status( $action_id );
329
- }
330
- }
331
-
332
-
333
- /* * * * * * * * * * * * * * * * * * * * * * * * * * *
334
- * All claim-related functions should operate solely
335
- * on the primary store.
336
- * * * * * * * * * * * * * * * * * * * * * * * * * * */
337
-
338
- /**
339
- * Get the claim count from the table data store.
340
- */
341
- public function get_claim_count() {
342
- return $this->primary_store->get_claim_count();
343
- }
344
-
345
- /**
346
- * Retrieve the claim ID for an action from the table data store.
347
- *
348
- * @param int $action_id Action ID.
349
- */
350
- public function get_claim_id( $action_id ) {
351
- return $this->primary_store->get_claim_id( $action_id );
352
- }
353
-
354
- /**
355
- * Release a claim in the table data store.
356
- *
357
- * @param ActionScheduler_ActionClaim $claim Claim object.
358
- */
359
- public function release_claim( ActionScheduler_ActionClaim $claim ) {
360
- $this->primary_store->release_claim( $claim );
361
- }
362
-
363
- /**
364
- * Release claims on an action in the table data store.
365
- *
366
- * @param int $action_id Action ID.
367
- */
368
- public function unclaim_action( $action_id ) {
369
- $this->primary_store->unclaim_action( $action_id );
370
- }
371
-
372
- /**
373
- * Retrieve a list of action IDs by claim.
374
- *
375
- * @param int $claim_id Claim ID.
376
- */
377
- public function find_actions_by_claim_id( $claim_id ) {
378
- return $this->primary_store->find_actions_by_claim_id( $claim_id );
379
- }
380
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpCommentLogger.php DELETED
@@ -1,240 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_wpCommentLogger
5
- */
6
- class ActionScheduler_wpCommentLogger extends ActionScheduler_Logger {
7
- const AGENT = 'ActionScheduler';
8
- const TYPE = 'action_log';
9
-
10
- /**
11
- * @param string $action_id
12
- * @param string $message
13
- * @param DateTime $date
14
- *
15
- * @return string The log entry ID
16
- */
17
- public function log( $action_id, $message, DateTime $date = NULL ) {
18
- if ( empty($date) ) {
19
- $date = as_get_datetime_object();
20
- } else {
21
- $date = as_get_datetime_object( clone $date );
22
- }
23
- $comment_id = $this->create_wp_comment( $action_id, $message, $date );
24
- return $comment_id;
25
- }
26
-
27
- protected function create_wp_comment( $action_id, $message, DateTime $date ) {
28
-
29
- $comment_date_gmt = $date->format('Y-m-d H:i:s');
30
- ActionScheduler_TimezoneHelper::set_local_timezone( $date );
31
- $comment_data = array(
32
- 'comment_post_ID' => $action_id,
33
- 'comment_date' => $date->format('Y-m-d H:i:s'),
34
- 'comment_date_gmt' => $comment_date_gmt,
35
- 'comment_author' => self::AGENT,
36
- 'comment_content' => $message,
37
- 'comment_agent' => self::AGENT,
38
- 'comment_type' => self::TYPE,
39
- );
40
- return wp_insert_comment($comment_data);
41
- }
42
-
43
- /**
44
- * @param string $entry_id
45
- *
46
- * @return ActionScheduler_LogEntry
47
- */
48
- public function get_entry( $entry_id ) {
49
- $comment = $this->get_comment( $entry_id );
50
- if ( empty($comment) || $comment->comment_type != self::TYPE ) {
51
- return new ActionScheduler_NullLogEntry();
52
- }
53
-
54
- $date = as_get_datetime_object( $comment->comment_date_gmt );
55
- ActionScheduler_TimezoneHelper::set_local_timezone( $date );
56
- return new ActionScheduler_LogEntry( $comment->comment_post_ID, $comment->comment_content, $date );
57
- }
58
-
59
- /**
60
- * @param string $action_id
61
- *
62
- * @return ActionScheduler_LogEntry[]
63
- */
64
- public function get_logs( $action_id ) {
65
- $status = 'all';
66
- if ( get_post_status($action_id) == 'trash' ) {
67
- $status = 'post-trashed';
68
- }
69
- $comments = get_comments(array(
70
- 'post_id' => $action_id,
71
- 'orderby' => 'comment_date_gmt',
72
- 'order' => 'ASC',
73
- 'type' => self::TYPE,
74
- 'status' => $status,
75
- ));
76
- $logs = array();
77
- foreach ( $comments as $c ) {
78
- $entry = $this->get_entry( $c );
79
- if ( !empty($entry) ) {
80
- $logs[] = $entry;
81
- }
82
- }
83
- return $logs;
84
- }
85
-
86
- protected function get_comment( $comment_id ) {
87
- return get_comment( $comment_id );
88
- }
89
-
90
-
91
-
92
- /**
93
- * @param WP_Comment_Query $query
94
- */
95
- public function filter_comment_queries( $query ) {
96
- foreach ( array('ID', 'parent', 'post_author', 'post_name', 'post_parent', 'type', 'post_type', 'post_id', 'post_ID') as $key ) {
97
- if ( !empty($query->query_vars[$key]) ) {
98
- return; // don't slow down queries that wouldn't include action_log comments anyway
99
- }
100
- }
101
- $query->query_vars['action_log_filter'] = TRUE;
102
- add_filter( 'comments_clauses', array( $this, 'filter_comment_query_clauses' ), 10, 2 );
103
- }
104
-
105
- /**
106
- * @param array $clauses
107
- * @param WP_Comment_Query $query
108
- *
109
- * @return array
110
- */
111
- public function filter_comment_query_clauses( $clauses, $query ) {
112
- if ( !empty($query->query_vars['action_log_filter']) ) {
113
- $clauses['where'] .= $this->get_where_clause();
114
- }
115
- return $clauses;
116
- }
117
-
118
- /**
119
- * Make sure Action Scheduler logs are excluded from comment feeds, which use WP_Query, not
120
- * the WP_Comment_Query class handled by @see self::filter_comment_queries().
121
- *
122
- * @param string $where
123
- * @param WP_Query $query
124
- *
125
- * @return string
126
- */
127
- public function filter_comment_feed( $where, $query ) {
128
- if ( is_comment_feed() ) {
129
- $where .= $this->get_where_clause();
130
- }
131
- return $where;
132
- }
133
-
134
- /**
135
- * Return a SQL clause to exclude Action Scheduler comments.
136
- *
137
- * @return string
138
- */
139
- protected function get_where_clause() {
140
- global $wpdb;
141
- return sprintf( " AND {$wpdb->comments}.comment_type != '%s'", self::TYPE );
142
- }
143
-
144
- /**
145
- * Remove action log entries from wp_count_comments()
146
- *
147
- * @param array $stats
148
- * @param int $post_id
149
- *
150
- * @return object
151
- */
152
- public function filter_comment_count( $stats, $post_id ) {
153
- global $wpdb;
154
-
155
- if ( 0 === $post_id ) {
156
- $stats = $this->get_comment_count();
157
- }
158
-
159
- return $stats;
160
- }
161
-
162
- /**
163
- * Retrieve the comment counts from our cache, or the database if the cached version isn't set.
164
- *
165
- * @return object
166
- */
167
- protected function get_comment_count() {
168
- global $wpdb;
169
-
170
- $stats = get_transient( 'as_comment_count' );
171
-
172
- if ( ! $stats ) {
173
- $stats = array();
174
-
175
- $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} WHERE comment_type NOT IN('order_note','action_log') GROUP BY comment_approved", ARRAY_A );
176
-
177
- $total = 0;
178
- $stats = array();
179
- $approved = array( '0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed' );
180
-
181
- foreach ( (array) $count as $row ) {
182
- // Don't count post-trashed toward totals
183
- if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) {
184
- $total += $row['num_comments'];
185
- }
186
- if ( isset( $approved[ $row['comment_approved'] ] ) ) {
187
- $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments'];
188
- }
189
- }
190
-
191
- $stats['total_comments'] = $total;
192
- $stats['all'] = $total;
193
-
194
- foreach ( $approved as $key ) {
195
- if ( empty( $stats[ $key ] ) ) {
196
- $stats[ $key ] = 0;
197
- }
198
- }
199
-
200
- $stats = (object) $stats;
201
- set_transient( 'as_comment_count', $stats );
202
- }
203
-
204
- return $stats;
205
- }
206
-
207
- /**
208
- * Delete comment count cache whenever there is new comment or the status of a comment changes. Cache
209
- * will be regenerated next time ActionScheduler_wpCommentLogger::filter_comment_count() is called.
210
- */
211
- public function delete_comment_count_cache() {
212
- delete_transient( 'as_comment_count' );
213
- }
214
-
215
- /**
216
- * @codeCoverageIgnore
217
- */
218
- public function init() {
219
- add_action( 'action_scheduler_before_process_queue', array( $this, 'disable_comment_counting' ), 10, 0 );
220
- add_action( 'action_scheduler_after_process_queue', array( $this, 'enable_comment_counting' ), 10, 0 );
221
-
222
- parent::init();
223
-
224
- add_action( 'pre_get_comments', array( $this, 'filter_comment_queries' ), 10, 1 );
225
- add_action( 'wp_count_comments', array( $this, 'filter_comment_count' ), 20, 2 ); // run after WC_Comments::wp_count_comments() to make sure we exclude order notes and action logs
226
- add_action( 'comment_feed_where', array( $this, 'filter_comment_feed' ), 10, 2 );
227
-
228
- // Delete comments count cache whenever there is a new comment or a comment status changes
229
- add_action( 'wp_insert_comment', array( $this, 'delete_comment_count_cache' ) );
230
- add_action( 'wp_set_comment_status', array( $this, 'delete_comment_count_cache' ) );
231
- }
232
-
233
- public function disable_comment_counting() {
234
- wp_defer_comment_counting(true);
235
- }
236
- public function enable_comment_counting() {
237
- wp_defer_comment_counting(false);
238
- }
239
-
240
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore.php DELETED
@@ -1,858 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_wpPostStore
5
- */
6
- class ActionScheduler_wpPostStore extends ActionScheduler_Store {
7
- const POST_TYPE = 'scheduled-action';
8
- const GROUP_TAXONOMY = 'action-group';
9
- const SCHEDULE_META_KEY = '_action_manager_schedule';
10
- const DEPENDENCIES_MET = 'as-post-store-dependencies-met';
11
-
12
- /** @var DateTimeZone */
13
- protected $local_timezone = NULL;
14
-
15
- public function save_action( ActionScheduler_Action $action, DateTime $scheduled_date = NULL ){
16
- try {
17
- $this->validate_action( $action );
18
- $post_array = $this->create_post_array( $action, $scheduled_date );
19
- $post_id = $this->save_post_array( $post_array );
20
- $this->save_post_schedule( $post_id, $action->get_schedule() );
21
- $this->save_action_group( $post_id, $action->get_group() );
22
- do_action( 'action_scheduler_stored_action', $post_id );
23
- return $post_id;
24
- } catch ( Exception $e ) {
25
- throw new RuntimeException( sprintf( __('Error saving action: %s', 'action-scheduler'), $e->getMessage() ), 0 );
26
- }
27
- }
28
-
29
- protected function create_post_array( ActionScheduler_Action $action, DateTime $scheduled_date = NULL ) {
30
- $post = array(
31
- 'post_type' => self::POST_TYPE,
32
- 'post_title' => $action->get_hook(),
33
- 'post_content' => json_encode($action->get_args()),
34
- 'post_status' => ( $action->is_finished() ? 'publish' : 'pending' ),
35
- 'post_date_gmt' => $this->get_scheduled_date_string( $action, $scheduled_date ),
36
- 'post_date' => $this->get_scheduled_date_string_local( $action, $scheduled_date ),
37
- );
38
- return $post;
39
- }
40
-
41
- protected function save_post_array( $post_array ) {
42
- add_filter( 'wp_insert_post_data', array( $this, 'filter_insert_post_data' ), 10, 1 );
43
- add_filter( 'pre_wp_unique_post_slug', array( $this, 'set_unique_post_slug' ), 10, 5 );
44
-
45
- $has_kses = false !== has_filter( 'content_save_pre', 'wp_filter_post_kses' );
46
-
47
- if ( $has_kses ) {
48
- // Prevent KSES from corrupting JSON in post_content.
49
- kses_remove_filters();
50
- }
51
-
52
- $post_id = wp_insert_post($post_array);
53
-
54
- if ( $has_kses ) {
55
- kses_init_filters();
56
- }
57
-
58
- remove_filter( 'wp_insert_post_data', array( $this, 'filter_insert_post_data' ), 10 );
59
- remove_filter( 'pre_wp_unique_post_slug', array( $this, 'set_unique_post_slug' ), 10 );
60
-
61
- if ( is_wp_error($post_id) || empty($post_id) ) {
62
- throw new RuntimeException(__('Unable to save action.', 'action-scheduler'));
63
- }
64
- return $post_id;
65
- }
66
-
67
- public function filter_insert_post_data( $postdata ) {
68
- if ( $postdata['post_type'] == self::POST_TYPE ) {
69
- $postdata['post_author'] = 0;
70
- if ( $postdata['post_status'] == 'future' ) {
71
- $postdata['post_status'] = 'publish';
72
- }
73
- }
74
- return $postdata;
75
- }
76
-
77
- /**
78
- * Create a (probably unique) post name for scheduled actions in a more performant manner than wp_unique_post_slug().
79
- *
80
- * When an action's post status is transitioned to something other than 'draft', 'pending' or 'auto-draft, like 'publish'
81
- * or 'failed' or 'trash', WordPress will find a unique slug (stored in post_name column) using the wp_unique_post_slug()
82
- * function. This is done to ensure URL uniqueness. The approach taken by wp_unique_post_slug() is to iterate over existing
83
- * post_name values that match, and append a number 1 greater than the largest. This makes sense when manually creating a
84
- * post from the Edit Post screen. It becomes a bottleneck when automatically processing thousands of actions, with a
85
- * database containing thousands of related post_name values.
86
- *
87
- * WordPress 5.1 introduces the 'pre_wp_unique_post_slug' filter for plugins to address this issue.
88
- *
89
- * We can short-circuit WordPress's wp_unique_post_slug() approach using the 'pre_wp_unique_post_slug' filter. This
90
- * method is available to be used as a callback on that filter. It provides a more scalable approach to generating a
91
- * post_name/slug that is probably unique. Because Action Scheduler never actually uses the post_name field, or an
92
- * action's slug, being probably unique is good enough.
93
- *
94
- * For more backstory on this issue, see:
95
- * - https://github.com/woocommerce/action-scheduler/issues/44 and
96
- * - https://core.trac.wordpress.org/ticket/21112
97
- *
98
- * @param string $override_slug Short-circuit return value.
99
- * @param string $slug The desired slug (post_name).
100
- * @param int $post_ID Post ID.
101
- * @param string $post_status The post status.
102
- * @param string $post_type Post type.
103
- * @return string
104
- */
105
- public function set_unique_post_slug( $override_slug, $slug, $post_ID, $post_status, $post_type ) {
106
- if ( self::POST_TYPE == $post_type ) {
107
- $override_slug = uniqid( self::POST_TYPE . '-', true ) . '-' . wp_generate_password( 32, false );
108
- }
109
- return $override_slug;
110
- }
111
-
112
- protected function save_post_schedule( $post_id, $schedule ) {
113
- update_post_meta( $post_id, self::SCHEDULE_META_KEY, $schedule );
114
- }
115
-
116
- protected function save_action_group( $post_id, $group ) {
117
- if ( empty($group) ) {
118
- wp_set_object_terms( $post_id, array(), self::GROUP_TAXONOMY, FALSE );
119
- } else {
120
- wp_set_object_terms( $post_id, array($group), self::GROUP_TAXONOMY, FALSE );
121
- }
122
- }
123
-
124
- public function fetch_action( $action_id ) {
125
- $post = $this->get_post( $action_id );
126
- if ( empty($post) || $post->post_type != self::POST_TYPE ) {
127
- return $this->get_null_action();
128
- }
129
-
130
- try {
131
- $action = $this->make_action_from_post( $post );
132
- } catch ( ActionScheduler_InvalidActionException $exception ) {
133
- do_action( 'action_scheduler_failed_fetch_action', $post->ID, $exception );
134
- return $this->get_null_action();
135
- }
136
-
137
- return $action;
138
- }
139
-
140
- protected function get_post( $action_id ) {
141
- if ( empty($action_id) ) {
142
- return NULL;
143
- }
144
- return get_post($action_id);
145
- }
146
-
147
- protected function get_null_action() {
148
- return new ActionScheduler_NullAction();
149
- }
150
-
151
- protected function make_action_from_post( $post ) {
152
- $hook = $post->post_title;
153
-
154
- $args = json_decode( $post->post_content, true );
155
- $this->validate_args( $args, $post->ID );
156
-
157
- $schedule = get_post_meta( $post->ID, self::SCHEDULE_META_KEY, true );
158
- $this->validate_schedule( $schedule, $post->ID );
159
-
160
- $group = wp_get_object_terms( $post->ID, self::GROUP_TAXONOMY, array('fields' => 'names') );
161
- $group = empty( $group ) ? '' : reset($group);
162
-
163
- return ActionScheduler::factory()->get_stored_action( $this->get_action_status_by_post_status( $post->post_status ), $hook, $args, $schedule, $group );
164
- }
165
-
166
- /**
167
- * @param string $post_status
168
- *
169
- * @throws InvalidArgumentException if $post_status not in known status fields returned by $this->get_status_labels()
170
- * @return string
171
- */
172
- protected function get_action_status_by_post_status( $post_status ) {
173
-
174
- switch ( $post_status ) {
175
- case 'publish' :
176
- $action_status = self::STATUS_COMPLETE;
177
- break;
178
- case 'trash' :
179
- $action_status = self::STATUS_CANCELED;
180
- break;
181
- default :
182
- if ( ! array_key_exists( $post_status, $this->get_status_labels() ) ) {
183
- throw new InvalidArgumentException( sprintf( 'Invalid post status: "%s". No matching action status available.', $post_status ) );
184
- }
185
- $action_status = $post_status;
186
- break;
187
- }
188
-
189
- return $action_status;
190
- }
191
-
192
- /**
193
- * @param string $action_status
194
- * @throws InvalidArgumentException if $post_status not in known status fields returned by $this->get_status_labels()
195
- * @return string
196
- */
197
- protected function get_post_status_by_action_status( $action_status ) {
198
-
199
- switch ( $action_status ) {
200
- case self::STATUS_COMPLETE :
201
- $post_status = 'publish';
202
- break;
203
- case self::STATUS_CANCELED :
204
- $post_status = 'trash';
205
- break;
206
- default :
207
- if ( ! array_key_exists( $action_status, $this->get_status_labels() ) ) {
208
- throw new InvalidArgumentException( sprintf( 'Invalid action status: "%s".', $action_status ) );
209
- }
210
- $post_status = $action_status;
211
- break;
212
- }
213
-
214
- return $post_status;
215
- }
216
-
217
- /**
218
- * @param string $hook
219
- * @param array $params
220
- *
221
- * @return string ID of the next action matching the criteria or NULL if not found
222
- */
223
- public function find_action( $hook, $params = array() ) {
224
- $params = wp_parse_args( $params, array(
225
- 'args' => NULL,
226
- 'status' => ActionScheduler_Store::STATUS_PENDING,
227
- 'group' => '',
228
- ));
229
- /** @var wpdb $wpdb */
230
- global $wpdb;
231
- $query = "SELECT p.ID FROM {$wpdb->posts} p";
232
- $args = array();
233
- if ( !empty($params['group']) ) {
234
- $query .= " INNER JOIN {$wpdb->term_relationships} tr ON tr.object_id=p.ID";
235
- $query .= " INNER JOIN {$wpdb->term_taxonomy} tt ON tr.term_taxonomy_id=tt.term_taxonomy_id";
236
- $query .= " INNER JOIN {$wpdb->terms} t ON tt.term_id=t.term_id AND t.slug=%s";
237
- $args[] = $params['group'];
238
- }
239
- $query .= " WHERE p.post_title=%s";
240
- $args[] = $hook;
241
- $query .= " AND p.post_type=%s";
242
- $args[] = self::POST_TYPE;
243
- if ( !is_null($params['args']) ) {
244
- $query .= " AND p.post_content=%s";
245
- $args[] = json_encode($params['args']);
246
- }
247
-
248
- if ( ! empty( $params['status'] ) ) {
249
- $query .= " AND p.post_status=%s";
250
- $args[] = $this->get_post_status_by_action_status( $params['status'] );
251
- }
252
-
253
- switch ( $params['status'] ) {
254
- case self::STATUS_COMPLETE:
255
- case self::STATUS_RUNNING:
256
- case self::STATUS_FAILED:
257
- $order = 'DESC'; // Find the most recent action that matches
258
- break;
259
- case self::STATUS_PENDING:
260
- default:
261
- $order = 'ASC'; // Find the next action that matches
262
- break;
263
- }
264
- $query .= " ORDER BY post_date_gmt $order LIMIT 1";
265
-
266
- $query = $wpdb->prepare( $query, $args );
267
-
268
- $id = $wpdb->get_var($query);
269
- return $id;
270
- }
271
-
272
- /**
273
- * Returns the SQL statement to query (or count) actions.
274
- *
275
- * @param array $query Filtering options
276
- * @param string $select_or_count Whether the SQL should select and return the IDs or just the row count
277
- * @throws InvalidArgumentException if $select_or_count not count or select
278
- * @return string SQL statement. The returned SQL is already properly escaped.
279
- */
280
- protected function get_query_actions_sql( array $query, $select_or_count = 'select' ) {
281
-
282
- if ( ! in_array( $select_or_count, array( 'select', 'count' ) ) ) {
283
- throw new InvalidArgumentException(__('Invalid schedule. Cannot save action.', 'action-scheduler'));
284
- }
285
-
286
- $query = wp_parse_args( $query, array(
287
- 'hook' => '',
288
- 'args' => NULL,
289
- 'date' => NULL,
290
- 'date_compare' => '<=',
291
- 'modified' => NULL,
292
- 'modified_compare' => '<=',
293
- 'group' => '',
294
- 'status' => '',
295
- 'claimed' => NULL,
296
- 'per_page' => 5,
297
- 'offset' => 0,
298
- 'orderby' => 'date',
299
- 'order' => 'ASC',
300
- 'search' => '',
301
- ) );
302
-
303
- /** @var wpdb $wpdb */
304
- global $wpdb;
305
- $sql = ( 'count' === $select_or_count ) ? 'SELECT count(p.ID)' : 'SELECT p.ID ';
306
- $sql .= "FROM {$wpdb->posts} p";
307
- $sql_params = array();
308
- if ( empty( $query['group'] ) && 'group' === $query['orderby'] ) {
309
- $sql .= " LEFT JOIN {$wpdb->term_relationships} tr ON tr.object_id=p.ID";
310
- $sql .= " LEFT JOIN {$wpdb->term_taxonomy} tt ON tr.term_taxonomy_id=tt.term_taxonomy_id";
311
- $sql .= " LEFT JOIN {$wpdb->terms} t ON tt.term_id=t.term_id";
312
- } elseif ( ! empty( $query['group'] ) ) {
313
- $sql .= " INNER JOIN {$wpdb->term_relationships} tr ON tr.object_id=p.ID";
314
- $sql .= " INNER JOIN {$wpdb->term_taxonomy} tt ON tr.term_taxonomy_id=tt.term_taxonomy_id";
315
- $sql .= " INNER JOIN {$wpdb->terms} t ON tt.term_id=t.term_id";
316
- $sql .= " AND t.slug=%s";
317
- $sql_params[] = $query['group'];
318
- }
319
- $sql .= " WHERE post_type=%s";
320
- $sql_params[] = self::POST_TYPE;
321
- if ( $query['hook'] ) {
322
- $sql .= " AND p.post_title=%s";
323
- $sql_params[] = $query['hook'];
324
- }
325
- if ( !is_null($query['args']) ) {
326
- $sql .= " AND p.post_content=%s";
327
- $sql_params[] = json_encode($query['args']);
328
- }
329
-
330
- if ( ! empty( $query['status'] ) ) {
331
- $sql .= " AND p.post_status=%s";
332
- $sql_params[] = $this->get_post_status_by_action_status( $query['status'] );
333
- }
334
-
335
- if ( $query['date'] instanceof DateTime ) {
336
- $date = clone $query['date'];
337
- $date->setTimezone( new DateTimeZone('UTC') );
338
- $date_string = $date->format('Y-m-d H:i:s');
339
- $comparator = $this->validate_sql_comparator($query['date_compare']);
340
- $sql .= " AND p.post_date_gmt $comparator %s";
341
- $sql_params[] = $date_string;
342
- }
343
-
344
- if ( $query['modified'] instanceof DateTime ) {
345
- $modified = clone $query['modified'];
346
- $modified->setTimezone( new DateTimeZone('UTC') );
347
- $date_string = $modified->format('Y-m-d H:i:s');
348
- $comparator = $this->validate_sql_comparator($query['modified_compare']);
349
- $sql .= " AND p.post_modified_gmt $comparator %s";
350
- $sql_params[] = $date_string;
351
- }
352
-
353
- if ( $query['claimed'] === TRUE ) {
354
- $sql .= " AND p.post_password != ''";
355
- } elseif ( $query['claimed'] === FALSE ) {
356
- $sql .= " AND p.post_password = ''";
357
- } elseif ( !is_null($query['claimed']) ) {
358
- $sql .= " AND p.post_password = %s";
359
- $sql_params[] = $query['claimed'];
360
- }
361
-
362
- if ( ! empty( $query['search'] ) ) {
363
- $sql .= " AND (p.post_title LIKE %s OR p.post_content LIKE %s OR p.post_password LIKE %s)";
364
- for( $i = 0; $i < 3; $i++ ) {
365
- $sql_params[] = sprintf( '%%%s%%', $query['search'] );
366
- }
367
- }
368
-
369
- if ( 'select' === $select_or_count ) {
370
- switch ( $query['orderby'] ) {
371
- case 'hook':
372
- $orderby = 'p.post_title';
373
- break;
374
- case 'group':
375
- $orderby = 't.name';
376
- break;
377
- case 'status':
378
- $orderby = 'p.post_status';
379
- break;
380
- case 'modified':
381
- $orderby = 'p.post_modified';
382
- break;
383
- case 'claim_id':
384
- $orderby = 'p.post_password';
385
- break;
386
- case 'schedule':
387
- case 'date':
388
- default:
389
- $orderby = 'p.post_date_gmt';
390
- break;
391
- }
392
- if ( 'ASC' === strtoupper( $query['order'] ) ) {
393
- $order = 'ASC';
394
- } else {
395
- $order = 'DESC';
396
- }
397
- $sql .= " ORDER BY $orderby $order";
398
- if ( $query['per_page'] > 0 ) {
399
- $sql .= " LIMIT %d, %d";
400
- $sql_params[] = $query['offset'];
401
- $sql_params[] = $query['per_page'];
402
- }
403
- }
404
-
405
- return $wpdb->prepare( $sql, $sql_params );
406
- }
407
-
408
- /**
409
- * @param array $query
410
- * @param string $query_type Whether to select or count the results. Default, select.
411
- * @return string|array The IDs of actions matching the query
412
- */
413
- public function query_actions( $query = array(), $query_type = 'select' ) {
414
- /** @var wpdb $wpdb */
415
- global $wpdb;
416
-
417
- $sql = $this->get_query_actions_sql( $query, $query_type );
418
-
419
- return ( 'count' === $query_type ) ? $wpdb->get_var( $sql ) : $wpdb->get_col( $sql );
420
- }
421
-
422
- /**
423
- * Get a count of all actions in the store, grouped by status
424
- *
425
- * @return array
426
- */
427
- public function action_counts() {
428
-
429
- $action_counts_by_status = array();
430
- $action_stati_and_labels = $this->get_status_labels();
431
- $posts_count_by_status = (array) wp_count_posts( self::POST_TYPE, 'readable' );
432
-
433
- foreach ( $posts_count_by_status as $post_status_name => $count ) {
434
-
435
- try {
436
- $action_status_name = $this->get_action_status_by_post_status( $post_status_name );
437
- } catch ( Exception $e ) {
438
- // Ignore any post statuses that aren't for actions
439
- continue;
440
- }
441
- if ( array_key_exists( $action_status_name, $action_stati_and_labels ) ) {
442
- $action_counts_by_status[ $action_status_name ] = $count;
443
- }
444
- }
445
-
446
- return $action_counts_by_status;
447
- }
448
-
449
- /**
450
- * @param string $action_id
451
- *
452
- * @throws InvalidArgumentException
453
- */
454
- public function cancel_action( $action_id ) {
455
- $post = get_post($action_id);
456
- if ( empty($post) || ($post->post_type != self::POST_TYPE) ) {
457
- throw new InvalidArgumentException(sprintf(__('Unidentified action %s', 'action-scheduler'), $action_id));
458
- }
459
- do_action( 'action_scheduler_canceled_action', $action_id );
460
- add_filter( 'pre_wp_unique_post_slug', array( $this, 'set_unique_post_slug' ), 10, 5 );
461
- wp_trash_post($action_id);
462
- remove_filter( 'pre_wp_unique_post_slug', array( $this, 'set_unique_post_slug' ), 10 );
463
- }
464
-
465
- public function delete_action( $action_id ) {
466
- $post = get_post($action_id);
467
- if ( empty($post) || ($post->post_type != self::POST_TYPE) ) {
468
- throw new InvalidArgumentException(sprintf(__('Unidentified action %s', 'action-scheduler'), $action_id));
469
- }
470
- do_action( 'action_scheduler_deleted_action', $action_id );
471
-
472
- wp_delete_post( $action_id, TRUE );
473
- }
474
-
475
- /**
476
- * @param string $action_id
477
- *
478
- * @throws InvalidArgumentException
479
- * @return ActionScheduler_DateTime The date the action is schedule to run, or the date that it ran.
480
- */
481
- public function get_date( $action_id ) {
482
- $next = $this->get_date_gmt( $action_id );
483
- return ActionScheduler_TimezoneHelper::set_local_timezone( $next );
484
- }
485
-
486
- /**
487
- * @param string $action_id
488
- *
489
- * @throws InvalidArgumentException
490
- * @return ActionScheduler_DateTime The date the action is schedule to run, or the date that it ran.
491
- */
492
- public function get_date_gmt( $action_id ) {
493
- $post = get_post($action_id);
494
- if ( empty($post) || ($post->post_type != self::POST_TYPE) ) {
495
- throw new InvalidArgumentException(sprintf(__('Unidentified action %s', 'action-scheduler'), $action_id));
496
- }
497
- if ( $post->post_status == 'publish' ) {
498
- return as_get_datetime_object($post->post_modified_gmt);
499
- } else {
500
- return as_get_datetime_object($post->post_date_gmt);
501
- }
502
- }
503
-
504
- /**
505
- * @param int $max_actions
506
- * @param DateTime $before_date Jobs must be schedule before this date. Defaults to now.
507
- * @param array $hooks Claim only actions with a hook or hooks.
508
- * @param string $group Claim only actions in the given group.
509
- *
510
- * @return ActionScheduler_ActionClaim
511
- * @throws RuntimeException When there is an error staking a claim.
512
- * @throws InvalidArgumentException When the given group is not valid.
513
- */
514
- public function stake_claim( $max_actions = 10, DateTime $before_date = null, $hooks = array(), $group = '' ) {
515
- $claim_id = $this->generate_claim_id();
516
- $this->claim_actions( $claim_id, $max_actions, $before_date, $hooks, $group );
517
- $action_ids = $this->find_actions_by_claim_id( $claim_id );
518
-
519
- return new ActionScheduler_ActionClaim( $claim_id, $action_ids );
520
- }
521
-
522
- /**
523
- * @return int
524
- */
525
- public function get_claim_count(){
526
- global $wpdb;
527
-
528
- $sql = "SELECT COUNT(DISTINCT post_password) FROM {$wpdb->posts} WHERE post_password != '' AND post_type = %s AND post_status IN ('in-progress','pending')";
529
- $sql = $wpdb->prepare( $sql, array( self::POST_TYPE ) );
530
-
531
- return $wpdb->get_var( $sql );
532
- }
533
-
534
- protected function generate_claim_id() {
535
- $claim_id = md5(microtime(true) . rand(0,1000));
536
- return substr($claim_id, 0, 20); // to fit in db field with 20 char limit
537
- }
538
-
539
- /**
540
- * @param string $claim_id
541
- * @param int $limit
542
- * @param DateTime $before_date Should use UTC timezone.
543
- * @param array $hooks Claim only actions with a hook or hooks.
544
- * @param string $group Claim only actions in the given group.
545
- *
546
- * @return int The number of actions that were claimed
547
- * @throws RuntimeException When there is a database error.
548
- * @throws InvalidArgumentException When the group is invalid.
549
- */
550
- protected function claim_actions( $claim_id, $limit, DateTime $before_date = null, $hooks = array(), $group = '' ) {
551
- // Set up initial variables.
552
- $date = null === $before_date ? as_get_datetime_object() : clone $before_date;
553
- $limit_ids = ! empty( $group );
554
- $ids = $limit_ids ? $this->get_actions_by_group( $group, $limit, $date ) : array();
555
-
556
- // If limiting by IDs and no posts found, then return early since we have nothing to update.
557
- if ( $limit_ids && 0 === count( $ids ) ) {
558
- return 0;
559
- }
560
-
561
- /** @var wpdb $wpdb */
562
- global $wpdb;
563
-
564
- /*
565
- * Build up custom query to update the affected posts. Parameters are built as a separate array
566
- * to make it easier to identify where they are in the query.
567
- *
568
- * We can't use $wpdb->update() here because of the "ID IN ..." clause.
569
- */
570
- $update = "UPDATE {$wpdb->posts} SET post_password = %s, post_modified_gmt = %s, post_modified = %s";
571
- $params = array(
572
- $claim_id,
573
- current_time( 'mysql', true ),
574
- current_time( 'mysql' ),
575
- );
576
-
577
- // Build initial WHERE clause.
578
- $where = "WHERE post_type = %s AND post_status = %s AND post_password = ''";
579
- $params[] = self::POST_TYPE;
580
- $params[] = ActionScheduler_Store::STATUS_PENDING;
581
-
582
- if ( ! empty( $hooks ) ) {
583
- $placeholders = array_fill( 0, count( $hooks ), '%s' );
584
- $where .= ' AND post_title IN (' . join( ', ', $placeholders ) . ')';
585
- $params = array_merge( $params, array_values( $hooks ) );
586
- }
587
-
588
- /*
589
- * Add the IDs to the WHERE clause. IDs not escaped because they came directly from a prior DB query.
590
- *
591
- * If we're not limiting by IDs, then include the post_date_gmt clause.
592
- */
593
- if ( $limit_ids ) {
594
- $where .= ' AND ID IN (' . join( ',', $ids ) . ')';
595
- } else {
596
- $where .= ' AND post_date_gmt <= %s';
597
- $params[] = $date->format( 'Y-m-d H:i:s' );
598
- }
599
-
600
- // Add the ORDER BY clause and,ms limit.
601
- $order = 'ORDER BY menu_order ASC, post_date_gmt ASC, ID ASC LIMIT %d';
602
- $params[] = $limit;
603
-
604
- // Run the query and gather results.
605
- $rows_affected = $wpdb->query( $wpdb->prepare( "{$update} {$where} {$order}", $params ) );
606
- if ( $rows_affected === false ) {
607
- throw new RuntimeException( __( 'Unable to claim actions. Database error.', 'action-scheduler' ) );
608
- }
609
-
610
- return (int) $rows_affected;
611
- }
612
-
613
- /**
614
- * Get IDs of actions within a certain group and up to a certain date/time.
615
- *
616
- * @param string $group The group to use in finding actions.
617
- * @param int $limit The number of actions to retrieve.
618
- * @param DateTime $date DateTime object representing cutoff time for actions. Actions retrieved will be
619
- * up to and including this DateTime.
620
- *
621
- * @return array IDs of actions in the appropriate group and before the appropriate time.
622
- * @throws InvalidArgumentException When the group does not exist.
623
- */
624
- protected function get_actions_by_group( $group, $limit, DateTime $date ) {
625
- // Ensure the group exists before continuing.
626
- if ( ! term_exists( $group, self::GROUP_TAXONOMY )) {
627
- throw new InvalidArgumentException( sprintf( __( 'The group "%s" does not exist.', 'action-scheduler' ), $group ) );
628
- }
629
-
630
- // Set up a query for post IDs to use later.
631
- $query = new WP_Query();
632
- $query_args = array(
633
- 'fields' => 'ids',
634
- 'post_type' => self::POST_TYPE,
635
- 'post_status' => ActionScheduler_Store::STATUS_PENDING,
636
- 'has_password' => false,
637
- 'posts_per_page' => $limit * 3,
638
- 'suppress_filters' => true,
639
- 'no_found_rows' => true,
640
- 'orderby' => array(
641
- 'menu_order' => 'ASC',
642
- 'date' => 'ASC',
643
- 'ID' => 'ASC',
644
- ),
645
- 'date_query' => array(
646
- 'column' => 'post_date_gmt',
647
- 'before' => $date->format( 'Y-m-d H:i' ),
648
- 'inclusive' => true,
649
- ),
650
- 'tax_query' => array(
651
- array(
652
- 'taxonomy' => self::GROUP_TAXONOMY,
653
- 'field' => 'slug',
654
- 'terms' => $group,
655
- 'include_children' => false,
656
- ),
657
- ),
658
- );
659
-
660
- return $query->query( $query_args );
661
- }
662
-
663
- /**
664
- * @param string $claim_id
665
- * @return array
666
- */
667
- public function find_actions_by_claim_id( $claim_id ) {
668
- /** @var wpdb $wpdb */
669
- global $wpdb;
670
- $sql = "SELECT ID FROM {$wpdb->posts} WHERE post_type = %s AND post_password = %s";
671
- $sql = $wpdb->prepare( $sql, array( self::POST_TYPE, $claim_id ) );
672
- $action_ids = $wpdb->get_col( $sql );
673
- return $action_ids;
674
- }
675
-
676
- public function release_claim( ActionScheduler_ActionClaim $claim ) {
677
- $action_ids = $this->find_actions_by_claim_id( $claim->get_id() );
678
- if ( empty($action_ids) ) {
679
- return; // nothing to do
680
- }
681
- $action_id_string = implode(',', array_map('intval', $action_ids));
682
- /** @var wpdb $wpdb */
683
- global $wpdb;
684
- $sql = "UPDATE {$wpdb->posts} SET post_password = '' WHERE ID IN ($action_id_string) AND post_password = %s";
685
- $sql = $wpdb->prepare( $sql, array( $claim->get_id() ) );
686
- $result = $wpdb->query($sql);
687
- if ( $result === false ) {
688
- /* translators: %s: claim ID */
689
- throw new RuntimeException( sprintf( __('Unable to unlock claim %s. Database error.', 'action-scheduler'), $claim->get_id() ) );
690
- }
691
- }
692
-
693
- /**
694
- * @param string $action_id
695
- */
696
- public function unclaim_action( $action_id ) {
697
- /** @var wpdb $wpdb */
698
- global $wpdb;
699
- $sql = "UPDATE {$wpdb->posts} SET post_password = '' WHERE ID = %d AND post_type = %s";
700
- $sql = $wpdb->prepare( $sql, $action_id, self::POST_TYPE );
701
- $result = $wpdb->query($sql);
702
- if ( $result === false ) {
703
- /* translators: %s: action ID */
704
- throw new RuntimeException( sprintf( __('Unable to unlock claim on action %s. Database error.', 'action-scheduler'), $action_id ) );
705
- }
706
- }
707
-
708
- public function mark_failure( $action_id ) {
709
- /** @var wpdb $wpdb */
710
- global $wpdb;
711
- $sql = "UPDATE {$wpdb->posts} SET post_status = %s WHERE ID = %d AND post_type = %s";
712
- $sql = $wpdb->prepare( $sql, self::STATUS_FAILED, $action_id, self::POST_TYPE );
713
- $result = $wpdb->query($sql);
714
- if ( $result === false ) {
715
- /* translators: %s: action ID */
716
- throw new RuntimeException( sprintf( __('Unable to mark failure on action %s. Database error.', 'action-scheduler'), $action_id ) );
717
- }
718
- }
719
-
720
- /**
721
- * Return an action's claim ID, as stored in the post password column
722
- *
723
- * @param string $action_id
724
- * @return mixed
725
- */
726
- public function get_claim_id( $action_id ) {
727
- return $this->get_post_column( $action_id, 'post_password' );
728
- }
729
-
730
- /**
731
- * Return an action's status, as stored in the post status column
732
- *
733
- * @param string $action_id
734
- * @return mixed
735
- */
736
- public function get_status( $action_id ) {
737
- $status = $this->get_post_column( $action_id, 'post_status' );
738
-
739
- if ( $status === null ) {
740
- throw new InvalidArgumentException( __( 'Invalid action ID. No status found.', 'action-scheduler' ) );
741
- }
742
-
743
- return $this->get_action_status_by_post_status( $status );
744
- }
745
-
746
- private function get_post_column( $action_id, $column_name ) {
747
- /** @var \wpdb $wpdb */
748
- global $wpdb;
749
- return $wpdb->get_var( $wpdb->prepare( "SELECT {$column_name} FROM {$wpdb->posts} WHERE ID=%d AND post_type=%s", $action_id, self::POST_TYPE ) );
750
- }
751
-
752
- /**
753
- * @param string $action_id
754
- */
755
- public function log_execution( $action_id ) {
756
- /** @var wpdb $wpdb */
757
- global $wpdb;
758
-
759
- $sql = "UPDATE {$wpdb->posts} SET menu_order = menu_order+1, post_status=%s, post_modified_gmt = %s, post_modified = %s WHERE ID = %d AND post_type = %s";
760
- $sql = $wpdb->prepare( $sql, self::STATUS_RUNNING, current_time('mysql', true), current_time('mysql'), $action_id, self::POST_TYPE );
761
- $wpdb->query($sql);
762
- }
763
-
764
- /**
765
- * Record that an action was completed.
766
- *
767
- * @param int $action_id ID of the completed action.
768
- * @throws InvalidArgumentException|RuntimeException
769
- */
770
- public function mark_complete( $action_id ) {
771
- $post = get_post($action_id);
772
- if ( empty($post) || ($post->post_type != self::POST_TYPE) ) {
773
- throw new InvalidArgumentException(sprintf(__('Unidentified action %s', 'action-scheduler'), $action_id));
774
- }
775
- add_filter( 'wp_insert_post_data', array( $this, 'filter_insert_post_data' ), 10, 1 );
776
- add_filter( 'pre_wp_unique_post_slug', array( $this, 'set_unique_post_slug' ), 10, 5 );
777
- $result = wp_update_post(array(
778
- 'ID' => $action_id,
779
- 'post_status' => 'publish',
780
- ), TRUE);
781
- remove_filter( 'wp_insert_post_data', array( $this, 'filter_insert_post_data' ), 10 );
782
- remove_filter( 'pre_wp_unique_post_slug', array( $this, 'set_unique_post_slug' ), 10 );
783
- if ( is_wp_error($result) ) {
784
- throw new RuntimeException($result->get_error_message());
785
- }
786
- }
787
-
788
- /**
789
- * Mark action as migrated when there is an error deleting the action.
790
- *
791
- * @param int $action_id Action ID.
792
- */
793
- public function mark_migrated( $action_id ) {
794
- wp_update_post(
795
- array(
796
- 'ID' => $action_id,
797
- 'post_status' => 'migrated'
798
- )
799
- );
800
- }
801
-
802
- /**
803
- * Determine whether the post store can be migrated.
804
- *
805
- * @return bool
806
- */
807
- public function migration_dependencies_met( $setting ) {
808
- global $wpdb;
809
-
810
- $dependencies_met = get_transient( self::DEPENDENCIES_MET );
811
- if ( empty( $dependencies_met ) ) {
812
- $found_action = $wpdb->get_var(
813
- $wpdb->prepare(
814
- "SELECT ID FROM {$wpdb->posts} WHERE post_type = %s AND CHAR_LENGTH(post_content) > 191 LIMIT 1",
815
- self::POST_TYPE
816
- )
817
- );
818
- $dependencies_met = $found_action ? 'no' : 'yes';
819
- set_transient( self::DEPENDENCIES_MET, $dependencies_met, DAY_IN_SECONDS );
820
- }
821
-
822
- return 'yes' == $dependencies_met ? $setting : false;
823
- }
824
-
825
- /**
826
- * InnoDB indexes have a maximum size of 767 bytes by default, which is only 191 characters with utf8mb4.
827
- *
828
- * Previously, AS wasn't concerned about args length, as we used the (unindex) post_content column. However,
829
- * as we prepare to move to custom tables, and can use an indexed VARCHAR column instead, we want to warn
830
- * developers of this impending requirement.
831
- *
832
- * @param ActionScheduler_Action $action
833
- */
834
- protected function validate_action( ActionScheduler_Action $action ) {
835
- try {
836
- parent::validate_action( $action );
837
- } catch ( Exception $e ) {
838
- $message = sprintf( __( '%s Support for strings longer than this will be removed in a future version.', 'action-scheduler' ), $e->getMessage() );
839
- _doing_it_wrong( 'ActionScheduler_Action::$args', $message, '2.1.0' );
840
- }
841
- }
842
-
843
- /**
844
- * @codeCoverageIgnore
845
- */
846
- public function init() {
847
- add_filter( 'action_scheduler_migration_dependencies_met', array( $this, 'migration_dependencies_met' ) );
848
-
849
- $post_type_registrar = new ActionScheduler_wpPostStore_PostTypeRegistrar();
850
- $post_type_registrar->register();
851
-
852
- $post_status_registrar = new ActionScheduler_wpPostStore_PostStatusRegistrar();
853
- $post_status_registrar->register();
854
-
855
- $taxonomy_registrar = new ActionScheduler_wpPostStore_TaxonomyRegistrar();
856
- $taxonomy_registrar->register();
857
- }
858
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore_PostStatusRegistrar.php DELETED
@@ -1,58 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_wpPostStore_PostStatusRegistrar
5
- * @codeCoverageIgnore
6
- */
7
- class ActionScheduler_wpPostStore_PostStatusRegistrar {
8
- public function register() {
9
- register_post_status( ActionScheduler_Store::STATUS_RUNNING, array_merge( $this->post_status_args(), $this->post_status_running_labels() ) );
10
- register_post_status( ActionScheduler_Store::STATUS_FAILED, array_merge( $this->post_status_args(), $this->post_status_failed_labels() ) );
11
- }
12
-
13
- /**
14
- * Build the args array for the post type definition
15
- *
16
- * @return array
17
- */
18
- protected function post_status_args() {
19
- $args = array(
20
- 'public' => false,
21
- 'exclude_from_search' => false,
22
- 'show_in_admin_all_list' => true,
23
- 'show_in_admin_status_list' => true,
24
- );
25
-
26
- return apply_filters( 'action_scheduler_post_status_args', $args );
27
- }
28
-
29
- /**
30
- * Build the args array for the post type definition
31
- *
32
- * @return array
33
- */
34
- protected function post_status_failed_labels() {
35
- $labels = array(
36
- 'label' => _x( 'Failed', 'post', 'action-scheduler' ),
37
- /* translators: %s: count */
38
- 'label_count' => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'action-scheduler' ),
39
- );
40
-
41
- return apply_filters( 'action_scheduler_post_status_failed_labels', $labels );
42
- }
43
-
44
- /**
45
- * Build the args array for the post type definition
46
- *
47
- * @return array
48
- */
49
- protected function post_status_running_labels() {
50
- $labels = array(
51
- 'label' => _x( 'In-Progress', 'post', 'action-scheduler' ),
52
- /* translators: %s: count */
53
- 'label_count' => _n_noop( 'In-Progress <span class="count">(%s)</span>', 'In-Progress <span class="count">(%s)</span>', 'action-scheduler' ),
54
- );
55
-
56
- return apply_filters( 'action_scheduler_post_status_running_labels', $labels );
57
- }
58
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore_PostTypeRegistrar.php DELETED
@@ -1,50 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_wpPostStore_PostTypeRegistrar
5
- * @codeCoverageIgnore
6
- */
7
- class ActionScheduler_wpPostStore_PostTypeRegistrar {
8
- public function register() {
9
- register_post_type( ActionScheduler_wpPostStore::POST_TYPE, $this->post_type_args() );
10
- }
11
-
12
- /**
13
- * Build the args array for the post type definition
14
- *
15
- * @return array
16
- */
17
- protected function post_type_args() {
18
- $args = array(
19
- 'label' => __( 'Scheduled Actions', 'action-scheduler' ),
20
- 'description' => __( 'Scheduled actions are hooks triggered on a cetain date and time.', 'action-scheduler' ),
21
- 'public' => false,
22
- 'map_meta_cap' => true,
23
- 'hierarchical' => false,
24
- 'supports' => array('title', 'editor','comments'),
25
- 'rewrite' => false,
26
- 'query_var' => false,
27
- 'can_export' => true,
28
- 'ep_mask' => EP_NONE,
29
- 'labels' => array(
30
- 'name' => __( 'Scheduled Actions', 'action-scheduler' ),
31
- 'singular_name' => __( 'Scheduled Action', 'action-scheduler' ),
32
- 'menu_name' => _x( 'Scheduled Actions', 'Admin menu name', 'action-scheduler' ),
33
- 'add_new' => __( 'Add', 'action-scheduler' ),
34
- 'add_new_item' => __( 'Add New Scheduled Action', 'action-scheduler' ),
35
- 'edit' => __( 'Edit', 'action-scheduler' ),
36
- 'edit_item' => __( 'Edit Scheduled Action', 'action-scheduler' ),
37
- 'new_item' => __( 'New Scheduled Action', 'action-scheduler' ),
38
- 'view' => __( 'View Action', 'action-scheduler' ),
39
- 'view_item' => __( 'View Action', 'action-scheduler' ),
40
- 'search_items' => __( 'Search Scheduled Actions', 'action-scheduler' ),
41
- 'not_found' => __( 'No actions found', 'action-scheduler' ),
42
- 'not_found_in_trash' => __( 'No actions found in trash', 'action-scheduler' ),
43
- ),
44
- );
45
-
46
- $args = apply_filters('action_scheduler_post_type_args', $args);
47
- return $args;
48
- }
49
- }
50
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore_TaxonomyRegistrar.php DELETED
@@ -1,26 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_wpPostStore_TaxonomyRegistrar
5
- * @codeCoverageIgnore
6
- */
7
- class ActionScheduler_wpPostStore_TaxonomyRegistrar {
8
- public function register() {
9
- register_taxonomy( ActionScheduler_wpPostStore::GROUP_TAXONOMY, ActionScheduler_wpPostStore::POST_TYPE, $this->taxonomy_args() );
10
- }
11
-
12
- protected function taxonomy_args() {
13
- $args = array(
14
- 'label' => __('Action Group', 'action-scheduler'),
15
- 'public' => false,
16
- 'hierarchical' => false,
17
- 'show_admin_column' => true,
18
- 'query_var' => false,
19
- 'rewrite' => false,
20
- );
21
-
22
- $args = apply_filters('action_scheduler_taxonomy_args', $args);
23
- return $args;
24
- }
25
- }
26
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/migration/ActionMigrator.php DELETED
@@ -1,109 +0,0 @@
1
- <?php
2
-
3
-
4
- namespace Action_Scheduler\Migration;
5
-
6
- /**
7
- * Class ActionMigrator
8
- *
9
- * @package Action_Scheduler\Migration
10
- *
11
- * @since 3.0.0
12
- *
13
- * @codeCoverageIgnore
14
- */
15
- class ActionMigrator {
16
- /** var ActionScheduler_Store */
17
- private $source;
18
-
19
- /** var ActionScheduler_Store */
20
- private $destination;
21
-
22
- /** var LogMigrator */
23
- private $log_migrator;
24
-
25
- /**
26
- * ActionMigrator constructor.
27
- *
28
- * @param ActionScheduler_Store $source_store Source store object.
29
- * @param ActionScheduler_Store $destination_store Destination store object.
30
- * @param LogMigrator $log_migrator Log migrator object.
31
- */
32
- public function __construct( \ActionScheduler_Store $source_store, \ActionScheduler_Store $destination_store, LogMigrator $log_migrator ) {
33
- $this->source = $source_store;
34
- $this->destination = $destination_store;
35
- $this->log_migrator = $log_migrator;
36
- }
37
-
38
- /**
39
- * Migrate an action.
40
- *
41
- * @param int $source_action_id Action ID.
42
- *
43
- * @return int 0|new action ID
44
- */
45
- public function migrate( $source_action_id ) {
46
- try {
47
- $action = $this->source->fetch_action( $source_action_id );
48
- $status = $this->source->get_status( $source_action_id );
49
- } catch ( \Exception $e ) {
50
- $action = null;
51
- $status = '';
52
- }
53
-
54
- if ( is_null( $action ) || empty( $status ) || ! $action->get_schedule()->get_date() ) {
55
- // null action or empty status means the fetch operation failed or the action didn't exist
56
- // null schedule means it's missing vital data
57
- // delete it and move on
58
- try {
59
- $this->source->delete_action( $source_action_id );
60
- } catch ( \Exception $e ) {
61
- // nothing to do, it didn't exist in the first place
62
- }
63
- do_action( 'action_scheduler/no_action_to_migrate', $source_action_id, $this->source, $this->destination );
64
-
65
- return 0;
66
- }
67
-
68
- try {
69
-
70
- // Make sure the last attempt date is set correctly for completed and failed actions
71
- $last_attempt_date = ( $status !== \ActionScheduler_Store::STATUS_PENDING ) ? $this->source->get_date( $source_action_id ) : null;
72
-
73
- $destination_action_id = $this->destination->save_action( $action, null, $last_attempt_date );
74
- } catch ( \Exception $e ) {
75
- do_action( 'action_scheduler/migrate_action_failed', $source_action_id, $this->source, $this->destination );
76
-
77
- return 0; // could not save the action in the new store
78
- }
79
-
80
- try {
81
- switch ( $status ) {
82
- case \ActionScheduler_Store::STATUS_FAILED :
83
- $this->destination->mark_failure( $destination_action_id );
84
- break;
85
- case \ActionScheduler_Store::STATUS_CANCELED :
86
- $this->destination->cancel_action( $destination_action_id );
87
- break;
88
- }
89
-
90
- $this->log_migrator->migrate( $source_action_id, $destination_action_id );
91
- $this->source->delete_action( $source_action_id );
92
-
93
- $test_action = $this->source->fetch_action( $source_action_id );
94
- if ( ! is_a( $test_action, 'ActionScheduler_NullAction' ) ) {
95
- throw new \RuntimeException( sprintf( __( 'Unable to remove source migrated action %s', 'action-scheduler' ), $source_action_id ) );
96
- }
97
- do_action( 'action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination );
98
-
99
- return $destination_action_id;
100
- } catch ( \Exception $e ) {
101
- // could not delete from the old store
102
- $this->source->mark_migrated( $source_action_id );
103
- do_action( 'action_scheduler/migrate_action_incomplete', $source_action_id, $destination_action_id, $this->source, $this->destination );
104
- do_action( 'action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination );
105
-
106
- return $destination_action_id;
107
- }
108
- }
109
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/migration/ActionScheduler_DBStoreMigrator.php DELETED
@@ -1,47 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_DBStoreMigrator
5
- *
6
- * A class for direct saving of actions to the table data store during migration.
7
- *
8
- * @since 3.0.0
9
- */
10
- class ActionScheduler_DBStoreMigrator extends ActionScheduler_DBStore {
11
-
12
- /**
13
- * Save an action with optional last attempt date.
14
- *
15
- * Normally, saving an action sets its attempted date to 0000-00-00 00:00:00 because when an action is first saved,
16
- * it can't have been attempted yet, but migrated completed actions will have an attempted date, so we need to save
17
- * that when first saving the action.
18
- *
19
- * @param ActionScheduler_Action $action
20
- * @param \DateTime $scheduled_date Optional date of the first instance to store.
21
- * @param \DateTime $last_attempt_date Optional date the action was last attempted.
22
- *
23
- * @return string The action ID
24
- * @throws \RuntimeException When the action is not saved.
25
- */
26
- public function save_action( ActionScheduler_Action $action, \DateTime $scheduled_date = null, \DateTime $last_attempt_date = null ){
27
- try {
28
- /** @var \wpdb $wpdb */
29
- global $wpdb;
30
-
31
- $action_id = parent::save_action( $action, $scheduled_date );
32
-
33
- if ( null !== $last_attempt_date ) {
34
- $data = [
35
- 'last_attempt_gmt' => $this->get_scheduled_date_string( $action, $last_attempt_date ),
36
- 'last_attempt_local' => $this->get_scheduled_date_string_local( $action, $last_attempt_date ),
37
- ];
38
-
39
- $wpdb->update( $wpdb->actionscheduler_actions, $data, array( 'action_id' => $action_id ), array( '%s', '%s' ), array( '%d' ) );
40
- }
41
-
42
- return $action_id;
43
- } catch ( \Exception $e ) {
44
- throw new \RuntimeException( sprintf( __( 'Error saving action: %s', 'action-scheduler' ), $e->getMessage() ), 0 );
45
- }
46
- }
47
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/migration/BatchFetcher.php DELETED
@@ -1,86 +0,0 @@
1
- <?php
2
-
3
-
4
- namespace Action_Scheduler\Migration;
5
-
6
-
7
- use ActionScheduler_Store as Store;
8
-
9
- /**
10
- * Class BatchFetcher
11
- *
12
- * @package Action_Scheduler\Migration
13
- *
14
- * @since 3.0.0
15
- *
16
- * @codeCoverageIgnore
17
- */
18
- class BatchFetcher {
19
- /** var ActionScheduler_Store */
20
- private $store;
21
-
22
- /**
23
- * BatchFetcher constructor.
24
- *
25
- * @param ActionScheduler_Store $source_store Source store object.
26
- */
27
- public function __construct( Store $source_store ) {
28
- $this->store = $source_store;
29
- }
30
-
31
- /**
32
- * Retrieve a list of actions.
33
- *
34
- * @param int $count The number of actions to retrieve
35
- *
36
- * @return int[] A list of action IDs
37
- */
38
- public function fetch( $count = 10 ) {
39
- foreach ( $this->get_query_strategies( $count ) as $query ) {
40
- $action_ids = $this->store->query_actions( $query );
41
- if ( ! empty( $action_ids ) ) {
42
- return $action_ids;
43
- }
44
- }
45
-
46
- return [];
47
- }
48
-
49
- /**
50
- * Generate a list of prioritized of action search parameters.
51
- *
52
- * @param int $count Number of actions to find.
53
- *
54
- * @return array
55
- */
56
- private function get_query_strategies( $count ) {
57
- $now = as_get_datetime_object();
58
- $args = [
59
- 'date' => $now,
60
- 'per_page' => $count,
61
- 'offset' => 0,
62
- 'orderby' => 'date',
63
- 'order' => 'ASC',
64
- ];
65
-
66
- $priorities = [
67
- Store::STATUS_PENDING,
68
- Store::STATUS_FAILED,
69
- Store::STATUS_CANCELED,
70
- Store::STATUS_COMPLETE,
71
- Store::STATUS_RUNNING,
72
- '', // any other unanticipated status
73
- ];
74
-
75
- foreach ( $priorities as $status ) {
76
- yield wp_parse_args( [
77
- 'status' => $status,
78
- 'date_compare' => '<=',
79
- ], $args );
80
- yield wp_parse_args( [
81
- 'status' => $status,
82
- 'date_compare' => '>=',
83
- ], $args );
84
- }
85
- }
86
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/migration/Config.php DELETED
@@ -1,168 +0,0 @@
1
- <?php
2
-
3
-
4
- namespace Action_Scheduler\Migration;
5
-
6
- use Action_Scheduler\WP_CLI\ProgressBar;
7
- use ActionScheduler_Logger as Logger;
8
- use ActionScheduler_Store as Store;
9
-
10
- /**
11
- * Class Config
12
- *
13
- * @package Action_Scheduler\Migration
14
- *
15
- * @since 3.0.0
16
- *
17
- * A config builder for the ActionScheduler\Migration\Runner class
18
- */
19
- class Config {
20
- /** @var ActionScheduler_Store */
21
- private $source_store;
22
-
23
- /** @var ActionScheduler_Logger */
24
- private $source_logger;
25
-
26
- /** @var ActionScheduler_Store */
27
- private $destination_store;
28
-
29
- /** @var ActionScheduler_Logger */
30
- private $destination_logger;
31
-
32
- /** @var Progress bar */
33
- private $progress_bar;
34
-
35
- /** @var bool */
36
- private $dry_run = false;
37
-
38
- /**
39
- * Config constructor.
40
- */
41
- public function __construct() {
42
-
43
- }
44
-
45
- /**
46
- * Get the configured source store.
47
- *
48
- * @return ActionScheduler_Store
49
- */
50
- public function get_source_store() {
51
- if ( empty( $this->source_store ) ) {
52
- throw new \RuntimeException( __( 'Source store must be configured before running a migration', 'action-scheduler' ) );
53
- }
54
-
55
- return $this->source_store;
56
- }
57
-
58
- /**
59
- * Set the configured source store.
60
- *
61
- * @param ActionScheduler_Store $store Source store object.
62
- */
63
- public function set_source_store( Store $store ) {
64
- $this->source_store = $store;
65
- }
66
-
67
- /**
68
- * Get the configured source loger.
69
- *
70
- * @return ActionScheduler_Logger
71
- */
72
- public function get_source_logger() {
73
- if ( empty( $this->source_logger ) ) {
74
- throw new \RuntimeException( __( 'Source logger must be configured before running a migration', 'action-scheduler' ) );
75
- }
76
-
77
- return $this->source_logger;
78
- }
79
-
80
- /**
81
- * Set the configured source logger.
82
- *
83
- * @param ActionScheduler_Logger $logger
84
- */
85
- public function set_source_logger( Logger $logger ) {
86
- $this->source_logger = $logger;
87
- }
88
-
89
- /**
90
- * Get the configured destination store.
91
- *
92
- * @return ActionScheduler_Store
93
- */
94
- public function get_destination_store() {
95
- if ( empty( $this->destination_store ) ) {
96
- throw new \RuntimeException( __( 'Destination store must be configured before running a migration', 'action-scheduler' ) );
97
- }
98
-
99
- return $this->destination_store;
100
- }
101
-
102
- /**
103
- * Set the configured destination store.
104
- *
105
- * @param ActionScheduler_Store $store
106
- */
107
- public function set_destination_store( Store $store ) {
108
- $this->destination_store = $store;
109
- }
110
-
111
- /**
112
- * Get the configured destination logger.
113
- *
114
- * @return ActionScheduler_Logger
115
- */
116
- public function get_destination_logger() {
117
- if ( empty( $this->destination_logger ) ) {
118
- throw new \RuntimeException( __( 'Destination logger must be configured before running a migration', 'action-scheduler' ) );
119
- }
120
-
121
- return $this->destination_logger;
122
- }
123
-
124
- /**
125
- * Set the configured destination logger.
126
- *
127
- * @param ActionScheduler_Logger $logger
128
- */
129
- public function set_destination_logger( Logger $logger ) {
130
- $this->destination_logger = $logger;
131
- }
132
-
133
- /**
134
- * Get flag indicating whether it's a dry run.
135
- *
136
- * @return bool
137
- */
138
- public function get_dry_run() {
139
- return $this->dry_run;
140
- }
141
-
142
- /**
143
- * Set flag indicating whether it's a dry run.
144
- *
145
- * @param bool $dry_run
146
- */
147
- public function set_dry_run( $dry_run ) {
148
- $this->dry_run = (bool) $dry_run;
149
- }
150
-
151
- /**
152
- * Get progress bar object.
153
- *
154
- * @return ActionScheduler\WPCLI\ProgressBar
155
- */
156
- public function get_progress_bar() {
157
- return $this->progress_bar;
158
- }
159
-
160
- /**
161
- * Set progress bar object.
162
- *
163
- * @param ActionScheduler\WPCLI\ProgressBar $progress_bar
164
- */
165
- public function set_progress_bar( ProgressBar $progress_bar ) {
166
- $this->progress_bar = $progress_bar;
167
- }
168
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/migration/Controller.php DELETED
@@ -1,206 +0,0 @@
1
- <?php
2
-
3
- namespace Action_Scheduler\Migration;
4
-
5
- use Action_Scheduler\WP_CLI\Migration_Command;
6
- use Action_Scheduler\WP_CLI\ProgressBar;
7
-
8
- /**
9
- * Class Controller
10
- *
11
- * The main plugin/initialization class for migration to custom tables.
12
- *
13
- * @package Action_Scheduler\Migration
14
- *
15
- * @since 3.0.0
16
- *
17
- * @codeCoverageIgnore
18
- */
19
- class Controller {
20
- private static $instance;
21
-
22
- /** @var Action_Scheduler\Migration\Scheduler */
23
- private $migration_scheduler;
24
-
25
- /** @var string */
26
- private $store_classname;
27
-
28
- /** @var string */
29
- private $logger_classname;
30
-
31
- /** @var bool */
32
- private $migrate_custom_store;
33
-
34
- /**
35
- * Controller constructor.
36
- *
37
- * @param Scheduler $migration_scheduler Migration scheduler object.
38
- */
39
- protected function __construct( Scheduler $migration_scheduler ) {
40
- $this->migration_scheduler = $migration_scheduler;
41
- $this->store_classname = '';
42
- }
43
-
44
- /**
45
- * Set the action store class name.
46
- *
47
- * @param string $class Classname of the store class.
48
- *
49
- * @return string
50
- */
51
- public function get_store_class( $class ) {
52
- if ( \ActionScheduler_DataController::is_migration_complete() ) {
53
- return \ActionScheduler_DataController::DATASTORE_CLASS;
54
- } elseif ( \ActionScheduler_Store::DEFAULT_CLASS !== $class ) {
55
- $this->store_classname = $class;
56
- return $class;
57
- } else {
58
- return 'ActionScheduler_HybridStore';
59
- }
60
- }
61
-
62
- /**
63
- * Set the action logger class name.
64
- *
65
- * @param string $class Classname of the logger class.
66
- *
67
- * @return string
68
- */
69
- public function get_logger_class( $class ) {
70
- \ActionScheduler_Store::instance();
71
-
72
- if ( $this->has_custom_datastore() ) {
73
- $this->logger_classname = $class;
74
- return $class;
75
- } else {
76
- return \ActionScheduler_DataController::LOGGER_CLASS;
77
- }
78
- }
79
-
80
- /**
81
- * Get flag indicating whether a custom datastore is in use.
82
- *
83
- * @return bool
84
- */
85
- public function has_custom_datastore() {
86
- return (bool) $this->store_classname;
87
- }
88
-
89
- /**
90
- * Set up the background migration process
91
- *
92
- * @return void
93
- */
94
- public function schedule_migration() {
95
- if ( \ActionScheduler_DataController::is_migration_complete() || $this->migration_scheduler->is_migration_scheduled() ) {
96
- return;
97
- }
98
-
99
- $this->migration_scheduler->schedule_migration();
100
- }
101
-
102
- /**
103
- * Get the default migration config object
104
- *
105
- * @return ActionScheduler\Migration\Config
106
- */
107
- public function get_migration_config_object() {
108
- static $config = null;
109
-
110
- if ( ! $config ) {
111
- $source_store = $this->store_classname ? new $this->store_classname() : new \ActionScheduler_wpPostStore();
112
- $source_logger = $this->logger_classname ? new $this->logger_classname() : new \ActionScheduler_wpCommentLogger();
113
-
114
- $config = new Config();
115
- $config->set_source_store( $source_store );
116
- $config->set_source_logger( $source_logger );
117
- $config->set_destination_store( new \ActionScheduler_DBStoreMigrator() );
118
- $config->set_destination_logger( new \ActionScheduler_DBLogger() );
119
-
120
- if ( defined( 'WP_CLI' ) && WP_CLI ) {
121
- $config->set_progress_bar( new ProgressBar( '', 0 ) );
122
- }
123
- }
124
-
125
- return apply_filters( 'action_scheduler/migration_config', $config );
126
- }
127
-
128
- /**
129
- * Hook dashboard migration notice.
130
- */
131
- public function hook_admin_notices() {
132
- if ( ! $this->allow_migration() || \ActionScheduler_DataController::is_migration_complete() ) {
133
- return;
134
- }
135
- add_action( 'admin_notices', array( $this, 'display_migration_notice' ), 10, 0 );
136
- }
137
-
138
- /**
139
- * Show a dashboard notice that migration is in progress.
140
- */
141
- public function display_migration_notice() {
142
- printf( '<div class="notice notice-warning"><p>%s</p></div>', __( 'Action Scheduler migration in progress. The list of scheduled actions may be incomplete.', 'action-scheduler' ) );
143
- }
144
-
145
- /**
146
- * Add store classes. Hook migration.
147
- */
148
- private function hook() {
149
- add_filter( 'action_scheduler_store_class', array( $this, 'get_store_class' ), 100, 1 );
150
- add_filter( 'action_scheduler_logger_class', array( $this, 'get_logger_class' ), 100, 1 );
151
- add_action( 'init', array( $this, 'maybe_hook_migration' ) );
152
- add_action( 'shutdown', array( $this, 'schedule_migration' ), 0, 0 );
153
-
154
- // Action Scheduler may be displayed as a Tools screen or WooCommerce > Status administration screen
155
- add_action( 'load-tools_page_action-scheduler', array( $this, 'hook_admin_notices' ), 10, 0 );
156
- add_action( 'load-woocommerce_page_wc-status', array( $this, 'hook_admin_notices' ), 10, 0 );
157
- }
158
-
159
- /**
160
- * Possibly hook the migration scheduler action.
161
- *
162
- * @author Jeremy Pry
163
- */
164
- public function maybe_hook_migration() {
165
- if ( ! $this->allow_migration() || \ActionScheduler_DataController::is_migration_complete() ) {
166
- return;
167
- }
168
-
169
- $this->migration_scheduler->hook();
170
- }
171
-
172
- /**
173
- * Allow datastores to enable migration to AS tables.
174
- */
175
- public function allow_migration() {
176
- if ( ! \ActionScheduler_DataController::dependencies_met() ) {
177
- return false;
178
- }
179
-
180
- if ( null === $this->migrate_custom_store ) {
181
- $this->migrate_custom_store = apply_filters( 'action_scheduler_migrate_data_store', false );
182
- }
183
-
184
- return ( ! $this->has_custom_datastore() ) || $this->migrate_custom_store;
185
- }
186
-
187
- /**
188
- * Proceed with the migration if the dependencies have been met.
189
- */
190
- public static function init() {
191
- if ( \ActionScheduler_DataController::dependencies_met() ) {
192
- self::instance()->hook();
193
- }
194
- }
195
-
196
- /**
197
- * Singleton factory.
198
- */
199
- public static function instance() {
200
- if ( ! isset( self::$instance ) ) {
201
- self::$instance = new static( new Scheduler() );
202
- }
203
-
204
- return self::$instance;
205
- }
206
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/migration/DryRun_ActionMigrator.php DELETED
@@ -1,28 +0,0 @@
1
- <?php
2
-
3
-
4
- namespace Action_Scheduler\Migration;
5
-
6
- /**
7
- * Class DryRun_ActionMigrator
8
- *
9
- * @package Action_Scheduler\Migration
10
- *
11
- * @since 3.0.0
12
- *
13
- * @codeCoverageIgnore
14
- */
15
- class DryRun_ActionMigrator extends ActionMigrator {
16
- /**
17
- * Simulate migrating an action.
18
- *
19
- * @param int $source_action_id Action ID.
20
- *
21
- * @return int
22
- */
23
- public function migrate( $source_action_id ) {
24
- do_action( 'action_scheduler/migrate_action_dry_run', $source_action_id );
25
-
26
- return 0;
27
- }
28
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/migration/DryRun_LogMigrator.php DELETED
@@ -1,23 +0,0 @@
1
- <?php
2
-
3
-
4
- namespace Action_Scheduler\Migration;
5
-
6
- /**
7
- * Class DryRun_LogMigrator
8
- *
9
- * @package Action_Scheduler\Migration
10
- *
11
- * @codeCoverageIgnore
12
- */
13
- class DryRun_LogMigrator extends LogMigrator {
14
- /**
15
- * Simulate migrating an action log.
16
- *
17
- * @param int $source_action_id Source logger object.
18
- * @param int $destination_action_id Destination logger object.
19
- */
20
- public function migrate( $source_action_id, $destination_action_id ) {
21
- // no-op
22
- }
23
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/migration/LogMigrator.php DELETED
@@ -1,49 +0,0 @@
1
- <?php
2
-
3
-
4
- namespace Action_Scheduler\Migration;
5
-
6
- use ActionScheduler_Logger;
7
-
8
- /**
9
- * Class LogMigrator
10
- *
11
- * @package Action_Scheduler\Migration
12
- *
13
- * @since 3.0.0
14
- *
15
- * @codeCoverageIgnore
16
- */
17
- class LogMigrator {
18
- /** @var ActionScheduler_Logger */
19
- private $source;
20
-
21
- /** @var ActionScheduler_Logger */
22
- private $destination;
23
-
24
- /**
25
- * ActionMigrator constructor.
26
- *
27
- * @param ActionScheduler_Logger $source_logger Source logger object.
28
- * @param ActionScheduler_Logger $destination_Logger Destination logger object.
29
- */
30
- public function __construct( ActionScheduler_Logger $source_logger, ActionScheduler_Logger $destination_Logger ) {
31
- $this->source = $source_logger;
32
- $this->destination = $destination_Logger;
33
- }
34
-
35
- /**
36
- * Migrate an action log.
37
- *
38
- * @param int $source_action_id Source logger object.
39
- * @param int $destination_action_id Destination logger object.
40
- */
41
- public function migrate( $source_action_id, $destination_action_id ) {
42
- $logs = $this->source->get_logs( $source_action_id );
43
- foreach ( $logs as $log ) {
44
- if ( $log->get_action_id() == $source_action_id ) {
45
- $this->destination->log( $destination_action_id, $log->get_message(), $log->get_date() );
46
- }
47
- }
48
- }
49
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/migration/Runner.php DELETED
@@ -1,136 +0,0 @@
1
- <?php
2
-
3
-
4
- namespace Action_Scheduler\Migration;
5
-
6
- /**
7
- * Class Runner
8
- *
9
- * @package Action_Scheduler\Migration
10
- *
11
- * @since 3.0.0
12
- *
13
- * @codeCoverageIgnore
14
- */
15
- class Runner {
16
- /** @var ActionScheduler_Store */
17
- private $source_store;
18
-
19
- /** @var ActionScheduler_Store */
20
- private $destination_store;
21
-
22
- /** @var ActionScheduler_Logger */
23
- private $source_logger;
24
-
25
- /** @var ActionScheduler_Logger */
26
- private $destination_logger;
27
-
28
- /** @var BatchFetcher */
29
- private $batch_fetcher;
30
-
31
- /** @var ActionMigrator */
32
- private $action_migrator;
33
-
34
- /** @var LogMigrator */
35
- private $log_migrator;
36
-
37
- /** @var ProgressBar */
38
- private $progress_bar;
39
-
40
- /**
41
- * Runner constructor.
42
- *
43
- * @param Config $config Migration configuration object.
44
- */
45
- public function __construct( Config $config ) {
46
- $this->source_store = $config->get_source_store();
47
- $this->destination_store = $config->get_destination_store();
48
- $this->source_logger = $config->get_source_logger();
49
- $this->destination_logger = $config->get_destination_logger();
50
-
51
- $this->batch_fetcher = new BatchFetcher( $this->source_store );
52
- if ( $config->get_dry_run() ) {
53
- $this->log_migrator = new DryRun_LogMigrator( $this->source_logger, $this->destination_logger );
54
- $this->action_migrator = new DryRun_ActionMigrator( $this->source_store, $this->destination_store, $this->log_migrator );
55
- } else {
56
- $this->log_migrator = new LogMigrator( $this->source_logger, $this->destination_logger );
57
- $this->action_migrator = new ActionMigrator( $this->source_store, $this->destination_store, $this->log_migrator );
58
- }
59
-
60
- if ( defined( 'WP_CLI' ) && WP_CLI ) {
61
- $this->progress_bar = $config->get_progress_bar();
62
- }
63
- }
64
-
65
- /**
66
- * Run migration batch.
67
- *
68
- * @param int $batch_size Optional batch size. Default 10.
69
- *
70
- * @return int Size of batch processed.
71
- */
72
- public function run( $batch_size = 10 ) {
73
- $batch = $this->batch_fetcher->fetch( $batch_size );
74
- $batch_size = count( $batch );
75
-
76
- if ( ! $batch_size ) {
77
- return 0;
78
- }
79
-
80
- if ( $this->progress_bar ) {
81
- /* translators: %d: amount of actions */
82
- $this->progress_bar->set_message( sprintf( _n( 'Migrating %d action', 'Migrating %d actions', $batch_size, 'action-scheduler' ), number_format_i18n( $batch_size ) ) );
83
- $this->progress_bar->set_count( $batch_size );
84
- }
85
-
86
- $this->migrate_actions( $batch );
87
-
88
- return $batch_size;
89
- }
90
-
91
- /**
92
- * Migration a batch of actions.
93
- *
94
- * @param array $action_ids List of action IDs to migrate.
95
- */
96
- public function migrate_actions( array $action_ids ) {
97
- do_action( 'action_scheduler/migration_batch_starting', $action_ids );
98
-
99
- \ActionScheduler::logger()->unhook_stored_action();
100
- $this->destination_logger->unhook_stored_action();
101
-
102
- foreach ( $action_ids as $source_action_id ) {
103
- $destination_action_id = $this->action_migrator->migrate( $source_action_id );
104
- if ( $destination_action_id ) {
105
- $this->destination_logger->log( $destination_action_id, sprintf(
106
- /* translators: 1: source action ID 2: source store class 3: destination action ID 4: destination store class */
107
- __( 'Migrated action with ID %1$d in %2$s to ID %3$d in %4$s', 'action-scheduler' ),
108
- $source_action_id,
109
- get_class( $this->source_store ),
110
- $destination_action_id,
111
- get_class( $this->destination_store )
112
- ) );
113
- }
114
-
115
- if ( $this->progress_bar ) {
116
- $this->progress_bar->tick();
117
- }
118
- }
119
-
120
- if ( $this->progress_bar ) {
121
- $this->progress_bar->finish();
122
- }
123
-
124
- \ActionScheduler::logger()->hook_stored_action();
125
-
126
- do_action( 'action_scheduler/migration_batch_complete', $action_ids );
127
- }
128
-
129
- /**
130
- * Initialize destination store and logger.
131
- */
132
- public function init_destination() {
133
- $this->destination_store->init();
134
- $this->destination_logger->init();
135
- }
136
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/migration/Scheduler.php DELETED
@@ -1,128 +0,0 @@
1
- <?php
2
-
3
-
4
- namespace Action_Scheduler\Migration;
5
-
6
- /**
7
- * Class Scheduler
8
- *
9
- * @package Action_Scheduler\WP_CLI
10
- *
11
- * @since 3.0.0
12
- *
13
- * @codeCoverageIgnore
14
- */
15
- class Scheduler {
16
- /** Migration action hook. */
17
- const HOOK = 'action_scheduler/migration_hook';
18
-
19
- /** Migration action group. */
20
- const GROUP = 'action-scheduler-migration';
21
-
22
- /**
23
- * Set up the callback for the scheduled job.
24
- */
25
- public function hook() {
26
- add_action( self::HOOK, array( $this, 'run_migration' ), 10, 0 );
27
- }
28
-
29
- /**
30
- * Remove the callback for the scheduled job.
31
- */
32
- public function unhook() {
33
- remove_action( self::HOOK, array( $this, 'run_migration' ), 10 );
34
- }
35
-
36
- /**
37
- * The migration callback.
38
- */
39
- public function run_migration() {
40
- $migration_runner = $this->get_migration_runner();
41
- $count = $migration_runner->run( $this->get_batch_size() );
42
-
43
- if ( $count === 0 ) {
44
- $this->mark_complete();
45
- } else {
46
- $this->schedule_migration( time() + $this->get_schedule_interval() );
47
- }
48
- }
49
-
50
- /**
51
- * Mark the migration complete.
52
- */
53
- public function mark_complete() {
54
- $this->unschedule_migration();
55
-
56
- \ActionScheduler_DataController::mark_migration_complete();
57
- do_action( 'action_scheduler/migration_complete' );
58
- }
59
-
60
- /**
61
- * Get a flag indicating whether the migration is scheduled.
62
- *
63
- * @return bool Whether there is a pending action in the store to handle the migration
64
- */
65
- public function is_migration_scheduled() {
66
- $next = as_next_scheduled_action( self::HOOK );
67
-
68
- return ! empty( $next );
69
- }
70
-
71
- /**
72
- * Schedule the migration.
73
- *
74
- * @param int $when Optional timestamp to run the next migration batch. Defaults to now.
75
- *
76
- * @return string The action ID
77
- */
78
- public function schedule_migration( $when = 0 ) {
79
- $next = as_next_scheduled_action( self::HOOK );
80
-
81
- if ( ! empty( $next ) ) {
82
- return $next;
83
- }
84
-
85
- if ( empty( $when ) ) {
86
- $when = time();
87
- }
88
-
89
- return as_schedule_single_action( $when, self::HOOK, array(), self::GROUP );
90
- }
91
-
92
- /**
93
- * Remove the scheduled migration action.
94
- */
95
- public function unschedule_migration() {
96
- as_unschedule_action( self::HOOK, null, self::GROUP );
97
- }
98
-
99
- /**
100
- * Get migration batch schedule interval.
101
- *
102
- * @return int Seconds between migration runs. Defaults to 0 seconds to allow chaining migration via Async Runners.
103
- */
104
- private function get_schedule_interval() {
105
- return (int) apply_filters( 'action_scheduler/migration_interval', 0 );
106
- }
107
-
108
- /**
109
- * Get migration batch size.
110
- *
111
- * @return int Number of actions to migrate in each batch. Defaults to 250.
112
- */
113
- private function get_batch_size() {
114
- return (int) apply_filters( 'action_scheduler/migration_batch_size', 250 );
115
- }
116
-
117
- /**
118
- * Get migration runner object.
119
- *
120
- * @return Runner
121
- */
122
- private function get_migration_runner() {
123
- $config = Controller::instance()->get_migration_config_object();
124
-
125
- return new Runner( $config );
126
- }
127
-
128
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/schedules/ActionScheduler_CanceledSchedule.php DELETED
@@ -1,57 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_SimpleSchedule
5
- */
6
- class ActionScheduler_CanceledSchedule extends ActionScheduler_SimpleSchedule {
7
-
8
- /**
9
- * Deprecated property @see $this->__wakeup() for details.
10
- **/
11
- private $timestamp = NULL;
12
-
13
- /**
14
- * @param DateTime $after
15
- *
16
- * @return DateTime|null
17
- */
18
- public function calculate_next( DateTime $after ) {
19
- return null;
20
- }
21
-
22
- /**
23
- * Cancelled actions should never have a next schedule, even if get_next()
24
- * is called with $after < $this->scheduled_date.
25
- *
26
- * @param DateTime $after
27
- * @return DateTime|null
28
- */
29
- public function get_next( DateTime $after ) {
30
- return null;
31
- }
32
-
33
- /**
34
- * @return bool
35
- */
36
- public function is_recurring() {
37
- return false;
38
- }
39
-
40
- /**
41
- * Unserialize recurring schedules serialized/stored prior to AS 3.0.0
42
- *
43
- * Prior to Action Scheduler 3.0.0, schedules used different property names to refer
44
- * to equivalent data. For example, ActionScheduler_IntervalSchedule::start_timestamp
45
- * was the same as ActionScheduler_SimpleSchedule::timestamp. Action Scheduler 3.0.0
46
- * aligned properties and property names for better inheritance. To maintain backward
47
- * compatibility with schedules serialized and stored prior to 3.0, we need to correctly
48
- * map the old property names with matching visibility.
49
- */
50
- public function __wakeup() {
51
- if ( ! is_null( $this->timestamp ) ) {
52
- $this->scheduled_timestamp = $this->timestamp;
53
- unset( $this->timestamp );
54
- }
55
- parent::__wakeup();
56
- }
57
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/schedules/ActionScheduler_CronSchedule.php DELETED
@@ -1,102 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_CronSchedule
5
- */
6
- class ActionScheduler_CronSchedule extends ActionScheduler_Abstract_RecurringSchedule implements ActionScheduler_Schedule {
7
-
8
- /**
9
- * Deprecated property @see $this->__wakeup() for details.
10
- **/
11
- private $start_timestamp = NULL;
12
-
13
- /**
14
- * Deprecated property @see $this->__wakeup() for details.
15
- **/
16
- private $cron = NULL;
17
-
18
- /**
19
- * Wrapper for parent constructor to accept a cron expression string and map it to a CronExpression for this
20
- * objects $recurrence property.
21
- *
22
- * @param DateTime $start The date & time to run the action at or after. If $start aligns with the CronSchedule passed via $recurrence, it will be used. If it does not align, the first matching date after it will be used.
23
- * @param CronExpression|string $recurrence The CronExpression used to calculate the schedule's next instance.
24
- * @param DateTime|null $first (Optional) The date & time the first instance of this interval schedule ran. Default null, meaning this is the first instance.
25
- */
26
- public function __construct( DateTime $start, $recurrence, DateTime $first = null ) {
27
- if ( ! is_a( $recurrence, 'CronExpression' ) ) {
28
- $recurrence = CronExpression::factory( $recurrence );
29
- }
30
-
31
- // For backward compatibility, we need to make sure the date is set to the first matching cron date, not whatever date is passed in. Importantly, by passing true as the 3rd param, if $start matches the cron expression, then it will be used. This was previously handled in the now deprecated next() method.
32
- $date = $recurrence->getNextRunDate( $start, 0, true );
33
-
34
- // parent::__construct() will set this to $date by default, but that may be different to $start now.
35
- $first = empty( $first ) ? $start : $first;
36
-
37
- parent::__construct( $date, $recurrence, $first );
38
- }
39
-
40
- /**
41
- * Calculate when an instance of this schedule would start based on a given
42
- * date & time using its the CronExpression.
43
- *
44
- * @param DateTime $after
45
- * @return DateTime
46
- */
47
- protected function calculate_next( DateTime $after ) {
48
- return $this->recurrence->getNextRunDate( $after, 0, false );
49
- }
50
-
51
- /**
52
- * @return string
53
- */
54
- public function get_recurrence() {
55
- return strval( $this->recurrence );
56
- }
57
-
58
- /**
59
- * Serialize cron schedules with data required prior to AS 3.0.0
60
- *
61
- * Prior to Action Scheduler 3.0.0, reccuring schedules used different property names to
62
- * refer to equivalent data. For example, ActionScheduler_IntervalSchedule::start_timestamp
63
- * was the same as ActionScheduler_SimpleSchedule::timestamp. Action Scheduler 3.0.0
64
- * aligned properties and property names for better inheritance. To guard against the
65
- * possibility of infinite loops if downgrading to Action Scheduler < 3.0.0, we need to
66
- * also store the data with the old property names so if it's unserialized in AS < 3.0,
67
- * the schedule doesn't end up with a null recurrence.
68
- *
69
- * @return array
70
- */
71
- public function __sleep() {
72
-
73
- $sleep_params = parent::__sleep();
74
-
75
- $this->start_timestamp = $this->scheduled_timestamp;
76
- $this->cron = $this->recurrence;
77
-
78
- return array_merge( $sleep_params, array(
79
- 'start_timestamp',
80
- 'cron'
81
- ) );
82
- }
83
-
84
- /**
85
- * Unserialize cron schedules serialized/stored prior to AS 3.0.0
86
- *
87
- * For more background, @see ActionScheduler_Abstract_RecurringSchedule::__wakeup().
88
- */
89
- public function __wakeup() {
90
- if ( is_null( $this->scheduled_timestamp ) && ! is_null( $this->start_timestamp ) ) {
91
- $this->scheduled_timestamp = $this->start_timestamp;
92
- unset( $this->start_timestamp );
93
- }
94
-
95
- if ( is_null( $this->recurrence ) && ! is_null( $this->cron ) ) {
96
- $this->recurrence = $this->cron;
97
- unset( $this->cron );
98
- }
99
- parent::__wakeup();
100
- }
101
- }
102
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/schedules/ActionScheduler_IntervalSchedule.php DELETED
@@ -1,81 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_IntervalSchedule
5
- */
6
- class ActionScheduler_IntervalSchedule extends ActionScheduler_Abstract_RecurringSchedule implements ActionScheduler_Schedule {
7
-
8
- /**
9
- * Deprecated property @see $this->__wakeup() for details.
10
- **/
11
- private $start_timestamp = NULL;
12
-
13
- /**
14
- * Deprecated property @see $this->__wakeup() for details.
15
- **/
16
- private $interval_in_seconds = NULL;
17
-
18
- /**
19
- * Calculate when this schedule should start after a given date & time using
20
- * the number of seconds between recurrences.
21
- *
22
- * @param DateTime $after
23
- * @return DateTime
24
- */
25
- protected function calculate_next( DateTime $after ) {
26
- $after->modify( '+' . (int) $this->get_recurrence() . ' seconds' );
27
- return $after;
28
- }
29
-
30
- /**
31
- * @return int
32
- */
33
- public function interval_in_seconds() {
34
- _deprecated_function( __METHOD__, '3.0.0', '(int)ActionScheduler_Abstract_RecurringSchedule::get_recurrence()' );
35
- return (int) $this->get_recurrence();
36
- }
37
-
38
- /**
39
- * Serialize interval schedules with data required prior to AS 3.0.0
40
- *
41
- * Prior to Action Scheduler 3.0.0, reccuring schedules used different property names to
42
- * refer to equivalent data. For example, ActionScheduler_IntervalSchedule::start_timestamp
43
- * was the same as ActionScheduler_SimpleSchedule::timestamp. Action Scheduler 3.0.0
44
- * aligned properties and property names for better inheritance. To guard against the
45
- * possibility of infinite loops if downgrading to Action Scheduler < 3.0.0, we need to
46
- * also store the data with the old property names so if it's unserialized in AS < 3.0,
47
- * the schedule doesn't end up with a null/false/0 recurrence.
48
- *
49
- * @return array
50
- */
51
- public function __sleep() {
52
-
53
- $sleep_params = parent::__sleep();
54
-
55
- $this->start_timestamp = $this->scheduled_timestamp;
56
- $this->interval_in_seconds = $this->recurrence;
57
-
58
- return array_merge( $sleep_params, array(
59
- 'start_timestamp',
60
- 'interval_in_seconds'
61
- ) );
62
- }
63
-
64
- /**
65
- * Unserialize interval schedules serialized/stored prior to AS 3.0.0
66
- *
67
- * For more background, @see ActionScheduler_Abstract_RecurringSchedule::__wakeup().
68
- */
69
- public function __wakeup() {
70
- if ( is_null( $this->scheduled_timestamp ) && ! is_null( $this->start_timestamp ) ) {
71
- $this->scheduled_timestamp = $this->start_timestamp;
72
- unset( $this->start_timestamp );
73
- }
74
-
75
- if ( is_null( $this->recurrence ) && ! is_null( $this->interval_in_seconds ) ) {
76
- $this->recurrence = $this->interval_in_seconds;
77
- unset( $this->interval_in_seconds );
78
- }
79
- parent::__wakeup();
80
- }
81
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/schedules/ActionScheduler_NullSchedule.php DELETED
@@ -1,28 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_NullSchedule
5
- */
6
- class ActionScheduler_NullSchedule extends ActionScheduler_SimpleSchedule {
7
-
8
- /**
9
- * Make the $date param optional and default to null.
10
- *
11
- * @param null $date The date & time to run the action.
12
- */
13
- public function __construct( DateTime $date = null ) {
14
- $this->scheduled_date = null;
15
- }
16
-
17
- /**
18
- * This schedule has no scheduled DateTime, so we need to override the parent __sleep()
19
- * @return array
20
- */
21
- public function __sleep() {
22
- return array();
23
- }
24
-
25
- public function __wakeup() {
26
- $this->scheduled_date = null;
27
- }
28
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/schedules/ActionScheduler_Schedule.php DELETED
@@ -1,18 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_Schedule
5
- */
6
- interface ActionScheduler_Schedule {
7
- /**
8
- * @param DateTime $after
9
- * @return DateTime|null
10
- */
11
- public function next( DateTime $after = NULL );
12
-
13
- /**
14
- * @return bool
15
- */
16
- public function is_recurring();
17
- }
18
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/schedules/ActionScheduler_SimpleSchedule.php DELETED
@@ -1,71 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_SimpleSchedule
5
- */
6
- class ActionScheduler_SimpleSchedule extends ActionScheduler_Abstract_Schedule {
7
-
8
- /**
9
- * Deprecated property @see $this->__wakeup() for details.
10
- **/
11
- private $timestamp = NULL;
12
-
13
- /**
14
- * @param DateTime $after
15
- *
16
- * @return DateTime|null
17
- */
18
- public function calculate_next( DateTime $after ) {
19
- return null;
20
- }
21
-
22
- /**
23
- * @return bool
24
- */
25
- public function is_recurring() {
26
- return false;
27
- }
28
-
29
- /**
30
- * Serialize schedule with data required prior to AS 3.0.0
31
- *
32
- * Prior to Action Scheduler 3.0.0, schedules used different property names to refer
33
- * to equivalent data. For example, ActionScheduler_IntervalSchedule::start_timestamp
34
- * was the same as ActionScheduler_SimpleSchedule::timestamp. Action Scheduler 3.0.0
35
- * aligned properties and property names for better inheritance. To guard against the
36
- * scheduled date for single actions always being seen as "now" if downgrading to
37
- * Action Scheduler < 3.0.0, we need to also store the data with the old property names
38
- * so if it's unserialized in AS < 3.0, the schedule doesn't end up with a null recurrence.
39
- *
40
- * @return array
41
- */
42
- public function __sleep() {
43
-
44
- $sleep_params = parent::__sleep();
45
-
46
- $this->timestamp = $this->scheduled_timestamp;
47
-
48
- return array_merge( $sleep_params, array(
49
- 'timestamp',
50
- ) );
51
- }
52
-
53
- /**
54
- * Unserialize recurring schedules serialized/stored prior to AS 3.0.0
55
- *
56
- * Prior to Action Scheduler 3.0.0, schedules used different property names to refer
57
- * to equivalent data. For example, ActionScheduler_IntervalSchedule::start_timestamp
58
- * was the same as ActionScheduler_SimpleSchedule::timestamp. Action Scheduler 3.0.0
59
- * aligned properties and property names for better inheritance. To maintain backward
60
- * compatibility with schedules serialized and stored prior to 3.0, we need to correctly
61
- * map the old property names with matching visibility.
62
- */
63
- public function __wakeup() {
64
-
65
- if ( is_null( $this->scheduled_timestamp ) && ! is_null( $this->timestamp ) ) {
66
- $this->scheduled_timestamp = $this->timestamp;
67
- unset( $this->timestamp );
68
- }
69
- parent::__wakeup();
70
- }
71
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/schema/ActionScheduler_LoggerSchema.php DELETED
@@ -1,48 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_LoggerSchema
5
- *
6
- * @codeCoverageIgnore
7
- *
8
- * Creates a custom table for storing action logs
9
- */
10
- class ActionScheduler_LoggerSchema extends ActionScheduler_Abstract_Schema {
11
- const LOG_TABLE = 'actionscheduler_logs';
12
-
13
- /**
14
- * @var int Increment this value to trigger a schema update.
15
- */
16
- protected $schema_version = 2;
17
-
18
- public function __construct() {
19
- $this->tables = [
20
- self::LOG_TABLE,
21
- ];
22
- }
23
-
24
- protected function get_table_definition( $table ) {
25
- global $wpdb;
26
- $table_name = $wpdb->$table;
27
- $charset_collate = $wpdb->get_charset_collate();
28
- $max_index_length = 191; // @see wp_get_db_schema()
29
- switch ( $table ) {
30
-
31
- case self::LOG_TABLE:
32
-
33
- return "CREATE TABLE {$table_name} (
34
- log_id bigint(20) unsigned NOT NULL auto_increment,
35
- action_id bigint(20) unsigned NOT NULL,
36
- message text NOT NULL,
37
- log_date_gmt datetime NOT NULL default '0000-00-00 00:00:00',
38
- log_date_local datetime NOT NULL default '0000-00-00 00:00:00',
39
- PRIMARY KEY (log_id),
40
- KEY action_id (action_id),
41
- KEY log_date_gmt (log_date_gmt)
42
- ) $charset_collate";
43
-
44
- default:
45
- return '';
46
- }
47
- }
48
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/classes/schema/ActionScheduler_StoreSchema.php DELETED
@@ -1,82 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_StoreSchema
5
- *
6
- * @codeCoverageIgnore
7
- *
8
- * Creates custom tables for storing scheduled actions
9
- */
10
- class ActionScheduler_StoreSchema extends ActionScheduler_Abstract_Schema {
11
- const ACTIONS_TABLE = 'actionscheduler_actions';
12
- const CLAIMS_TABLE = 'actionscheduler_claims';
13
- const GROUPS_TABLE = 'actionscheduler_groups';
14
-
15
- /**
16
- * @var int Increment this value to trigger a schema update.
17
- */
18
- protected $schema_version = 2;
19
-
20
- public function __construct() {
21
- $this->tables = [
22
- self::ACTIONS_TABLE,
23
- self::CLAIMS_TABLE,
24
- self::GROUPS_TABLE,
25
- ];
26
- }
27
-
28
- protected function get_table_definition( $table ) {
29
- global $wpdb;
30
- $table_name = $wpdb->$table;
31
- $charset_collate = $wpdb->get_charset_collate();
32
- $max_index_length = 191; // @see wp_get_db_schema()
33
- switch ( $table ) {
34
-
35
- case self::ACTIONS_TABLE:
36
-
37
- return "CREATE TABLE {$table_name} (
38
- action_id bigint(20) unsigned NOT NULL auto_increment,
39
- hook varchar(191) NOT NULL,
40
- status varchar(20) NOT NULL,
41
- scheduled_date_gmt datetime NOT NULL default '0000-00-00 00:00:00',
42
- scheduled_date_local datetime NOT NULL default '0000-00-00 00:00:00',
43
- args varchar($max_index_length),
44
- schedule longtext,
45
- group_id bigint(20) unsigned NOT NULL default '0',
46
- attempts int(11) NOT NULL default '0',
47
- last_attempt_gmt datetime NOT NULL default '0000-00-00 00:00:00',
48
- last_attempt_local datetime NOT NULL default '0000-00-00 00:00:00',
49
- claim_id bigint(20) unsigned NOT NULL default '0',
50
- PRIMARY KEY (action_id),
51
- KEY hook (hook($max_index_length)),
52
- KEY status (status),
53
- KEY scheduled_date_gmt (scheduled_date_gmt),
54
- KEY args (args($max_index_length)),
55
- KEY group_id (group_id),
56
- KEY last_attempt_gmt (last_attempt_gmt),
57
- KEY claim_id (claim_id)
58
- ) $charset_collate";
59
-
60
- case self::CLAIMS_TABLE:
61
-
62
- return "CREATE TABLE {$table_name} (
63
- claim_id bigint(20) unsigned NOT NULL auto_increment,
64
- date_created_gmt datetime NOT NULL default '0000-00-00 00:00:00',
65
- PRIMARY KEY (claim_id),
66
- KEY date_created_gmt (date_created_gmt)
67
- ) $charset_collate";
68
-
69
- case self::GROUPS_TABLE:
70
-
71
- return "CREATE TABLE {$table_name} (
72
- group_id bigint(20) unsigned NOT NULL auto_increment,
73
- slug varchar(255) NOT NULL,
74
- PRIMARY KEY (group_id),
75
- KEY slug (slug($max_index_length))
76
- ) $charset_collate";
77
-
78
- default:
79
- return '';
80
- }
81
- }
82
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/deprecated/ActionScheduler_Abstract_QueueRunner_Deprecated.php DELETED
@@ -1,27 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Abstract class with common Queue Cleaner functionality.
5
- */
6
- abstract class ActionScheduler_Abstract_QueueRunner_Deprecated {
7
-
8
- /**
9
- * Get the maximum number of seconds a batch can run for.
10
- *
11
- * @deprecated 2.1.1
12
- * @return int The number of seconds.
13
- */
14
- protected function get_maximum_execution_time() {
15
- _deprecated_function( __METHOD__, '2.1.1', 'ActionScheduler_Abstract_QueueRunner::get_time_limit()' );
16
-
17
- $maximum_execution_time = 30;
18
-
19
- // Apply deprecated filter
20
- if ( has_filter( 'action_scheduler_maximum_execution_time' ) ) {
21
- _deprecated_function( 'action_scheduler_maximum_execution_time', '2.1.1', 'action_scheduler_queue_runner_time_limit' );
22
- $maximum_execution_time = apply_filters( 'action_scheduler_maximum_execution_time', $maximum_execution_time );
23
- }
24
-
25
- return absint( $maximum_execution_time );
26
- }
27
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/deprecated/ActionScheduler_AdminView_Deprecated.php DELETED
@@ -1,147 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_AdminView_Deprecated
5
- *
6
- * Store deprecated public functions previously found in the ActionScheduler_AdminView class.
7
- * Keeps them out of the way of the main class.
8
- *
9
- * @codeCoverageIgnore
10
- */
11
- class ActionScheduler_AdminView_Deprecated {
12
-
13
- public function action_scheduler_post_type_args( $args ) {
14
- _deprecated_function( __METHOD__, '2.0.0' );
15
- return $args;
16
- }
17
-
18
- /**
19
- * Customise the post status related views displayed on the Scheduled Actions administration screen.
20
- *
21
- * @param array $views An associative array of views and view labels which can be used to filter the 'scheduled-action' posts displayed on the Scheduled Actions administration screen.
22
- * @return array $views An associative array of views and view labels which can be used to filter the 'scheduled-action' posts displayed on the Scheduled Actions administration screen.
23
- */
24
- public function list_table_views( $views ) {
25
- _deprecated_function( __METHOD__, '2.0.0' );
26
- return $views;
27
- }
28
-
29
- /**
30
- * Do not include the "Edit" action for the Scheduled Actions administration screen.
31
- *
32
- * Hooked to the 'bulk_actions-edit-action-scheduler' filter.
33
- *
34
- * @param array $actions An associative array of actions which can be performed on the 'scheduled-action' post type.
35
- * @return array $actions An associative array of actions which can be performed on the 'scheduled-action' post type.
36
- */
37
- public function bulk_actions( $actions ) {
38
- _deprecated_function( __METHOD__, '2.0.0' );
39
- return $actions;
40
- }
41
-
42
- /**
43
- * Completely customer the columns displayed on the Scheduled Actions administration screen.
44
- *
45
- * Because we can't filter the content of the default title and date columns, we need to recreate our own
46
- * custom columns for displaying those post fields. For the column content, @see self::list_table_column_content().
47
- *
48
- * @param array $columns An associative array of columns that are use for the table on the Scheduled Actions administration screen.
49
- * @return array $columns An associative array of columns that are use for the table on the Scheduled Actions administration screen.
50
- */
51
- public function list_table_columns( $columns ) {
52
- _deprecated_function( __METHOD__, '2.0.0' );
53
- return $columns;
54
- }
55
-
56
- /**
57
- * Make our custom title & date columns use defaulting title & date sorting.
58
- *
59
- * @param array $columns An associative array of columns that can be used to sort the table on the Scheduled Actions administration screen.
60
- * @return array $columns An associative array of columns that can be used to sort the table on the Scheduled Actions administration screen.
61
- */
62
- public static function list_table_sortable_columns( $columns ) {
63
- _deprecated_function( __METHOD__, '2.0.0' );
64
- return $columns;
65
- }
66
-
67
- /**
68
- * Print the content for our custom columns.
69
- *
70
- * @param string $column_name The key for the column for which we should output our content.
71
- * @param int $post_id The ID of the 'scheduled-action' post for which this row relates.
72
- */
73
- public static function list_table_column_content( $column_name, $post_id ) {
74
- _deprecated_function( __METHOD__, '2.0.0' );
75
- }
76
-
77
- /**
78
- * Hide the inline "Edit" action for all 'scheduled-action' posts.
79
- *
80
- * Hooked to the 'post_row_actions' filter.
81
- *
82
- * @param array $actions An associative array of actions which can be performed on the 'scheduled-action' post type.
83
- * @return array $actions An associative array of actions which can be performed on the 'scheduled-action' post type.
84
- */
85
- public static function row_actions( $actions, $post ) {
86
- _deprecated_function( __METHOD__, '2.0.0' );
87
- return $actions;
88
- }
89
-
90
- /**
91
- * Run an action when triggered from the Action Scheduler administration screen.
92
- *
93
- * @codeCoverageIgnore
94
- */
95
- public static function maybe_execute_action() {
96
- _deprecated_function( __METHOD__, '2.0.0' );
97
- }
98
-
99
- /**
100
- * Convert an interval of seconds into a two part human friendly string.
101
- *
102
- * The WordPress human_time_diff() function only calculates the time difference to one degree, meaning
103
- * even if an action is 1 day and 11 hours away, it will display "1 day". This funciton goes one step
104
- * further to display two degrees of accuracy.
105
- *
106
- * Based on Crontrol::interval() function by Edward Dale: https://wordpress.org/plugins/wp-crontrol/
107
- *
108
- * @param int $interval A interval in seconds.
109
- * @return string A human friendly string representation of the interval.
110
- */
111
- public static function admin_notices() {
112
- _deprecated_function( __METHOD__, '2.0.0' );
113
- }
114
-
115
- /**
116
- * Filter search queries to allow searching by Claim ID (i.e. post_password).
117
- *
118
- * @param string $orderby MySQL orderby string.
119
- * @param WP_Query $query Instance of a WP_Query object
120
- * @return string MySQL orderby string.
121
- */
122
- public function custom_orderby( $orderby, $query ){
123
- _deprecated_function( __METHOD__, '2.0.0' );
124
- }
125
-
126
- /**
127
- * Filter search queries to allow searching by Claim ID (i.e. post_password).
128
- *
129
- * @param string $search MySQL search string.
130
- * @param WP_Query $query Instance of a WP_Query object
131
- * @return string MySQL search string.
132
- */
133
- public function search_post_password( $search, $query ) {
134
- _deprecated_function( __METHOD__, '2.0.0' );
135
- }
136
-
137
- /**
138
- * Change messages when a scheduled action is updated.
139
- *
140
- * @param array $messages
141
- * @return array
142
- */
143
- public function post_updated_messages( $messages ) {
144
- _deprecated_function( __METHOD__, '2.0.0' );
145
- return $messages;
146
- }
147
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/deprecated/ActionScheduler_Schedule_Deprecated.php DELETED
@@ -1,29 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_Abstract_Schedule
5
- */
6
- abstract class ActionScheduler_Schedule_Deprecated implements ActionScheduler_Schedule {
7
-
8
- /**
9
- * Get the date & time this schedule was created to run, or calculate when it should be run
10
- * after a given date & time.
11
- *
12
- * @param DateTime $after
13
- *
14
- * @return DateTime|null
15
- */
16
- public function next( DateTime $after = NULL ) {
17
- if ( empty( $after ) ) {
18
- $return_value = $this->get_date();
19
- $replacement_method = 'get_date()';
20
- } else {
21
- $return_value = $this->get_next( $after );
22
- $replacement_method = 'get_next( $after )';
23
- }
24
-
25
- _deprecated_function( __METHOD__, '3.0.0', __CLASS__ . '::' . $replacement_method );
26
-
27
- return $return_value;
28
- }
29
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/deprecated/ActionScheduler_Store_Deprecated.php DELETED
@@ -1,49 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Class ActionScheduler_Store_Deprecated
5
- * @codeCoverageIgnore
6
- */
7
- abstract class ActionScheduler_Store_Deprecated {
8
-
9
- /**
10
- * Mark an action that failed to fetch correctly as failed.
11
- *
12
- * @since 2.2.6
13
- *
14
- * @param int $action_id The ID of the action.
15
- */
16
- public function mark_failed_fetch_action( $action_id ) {
17
- _deprecated_function( __METHOD__, '3.0.0', 'ActionScheduler_Store::mark_failure()' );
18
- self::$store->mark_failure( $action_id );
19
- }
20
-
21
- /**
22
- * Add base hooks
23
- *
24
- * @since 2.2.6
25
- */
26
- protected static function hook() {
27
- _deprecated_function( __METHOD__, '3.0.0' );
28
- }
29
-
30
- /**
31
- * Remove base hooks
32
- *
33
- * @since 2.2.6
34
- */
35
- protected static function unhook() {
36
- _deprecated_function( __METHOD__, '3.0.0' );
37
- }
38
-
39
- /**
40
- * Get the site's local time.
41
- *
42
- * @deprecated 2.1.0
43
- * @return DateTimeZone
44
- */
45
- protected function get_local_timezone() {
46
- _deprecated_function( __FUNCTION__, '2.1.0', 'ActionScheduler_TimezoneHelper::set_local_timezone()' );
47
- return ActionScheduler_TimezoneHelper::get_local_timezone();
48
- }
49
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/deprecated/functions.php DELETED
@@ -1,126 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Deprecated API functions for scheduling actions
5
- *
6
- * Functions with the wc prefix were deprecated to avoid confusion with
7
- * Action Scheduler being included in WooCommerce core, and it providing
8
- * a different set of APIs for working with the action queue.
9
- */
10
-
11
- /**
12
- * Schedule an action to run one time
13
- *
14
- * @param int $timestamp When the job will run
15
- * @param string $hook The hook to trigger
16
- * @param array $args Arguments to pass when the hook triggers
17
- * @param string $group The group to assign this job to
18
- *
19
- * @return string The job ID
20
- */
21
- function wc_schedule_single_action( $timestamp, $hook, $args = array(), $group = '' ) {
22
- _deprecated_function( __FUNCTION__, '2.1.0', 'as_schedule_single_action()' );
23
- return as_schedule_single_action( $timestamp, $hook, $args, $group );
24
- }
25
-
26
- /**
27
- * Schedule a recurring action
28
- *
29
- * @param int $timestamp When the first instance of the job will run
30
- * @param int $interval_in_seconds How long to wait between runs
31
- * @param string $hook The hook to trigger
32
- * @param array $args Arguments to pass when the hook triggers
33
- * @param string $group The group to assign this job to
34
- *
35
- * @deprecated 2.1.0
36
- *
37
- * @return string The job ID
38
- */
39
- function wc_schedule_recurring_action( $timestamp, $interval_in_seconds, $hook, $args = array(), $group = '' ) {
40
- _deprecated_function( __FUNCTION__, '2.1.0', 'as_schedule_recurring_action()' );
41
- return as_schedule_recurring_action( $timestamp, $interval_in_seconds, $hook, $args, $group );
42
- }
43
-
44
- /**
45
- * Schedule an action that recurs on a cron-like schedule.
46
- *
47
- * @param int $timestamp The schedule will start on or after this time
48
- * @param string $schedule A cron-link schedule string
49
- * @see http://en.wikipedia.org/wiki/Cron
50
- * * * * * * *
51
- * ┬ ┬ ┬ ┬ ┬ ┬
52
- * | | | | | |
53
- * | | | | | + year [optional]
54
- * | | | | +----- day of week (0 - 7) (Sunday=0 or 7)
55
- * | | | +---------- month (1 - 12)
56
- * | | +--------------- day of month (1 - 31)
57
- * | +-------------------- hour (0 - 23)
58
- * +------------------------- min (0 - 59)
59
- * @param string $hook The hook to trigger
60
- * @param array $args Arguments to pass when the hook triggers
61
- * @param string $group The group to assign this job to
62
- *
63
- * @deprecated 2.1.0
64
- *
65
- * @return string The job ID
66
- */
67
- function wc_schedule_cron_action( $timestamp, $schedule, $hook, $args = array(), $group = '' ) {
68
- _deprecated_function( __FUNCTION__, '2.1.0', 'as_schedule_cron_action()' );
69
- return as_schedule_cron_action( $timestamp, $schedule, $hook, $args, $group );
70
- }
71
-
72
- /**
73
- * Cancel the next occurrence of a job.
74
- *
75
- * @param string $hook The hook that the job will trigger
76
- * @param array $args Args that would have been passed to the job
77
- * @param string $group
78
- *
79
- * @deprecated 2.1.0
80
- */
81
- function wc_unschedule_action( $hook, $args = array(), $group = '' ) {
82
- _deprecated_function( __FUNCTION__, '2.1.0', 'as_unschedule_action()' );
83
- as_unschedule_action( $hook, $args, $group );
84
- }
85
-
86
- /**
87
- * @param string $hook
88
- * @param array $args
89
- * @param string $group
90
- *
91
- * @deprecated 2.1.0
92
- *
93
- * @return int|bool The timestamp for the next occurrence, or false if nothing was found
94
- */
95
- function wc_next_scheduled_action( $hook, $args = NULL, $group = '' ) {
96
- _deprecated_function( __FUNCTION__, '2.1.0', 'as_next_scheduled_action()' );
97
- return as_next_scheduled_action( $hook, $args, $group );
98
- }
99
-
100
- /**
101
- * Find scheduled actions
102
- *
103
- * @param array $args Possible arguments, with their default values:
104
- * 'hook' => '' - the name of the action that will be triggered
105
- * 'args' => NULL - the args array that will be passed with the action
106
- * 'date' => NULL - the scheduled date of the action. Expects a DateTime object, a unix timestamp, or a string that can parsed with strtotime(). Used in UTC timezone.
107
- * 'date_compare' => '<=' - operator for testing "date". accepted values are '!=', '>', '>=', '<', '<=', '='
108
- * 'modified' => NULL - the date the action was last updated. Expects a DateTime object, a unix timestamp, or a string that can parsed with strtotime(). Used in UTC timezone.
109
- * 'modified_compare' => '<=' - operator for testing "modified". accepted values are '!=', '>', '>=', '<', '<=', '='
110
- * 'group' => '' - the group the action belongs to
111
- * 'status' => '' - ActionScheduler_Store::STATUS_COMPLETE or ActionScheduler_Store::STATUS_PENDING
112
- * 'claimed' => NULL - TRUE to find claimed actions, FALSE to find unclaimed actions, a string to find a specific claim ID
113
- * 'per_page' => 5 - Number of results to return
114
- * 'offset' => 0
115
- * 'orderby' => 'date' - accepted values are 'hook', 'group', 'modified', or 'date'
116
- * 'order' => 'ASC'
117
- * @param string $return_format OBJECT, ARRAY_A, or ids
118
- *
119
- * @deprecated 2.1.0
120
- *
121
- * @return array
122
- */
123
- function wc_get_scheduled_actions( $args = array(), $return_format = OBJECT ) {
124
- _deprecated_function( __FUNCTION__, '2.1.0', 'as_get_scheduled_actions()' );
125
- return as_get_scheduled_actions( $args, $return_format );
126
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/functions.php DELETED
@@ -1,251 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * General API functions for scheduling actions
5
- */
6
-
7
- /**
8
- * Enqueue an action to run one time, as soon as possible
9
- *
10
- * @param string $hook The hook to trigger.
11
- * @param array $args Arguments to pass when the hook triggers.
12
- * @param string $group The group to assign this job to.
13
- * @return string The action ID.
14
- */
15
- function as_enqueue_async_action( $hook, $args = array(), $group = '' ) {
16
- return ActionScheduler::factory()->async( $hook, $args, $group );
17
- }
18
-
19
- /**
20
- * Schedule an action to run one time
21
- *
22
- * @param int $timestamp When the job will run
23
- * @param string $hook The hook to trigger
24
- * @param array $args Arguments to pass when the hook triggers
25
- * @param string $group The group to assign this job to
26
- *
27
- * @return string The job ID
28
- */
29
- function as_schedule_single_action( $timestamp, $hook, $args = array(), $group = '' ) {
30
- return ActionScheduler::factory()->single( $hook, $args, $timestamp, $group );
31
- }
32
-
33
- /**
34
- * Schedule a recurring action
35
- *
36
- * @param int $timestamp When the first instance of the job will run
37
- * @param int $interval_in_seconds How long to wait between runs
38
- * @param string $hook The hook to trigger
39
- * @param array $args Arguments to pass when the hook triggers
40
- * @param string $group The group to assign this job to
41
- *
42
- * @return string The job ID
43
- */
44
- function as_schedule_recurring_action( $timestamp, $interval_in_seconds, $hook, $args = array(), $group = '' ) {
45
- return ActionScheduler::factory()->recurring( $hook, $args, $timestamp, $interval_in_seconds, $group );
46
- }
47
-
48
- /**
49
- * Schedule an action that recurs on a cron-like schedule.
50
- *
51
- * @param int $base_timestamp The first instance of the action will be scheduled
52
- * to run at a time calculated after this timestamp matching the cron
53
- * expression. This can be used to delay the first instance of the action.
54
- * @param string $schedule A cron-link schedule string
55
- * @see http://en.wikipedia.org/wiki/Cron
56
- * * * * * * *
57
- * ┬ ┬ ┬ ┬ ┬ ┬
58
- * | | | | | |
59
- * | | | | | + year [optional]
60
- * | | | | +----- day of week (0 - 7) (Sunday=0 or 7)
61
- * | | | +---------- month (1 - 12)
62
- * | | +--------------- day of month (1 - 31)
63
- * | +-------------------- hour (0 - 23)
64
- * +------------------------- min (0 - 59)
65
- * @param string $hook The hook to trigger
66
- * @param array $args Arguments to pass when the hook triggers
67
- * @param string $group The group to assign this job to
68
- *
69
- * @return string The job ID
70
- */
71
- function as_schedule_cron_action( $timestamp, $schedule, $hook, $args = array(), $group = '' ) {
72
- return ActionScheduler::factory()->cron( $hook, $args, $timestamp, $schedule, $group );
73
- }
74
-
75
- /**
76
- * Cancel the next occurrence of a scheduled action.
77
- *
78
- * While only the next instance of a recurring or cron action is unscheduled by this method, that will also prevent
79
- * all future instances of that recurring or cron action from being run. Recurring and cron actions are scheduled in
80
- * a sequence instead of all being scheduled at once. Each successive occurrence of a recurring action is scheduled
81
- * only after the former action is run. If the next instance is never run, because it's unscheduled by this function,
82
- * then the following instance will never be scheduled (or exist), which is effectively the same as being unscheduled
83
- * by this method also.
84
- *
85
- * @param string $hook The hook that the job will trigger
86
- * @param array $args Args that would have been passed to the job
87
- * @param string $group
88
- *
89
- * @return string The scheduled action ID if a scheduled action was found, or empty string if no matching action found.
90
- */
91
- function as_unschedule_action( $hook, $args = array(), $group = '' ) {
92
- $params = array();
93
- if ( is_array($args) ) {
94
- $params['args'] = $args;
95
- }
96
- if ( !empty($group) ) {
97
- $params['group'] = $group;
98
- }
99
- $job_id = ActionScheduler::store()->find_action( $hook, $params );
100
-
101
- if ( ! empty( $job_id ) ) {
102
- ActionScheduler::store()->cancel_action( $job_id );
103
- }
104
-
105
- return $job_id;
106
- }
107
-
108
- /**
109
- * Cancel all occurrences of a scheduled action.
110
- *
111
- * @param string $hook The hook that the job will trigger
112
- * @param array $args Args that would have been passed to the job
113
- * @param string $group
114
- */
115
- function as_unschedule_all_actions( $hook, $args = array(), $group = '' ) {
116
- if ( empty( $args ) ) {
117
- if ( ! empty( $hook ) && empty( $group ) ) {
118
- ActionScheduler_Store::instance()->cancel_actions_by_hook( $hook );
119
- return;
120
- }
121
- if ( ! empty( $group ) && empty( $hook ) ) {
122
- ActionScheduler_Store::instance()->cancel_actions_by_group( $group );
123
- return;
124
- }
125
- }
126
- do {
127
- $unscheduled_action = as_unschedule_action( $hook, $args, $group );
128
- } while ( ! empty( $unscheduled_action ) );
129
- }
130
-
131
- /**
132
- * Check if there is an existing action in the queue with a given hook, args and group combination.
133
- *
134
- * An action in the queue could be pending, in-progress or aysnc. If the is pending for a time in
135
- * future, its scheduled date will be returned as a timestamp. If it is currently being run, or an
136
- * async action sitting in the queue waiting to be processed, in which case boolean true will be
137
- * returned. Or there may be no async, in-progress or pending action for this hook, in which case,
138
- * boolean false will be the return value.
139
- *
140
- * @param string $hook
141
- * @param array $args
142
- * @param string $group
143
- *
144
- * @return int|bool The timestamp for the next occurrence of a pending scheduled action, true for an async or in-progress action or false if there is no matching action.
145
- */
146
- function as_next_scheduled_action( $hook, $args = NULL, $group = '' ) {
147
- $params = array();
148
- if ( is_array($args) ) {
149
- $params['args'] = $args;
150
- }
151
- if ( !empty($group) ) {
152
- $params['group'] = $group;
153
- }
154
-
155
- $params['status'] = ActionScheduler_Store::STATUS_RUNNING;
156
- $job_id = ActionScheduler::store()->find_action( $hook, $params );
157
- if ( ! empty( $job_id ) ) {
158
- return true;
159
- }
160
-
161
- $params['status'] = ActionScheduler_Store::STATUS_PENDING;
162
- $job_id = ActionScheduler::store()->find_action( $hook, $params );
163
- if ( empty($job_id) ) {
164
- return false;
165
- }
166
- $job = ActionScheduler::store()->fetch_action( $job_id );
167
- $scheduled_date = $job->get_schedule()->get_date();
168
- if ( $scheduled_date ) {
169
- return (int) $scheduled_date->format( 'U' );
170
- } elseif ( NULL === $scheduled_date ) { // pending async action with NullSchedule
171
- return true;
172
- }
173
- return false;
174
- }
175
-
176
- /**
177
- * Find scheduled actions
178
- *
179
- * @param array $args Possible arguments, with their default values:
180
- * 'hook' => '' - the name of the action that will be triggered
181
- * 'args' => NULL - the args array that will be passed with the action
182
- * 'date' => NULL - the scheduled date of the action. Expects a DateTime object, a unix timestamp, or a string that can parsed with strtotime(). Used in UTC timezone.
183
- * 'date_compare' => '<=' - operator for testing "date". accepted values are '!=', '>', '>=', '<', '<=', '='
184
- * 'modified' => NULL - the date the action was last updated. Expects a DateTime object, a unix timestamp, or a string that can parsed with strtotime(). Used in UTC timezone.
185
- * 'modified_compare' => '<=' - operator for testing "modified". accepted values are '!=', '>', '>=', '<', '<=', '='
186
- * 'group' => '' - the group the action belongs to
187
- * 'status' => '' - ActionScheduler_Store::STATUS_COMPLETE or ActionScheduler_Store::STATUS_PENDING
188
- * 'claimed' => NULL - TRUE to find claimed actions, FALSE to find unclaimed actions, a string to find a specific claim ID
189
- * 'per_page' => 5 - Number of results to return
190
- * 'offset' => 0
191
- * 'orderby' => 'date' - accepted values are 'hook', 'group', 'modified', or 'date'
192
- * 'order' => 'ASC'
193
- *
194
- * @param string $return_format OBJECT, ARRAY_A, or ids
195
- *
196
- * @return array
197
- */
198
- function as_get_scheduled_actions( $args = array(), $return_format = OBJECT ) {
199
- $store = ActionScheduler::store();
200
- foreach ( array('date', 'modified') as $key ) {
201
- if ( isset($args[$key]) ) {
202
- $args[$key] = as_get_datetime_object($args[$key]);
203
- }
204
- }
205
- $ids = $store->query_actions( $args );
206
-
207
- if ( $return_format == 'ids' || $return_format == 'int' ) {
208
- return $ids;
209
- }
210
-
211
- $actions = array();
212
- foreach ( $ids as $action_id ) {
213
- $actions[$action_id] = $store->fetch_action( $action_id );
214
- }
215
-
216
- if ( $return_format == ARRAY_A ) {
217
- foreach ( $actions as $action_id => $action_object ) {
218
- $actions[$action_id] = get_object_vars($action_object);
219
- }
220
- }
221
-
222
- return $actions;
223
- }
224
-
225
- /**
226
- * Helper function to create an instance of DateTime based on a given
227
- * string and timezone. By default, will return the current date/time
228
- * in the UTC timezone.
229
- *
230
- * Needed because new DateTime() called without an explicit timezone
231
- * will create a date/time in PHP's timezone, but we need to have
232
- * assurance that a date/time uses the right timezone (which we almost
233
- * always want to be UTC), which means we need to always include the
234
- * timezone when instantiating datetimes rather than leaving it up to
235
- * the PHP default.
236
- *
237
- * @param mixed $date_string A date/time string. Valid formats are explained in http://php.net/manual/en/datetime.formats.php
238
- * @param string $timezone A timezone identifier, like UTC or Europe/Lisbon. The list of valid identifiers is available http://php.net/manual/en/timezones.php
239
- *
240
- * @return ActionScheduler_DateTime
241
- */
242
- function as_get_datetime_object( $date_string = null, $timezone = 'UTC' ) {
243
- if ( is_object( $date_string ) && $date_string instanceof DateTime ) {
244
- $date = new ActionScheduler_DateTime( $date_string->format( 'Y-m-d H:i:s' ), new DateTimeZone( $timezone ) );
245
- } elseif ( is_numeric( $date_string ) ) {
246
- $date = new ActionScheduler_DateTime( '@' . $date_string, new DateTimeZone( $timezone ) );
247
- } else {
248
- $date = new ActionScheduler_DateTime( $date_string, new DateTimeZone( $timezone ) );
249
- }
250
- return $date;
251
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/lib/WP_Async_Request.php DELETED
@@ -1,170 +0,0 @@
1
- <?php
2
- /**
3
- * WP Async Request
4
- *
5
- * @package WP-Background-Processing
6
- */
7
- /*
8
- Library URI: https://github.com/deliciousbrains/wp-background-processing/blob/fbbc56f2480910d7959972ec9ec0819a13c6150a/classes/wp-async-request.php
9
- Author: Delicious Brains Inc.
10
- Author URI: https://deliciousbrains.com/
11
- License: GNU General Public License v2.0
12
- License URI: https://github.com/deliciousbrains/wp-background-processing/commit/126d7945dd3d39f39cb6488ca08fe1fb66cb351a
13
- */
14
-
15
- if ( ! class_exists( 'WP_Async_Request' ) ) {
16
-
17
- /**
18
- * Abstract WP_Async_Request class.
19
- *
20
- * @abstract
21
- */
22
- abstract class WP_Async_Request {
23
-
24
- /**
25
- * Prefix
26
- *
27
- * (default value: 'wp')
28
- *
29
- * @var string
30
- * @access protected
31
- */
32
- protected $prefix = 'wp';
33
-
34
- /**
35
- * Action
36
- *
37
- * (default value: 'async_request')
38
- *
39
- * @var string
40
- * @access protected
41
- */
42
- protected $action = 'async_request';
43
-
44
- /**
45
- * Identifier
46
- *
47
- * @var mixed
48
- * @access protected
49
- */
50
- protected $identifier;
51
-
52
- /**
53
- * Data
54
- *
55
- * (default value: array())
56
- *
57
- * @var array
58
- * @access protected
59
- */
60
- protected $data = array();
61
-
62
- /**
63
- * Initiate new async request
64
- */
65
- public function __construct() {
66
- $this->identifier = $this->prefix . '_' . $this->action;
67
-
68
- add_action( 'wp_ajax_' . $this->identifier, array( $this, 'maybe_handle' ) );
69
- add_action( 'wp_ajax_nopriv_' . $this->identifier, array( $this, 'maybe_handle' ) );
70
- }
71
-
72
- /**
73
- * Set data used during the request
74
- *
75
- * @param array $data Data.
76
- *
77
- * @return $this
78
- */
79
- public function data( $data ) {
80
- $this->data = $data;
81
-
82
- return $this;
83
- }
84
-
85
- /**
86
- * Dispatch the async request
87
- *
88
- * @return array|WP_Error
89
- */
90
- public function dispatch() {
91
- $url = add_query_arg( $this->get_query_args(), $this->get_query_url() );
92
- $args = $this->get_post_args();
93
-
94
- return wp_remote_post( esc_url_raw( $url ), $args );
95
- }
96
-
97
- /**
98
- * Get query args
99
- *
100
- * @return array
101
- */
102
- protected function get_query_args() {
103
- if ( property_exists( $this, 'query_args' ) ) {
104
- return $this->query_args;
105
- }
106
-
107
- return array(
108
- 'action' => $this->identifier,
109
- 'nonce' => wp_create_nonce( $this->identifier ),
110
- );
111
- }
112
-
113
- /**
114
- * Get query URL
115
- *
116
- * @return string
117
- */
118
- protected function get_query_url() {
119
- if ( property_exists( $this, 'query_url' ) ) {
120
- return $this->query_url;
121
- }
122
-
123
- return admin_url( 'admin-ajax.php' );
124
- }
125
-
126
- /**
127
- * Get post args
128
- *
129
- * @return array
130
- */
131
- protected function get_post_args() {
132
- if ( property_exists( $this, 'post_args' ) ) {
133
- return $this->post_args;
134
- }
135
-
136
- return array(
137
- 'timeout' => 0.01,
138
- 'blocking' => false,
139
- 'body' => $this->data,
140
- 'cookies' => $_COOKIE,
141
- 'sslverify' => apply_filters( 'https_local_ssl_verify', false ),
142
- );
143
- }
144
-
145
- /**
146
- * Maybe handle
147
- *
148
- * Check for correct nonce and pass to handler.
149
- */
150
- public function maybe_handle() {
151
- // Don't lock up other requests while processing
152
- session_write_close();
153
-
154
- check_ajax_referer( $this->identifier, 'nonce' );
155
-
156
- $this->handle();
157
-
158
- wp_die();
159
- }
160
-
161
- /**
162
- * Handle
163
- *
164
- * Override this method to perform any actions required
165
- * during the async request.
166
- */
167
- abstract protected function handle();
168
-
169
- }
170
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/lib/cron-expression/CronExpression.php DELETED
@@ -1,318 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * CRON expression parser that can determine whether or not a CRON expression is
5
- * due to run, the next run date and previous run date of a CRON expression.
6
- * The determinations made by this class are accurate if checked run once per
7
- * minute (seconds are dropped from date time comparisons).
8
- *
9
- * Schedule parts must map to:
10
- * minute [0-59], hour [0-23], day of month, month [1-12|JAN-DEC], day of week
11
- * [1-7|MON-SUN], and an optional year.
12
- *
13
- * @author Michael Dowling <mtdowling@gmail.com>
14
- * @link http://en.wikipedia.org/wiki/Cron
15
- */
16
- class CronExpression
17
- {
18
- const MINUTE = 0;
19
- const HOUR = 1;
20
- const DAY = 2;
21
- const MONTH = 3;
22
- const WEEKDAY = 4;
23
- const YEAR = 5;
24
-
25
- /**
26
- * @var array CRON expression parts
27
- */
28
- private $cronParts;
29
-
30
- /**
31
- * @var CronExpression_FieldFactory CRON field factory
32
- */
33
- private $fieldFactory;
34
-
35
- /**
36
- * @var array Order in which to test of cron parts
37
- */
38
- private static $order = array(self::YEAR, self::MONTH, self::DAY, self::WEEKDAY, self::HOUR, self::MINUTE);
39
-
40
- /**
41
- * Factory method to create a new CronExpression.
42
- *
43
- * @param string $expression The CRON expression to create. There are
44
- * several special predefined values which can be used to substitute the
45
- * CRON expression:
46
- *
47
- * @yearly, @annually) - Run once a year, midnight, Jan. 1 - 0 0 1 1 *
48
- * @monthly - Run once a month, midnight, first of month - 0 0 1 * *
49
- * @weekly - Run once a week, midnight on Sun - 0 0 * * 0
50
- * @daily - Run once a day, midnight - 0 0 * * *
51
- * @hourly - Run once an hour, first minute - 0 * * * *
52
- *
53
- *@param CronExpression_FieldFactory $fieldFactory (optional) Field factory to use
54
- *
55
- * @return CronExpression
56
- */
57
- public static function factory($expression, CronExpression_FieldFactory $fieldFactory = null)
58
- {
59
- $mappings = array(
60
- '@yearly' => '0 0 1 1 *',
61
- '@annually' => '0 0 1 1 *',
62
- '@monthly' => '0 0 1 * *',
63
- '@weekly' => '0 0 * * 0',
64
- '@daily' => '0 0 * * *',
65
- '@hourly' => '0 * * * *'
66
- );
67
-
68
- if (isset($mappings[$expression])) {
69
- $expression = $mappings[$expression];
70
- }
71
-
72
- return new self($expression, $fieldFactory ? $fieldFactory : new CronExpression_FieldFactory());
73
- }
74
-
75
- /**
76
- * Parse a CRON expression
77
- *
78
- * @param string $expression CRON expression (e.g. '8 * * * *')
79
- * @param CronExpression_FieldFactory $fieldFactory Factory to create cron fields
80
- */
81
- public function __construct($expression, CronExpression_FieldFactory $fieldFactory)
82
- {
83
- $this->fieldFactory = $fieldFactory;
84
- $this->setExpression($expression);
85
- }
86
-
87
- /**
88
- * Set or change the CRON expression
89
- *
90
- * @param string $value CRON expression (e.g. 8 * * * *)
91
- *
92
- * @return CronExpression
93
- * @throws InvalidArgumentException if not a valid CRON expression
94
- */
95
- public function setExpression($value)
96
- {
97
- $this->cronParts = preg_split('/\s/', $value, -1, PREG_SPLIT_NO_EMPTY);
98
- if (count($this->cronParts) < 5) {
99
- throw new InvalidArgumentException(
100
- $value . ' is not a valid CRON expression'
101
- );
102
- }
103
-
104
- foreach ($this->cronParts as $position => $part) {
105
- $this->setPart($position, $part);
106
- }
107
-
108
- return $this;
109
- }
110
-
111
- /**
112
- * Set part of the CRON expression
113
- *
114
- * @param int $position The position of the CRON expression to set
115
- * @param string $value The value to set
116
- *
117
- * @return CronExpression
118
- * @throws InvalidArgumentException if the value is not valid for the part
119
- */
120
- public function setPart($position, $value)
121
- {
122
- if (!$this->fieldFactory->getField($position)->validate($value)) {
123
- throw new InvalidArgumentException(
124
- 'Invalid CRON field value ' . $value . ' as position ' . $position
125
- );
126
- }
127
-
128
- $this->cronParts[$position] = $value;
129
-
130
- return $this;
131
- }
132
-
133
- /**
134
- * Get a next run date relative to the current date or a specific date
135
- *
136
- * @param string|DateTime $currentTime (optional) Relative calculation date
137
- * @param int $nth (optional) Number of matches to skip before returning a
138
- * matching next run date. 0, the default, will return the current
139
- * date and time if the next run date falls on the current date and
140
- * time. Setting this value to 1 will skip the first match and go to
141
- * the second match. Setting this value to 2 will skip the first 2
142
- * matches and so on.
143
- * @param bool $allowCurrentDate (optional) Set to TRUE to return the
144
- * current date if it matches the cron expression
145
- *
146
- * @return DateTime
147
- * @throws RuntimeException on too many iterations
148
- */
149
- public function getNextRunDate($currentTime = 'now', $nth = 0, $allowCurrentDate = false)
150
- {
151
- return $this->getRunDate($currentTime, $nth, false, $allowCurrentDate);
152
- }
153
-
154
- /**
155
- * Get a previous run date relative to the current date or a specific date
156
- *
157
- * @param string|DateTime $currentTime (optional) Relative calculation date
158
- * @param int $nth (optional) Number of matches to skip before returning
159
- * @param bool $allowCurrentDate (optional) Set to TRUE to return the
160
- * current date if it matches the cron expression
161
- *
162
- * @return DateTime
163
- * @throws RuntimeException on too many iterations
164
- * @see CronExpression::getNextRunDate
165
- */
166
- public function getPreviousRunDate($currentTime = 'now', $nth = 0, $allowCurrentDate = false)
167
- {
168
- return $this->getRunDate($currentTime, $nth, true, $allowCurrentDate);
169
- }
170
-
171
- /**
172
- * Get multiple run dates starting at the current date or a specific date
173
- *
174
- * @param int $total Set the total number of dates to calculate
175
- * @param string|DateTime $currentTime (optional) Relative calculation date
176
- * @param bool $invert (optional) Set to TRUE to retrieve previous dates
177
- * @param bool $allowCurrentDate (optional) Set to TRUE to return the
178
- * current date if it matches the cron expression
179
- *
180
- * @return array Returns an array of run dates
181
- */
182
- public function getMultipleRunDates($total, $currentTime = 'now', $invert = false, $allowCurrentDate = false)
183
- {
184
- $matches = array();
185
- for ($i = 0; $i < max(0, $total); $i++) {
186
- $matches[] = $this->getRunDate($currentTime, $i, $invert, $allowCurrentDate);
187
- }
188
-
189
- return $matches;
190
- }
191
-
192
- /**
193
- * Get all or part of the CRON expression
194
- *
195
- * @param string $part (optional) Specify the part to retrieve or NULL to
196
- * get the full cron schedule string.
197
- *
198
- * @return string|null Returns the CRON expression, a part of the
199
- * CRON expression, or NULL if the part was specified but not found
200
- */
201
- public function getExpression($part = null)
202
- {
203
- if (null === $part) {
204
- return implode(' ', $this->cronParts);
205
- } elseif (array_key_exists($part, $this->cronParts)) {
206
- return $this->cronParts[$part];
207
- }
208
-
209
- return null;
210
- }
211
-
212
- /**
213
- * Helper method to output the full expression.
214
- *
215
- * @return string Full CRON expression
216
- */
217
- public function __toString()
218
- {
219
- return $this->getExpression();
220
- }
221
-
222
- /**
223
- * Determine if the cron is due to run based on the current date or a
224
- * specific date. This method assumes that the current number of
225
- * seconds are irrelevant, and should be called once per minute.
226
- *
227
- * @param string|DateTime $currentTime (optional) Relative calculation date
228
- *
229
- * @return bool Returns TRUE if the cron is due to run or FALSE if not
230
- */
231
- public function isDue($currentTime = 'now')
232
- {
233
- if ('now' === $currentTime) {
234
- $currentDate = date('Y-m-d H:i');
235
- $currentTime = strtotime($currentDate);
236
- } elseif ($currentTime instanceof DateTime) {
237
- $currentDate = $currentTime->format('Y-m-d H:i');
238
- $currentTime = strtotime($currentDate);
239
- } else {
240
- $currentTime = new DateTime($currentTime);
241
- $currentTime->setTime($currentTime->format('H'), $currentTime->format('i'), 0);
242
- $currentDate = $currentTime->format('Y-m-d H:i');
243
- $currentTime = (int)($currentTime->getTimestamp());
244
- }
245
-
246
- return $this->getNextRunDate($currentDate, 0, true)->getTimestamp() == $currentTime;
247
- }
248
-
249
- /**
250
- * Get the next or previous run date of the expression relative to a date
251
- *
252
- * @param string|DateTime $currentTime (optional) Relative calculation date
253
- * @param int $nth (optional) Number of matches to skip before returning
254
- * @param bool $invert (optional) Set to TRUE to go backwards in time
255
- * @param bool $allowCurrentDate (optional) Set to TRUE to return the
256
- * current date if it matches the cron expression
257
- *
258
- * @return DateTime
259
- * @throws RuntimeException on too many iterations
260
- */
261
- protected function getRunDate($currentTime = null, $nth = 0, $invert = false, $allowCurrentDate = false)
262
- {
263
- if ($currentTime instanceof DateTime) {
264
- $currentDate = $currentTime;
265
- } else {
266
- $currentDate = new DateTime($currentTime ? $currentTime : 'now');
267
- $currentDate->setTimezone(new DateTimeZone(date_default_timezone_get()));
268
- }
269
-
270
- $currentDate->setTime($currentDate->format('H'), $currentDate->format('i'), 0);
271
- $nextRun = clone $currentDate;
272
- $nth = (int) $nth;
273
-
274
- // Set a hard limit to bail on an impossible date
275
- for ($i = 0; $i < 1000; $i++) {
276
-
277
- foreach (self::$order as $position) {
278
- $part = $this->getExpression($position);
279
- if (null === $part) {
280
- continue;
281
- }
282
-
283
- $satisfied = false;
284
- // Get the field object used to validate this part
285
- $field = $this->fieldFactory->getField($position);
286
- // Check if this is singular or a list
287
- if (strpos($part, ',') === false) {
288
- $satisfied = $field->isSatisfiedBy($nextRun, $part);
289
- } else {
290
- foreach (array_map('trim', explode(',', $part)) as $listPart) {
291
- if ($field->isSatisfiedBy($nextRun, $listPart)) {
292
- $satisfied = true;
293
- break;
294
- }
295
- }
296
- }
297
-
298
- // If the field is not satisfied, then start over
299
- if (!$satisfied) {
300
- $field->increment($nextRun, $invert);
301
- continue 2;
302
- }
303
- }
304
-
305
- // Skip this match if needed
306
- if ((!$allowCurrentDate && $nextRun == $currentDate) || --$nth > -1) {
307
- $this->fieldFactory->getField(0)->increment($nextRun, $invert);
308
- continue;
309
- }
310
-
311
- return $nextRun;
312
- }
313
-
314
- // @codeCoverageIgnoreStart
315
- throw new RuntimeException('Impossible CRON expression');
316
- // @codeCoverageIgnoreEnd
317
- }
318
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/lib/cron-expression/CronExpression_AbstractField.php DELETED
@@ -1,100 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Abstract CRON expression field
5
- *
6
- * @author Michael Dowling <mtdowling@gmail.com>
7
- */
8
- abstract class CronExpression_AbstractField implements CronExpression_FieldInterface
9
- {
10
- /**
11
- * Check to see if a field is satisfied by a value
12
- *
13
- * @param string $dateValue Date value to check
14
- * @param string $value Value to test
15
- *
16
- * @return bool
17
- */
18
- public function isSatisfied($dateValue, $value)
19
- {
20
- if ($this->isIncrementsOfRanges($value)) {
21
- return $this->isInIncrementsOfRanges($dateValue, $value);
22
- } elseif ($this->isRange($value)) {
23
- return $this->isInRange($dateValue, $value);
24
- }
25
-
26
- return $value == '*' || $dateValue == $value;
27
- }
28
-
29
- /**
30
- * Check if a value is a range
31
- *
32
- * @param string $value Value to test
33
- *
34
- * @return bool
35
- */
36
- public function isRange($value)
37
- {
38
- return strpos($value, '-') !== false;
39
- }
40
-
41
- /**
42
- * Check if a value is an increments of ranges
43
- *
44
- * @param string $value Value to test
45
- *
46
- * @return bool
47
- */
48
- public function isIncrementsOfRanges($value)
49
- {
50
- return strpos($value, '/') !== false;
51
- }
52
-
53
- /**
54
- * Test if a value is within a range
55
- *
56
- * @param string $dateValue Set date value
57
- * @param string $value Value to test
58
- *
59
- * @return bool
60
- */
61
- public function isInRange($dateValue, $value)
62
- {
63
- $parts = array_map('trim', explode('-', $value, 2));
64
-
65
- return $dateValue >= $parts[0] && $dateValue <= $parts[1];
66
- }
67
-
68
- /**
69
- * Test if a value is within an increments of ranges (offset[-to]/step size)
70
- *
71
- * @param string $dateValue Set date value
72
- * @param string $value Value to test
73
- *
74
- * @return bool
75
- */
76
- public function isInIncrementsOfRanges($dateValue, $value)
77
- {
78
- $parts = array_map('trim', explode('/', $value, 2));
79
- $stepSize = isset($parts[1]) ? $parts[1] : 0;
80
- if ($parts[0] == '*' || $parts[0] === '0') {
81
- return (int) $dateValue % $stepSize == 0;
82
- }
83
-
84
- $range = explode('-', $parts[0], 2);
85
- $offset = $range[0];
86
- $to = isset($range[1]) ? $range[1] : $dateValue;
87
- // Ensure that the date value is within the range
88
- if ($dateValue < $offset || $dateValue > $to) {
89
- return false;
90
- }
91
-
92
- for ($i = $offset; $i <= $to; $i+= $stepSize) {
93
- if ($i == $dateValue) {
94
- return true;
95
- }
96
- }
97
-
98
- return false;
99
- }
100
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/lib/cron-expression/CronExpression_DayOfMonthField.php DELETED
@@ -1,110 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Day of month field. Allows: * , / - ? L W
5
- *
6
- * 'L' stands for "last" and specifies the last day of the month.
7
- *
8
- * The 'W' character is used to specify the weekday (Monday-Friday) nearest the
9
- * given day. As an example, if you were to specify "15W" as the value for the
10
- * day-of-month field, the meaning is: "the nearest weekday to the 15th of the
11
- * month". So if the 15th is a Saturday, the trigger will fire on Friday the
12
- * 14th. If the 15th is a Sunday, the trigger will fire on Monday the 16th. If
13
- * the 15th is a Tuesday, then it will fire on Tuesday the 15th. However if you
14
- * specify "1W" as the value for day-of-month, and the 1st is a Saturday, the
15
- * trigger will fire on Monday the 3rd, as it will not 'jump' over the boundary
16
- * of a month's days. The 'W' character can only be specified when the
17
- * day-of-month is a single day, not a range or list of days.
18
- *
19
- * @author Michael Dowling <mtdowling@gmail.com>
20
- */
21
- class CronExpression_DayOfMonthField extends CronExpression_AbstractField
22
- {
23
- /**
24
- * Get the nearest day of the week for a given day in a month
25
- *
26
- * @param int $currentYear Current year
27
- * @param int $currentMonth Current month
28
- * @param int $targetDay Target day of the month
29
- *
30
- * @return DateTime Returns the nearest date
31
- */
32
- private static function getNearestWeekday($currentYear, $currentMonth, $targetDay)
33
- {
34
- $tday = str_pad($targetDay, 2, '0', STR_PAD_LEFT);
35
- $target = new DateTime("$currentYear-$currentMonth-$tday");
36
- $currentWeekday = (int) $target->format('N');
37
-
38
- if ($currentWeekday < 6) {
39
- return $target;
40
- }
41
-
42
- $lastDayOfMonth = $target->format('t');
43
-
44
- foreach (array(-1, 1, -2, 2) as $i) {
45
- $adjusted = $targetDay + $i;
46
- if ($adjusted > 0 && $adjusted <= $lastDayOfMonth) {
47
- $target->setDate($currentYear, $currentMonth, $adjusted);
48
- if ($target->format('N') < 6 && $target->format('m') == $currentMonth) {
49
- return $target;
50
- }
51
- }
52
- }
53
- }
54
-
55
- /**
56
- * {@inheritdoc}
57
- */
58
- public function isSatisfiedBy(DateTime $date, $value)
59
- {
60
- // ? states that the field value is to be skipped
61
- if ($value == '?') {
62
- return true;
63
- }
64
-
65
- $fieldValue = $date->format('d');
66
-
67
- // Check to see if this is the last day of the month
68
- if ($value == 'L') {
69
- return $fieldValue == $date->format('t');
70
- }
71
-
72
- // Check to see if this is the nearest weekday to a particular value
73
- if (strpos($value, 'W')) {
74
- // Parse the target day
75
- $targetDay = substr($value, 0, strpos($value, 'W'));
76
- // Find out if the current day is the nearest day of the week
77
- return $date->format('j') == self::getNearestWeekday(
78
- $date->format('Y'),
79
- $date->format('m'),
80
- $targetDay
81
- )->format('j');
82
- }
83
-
84
- return $this->isSatisfied($date->format('d'), $value);
85
- }
86
-
87
- /**
88
- * {@inheritdoc}
89
- */
90
- public function increment(DateTime $date, $invert = false)
91
- {
92
- if ($invert) {
93
- $date->modify('previous day');
94
- $date->setTime(23, 59);
95
- } else {
96
- $date->modify('next day');
97
- $date->setTime(0, 0);
98
- }
99
-
100
- return $this;
101
- }
102
-
103
- /**
104
- * {@inheritdoc}
105
- */
106
- public function validate($value)
107
- {
108
- return (bool) preg_match('/[\*,\/\-\?LW0-9A-Za-z]+/', $value);
109
- }
110
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/lib/cron-expression/CronExpression_DayOfWeekField.php DELETED
@@ -1,124 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Day of week field. Allows: * / , - ? L #
5
- *
6
- * Days of the week can be represented as a number 0-7 (0|7 = Sunday)
7
- * or as a three letter string: SUN, MON, TUE, WED, THU, FRI, SAT.
8
- *
9
- * 'L' stands for "last". It allows you to specify constructs such as
10
- * "the last Friday" of a given month.
11
- *
12
- * '#' is allowed for the day-of-week field, and must be followed by a
13
- * number between one and five. It allows you to specify constructs such as
14
- * "the second Friday" of a given month.
15
- *
16
- * @author Michael Dowling <mtdowling@gmail.com>
17
- */
18
- class CronExpression_DayOfWeekField extends CronExpression_AbstractField
19
- {
20
- /**
21
- * {@inheritdoc}
22
- */
23
- public function isSatisfiedBy(DateTime $date, $value)
24
- {
25
- if ($value == '?') {
26
- return true;
27
- }
28
-
29
- // Convert text day of the week values to integers
30
- $value = str_ireplace(
31
- array('SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'),
32
- range(0, 6),
33
- $value
34
- );
35
-
36
- $currentYear = $date->format('Y');
37
- $currentMonth = $date->format('m');
38
- $lastDayOfMonth = $date->format('t');
39
-
40
- // Find out if this is the last specific weekday of the month
41
- if (strpos($value, 'L')) {
42
- $weekday = str_replace('7', '0', substr($value, 0, strpos($value, 'L')));
43
- $tdate = clone $date;
44
- $tdate->setDate($currentYear, $currentMonth, $lastDayOfMonth);
45
- while ($tdate->format('w') != $weekday) {
46
- $tdate->setDate($currentYear, $currentMonth, --$lastDayOfMonth);
47
- }
48
-
49
- return $date->format('j') == $lastDayOfMonth;
50
- }
51
-
52
- // Handle # hash tokens
53
- if (strpos($value, '#')) {
54
- list($weekday, $nth) = explode('#', $value);
55
- // Validate the hash fields
56
- if ($weekday < 1 || $weekday > 5) {
57
- throw new InvalidArgumentException("Weekday must be a value between 1 and 5. {$weekday} given");
58
- }
59
- if ($nth > 5) {
60
- throw new InvalidArgumentException('There are never more than 5 of a given weekday in a month');
61
- }
62
- // The current weekday must match the targeted weekday to proceed
63
- if ($date->format('N') != $weekday) {
64
- return false;
65
- }
66
-
67
- $tdate = clone $date;
68
- $tdate->setDate($currentYear, $currentMonth, 1);
69
- $dayCount = 0;
70
- $currentDay = 1;
71
- while ($currentDay < $lastDayOfMonth + 1) {
72
- if ($tdate->format('N') == $weekday) {
73
- if (++$dayCount >= $nth) {
74
- break;
75
- }
76
- }
77
- $tdate->setDate($currentYear, $currentMonth, ++$currentDay);
78
- }
79
-
80
- return $date->format('j') == $currentDay;
81
- }
82
-
83
- // Handle day of the week values
84
- if (strpos($value, '-')) {
85
- $parts = explode('-', $value);
86
- if ($parts[0] == '7') {
87
- $parts[0] = '0';
88
- } elseif ($parts[1] == '0') {
89
- $parts[1] = '7';
90
- }
91
- $value = implode('-', $parts);
92
- }
93
-
94
- // Test to see which Sunday to use -- 0 == 7 == Sunday
95
- $format = in_array(7, str_split($value)) ? 'N' : 'w';
96
- $fieldValue = $date->format($format);
97
-
98
- return $this->isSatisfied($fieldValue, $value);
99
- }
100
-
101
- /**
102
- * {@inheritdoc}
103
- */
104
- public function increment(DateTime $date, $invert = false)
105
- {
106
- if ($invert) {
107
- $date->modify('-1 day');
108
- $date->setTime(23, 59, 0);
109
- } else {
110
- $date->modify('+1 day');
111
- $date->setTime(0, 0, 0);
112
- }
113
-
114
- return $this;
115
- }
116
-
117
- /**
118
- * {@inheritdoc}
119
- */
120
- public function validate($value)
121
- {
122
- return (bool) preg_match('/[\*,\/\-0-9A-Z]+/', $value);
123
- }
124
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/lib/cron-expression/CronExpression_FieldFactory.php DELETED
@@ -1,55 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * CRON field factory implementing a flyweight factory
5
- *
6
- * @author Michael Dowling <mtdowling@gmail.com>
7
- * @link http://en.wikipedia.org/wiki/Cron
8
- */
9
- class CronExpression_FieldFactory
10
- {
11
- /**
12
- * @var array Cache of instantiated fields
13
- */
14
- private $fields = array();
15
-
16
- /**
17
- * Get an instance of a field object for a cron expression position
18
- *
19
- * @param int $position CRON expression position value to retrieve
20
- *
21
- * @return CronExpression_FieldInterface
22
- * @throws InvalidArgumentException if a position is not valid
23
- */
24
- public function getField($position)
25
- {
26
- if (!isset($this->fields[$position])) {
27
- switch ($position) {
28
- case 0:
29
- $this->fields[$position] = new CronExpression_MinutesField();
30
- break;
31
- case 1:
32
- $this->fields[$position] = new CronExpression_HoursField();
33
- break;
34
- case 2:
35
- $this->fields[$position] = new CronExpression_DayOfMonthField();
36
- break;
37
- case 3:
38
- $this->fields[$position] = new CronExpression_MonthField();
39
- break;
40
- case 4:
41
- $this->fields[$position] = new CronExpression_DayOfWeekField();
42
- break;
43
- case 5:
44
- $this->fields[$position] = new CronExpression_YearField();
45
- break;
46
- default:
47
- throw new InvalidArgumentException(
48
- $position . ' is not a valid position'
49
- );
50
- }
51
- }
52
-
53
- return $this->fields[$position];
54
- }
55
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/lib/cron-expression/CronExpression_FieldInterface.php DELETED
@@ -1,39 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * CRON field interface
5
- *
6
- * @author Michael Dowling <mtdowling@gmail.com>
7
- */
8
- interface CronExpression_FieldInterface
9
- {
10
- /**
11
- * Check if the respective value of a DateTime field satisfies a CRON exp
12
- *
13
- * @param DateTime $date DateTime object to check
14
- * @param string $value CRON expression to test against
15
- *
16
- * @return bool Returns TRUE if satisfied, FALSE otherwise
17
- */
18
- public function isSatisfiedBy(DateTime $date, $value);
19
-
20
- /**
21
- * When a CRON expression is not satisfied, this method is used to increment
22
- * or decrement a DateTime object by the unit of the cron field
23
- *
24
- * @param DateTime $date DateTime object to change
25
- * @param bool $invert (optional) Set to TRUE to decrement
26
- *
27
- * @return CronExpression_FieldInterface
28
- */
29
- public function increment(DateTime $date, $invert = false);
30
-
31
- /**
32
- * Validates a CRON expression for a given field
33
- *
34
- * @param string $value CRON expression value to validate
35
- *
36
- * @return bool Returns TRUE if valid, FALSE otherwise
37
- */
38
- public function validate($value);
39
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/lib/cron-expression/CronExpression_HoursField.php DELETED
@@ -1,47 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Hours field. Allows: * , / -
5
- *
6
- * @author Michael Dowling <mtdowling@gmail.com>
7
- */
8
- class CronExpression_HoursField extends CronExpression_AbstractField
9
- {
10
- /**
11
- * {@inheritdoc}
12
- */
13
- public function isSatisfiedBy(DateTime $date, $value)
14
- {
15
- return $this->isSatisfied($date->format('H'), $value);
16
- }
17
-
18
- /**
19
- * {@inheritdoc}
20
- */
21
- public function increment(DateTime $date, $invert = false)
22
- {
23
- // Change timezone to UTC temporarily. This will
24
- // allow us to go back or forwards and hour even
25
- // if DST will be changed between the hours.
26
- $timezone = $date->getTimezone();
27
- $date->setTimezone(new DateTimeZone('UTC'));
28
- if ($invert) {
29
- $date->modify('-1 hour');
30
- $date->setTime($date->format('H'), 59);
31
- } else {
32
- $date->modify('+1 hour');
33
- $date->setTime($date->format('H'), 0);
34
- }
35
- $date->setTimezone($timezone);
36
-
37
- return $this;
38
- }
39
-
40
- /**
41
- * {@inheritdoc}
42
- */
43
- public function validate($value)
44
- {
45
- return (bool) preg_match('/[\*,\/\-0-9]+/', $value);
46
- }
47
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/lib/cron-expression/CronExpression_MinutesField.php DELETED
@@ -1,39 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Minutes field. Allows: * , / -
5
- *
6
- * @author Michael Dowling <mtdowling@gmail.com>
7
- */
8
- class CronExpression_MinutesField extends CronExpression_AbstractField
9
- {
10
- /**
11
- * {@inheritdoc}
12
- */
13
- public function isSatisfiedBy(DateTime $date, $value)
14
- {
15
- return $this->isSatisfied($date->format('i'), $value);
16
- }
17
-
18
- /**
19
- * {@inheritdoc}
20
- */
21
- public function increment(DateTime $date, $invert = false)
22
- {
23
- if ($invert) {
24
- $date->modify('-1 minute');
25
- } else {
26
- $date->modify('+1 minute');
27
- }
28
-
29
- return $this;
30
- }
31
-
32
- /**
33
- * {@inheritdoc}
34
- */
35
- public function validate($value)
36
- {
37
- return (bool) preg_match('/[\*,\/\-0-9]+/', $value);
38
- }
39
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/lib/cron-expression/CronExpression_MonthField.php DELETED
@@ -1,55 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Month field. Allows: * , / -
5
- *
6
- * @author Michael Dowling <mtdowling@gmail.com>
7
- */
8
- class CronExpression_MonthField extends CronExpression_AbstractField
9
- {
10
- /**
11
- * {@inheritdoc}
12
- */
13
- public function isSatisfiedBy(DateTime $date, $value)
14
- {
15
- // Convert text month values to integers
16
- $value = str_ireplace(
17
- array(
18
- 'JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN',
19
- 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'
20
- ),
21
- range(1, 12),
22
- $value
23
- );
24
-
25
- return $this->isSatisfied($date->format('m'), $value);
26
- }
27
-
28
- /**
29
- * {@inheritdoc}
30
- */
31
- public function increment(DateTime $date, $invert = false)
32
- {
33
- if ($invert) {
34
- // $date->modify('last day of previous month'); // remove for php 5.2 compat
35
- $date->modify('previous month');
36
- $date->modify($date->format('Y-m-t'));
37
- $date->setTime(23, 59);
38
- } else {
39
- //$date->modify('first day of next month'); // remove for php 5.2 compat
40
- $date->modify('next month');
41
- $date->modify($date->format('Y-m-01'));
42
- $date->setTime(0, 0);
43
- }
44
-
45
- return $this;
46
- }
47
-
48
- /**
49
- * {@inheritdoc}
50
- */
51
- public function validate($value)
52
- {
53
- return (bool) preg_match('/[\*,\/\-0-9A-Z]+/', $value);
54
- }
55
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/lib/cron-expression/CronExpression_YearField.php DELETED
@@ -1,43 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Year field. Allows: * , / -
5
- *
6
- * @author Michael Dowling <mtdowling@gmail.com>
7
- */
8
- class CronExpression_YearField extends CronExpression_AbstractField
9
- {
10
- /**
11
- * {@inheritdoc}
12
- */
13
- public function isSatisfiedBy(DateTime $date, $value)
14
- {
15
- return $this->isSatisfied($date->format('Y'), $value);
16
- }
17
-
18
- /**
19
- * {@inheritdoc}
20
- */
21
- public function increment(DateTime $date, $invert = false)
22
- {
23
- if ($invert) {
24
- $date->modify('-1 year');
25
- $date->setDate($date->format('Y'), 12, 31);
26
- $date->setTime(23, 59, 0);
27
- } else {
28
- $date->modify('+1 year');
29
- $date->setDate($date->format('Y'), 1, 1);
30
- $date->setTime(0, 0, 0);
31
- }
32
-
33
- return $this;
34
- }
35
-
36
- /**
37
- * {@inheritdoc}
38
- */
39
- public function validate($value)
40
- {
41
- return (bool) preg_match('/[\*,\/\-0-9]+/', $value);
42
- }
43
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/lib/cron-expression/LICENSE DELETED
@@ -1,19 +0,0 @@
1
- Copyright (c) 2011 Michael Dowling <mtdowling@gmail.com> and contributors
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy
4
- of this software and associated documentation files (the "Software"), to deal
5
- in the Software without restriction, including without limitation the rights
6
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- copies of the Software, and to permit persons to whom the Software is
8
- furnished to do so, subject to the following conditions:
9
-
10
- The above copyright notice and this permission notice shall be included in
11
- all copies or substantial portions of the Software.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- THE SOFTWARE.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/lib/cron-expression/README.md DELETED
@@ -1,92 +0,0 @@
1
- PHP Cron Expression Parser
2
- ==========================
3
-
4
- [![Latest Stable Version](https://poser.pugx.org/mtdowling/cron-expression/v/stable.png)](https://packagist.org/packages/mtdowling/cron-expression) [![Total Downloads](https://poser.pugx.org/mtdowling/cron-expression/downloads.png)](https://packagist.org/packages/mtdowling/cron-expression) [![Build Status](https://secure.travis-ci.org/mtdowling/cron-expression.png)](http://travis-ci.org/mtdowling/cron-expression)
5
-
6
- The PHP cron expression parser can parse a CRON expression, determine if it is
7
- due to run, calculate the next run date of the expression, and calculate the previous
8
- run date of the expression. You can calculate dates far into the future or past by
9
- skipping n number of matching dates.
10
-
11
- The parser can handle increments of ranges (e.g. */12, 2-59/3), intervals (e.g. 0-9),
12
- lists (e.g. 1,2,3), W to find the nearest weekday for a given day of the month, L to
13
- find the last day of the month, L to find the last given weekday of a month, and hash
14
- (#) to find the nth weekday of a given month.
15
-
16
- Credits
17
- ==========
18
-
19
- Created by Micheal Dowling. Ported to PHP 5.2 by Flightless, Inc.
20
- Based on version 1.0.3: https://github.com/mtdowling/cron-expression/tree/v1.0.3
21
-
22
- Installing
23
- ==========
24
-
25
- Add the following to your project's composer.json:
26
-
27
- ```javascript
28
- {
29
- "require": {
30
- "mtdowling/cron-expression": "1.0.*"
31
- }
32
- }
33
- ```
34
-
35
- Usage
36
- =====
37
- ```php
38
- <?php
39
-
40
- require_once '/vendor/autoload.php';
41
-
42
- // Works with predefined scheduling definitions
43
- $cron = Cron\CronExpression::factory('@daily');
44
- $cron->isDue();
45
- echo $cron->getNextRunDate()->format('Y-m-d H:i:s');
46
- echo $cron->getPreviousRunDate()->format('Y-m-d H:i:s');
47
-
48
- // Works with complex expressions
49
- $cron = Cron\CronExpression::factory('3-59/15 2,6-12 */15 1 2-5');
50
- echo $cron->getNextRunDate()->format('Y-m-d H:i:s');
51
-
52
- // Calculate a run date two iterations into the future
53
- $cron = Cron\CronExpression::factory('@daily');
54
- echo $cron->getNextRunDate(null, 2)->format('Y-m-d H:i:s');
55
-
56
- // Calculate a run date relative to a specific time
57
- $cron = Cron\CronExpression::factory('@monthly');
58
- echo $cron->getNextRunDate('2010-01-12 00:00:00')->format('Y-m-d H:i:s');
59
- ```
60
-
61
- CRON Expressions
62
- ================
63
-
64
- A CRON expression is a string representing the schedule for a particular command to execute. The parts of a CRON schedule are as follows:
65
-
66
- * * * * * *
67
- - - - - - -
68
- | | | | | |
69
- | | | | | + year [optional]
70
- | | | | +----- day of week (0 - 7) (Sunday=0 or 7)
71
- | | | +---------- month (1 - 12)
72
- | | +--------------- day of month (1 - 31)
73
- | +-------------------- hour (0 - 23)
74
- +------------------------- min (0 - 59)
75
-
76
- Requirements
77
- ============
78
-
79
- - PHP 5.3+
80
- - PHPUnit is required to run the unit tests
81
- - Composer is required to run the unit tests
82
-
83
- CHANGELOG
84
- =========
85
-
86
- 1.0.3 (2013-11-23)
87
- ------------------
88
-
89
- * Only set default timezone if the given $currentTime is not a DateTime instance (#34)
90
- * Fixes issue #28 where PHP increments of ranges were failing due to PHP casting hyphens to 0
91
- * Now supports expressions with any number of extra spaces, tabs, or newlines
92
- * Using static instead of self in `CronExpression::factory`
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/libraries/action-scheduler/license.txt DELETED
@@ -1,674 +0,0 @@
1
- GNU GENERAL PUBLIC LICENSE
2
- Version 3, 29 June 2007
3
-
4
- Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
- Everyone is permitted to copy and distribute verbatim copies
6
- of this license document, but changing it is not allowed.
7
-
8
- Preamble
9
-
10
- The GNU General Public License is a free, copyleft license for
11
- software and other kinds of works.
12
-
13
- The licenses for most software and other practical works are designed
14
- to take away your freedom to share and change the works. By contrast,
15
- the GNU General Public License is intended to guarantee your freedom to
16
- share and change all versions of a program--to make sure it remains free
17
- software for all its users. We, the Free Software Foundation, use the
18
- GNU General Public License for most of our software; it applies also to
19
- any other work released this way by its authors. You can apply it to
20
- your programs, too.
21
-
22
- When we speak of free software, we are referring to freedom, not
23
- price. Our General Public Licenses are designed to make sure that you
24
- have the freedom to distribute copies of free software (and charge for
25
- them if you wish), that you receive source code or can get it if you
26
- want it, that you can change the software or use pieces of it in new
27
- free programs, and that you know you can do these things.
28
-
29
- To protect your rights, we need to prevent others from denying you
30
- these rights or asking you to surrender the rights. Therefore, you have
31
- certain responsibilities if you distribute copies of the software, or if
32
- you modify it: responsibilities to respect the freedom of others.
33
-
34
- For example, if you distribute copies of such a program, whether
35
- gratis or for a fee, you must pass on to the recipients the same
36
- freedoms that you received. You must make sure that they, too, receive
37
- or can get the source code. And you must show them these terms so they
38
- know their rights.
39
-
40
- Developers that use the GNU GPL protect your rights with two steps:
41
- (1) assert copyright on the software, and (2) offer you this License
42
- giving you legal permission to copy, distribute and/or modify it.
43
-
44
- For the developers' and authors' protection, the GPL clearly explains
45
- that there is no warranty for this free software. For both users' and
46
- authors' sake, the GPL requires that modified versions be marked as
47
- changed, so that their problems will not be attributed erroneously to
48
- authors of previous versions.
49
-
50
- Some devices are designed to deny users access to install or run
51
- modified versions of the software inside them, although the manufacturer
52
- can do so. This is fundamentally incompatible with the aim of
53
- protecting users' freedom to change the software. The systematic
54
- pattern of such abuse occurs in the area of products for individuals to
55
- use, which is precisely where it is most unacceptable. Therefore, we
56
- have designed this version of the GPL to prohibit the practice for those
57
- products. If such problems arise substantially in other domains, we
58
- stand ready to extend this provision to those domains in future versions
59
- of the GPL, as needed to protect the freedom of users.
60
-
61
- Finally, every program is threatened constantly by software patents.
62
- States should not allow patents to restrict development and use of
63
- software on general-purpose computers, but in those that do, we wish to
64
- avoid the special danger that patents applied to a free program could
65
- make it effectively proprietary. To prevent this, the GPL assures that
66
- patents cannot be used to render the program non-free.
67
-
68
- The precise terms and conditions for copying, distribution and
69
- modification follow.
70
-
71
- TERMS AND CONDITIONS
72
-
73
- 0. Definitions.
74
-
75
- "This License" refers to version 3 of the GNU General Public License.
76
-
77
- "Copyright" also means copyright-like laws that apply to other kinds of
78
- works, such as semiconductor masks.
79
-
80
- "The Program" refers to any copyrightable work licensed under this
81
- License. Each licensee is addressed as "you". "Licensees" and
82
- "recipients" may be individuals or organizations.
83
-
84
- To "modify" a work means to copy from or adapt all or part of the work
85
- in a fashion requiring copyright permission, other than the making of an
86
- exact copy. The resulting work is called a "modified version" of the
87
- earlier work or a work "based on" the earlier work.
88
-
89
- A "covered work" means either the unmodified Program or a work based
90
- on the Program.
91
-
92
- To "propagate" a work means to do anything with it that, without
93
- permission, would make you directly or secondarily liable for
94
- infringement under applicable copyright law, except executing it on a
95
- computer or modifying a private copy. Propagation includes copying,
96
- distribution (with or without modification), making available to the
97
- public, and in some countries other activities as well.
98
-
99
- To "convey" a work means any kind of propagation that enables other
100
- parties to make or receive copies. Mere interaction with a user through
101
- a computer network, with no transfer of a copy, is not conveying.
102
-
103
- An interactive user interface displays "Appropriate Legal Notices"
104
- to the extent that it includes a convenient and prominently visible
105
- feature that (1) displays an appropriate copyright notice, and (2)
106
- tells the user that there is no warranty for the work (except to the
107
- extent that warranties are provided), that licensees may convey the
108
- work under this License, and how to view a copy of this License. If
109
- the interface presents a list of user commands or options, such as a
110
- menu, a prominent item in the list meets this criterion.
111
-
112
- 1. Source Code.
113
-
114
- The "source code" for a work means the preferred form of the work
115
- for making modifications to it. "Object code" means any non-source
116
- form of a work.
117
-
118
- A "Standard Interface" means an interface that either is an official
119
- standard defined by a recognized standards body, or, in the case of
120
- interfaces specified for a particular programming language, one that
121
- is widely used among developers working in that language.
122
-
123
- The "System Libraries" of an executable work include anything, other
124
- than the work as a whole, that (a) is included in the normal form of
125
- packaging a Major Component, but which is not part of that Major
126
- Component, and (b) serves only to enable use of the work with that
127
- Major Component, or to implement a Standard Interface for which an
128
- implementation is available to the public in source code form. A
129
- "Major Component", in this context, means a major essential component
130
- (kernel, window system, and so on) of the specific operating system
131
- (if any) on which the executable work runs, or a compiler used to
132
- produce the work, or an object code interpreter used to run it.
133
-
134
- The "Corresponding Source" for a work in object code form means all
135
- the source code needed to generate, install, and (for an executable
136
- work) run the object code and to modify the work, including scripts to
137
- control those activities. However, it does not include the work's
138
- System Libraries, or general-purpose tools or generally available free
139
- programs which are used unmodified in performing those activities but
140
- which are not part of the work. For example, Corresponding Source
141
- includes interface definition files associated with source files for
142
- the work, and the source code for shared libraries and dynamically
143
- linked subprograms that the work is specifically designed to require,
144
- such as by intimate data communication or control flow between those
145
- subprograms and other parts of the work.
146
-
147
- The Corresponding Source need not include anything that users
148
- can regenerate automatically from other parts of the Corresponding
149
- Source.
150
-
151
- The Corresponding Source for a work in source code form is that
152
- same work.
153
-
154
- 2. Basic Permissions.
155
-
156
- All rights granted under this License are granted for the term of
157
- copyright on the Program, and are irrevocable provided the stated
158
- conditions are met. This License explicitly affirms your unlimited
159
- permission to run the unmodified Program. The output from running a
160
- covered work is covered by this License only if the output, given its
161
- content, constitutes a covered work. This License acknowledges your
162
- rights of fair use or other equivalent, as provided by copyright law.
163
-
164
- You may make, run and propagate covered works that you do not
165
- convey, without conditions so long as your license otherwise remains
166
- in force. You may convey covered works to others for the sole purpose
167
- of having them make modifications exclusively for you, or provide you
168
- with facilities for running those works, provided that you comply with
169
- the terms of this License in conveying all material for which you do
170
- not control copyright. Those thus making or running the covered works
171
- for you must do so exclusively on your behalf, under your direction
172
- and control, on terms that prohibit them from making any copies of
173
- your copyrighted material outside their relationship with you.
174
-
175
- Conveying under any other circumstances is permitted solely under
176
- the conditions stated below. Sublicensing is not allowed; section 10
177
- makes it unnecessary.
178
-
179
- 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180
-
181
- No covered work shall be deemed part of an effective technological
182
- measure under any applicable law fulfilling obligations under article
183
- 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184
- similar laws prohibiting or restricting circumvention of such
185
- measures.
186
-
187
- When you convey a covered work, you waive any legal power to forbid
188
- circumvention of technological measures to the extent such circumvention
189
- is effected by exercising rights under this License with respect to
190
- the covered work, and you disclaim any intention to limit operation or
191
- modification of the work as a means of enforcing, against the work's
192
- users, your or third parties' legal rights to forbid circumvention of
193
- technological measures.
194
-
195
- 4. Conveying Verbatim Copies.
196
-
197
- You may convey verbatim copies of the Program's source code as you
198
- receive it, in any medium, provided that you conspicuously and
199
- appropriately publish on each copy an appropriate copyright notice;
200
- keep intact all notices stating that this License and any
201
- non-permissive terms added in accord with section 7 apply to the code;
202
- keep intact all notices of the absence of any warranty; and give all
203
- recipients a copy of this License along with the Program.
204
-
205
- You may charge any price or no price for each copy that you convey,
206
- and you may offer support or warranty protection for a fee.
207
-
208
- 5. Conveying Modified Source Versions.
209
-
210
- You may convey a work based on the Program, or the modifications to
211
- produce it from the Program, in the form of source code under the
212
- terms of section 4, provided that you also meet all of these conditions:
213
-
214
- a) The work must carry prominent notices stating that you modified
215
- it, and giving a relevant date.
216
-
217
- b) The work must carry prominent notices stating that it is
218
- released under this License and any conditions added under section
219
- 7. This requirement modifies the requirement in section 4 to
220
- "keep intact all notices".
221
-
222
- c) You must license the entire work, as a whole, under this
223
- License to anyone who comes into possession of a copy. This
224
- License will therefore apply, along with any applicable section 7
225
- additional terms, to the whole of the work, and all its parts,
226
- regardless of how they are packaged. This License gives no
227
- permission to license the work in any other way, but it does not
228
- invalidate such permission if you have separately received it.
229
-
230
- d) If the work has interactive user interfaces, each must display
231
- Appropriate Legal Notices; however, if the Program has interactive
232
- interfaces that do not display Appropriate Legal Notices, your
233
- work need not make them do so.
234
-
235
- A compilation of a covered work with other separate and independent
236
- works, which are not by their nature extensions of the covered work,
237
- and which are not combined with it such as to form a larger program,
238
- in or on a volume of a storage or distribution medium, is called an
239
- "aggregate" if the compilation and its resulting copyright are not
240
- used to limit the access or legal rights of the compilation's users
241
- beyond what the individual works permit. Inclusion of a covered work
242
- in an aggregate does not cause this License to apply to the other
243
- parts of the aggregate.
244
-
245
- 6. Conveying Non-Source Forms.
246
-
247
- You may convey a covered work in object code form under the terms
248
- of sections 4 and 5, provided that you also convey the
249
- machine-readable Corresponding Source under the terms of this License,
250
- in one of these ways:
251
-
252
- a) Convey the object code in, or embodied in, a physical product
253
- (including a physical distribution medium), accompanied by the
254
- Corresponding Source fixed on a durable physical medium
255
- customarily used for software interchange.
256
-
257
- b) Convey the object code in, or embodied in, a physical product
258
- (including a physical distribution medium), accompanied by a
259
- written offer, valid for at least three years and valid for as
260
- long as you offer spare parts or customer support for that product
261
- model, to give anyone who possesses the object code either (1) a
262
- copy of the Corresponding Source for all the software in the
263
- product that is covered by this License, on a durable physical
264
- medium customarily used for software interchange, for a price no
265
- more than your reasonable cost of physically performing this
266
- conveying of source, or (2) access to copy the
267
- Corresponding Source from a network server at no charge.
268
-
269
- c) Convey individual copies of the object code with a copy of the
270
- written offer to provide the Corresponding Source. This
271
- alternative is allowed only occasionally and noncommercially, and
272
- only if you received the object code with such an offer, in accord
273
- with subsection 6b.
274
-
275
- d) Convey the object code by offering access from a designated
276
- place (gratis or for a charge), and offer equivalent access to the
277
- Corresponding Source in the same way through the same place at no
278
- further charge. You need not require recipients to copy the
279
- Corresponding Source along with the object code. If the place to
280
- copy the object code is a network server, the Corresponding Source
281
- may be on a different server (operated by you or a third party)
282
- that supports equivalent copying facilities, provided you maintain
283
- clear directions next to the object code saying where to find the
284
- Corresponding Source. Regardless of what server hosts the
285
- Corresponding Source, you remain obligated to ensure that it is
286
- available for as long as needed to satisfy these requirements.
287
-
288
- e) Convey the object code using peer-to-peer transmission, provided
289
- you inform other peers where the object code and Corresponding
290
- Source of the work are being offered to the general public at no
291
- charge under subsection 6d.
292
-
293
- A separable portion of the object code, whose source code is excluded
294
- from the Corresponding Source as a System Library, need not be
295
- included in conveying the object code work.
296
-
297
- A "User Product" is either (1) a "consumer product", which means any
298
- tangible personal property which is normally used for personal, family,
299
- or household purposes, or (2) anything designed or sold for incorporation
300
- into a dwelling. In determining whether a product is a consumer product,
301
- doubtful cases shall be resolved in favor of coverage. For a particular
302
- product received by a particular user, "normally used" refers to a
303
- typical or common use of that class of product, regardless of the status
304
- of the particular user or of the way in which the particular user
305
- actually uses, or expects or is expected to use, the product. A product
306
- is a consumer product regardless of whether the product has substantial
307
- commercial, industrial or non-consumer uses, unless such uses represent
308
- the only significant mode of use of the product.
309
-
310
- "Installation Information" for a User Product means any methods,
311
- procedures, authorization keys, or other information required to install
312
- and execute modified versions of a covered work in that User Product from
313
- a modified version of its Corresponding Source. The information must
314
- suffice to ensure that the continued functioning of the modified object
315
- code is in no case prevented or interfered with solely because
316
- modification has been made.
317
-
318
- If you convey an object code work under this section in, or with, or
319
- specifically for use in, a User Product, and the conveying occurs as
320
- part of a transaction in which the right of possession and use of the
321
- User Product is transferred to the recipient in perpetuity or for a
322
- fixed term (regardless of how the transaction is characterized), the
323
- Corresponding Source conveyed under this section must be accompanied
324
- by the Installation Information. But this requirement does not apply
325
- if neither you nor any third party retains the ability to install
326
- modified object code on the User Product (for example, the work has
327
- been installed in ROM).
328
-
329
- The requirement to provide Installation Information does not include a
330
- requirement to continue to provide support service, warranty, or updates
331
- for a work that has been modified or installed by the recipient, or for
332
- the User Product in which it has been modified or installed. Access to a
333
- network may be denied when the modification itself materially and
334
- adversely affects the operation of the network or violates the rules and
335
- protocols for communication across the network.
336
-
337
- Corresponding Source conveyed, and Installation Information provided,
338
- in accord with this section must be in a format that is publicly
339
- documented (and with an implementation available to the public in
340
- source code form), and must require no special password or key for
341
- unpacking, reading or copying.
342
-
343
- 7. Additional Terms.
344
-
345
- "Additional permissions" are terms that supplement the terms of this
346
- License by making exceptions from one or more of its conditions.
347
- Additional permissions that are applicable to the entire Program shall
348
- be treated as though they were included in this License, to the extent
349
- that they are valid under applicable law. If additional permissions
350
- apply only to part of the Program, that part may be used separately
351
- under those permissions, but the entire Program remains governed by
352
- this License without regard to the additional permissions.
353
-
354
- When you convey a copy of a covered work, you may at your option
355
- remove any additional permissions from that copy, or from any part of
356
- it. (Additional permissions may be written to require their own
357
- removal in certain cases when you modify the work.) You may place
358
- additional permissions on material, added by you to a covered work,
359
- for which you have or can give appropriate copyright permission.
360
-
361
- Notwithstanding any other provision of this License, for material you
362
- add to a covered work, you may (if authorized by the copyright holders of
363
- that material) supplement the terms of this License with terms:
364
-
365
- a) Disclaiming warranty or limiting liability differently from the
366
- terms of sections 15 and 16 of this License; or
367
-
368
- b) Requiring preservation of specified reasonable legal notices or
369
- author attributions in that material or in the Appropriate Legal
370
- Notices displayed by works containing it; or
371
-
372
- c) Prohibiting misrepresentation of the origin of that material, or
373
- requiring that modified versions of such material be marked in
374
- reasonable ways as different from the original version; or
375
-
376
- d) Limiting the use for publicity purposes of names of licensors or
377
- authors of the material; or
378
-
379
- e) Declining to grant rights under trademark law for use of some
380
- trade names, trademarks, or service marks; or
381
-
382
- f) Requiring indemnification of licensors and authors of that
383
- material by anyone who conveys the material (or modified versions of
384
- it) with contractual assumptions of liability to the recipient, for
385
- any liability that these contractual assumptions directly impose on
386
- those licensors and authors.
387
-
388
- All other non-permissive additional terms are considered "further
389
- restrictions" within the meaning of section 10. If the Program as you
390
- received it, or any part of it, contains a notice stating that it is
391
- governed by this License along with a term that is a further
392
- restriction, you may remove that term. If a license document contains
393
- a further restriction but permits relicensing or conveying under this
394
- License, you may add to a covered work material governed by the terms
395
- of that license document, provided that the further restriction does
396
- not survive such relicensing or conveying.
397
-
398
- If you add terms to a covered work in accord with this section, you
399
- must place, in the relevant source files, a statement of the
400
- additional terms that apply to those files, or a notice indicating
401
- where to find the applicable terms.
402
-
403
- Additional terms, permissive or non-permissive, may be stated in the
404
- form of a separately written license, or stated as exceptions;
405
- the above requirements apply either way.
406
-
407
- 8. Termination.
408
-
409
- You may not propagate or modify a covered work except as expressly
410
- provided under this License. Any attempt otherwise to propagate or
411
- modify it is void, and will automatically terminate your rights under
412
- this License (including any patent licenses granted under the third
413
- paragraph of section 11).
414
-
415
- However, if you cease all violation of this License, then your
416
- license from a particular copyright holder is reinstated (a)
417
- provisionally, unless and until the copyright holder explicitly and
418
- finally terminates your license, and (b) permanently, if the copyright
419
- holder fails to notify you of the violation by some reasonable means
420
- prior to 60 days after the cessation.
421
-
422
- Moreover, your license from a particular copyright holder is
423
- reinstated permanently if the copyright holder notifies you of the
424
- violation by some reasonable means, this is the first time you have
425
- received notice of violation of this License (for any work) from that
426
- copyright holder, and you cure the violation prior to 30 days after
427
- your receipt of the notice.
428
-
429
- Termination of your rights under this section does not terminate the
430
- licenses of parties who have received copies or rights from you under
431
- this License. If your rights have been terminated and not permanently
432
- reinstated, you do not qualify to receive new licenses for the same
433
- material under section 10.
434
-
435
- 9. Acceptance Not Required for Having Copies.
436
-
437
- You are not required to accept this License in order to receive or
438
- run a copy of the Program. Ancillary propagation of a covered work
439
- occurring solely as a consequence of using peer-to-peer transmission
440
- to receive a copy likewise does not require acceptance. However,
441
- nothing other than this License grants you permission to propagate or
442
- modify any covered work. These actions infringe copyright if you do
443
- not accept this License. Therefore, by modifying or propagating a
444
- covered work, you indicate your acceptance of this License to do so.
445
-
446
- 10. Automatic Licensing of Downstream Recipients.
447
-
448
- Each time you convey a covered work, the recipient automatically
449
- receives a license from the original licensors, to run, modify and
450
- propagate that work, subject to this License. You are not responsible
451
- for enforcing compliance by third parties with this License.
452
-
453
- An "entity transaction" is a transaction transferring control of an
454
- organization, or substantially all assets of one, or subdividing an
455
- organization, or merging organizations. If propagation of a covered
456
- work results from an entity transaction, each party to that
457
- transaction who receives a copy of the work also receives whatever
458
- licenses to the work the party's predecessor in interest had or could
459
- give under the previous paragraph, plus a right to possession of the
460
- Corresponding Source of the work from the predecessor in interest, if
461
- the predecessor has it or can get it with reasonable efforts.
462
-
463
- You may not impose any further restrictions on the exercise of the
464
- rights granted or affirmed under this License. For example, you may
465
- not impose a license fee, royalty, or other charge for exercise of
466
- rights granted under this License, and you may not initiate litigation
467
- (including a cross-claim or counterclaim in a lawsuit) alleging that
468
- any patent claim is infringed by making, using, selling, offering for
469
- sale, or importing the Program or any portion of it.
470
-
471
- 11. Patents.
472
-
473
- A "contributor" is a copyright holder who authorizes use under this
474
- License of the Program or a work on which the Program is based. The
475
- work thus licensed is called the contributor's "contributor version".
476
-
477
- A contributor's "essential patent claims" are all patent claims
478
- owned or controlled by the contributor, whether already acquired or
479
- hereafter acquired, that would be infringed by some manner, permitted
480
- by this License, of making, using, or selling its contributor version,
481
- but do not include claims that would be infringed only as a
482
- consequence of further modification of the contributor version. For
483
- purposes of this definition, "control" includes the right to grant
484
- patent sublicenses in a manner consistent with the requirements of
485
- this License.
486
-
487
- Each contributor grants you a non-exclusive, worldwide, royalty-free
488
- patent license under the contributor's essential patent claims, to
489
- make, use, sell, offer for sale, import and otherwise run, modify and
490
- propagate the contents of its contributor version.
491
-
492
- In the following three paragraphs, a "patent license" is any express
493
- agreement or commitment, however denominated, not to enforce a patent
494
- (such as an express permission to practice a patent or covenant not to
495
- sue for patent infringement). To "grant" such a patent license to a
496
- party means to make such an agreement or commitment not to enforce a
497
- patent against the party.
498
-
499
- If you convey a covered work, knowingly relying on a patent license,
500
- and the Corresponding Source of the work is not available for anyone
501
- to copy, free of charge and under the terms of this License, through a
502
- publicly available network server or other readily accessible means,
503
- then you must either (1) cause the Corresponding Source to be so
504
- available, or (2) arrange to deprive yourself of the benefit of the
505
- patent license for this particular work, or (3) arrange, in a manner
506
- consistent with the requirements of this License, to extend the patent
507
- license to downstream recipients. "Knowingly relying" means you have
508
- actual knowledge that, but for the patent license, your conveying the
509
- covered work in a country, or your recipient's use of the covered work
510
- in a country, would infringe one or more identifiable patents in that
511
- country that you have reason to believe are valid.
512
-
513
- If, pursuant to or in connection with a single transaction or
514
- arrangement, you convey, or propagate by procuring conveyance of, a
515
- covered work, and grant a patent license to some of the parties
516
- receiving the covered work authorizing them to use, propagate, modify
517
- or convey a specific copy of the covered work, then the patent license
518
- you grant is automatically extended to all recipients of the covered
519
- work and works based on it.
520
-
521
- A patent license is "discriminatory" if it does not include within
522
- the scope of its coverage, prohibits the exercise of, or is
523
- conditioned on the non-exercise of one or more of the rights that are
524
- specifically granted under this License. You may not convey a covered
525
- work if you are a party to an arrangement with a third party that is
526
- in the business of distributing software, under which you make payment
527
- to the third party based on the extent of your activity of conveying
528
- the work, and under which the third party grants, to any of the
529
- parties who would receive the covered work from you, a discriminatory
530
- patent license (a) in connection with copies of the covered work
531
- conveyed by you (or copies made from those copies), or (b) primarily
532
- for and in connection with specific products or compilations that
533
- contain the covered work, unless you entered into that arrangement,
534
- or that patent license was granted, prior to 28 March 2007.
535
-
536
- Nothing in this License shall be construed as excluding or limiting
537
- any implied license or other defenses to infringement that may
538
- otherwise be available to you under applicable patent law.
539
-
540
- 12. No Surrender of Others' Freedom.
541
-
542
- If conditions are imposed on you (whether by court order, agreement or
543
- otherwise) that contradict the conditions of this License, they do not
544
- excuse you from the conditions of this License. If you cannot convey a
545
- covered work so as to satisfy simultaneously your obligations under this
546
- License and any other pertinent obligations, then as a consequence you may
547
- not convey it at all. For example, if you agree to terms that obligate you
548
- to collect a royalty for further conveying from those to whom you convey
549
- the Program, the only way you could satisfy both those terms and this
550
- License would be to refrain entirely from conveying the Program.
551
-
552
- 13. Use with the GNU Affero General Public License.
553
-
554
- Notwithstanding any other provision of this License, you have
555
- permission to link or combine any covered work with a work licensed
556
- under version 3 of the GNU Affero General Public License into a single
557
- combined work, and to convey the resulting work. The terms of this
558
- License will continue to apply to the part which is the covered work,
559
- but the special requirements of the GNU Affero General Public License,
560
- section 13, concerning interaction through a network will apply to the
561
- combination as such.
562
-
563
- 14. Revised Versions of this License.
564
-
565
- The Free Software Foundation may publish revised and/or new versions of
566
- the GNU General Public License from time to time. Such new versions will
567
- be similar in spirit to the present version, but may differ in detail to
568
- address new problems or concerns.
569
-
570
- Each version is given a distinguishing version number. If the
571
- Program specifies that a certain numbered version of the GNU General
572
- Public License "or any later version" applies to it, you have the
573
- option of following the terms and conditions either of that numbered
574
- version or of any later version published by the Free Software
575
- Foundation. If the Program does not specify a version number of the
576
- GNU General Public License, you may choose any version ever published
577
- by the Free Software Foundation.
578
-
579
- If the Program specifies that a proxy can decide which future
580
- versions of the GNU General Public License can be used, that proxy's
581
- public statement of acceptance of a version permanently authorizes you
582
- to choose that version for the Program.
583
-
584
- Later license versions may give you additional or different
585
- permissions. However, no additional obligations are imposed on any
586
- author or copyright holder as a result of your choosing to follow a
587
- later version.
588
-
589
- 15. Disclaimer of Warranty.
590
-
591
- THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592
- APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593
- HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594
- OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595
- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596
- PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597
- IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598
- ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599
-
600
- 16. Limitation of Liability.
601
-
602
- IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603
- WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604
- THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605
- GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606
- USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607
- DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608
- PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609
- EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610
- SUCH DAMAGES.
611
-
612
- 17. Interpretation of Sections 15 and 16.
613
-
614
- If the disclaimer of warranty and limitation of liability provided
615
- above cannot be given local legal effect according to their terms,
616
- reviewing courts shall apply local law that most closely approximates
617
- an absolute waiver of all civil liability in connection with the
618
- Program, unless a warranty or assumption of liability accompanies a
619
- copy of the Program in return for a fee.
620
-
621
- END OF TERMS AND CONDITIONS
622
-
623
- How to Apply These Terms to Your New Programs
624
-
625
- If you develop a new program, and you want it to be of the greatest
626
- possible use to the public, the best way to achieve this is to make it
627
- free software which everyone can redistribute and change under these terms.
628
-
629
- To do so, attach the following notices to the program. It is safest
630
- to attach them to the start of each source file to most effectively
631
- state the exclusion of warranty; and each file should have at least
632
- the "copyright" line and a pointer to where the full notice is found.
633
-
634
- <one line to give the program's name and a brief idea of what it does.>
635
- Copyright (C) <year> <name of author>
636
-
637
- This program is free software: you can redistribute it and/or modify
638
- it under the terms of the GNU General Public License as published by
639
- the Free Software Foundation, either version 3 of the License, or
640
- (at your option) any later version.
641
-
642
- This program is distributed in the hope that it will be useful,
643
- but WITHOUT ANY WARRANTY; without even the implied warranty of
644
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645
- GNU General Public License for more details.
646
-
647
- You should have received a copy of the GNU General Public License
648
- along with this program. If not, see <https://www.gnu.org/licenses/>.
649
-
650
- Also add information on how to contact you by electronic and paper mail.
651
-
652
- If the program does terminal interaction, make it output a short
653
- notice like this when it starts in an interactive mode:
654
-
655
- <program> Copyright (C) <year> <name of author>
656
- This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657
- This is free software, and you are welcome to redistribute it
658
- under certain conditions; type `show c' for details.
659
-
660
- The hypothetical commands `show w' and `show c' should show the appropriate
661
- parts of the General Public License. Of course, your program's commands
662
- might be different; for a GUI interface, you would use an "about box".
663
-
664
- You should also get your employer (if you work as a programmer) or school,
665
- if any, to sign a "copyright disclaimer" for the program, if necessary.
666
- For more information on this, and how to apply and follow the GNU GPL, see
667
- <https://www.gnu.org/licenses/>.
668
-
669
- The GNU General Public License does not permit incorporating your program
670
- into proprietary programs. If your program is a subroutine library, you
671
- may consider it more useful to permit linking proprietary applications with
672
- the library. If this is what you want to do, use the GNU Lesser General
673
- Public License instead of this License. But first, please read
674
- <https://www.gnu.org/licenses/why-not-lgpl.html>.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/templates/template_1.php CHANGED
@@ -116,15 +116,6 @@ $admin_phone = get_user_meta( $uid, 'billing_phone', true );
116
  width: 100% !important;
117
  }
118
  }
119
- </style></p><p><style type="text/css">
120
- @media only screen and (max-width:480px) {
121
- @-ms-viewport {
122
- width: 320px;
123
- }
124
- @viewport {
125
- width: 320px;
126
- }
127
- }
128
  </style></p><p><style type="text/css">
129
  @import url(https://fonts.googleapis.com/css?family=Lato);
130
  @import url(https://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700);
116
  width: 100% !important;
117
  }
118
  }
 
 
 
 
 
 
 
 
 
119
  </style></p><p><style type="text/css">
120
  @import url(https://fonts.googleapis.com/css?family=Lato);
121
  @import url(https://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700);
readme.txt CHANGED
@@ -4,7 +4,7 @@ Contributors: ashokrane, pinal.shah, bhavik.kiri, chetnapatel, tychesoftwares, d
4
  Tags: cart abandonment, abandon cart, cart recovery, recover woocommerce cart, increase woocommerce conversion rate, increase sales with woocommerce
5
  Author URI: https://www.tychesoftwares.com/
6
  Requires at least: 1.3
7
- Tested up to: 5.7
8
  Stable tag: trunk
9
  Requires PHP: 5.6
10
  License: GPLv2 or late
@@ -222,6 +222,15 @@ The admin can use the merge code `{{cart.unsubscribe}}' in the email templates.
222
  6. Product Report Tab.
223
 
224
  == Changelog ==
 
 
 
 
 
 
 
 
 
225
  = 5.8.8 (06.04.2021) =
226
  * Enhancement - Introduced Abandoned & Recovered Cart data graph in the plugin dashboard.
227
  * Tweak - Updated the Pro settings to reflect the new settings included in the Pro Version.
4
  Tags: cart abandonment, abandon cart, cart recovery, recover woocommerce cart, increase woocommerce conversion rate, increase sales with woocommerce
5
  Author URI: https://www.tychesoftwares.com/
6
  Requires at least: 1.3
7
+ Tested up to: 5.8
8
  Stable tag: trunk
9
  Requires PHP: 5.6
10
  License: GPLv2 or late
222
  6. Product Report Tab.
223
 
224
  == Changelog ==
225
+ = 5.9.0 (26.07.2021) =
226
+ * Enhancement - Introduced UTM tags to be added to reminder email links to help with Google Analytics.
227
+ * Tweak - Added a filter to hide SKU in reminder emails.
228
+ * Tweak - Removed the Action Scheduler library from the plugin. The plugin will now use the library from WooCommerce.
229
+ * Tweak - The test email field will now be pre-populated with the email address of the logged-in user.
230
+ * Fix - Made the plugin compatible with PHP 8.0
231
+ * Fix - No reminder emails were being sent to WC orders with the status Pending Payment and Failed.
232
+ * Fix - Undefined was displayed for cart status when clicking on View Details in the Abandoned Orders page. This was later replaced by valid cart status.
233
+
234
  = 5.8.8 (06.04.2021) =
235
  * Enhancement - Introduced Abandoned & Recovered Cart data graph in the plugin dashboard.
236
  * Tweak - Updated the Pro settings to reflect the new settings included in the Pro Version.
woocommerce-ac.php CHANGED
@@ -3,14 +3,14 @@
3
  * Plugin Name: Abandoned Cart Lite for WooCommerce
4
  * Plugin URI: http://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro
5
  * Description: This plugin captures abandoned carts by logged-in users & emails them about it. <strong><a href="http://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro">Click here to get the PRO Version.</a></strong>
6
- * Version: 5.8.8
7
  * Author: Tyche Softwares
8
  * Author URI: http://www.tychesoftwares.com/
9
  * Text Domain: woocommerce-abandoned-cart
10
  * Domain Path: /i18n/languages/
11
  * Requires PHP: 5.6
12
  * WC requires at least: 3.0.0
13
- * WC tested up to: 5.1.0
14
  *
15
  * @package Abandoned-Cart-Lite-for-WooCommerce
16
  */
@@ -118,7 +118,7 @@ if ( ! class_exists( 'woocommerce_abandon_cart_lite' ) ) {
118
  }
119
 
120
  if ( ! defined( 'WCAL_PLUGIN_VERSION' ) ) {
121
- define( 'WCAL_PLUGIN_VERSION', '5.8.8' );
122
  }
123
 
124
  if ( ! defined( 'WCAL_PLUGIN_PATH' ) ) {
@@ -176,7 +176,11 @@ if ( ! class_exists( 'woocommerce_abandon_cart_lite' ) ) {
176
  register_deactivation_hook( __FILE__, array( &$this, 'wcal_deactivate' ) );
177
 
178
  // Action Scheduler for Cron.
179
- require_once 'includes/libraries/action-scheduler/action-scheduler.php';
 
 
 
 
180
  add_action( 'init', array( &$this, 'wcal_add_scheduled_action' ) );
181
  require_once 'cron/class-wcal-cron.php';
182
  require_once 'includes/class-wcal-process-base.php';
@@ -247,13 +251,33 @@ if ( ! class_exists( 'woocommerce_abandon_cart_lite' ) ) {
247
  include_once 'includes/frontend/class-wcal-frontend.php';
248
  }
249
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
250
  /**
251
  * Add Recurring Scheduled Action.
252
  */
253
  public static function wcal_add_scheduled_action() {
254
- if ( false === as_next_scheduled_action( 'woocommerce_ac_send_email_action' ) ) {
255
- wp_clear_scheduled_hook( 'woocommerce_ac_send_email_action' ); // Remove the cron job is present.
256
- as_schedule_recurring_action( time() + 60, 900, 'woocommerce_ac_send_email_action' ); // Schedule recurring action.
 
 
257
  }
258
  }
259
 
@@ -829,6 +853,15 @@ if ( ! class_exists( 'woocommerce_abandon_cart_lite' ) ) {
829
  array( 'When a contact receives your email and clicks reply, which email address should that reply be sent to?', 'woocommerce-abandoned-cart' )
830
  );
831
 
 
 
 
 
 
 
 
 
 
832
  // Finally, we register the fields with WordPress.
833
  register_setting(
834
  'woocommerce_ac_settings',
@@ -890,6 +923,11 @@ if ( ! class_exists( 'woocommerce_abandon_cart_lite' ) ) {
890
  'wcal_reply_email'
891
  );
892
 
 
 
 
 
 
893
  do_action( 'wcal_add_new_settings' );
894
  }
895
 
@@ -1190,6 +1228,23 @@ if ( ! class_exists( 'woocommerce_abandon_cart_lite' ) ) {
1190
  echo wp_kses_post( $html );
1191
  }
1192
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1193
  /**
1194
  * Add a submenu page under the WooCommerce.
1195
  *
@@ -3449,7 +3504,11 @@ if ( ! class_exists( 'woocommerce_abandon_cart_lite' ) ) {
3449
  <label for="woocommerce_ac_email_preview"><b><?php esc_html_e( 'Send a test email to:', 'woocommerce-abandoned-cart' ); ?></b></label>
3450
  </th>
3451
  <td>
3452
- <input type="text" id="send_test_email" name="send_test_email" class="regular-text" >
 
 
 
 
3453
  <input type="button" value="Send a test email" id="preview_email" onclick="javascript:void(0);">
3454
  <img class="help_tip" width="16" height="16" data-tip='<?php esc_html_e( 'Enter the email id to which the test email needs to be sent.', 'woocommerce-abandoned-cart' ); ?>' src="<?php echo esc_url( WC()->plugin_url() ); ?>/assets/images/help.png" />
3455
  <br>
3
  * Plugin Name: Abandoned Cart Lite for WooCommerce
4
  * Plugin URI: http://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro
5
  * Description: This plugin captures abandoned carts by logged-in users & emails them about it. <strong><a href="http://www.tychesoftwares.com/store/premium-plugins/woocommerce-abandoned-cart-pro">Click here to get the PRO Version.</a></strong>
6
+ * Version: 5.9.0
7
  * Author: Tyche Softwares
8
  * Author URI: http://www.tychesoftwares.com/
9
  * Text Domain: woocommerce-abandoned-cart
10
  * Domain Path: /i18n/languages/
11
  * Requires PHP: 5.6
12
  * WC requires at least: 3.0.0
13
+ * WC tested up to: 5.5.2
14
  *
15
  * @package Abandoned-Cart-Lite-for-WooCommerce
16
  */
118
  }
119
 
120
  if ( ! defined( 'WCAL_PLUGIN_VERSION' ) ) {
121
+ define( 'WCAL_PLUGIN_VERSION', '5.9.0' );
122
  }
123
 
124
  if ( ! defined( 'WCAL_PLUGIN_PATH' ) ) {
176
  register_deactivation_hook( __FILE__, array( &$this, 'wcal_deactivate' ) );
177
 
178
  // Action Scheduler for Cron.
179
+ if ( file_exists( WP_PLUGIN_DIR . '/woocommerce/packages/action-scheduler/action-scheduler.php' ) ) {
180
+ require_once WP_PLUGIN_DIR . '/woocommerce/packages/action-scheduler/action-scheduler.php';
181
+ } else {
182
+ add_action( 'admin_notices', array( &$this, 'wcal_as_failed_notice' ) );
183
+ }
184
  add_action( 'init', array( &$this, 'wcal_add_scheduled_action' ) );
185
  require_once 'cron/class-wcal-cron.php';
186
  require_once 'includes/class-wcal-process-base.php';
251
  include_once 'includes/frontend/class-wcal-frontend.php';
252
  }
253
 
254
+ /**
255
+ * Action Scheduler library load failed. So add an admin notice.
256
+ *
257
+ * @since 5.9.0
258
+ */
259
+ public static function wcal_as_failed_notice() {
260
+ $as_link = "<a href='https://www.tychesoftwares.com/moving-to-the-action-scheduler-library/' target='_blank'>Action Scheduler library</a>";
261
+ ?>
262
+ <div class="notice notice-error">
263
+ <p>
264
+ <?php
265
+ echo wp_kses_post( __( "Abandoned Cart Lite for WooCommerce was unable to load the $as_link. Please ensure you are running WooCommerce 4.0.0 or higher to send automated reminder emails. Currrently no automated reminder emails are being sent for abandoned carts.", 'woocommerce-abandoned-cart' ) ); // phpcs:ignore
266
+ ?>
267
+ </p>
268
+ </div>
269
+ <?php
270
+ }
271
+
272
  /**
273
  * Add Recurring Scheduled Action.
274
  */
275
  public static function wcal_add_scheduled_action() {
276
+ if ( function_exists( 'as_next_scheduled_action' ) ) {
277
+ if ( false === as_next_scheduled_action( 'woocommerce_ac_send_email_action' ) ) {
278
+ wp_clear_scheduled_hook( 'woocommerce_ac_send_email_action' ); // Remove the cron job is present.
279
+ as_schedule_recurring_action( time() + 60, 900, 'woocommerce_ac_send_email_action' ); // Schedule recurring action.
280
+ }
281
  }
282
  }
283
 
853
  array( 'When a contact receives your email and clicks reply, which email address should that reply be sent to?', 'woocommerce-abandoned-cart' )
854
  );
855
 
856
+ add_settings_field(
857
+ 'wcal_add_utm_to_links',
858
+ __( 'UTM parameters to be added to all the links in reminder emails', 'woocommerce-ac' ),
859
+ array( &$this, 'wcal_add_utm_to_links_callback' ),
860
+ 'woocommerce_ac_email_page',
861
+ 'ac_email_settings_section',
862
+ array( __( 'UTM parameters that should be added to all the links in reminder emails.', 'woocommerce-ac' ) )
863
+ );
864
+
865
  // Finally, we register the fields with WordPress.
866
  register_setting(
867
  'woocommerce_ac_settings',
923
  'wcal_reply_email'
924
  );
925
 
926
+ register_setting(
927
+ 'woocommerce_ac_email_settings',
928
+ 'wcal_add_utm_to_links'
929
+ );
930
+
931
  do_action( 'wcal_add_new_settings' );
932
  }
933
 
1228
  echo wp_kses_post( $html );
1229
  }
1230
 
1231
+ /**
1232
+ * Callback for UTM parameters.
1233
+ *
1234
+ * @param array $args - Arguments for the setting.
1235
+ * @since 5.9.0
1236
+ */
1237
+ public static function wcal_add_utm_to_links_callback( $args ) {
1238
+
1239
+ $wcal_add_utm_to_links = get_option( 'wcal_add_utm_to_links', '' );
1240
+
1241
+ ?>
1242
+ <textarea id='wcal_add_utm_to_links' rows='4' cols='50' name='wcal_add_utm_to_links' ><?php echo esc_html( $wcal_add_utm_to_links ); ?></textarea>
1243
+ <?php
1244
+ $html = '<label for="wcal_add_utm_to_links">' . $args[0] . '</label>';
1245
+ echo wp_kses_post( $html );
1246
+ }
1247
+
1248
  /**
1249
  * Add a submenu page under the WooCommerce.
1250
  *
3504
  <label for="woocommerce_ac_email_preview"><b><?php esc_html_e( 'Send a test email to:', 'woocommerce-abandoned-cart' ); ?></b></label>
3505
  </th>
3506
  <td>
3507
+ <?php
3508
+ $user = wp_get_current_user();
3509
+ $admin_email = isset( $user->user_email ) ? $user->user_email : '';
3510
+ ?>
3511
+ <input type="text" id="send_test_email" name="send_test_email" class="regular-text" value="<?php echo esc_attr( $admin_email ); ?>" >
3512
  <input type="button" value="Send a test email" id="preview_email" onclick="javascript:void(0);">
3513
  <img class="help_tip" width="16" height="16" data-tip='<?php esc_html_e( 'Enter the email id to which the test email needs to be sent.', 'woocommerce-abandoned-cart' ); ?>' src="<?php echo esc_url( WC()->plugin_url() ); ?>/assets/images/help.png" />
3514
  <br>