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: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358:
<?php
if ( !class_exists('Inbound_Upgrade_Routines') ) {
class Inbound_Upgrade_Routines {
static $routines;
static $past_version;
static $current_version;
public static function load() {
self::define_routines();
self::load_routines();
}
public static function add_update_check() {
self::set_versions( array('scope'=>'shared') );
if ( self::$past_version != self::$current_version ) {
self::load();
}
}
public static function define_routines() {
self::$routines['page-views-table-1'] = array(
'id' => 'page-views-table-1',
'scope' => 'shared',
'introduced' => '2.0.2',
'callback' => array( __CLASS__ , 'alter_page_views_table')
);
self::$routines['events-table-1'] = array(
'id' => 'events-table-1',
'scope' => 'shared',
'introduced' => '1.0.2',
'callback' => array( __CLASS__ , 'alter_events_table_1')
);
self::$routines['events-table-2'] = array(
'id' => 'events-table-2',
'scope' => 'shared',
'introduced' => '1.0.5',
'callback' => array( __CLASS__ , 'alter_events_table_1_0_5')
);
self::$routines['events-table-3'] = array(
'id' => 'events-table-3',
'scope' => 'shared',
'introduced' => '1.0.8',
'callback' => array( __CLASS__ , 'alter_events_table_1_0_8')
);
self::$routines['automation-queue-table-1'] = array(
'id' => 'automation-queue-table-1',
'scope' => 'shared',
'introduced' => '1.0.3',
'callback' => array( __CLASS__ , 'alter_automation_queue_table_1')
);
self::$routines['events-pageviews-107'] = array(
'id' => 'events-pageviews-107',
'scope' => 'shared',
'introduced' => '1.0.7',
'callback' => array( __CLASS__ , 'alter_events_pageviews_107')
);
self::$routines['inbound-settings-109'] = array(
'id' => 'inbound-settings-109',
'scope' => 'shared',
'introduced' => '1.0.9',
'callback' => array( __CLASS__ , 'alter_inbound_settings_109')
);
self::$routines['inbound-settings-203'] = array(
'id' => 'inbound-settings-203',
'scope' => 'shared',
'introduced' => '2.0.3',
'callback' => array( __CLASS__ , 'alter_inbound_settings_203')
);
}
public static function load_routines() {
self::$routines = apply_filters( 'inbound-pro/upgrade-routines' , self::$routines);
foreach (self::$routines as $routine) {
self::set_versions($routine);
if (
self::$past_version
&&
!version_compare( self::$past_version , $routine['introduced'] , '<')
&&
!isset($_GET['force_upgrade_routines'])
) {
continue;
}
call_user_func(array($routine['callback'][0] , $routine['callback'][1]) );
}
update_option('inbound_shared_version' , INBOUNDNOW_SHARED_DBRV , false);
}
public static function set_versions( $routine ) {
switch($routine['scope']) {
case 'shared':
self::$past_version = get_option('inbound_shared_version');
self::$current_version = INBOUNDNOW_SHARED_DBRV;
break;
case 'leads':
self::$past_version = get_transient('leads_shared_version');
self::$current_version = WPL_CURRENT_VERSION;
break;
case 'landing-pages':
self::$past_version = get_transient('lp_current_version');
self::$current_version = LANDINGPAGES_CURRENT_VERSION;
break;
case 'cta':
self::$past_version = get_transient('cta_current_version');
self::$current_version = WP_CTA_CURRENT_VERSION;
break;
}
}
public static function alter_page_views_table() {
global $wpdb;
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
$table_name = $wpdb->prefix . "inbound_page_views";
$col_check = $wpdb->get_row("SELECT * FROM " . $table_name ." limit 1");
if(!isset($col_check->ip)) {
$wpdb->get_results("ALTER TABLE {$table_name} ADD `ip` VARCHAR(45) NOT NULL");
} else {
$wpdb->get_results( "ALTER TABLE {$table_name} MODIFY COLUMN `ip` VARCHAR(45)" );
}
if(!isset($col_check->cta_id)) {
$wpdb->get_results("ALTER TABLE {$table_name} ADD `cta_id` VARCHAR(20) NOT NULL");
} else {
$wpdb->get_results( "ALTER TABLE {$table_name} MODIFY COLUMN `cta_id` VARCHAR(20)" );
}
}
public static function alter_events_table_1() {
global $wpdb;
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
$table_name = $wpdb->prefix . "inbound_events";
$col_check = $wpdb->get_row("SELECT * FROM " . $table_name ." limit 1");
if(!isset($col_check->funnel)) {
$wpdb->get_results("ALTER TABLE {$table_name} ADD `funnel` text NOT NULL");
}
if(!isset($col_check->source)) {
$wpdb->get_results("ALTER TABLE {$table_name} ADD `source` text NOT NULL");
}
if(!isset($col_check->list_id)) {
$wpdb->get_results("ALTER TABLE {$table_name} ADD `list_id` bigint(20) NOT NULL");
}
}
public static function alter_events_table_1_0_5() {
global $wpdb;
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
$table_name = $wpdb->prefix . "inbound_events";
$col_check = $wpdb->get_row("SELECT * FROM " . $table_name ." limit 1");
if(!isset($col_check->rule_id)) {
$wpdb->get_results("ALTER TABLE {$table_name} ADD `rule_id` bigint(20) NOT NULL");
}
if(!isset($col_check->job_id)) {
$wpdb->get_results("ALTER TABLE {$table_name} ADD `job_id` bigint(20) NOT NULL");
}
}
public static function alter_events_table_1_0_8() {
global $wpdb;
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
$table_name = $wpdb->prefix . "inbound_events";
$col_check = $wpdb->get_row("SELECT * FROM " . $table_name ." limit 1");
if(!isset($col_check->comment_id)) {
$wpdb->get_results("ALTER TABLE {$table_name} ADD `comment_id` bigint(20) NOT NULL");
}
}
public static function alter_events_pageviews_107() {
global $wpdb;
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
$table_name = $wpdb->prefix . "inbound_events";
$wpdb->get_results( "ALTER TABLE {$table_name} MODIFY COLUMN `page_id` VARCHAR(20)" );
$table_name = $wpdb->prefix . "inbound_page_views";
$wpdb->get_results( "ALTER TABLE {$table_name} MODIFY COLUMN `page_id` VARCHAR(20)" );
}
public static function alter_automation_queue_table_1() {
global $wpdb;
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
$table_name = $wpdb->prefix . "inbound_automation_queue";
$col_check = $wpdb->get_row("SELECT * FROM " . $table_name ." limit 1");
if(!isset($col_check->lead_id)) {
$wpdb->get_results("ALTER TABLE {$table_name} ADD `lead_id` bigint(20) NOT NULL");
}
}
public static function alter_inbound_settings_109() {
if (class_exists('Inbound_Options_API')) {
$inbound_settings = Inbound_Options_API::get_option('inbound-pro', 'settings', array());
if (isset($inbound_settings['mailer'])) {
return;
}
$inbound_settings['mailer'] = (isset($inbound_settings['inbound-mailer'])) ? $inbound_settings['inbound-mailer'] : array();
unset($inbound_settings['inbound-mailer']);
Inbound_Options_API::update_option('inbound-pro', 'settings', $inbound_settings);
}
}
public static function alter_inbound_settings_203() {
global $wpdb;
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
$table_name = $wpdb->prefix . "inbound_events";
$wpdb->get_results( "ALTER TABLE {$table_name} MODIFY COLUMN `id` BIGINT(20),
MODIFY COLUMN `lead_id` BIGINT(20),
MODIFY COLUMN `form_id` BIGINT(20),
MODIFY COLUMN `cta_id` BIGINT(20),
MODIFY COLUMN `email_id` BIGINT(20),
MODIFY COLUMN `rule_id` BIGINT(20),
MODIFY COLUMN `job_id` BIGINT(20),
MODIFY COLUMN `list_id` BIGINT(20),
MODIFY COLUMN `comment_id` BIGINT(20)");
}
}
add_action('admin_init' , array( 'Inbound_Upgrade_Routines' , 'add_update_check') );
if (isset($_REQUEST['force_upgrade_routines']) && $_REQUEST['force_upgrade_routines'] ) {
Inbound_Events::create_page_views_table();
Inbound_Events::create_events_table();
if (class_exists('Inbound_Automation_Activation')) {
Inbound_Automation_Activation::create_automation_queue_table();
}
if (class_exists('Inbound_Mailer_Activation')) {
Inbound_Mailer_Activation::create_email_queue_table();
}
Inbound_Upgrade_Routines::load();
}
}