Skip to content

Commit

Permalink
Check for is_not_in_the_last when workflow has never run
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoJunkie committed Jan 23, 2025
1 parent 2d3d624 commit d0451e8
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 6 deletions.
2 changes: 0 additions & 2 deletions automatewoo-workflow-rule-last-run-date.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@
exit; // Exit if accessed directly
}

error_log( 'automatewoo-workflow-rule-last-run-date.php loaded' );
add_filter( 'automatewoo/rules/includes', 'to51_automatewoo_workflow_last_run_rules' );

/**
* @param array $rules
* @return array
*/
function to51_automatewoo_workflow_last_run_rules( $rules ) {
error_log( 'to51_automatewoo_workflow_last_run_rules' );
$rules['workflow_last_run_date'] = dirname( __FILE__ ) . '/includes/class-workflow-last-run-date.php';
return $rules;
}
5 changes: 1 addition & 4 deletions includes/class-workflow-last-run-date.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public function init() {
*/
public function validate( $data_item, $compare, $value = null ) {
$workflow = $this->get_workflow();

if ( ! $workflow ) {
return false;
}
Expand All @@ -52,11 +51,9 @@ public function validate( $data_item, $compare, $value = null ) {
$query->where_workflow( $workflow->get_id() );
$query->set_limit( 1 );
$query->set_ordering( 'date', 'DESC' );

$logs = $query->get_results();

if ( empty( $logs ) ) {
return $compare === 'is_not_set';
return $compare === 'is_not_set' || $compare === 'is_not_in_the_last';
}

return $this->validate_date( $compare, $value, $logs[0]->get_date() );
Expand Down

0 comments on commit d0451e8

Please sign in to comment.