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: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253:
<?php
class Inbound_Automation_Activation {
public static function activate() {
if (!get_option('inbound_activate_automation' , false) ) {
return;
}
self::store_version_data();
self::set_default_settings();
self::activate_shared();
self::create_automation_queue_table();
self::run_updates();
do_action('activate/automation');
delete_option('inbound_activate_automation');
}
public static function run_updates() {
$updaters = get_class_methods('Inbound_Automation_Activation_Update_Routines');
if (!$updaters) {
return;
}
$completed = ( get_option( 'ma_completed_upgrade_routines' ) ) ? get_option( 'ma_completed_upgrade_routines' ) : array();
$remaining = array_diff( $updaters , $completed );
foreach ( $remaining as $updater ) {
Inbound_Automation_Activation_Update_Routines::$updater();
$completed[] = $updater;
}
update_option( 'ma_completed_upgrade_routines' , $completed );
}
public static function run_upgrade_routine_checks() {
if (isset($_GET['plugin_action']) && $_GET['plugin_action'] == 'upgrade_routines' && $_GET['plugin'] =='marketing-automation' ) {
self::run_updates();
wp_redirect(admin_url('edit.php?post_type=automation'));
exit;
}
$updaters = get_class_methods('Inbound_Automation_Activation_Update_Routines');
if (!$updaters) {
return;
}
$completed = ( get_option( 'ma_completed_upgrade_routines' ) ) ? get_option( 'ma_completed_upgrade_routines' ) : array();
$remaining = array_diff( $updaters , $completed );
if (count($remaining)>0) {
add_action( 'admin_notices', array( __CLASS__ , 'display_upgrade_routine_notice' ) );
}
}
public static function display_upgrade_routine_notice() {
?>
<div class="error">
<p><?php _e( 'We\'ve noticed that <strong>Automation Component</strong> requires a <strong>database upgrade</strong>. Please click the following link:', 'inbound-pro' ); ?> <a href='?plugin=marketing-automation&plugin_action=upgrade_routines'><?php _e('Run Upgrade Processes' , 'inbound-pro' ); ?></a></p>
</div>
<?php
}
public static function store_version_data() {
$old = get_transient('automation_current_version');
set_transient( 'automation_previous_version' , $old );
set_transient( 'automation_current_version' , INBOUND_AUTOMATION_CURRENT_VERSION );
}
public static function set_default_settings() {
}
public static function activate_shared() {
set_transient( 'Inbound_Activate', true );
}
public static function abort_activation( $args ) {
echo $args['title'] . '<br>';
echo $args['message'] . '<br>';
echo 'Details:<br>';
print_r ($args['details']);
echo '<br>';
echo $args['solution'];
deactivate_plugins( WP_CTA_FILE );
exit;
}
public static function create_automation_queue_table() {
global $wpdb;
$table_name = $wpdb->prefix . "inbound_automation_queue";
$charset_collate = '';
if ( ! empty( $wpdb->charset ) ) {
$charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}";
}
if ( ! empty( $wpdb->collate ) ) {
$charset_collate .= " COLLATE {$wpdb->collate}";
}
$sql = "CREATE TABLE IF NOT EXISTS $table_name (
`id` BIGINT(9) NOT NULL AUTO_INCREMENT,
`rule_id` varchar(255) NOT NULL,
`lead_id` varchar(255) NOT NULL,
`tasks` text NOT NULL,
`trigger_data` text NOT NULL,
`datetime` datetime NOT NULL,
`status` varchar(255) NOT NULL,
UNIQUE KEY id (id)
) $charset_collate;";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql );
}
public static function run_version_checks() {
global $wp_version;
if ( version_compare( phpversion(), self::$version_php, '<' ) ) {
self::abort_activation(
array(
'title' => 'Installation aborted',
'message' => __('Calls to Action plugin could not be installed' , 'landing-pages'),
'details' => array(
__( 'Server PHP Version' , 'landing-pages' ) => phpversion(),
__( 'Required PHP Version' , 'landing-pages' ) => self::$version_php
),
'solultion' => sprintf( __( 'Please contact your hosting provider to upgrade PHP to %s or greater' , 'landing-pages' ) , self::$version_php )
)
);
}
if ( version_compare( $wp_version , self::$version_wp, '<' ) ) {
self::abort_activation( array(
'title' => 'Installation aborted',
'message' => __('Calls to Action plugin could not be installed' , 'landing-pages'),
'details' => array(
__( 'WordPress Version' , 'landing-pages' ) => $wp_version,
__( 'Required WordPress Version' , 'landing-pages' ) => self::$version_wp
),
'solultion' => sprintf( __( 'Please update landing pages to version %s or greater.' , 'landing-pages' ) , self::$version_wp )
)
);
}
if ( defined('LANDINGPAGES_CURRENT_VERSION') && version_compare( LANDINGPAGES_CURRENT_VERSION , self::$version_lp , '<' ) ) {
self::abort_activation( array(
'title' => 'Installation aborted',
'message' => __('Calls to Action plugin could not be installed' , 'landing-pages'),
'details' => array(
__( 'Calls to Action Version' , 'landing-pages' ) => LANDINGPAGES_CURRENT_VERSION,
__( 'Required Calls to Action Version' , 'landing-pages' ) => self::$version_lp
),
'solultion' => sprintf( __( 'Please update Calls to Action to version %s or greater.' , 'landing-pages' ) , self::$version_lp )
)
);
}
if ( defined('WPL_CURRENT_VERSION') && version_compare( WPL_CURRENT_VERSION , self::$version_leads , '<' ) ) {
self::abort_activation( array(
'title' => 'Installation aborted',
'message' => __('Calls to Action plugin could not be installed' , 'landing-pages'),
'details' => array(
__( 'Leads Version' , 'landing-pages' ) => WPL_CURRENT_VERSION,
__( 'Required Leads Version' , 'landing-pages' ) => self::$version_leads
),
'solultion' => sprintf( __( 'Please update Leads to version %s or greater.' , 'landing-pages' ) , self::$version_leads )
)
);
}
}
}
add_action( 'admin_init' , array( 'Inbound_Automation_Activation' , 'run_upgrade_routine_checks' ) );
add_action( 'admin_init' , array( 'Inbound_Automation_Activation' , 'activate' ) );