1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106:
<?php
if ( !class_exists( 'Inbound_Automation_Action_Kill_Tasks' ) ) {
class Inbound_Automation_Action_Kill_Tasks {
function __construct() {
add_filter( 'inbound_automation_actions' , array( __CLASS__ , 'define_action' ) , 1 , 1);
}
public static function define_action( $actions ) {
$rules_array = Inbound_Automation_Post_Type::get_rules_as_array();
$actions['kill_lead_tasks'] = array (
'class_name' => get_class(),
'id' => 'kill_lead_tasks',
'label' => __('Terminate Email Series for Lead' , 'inbound-pro'),
'description' => __('If this action fires we will look for all email series tasks targeting a lead email and cancel them.', 'inbound-pro'),
'settings' => array (
array (
'id' => 'cancel_criteria',
'label' => __( 'Cancel Options' , 'inbound-pro' ),
'type' => 'dropdown',
'description' => __( 'Select whether to terminate automation jobs related to this lead for all current running jobs or pertaining to a specific rule id' , 'inbound-pro' ),
'options' => array(
'all_tasks' => __( 'All jobs targeting this lead.' , 'inbound-pro' ),
'specific_rule' => __( 'Jobs targeting this lead belonging to a specific rule' , 'inbound-pro' )
)
),
array (
'id' => 'target_rule_id',
'label' => __( 'Rule:' , 'inbound-pro' ),
'type' => 'dropdown',
'hidden' => true,
'description' => __( 'Select the rule we want to terminate jobs related to this lead.' , 'inbound-pro' ),
'reveal' => array(
'selector' => 'cancel_criteria',
'value' => 'specific_rule'
),
'options' => $rules_array
)
)
);
return $actions;
}
public static function run_action( $action , $trigger_data ) {
global $wpdb;
$table_name = $wpdb->prefix . "inbound_automation_queue";
$trigger_data = apply_filters( 'action/kill_lead_taks/trigger_data' , $trigger_data );
$response = array();
switch ($action['cancel_criteria']) {
case 'all_tasks':
$wpdb->query("DELETE FROM $table_name WHERE `trigger_data` LIKE '%{$trigger_data['lead_data']['email']}%' AND `tasks` LIKE '%send_email%'");
BREAK;
case 'specific_rule':
$wpdb->query("DELETE FROM $table_name WHERE `trigger_data` LIKE '%{$trigger_data['lead_data']['email']}%' AND `tasks` LIKE '%send_email%' AND `rule_id` = '{$action['target_rule_id']}'");
error_log("DELETE FROM $table_name WHERE `trigger_data` LIKE '%{$trigger_data['lead_data']['email']}%' AND `tasks` LIKE '%send_email%' AND `rule_id` = '{$action['target_rule_id']}'");
BREAK;
}
inbound_record_log(
__( 'Terminate Email Series' , 'inbound-pro') ,
'<h2>'.__('Total Deleted', 'inbound-pro') .'</h2><pre>'.$wpdb->insert_id.'</pre>' .
'<h2>'.__('Action Settings' , 'inbound-pro') .'</h2><pre>'. print_r($action,true).'</pre><h2>'.__('Action Settings' , 'inbound-pro') .'</h2><pre>'.print_r($trigger_data,true) .'</pre>',
$action['rule_id'] ,
$action['job_id'] ,
'action_event'
);
}
}
new Inbound_Automation_Action_Kill_Tasks();
}