-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
115 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,22 @@ | ||
# automatewoo-workflow-rule-last-run-date | ||
| :exclamation: This is a public repository | | ||
|--------------------------------------------| | ||
|
||
# AutomateWoo Workflow Rule - Last Run Date | ||
|
||
Extends the functionality of AutomateWoo with a custom "Workflow" rule which checks the last time a workflow ran. | ||
|
||
## Usage | ||
|
||
This works similarly to the [AutomateWoo "Workflow – Last Run Date For Customer" rule](https://woocommerce.com/document/automatewoo/rules/list/#section-4), except it checks for when the workflow ran at all, not just for a particular customer. Input your the timeframe to check against. If the workflow ran within the defined timeframe, it will return true. | ||
|
||
Tips: | ||
- Is available for any trigger, since it doesn't use a specific order or subscription object | ||
|
||
 | ||
|
||
## Support | ||
|
||
This plugin is provided without any support or guarantees of functionality. If you'd like to contribute, feel free to open a PR on this repo. If you have a request, please open an issue. | ||
|
||
> [!WARNING] | ||
> Please test thoroughly before deploying to a production site. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
/* | ||
* Plugin Name: AutomateWoo Workflow Rule - Last Run Date | ||
* Plugin URI: https://github.com/a8cteam51/automatewoo-workflow-rule-last-run-date | ||
* Description: Extends the functionality of AutomateWoo with a custom rule which checks when a workflow last ran | ||
* Version: 1.0.0 | ||
* Author: WP Special Projects | ||
* Author URI: https://wpspecialprojects.wordpress.com/ | ||
* License: GPL v2 or later | ||
*/ | ||
|
||
if ( ! defined( 'ABSPATH' ) ) { | ||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace AutomateWoo\Rules; | ||
|
||
defined( 'ABSPATH' ) || exit; | ||
|
||
/** | ||
* Rule to check when workflow last ran. | ||
*/ | ||
class Workflow_Last_Run_Date extends Abstract_Date { | ||
|
||
/** | ||
* What data we're using to validate. | ||
* | ||
* @var string | ||
*/ | ||
public $data_item = 'shop'; | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
public function __construct() { | ||
$this->has_is_past_comparision = true; | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Init. | ||
*/ | ||
public function init() { | ||
$this->title = __( 'Workflow - Last Run Date', 'automatewoo' ); | ||
} | ||
|
||
/** | ||
* Validates rule. | ||
* | ||
* @param mixed $data_item The data item passed by the trigger (unused). | ||
* @param string $compare The type of comparison. | ||
* @param mixed $value The values we have to compare. Null is allowed when $compare is is_not_set. | ||
* | ||
* @return bool | ||
*/ | ||
public function validate( $data_item, $compare, $value = null ) { | ||
$workflow = $this->get_workflow(); | ||
|
||
if ( ! $workflow ) { | ||
return false; | ||
} | ||
|
||
// Query the most recent log entry | ||
$query = new \AutomateWoo\Log_Query(); | ||
$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 $this->validate_date( $compare, $value, $logs[0]->get_date() ); | ||
} | ||
} | ||
|
||
return new Workflow_Last_Run_Date(); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.