@@ -18,44 +18,44 @@ |
||
| 18 | 18 | class EE_DMS_Unknown_1_0_0 extends EE_Data_Migration_Script_Base |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Returns whether or not this data migration script can operate on the given version of the database. |
|
| 23 | - * Eg, if this migration script can migrate from 3.1.26 or higher (but not anything after 4.0.0), and |
|
| 24 | - * it's passed a string like '3.1.38B', it should return true |
|
| 25 | - * |
|
| 26 | - * @param string $version_string |
|
| 27 | - * @return boolean |
|
| 28 | - */ |
|
| 29 | - public function can_migrate_from_version($version_string) |
|
| 30 | - { |
|
| 31 | - return false; |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - public function schema_changes_after_migration() |
|
| 35 | - { |
|
| 36 | - return; |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - public function schema_changes_before_migration() |
|
| 40 | - { |
|
| 41 | - return; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * All children of this must call parent::__construct() at the end of their constructor or suffer the consequences! |
|
| 47 | - * |
|
| 48 | - * @param TableManager $table_manager |
|
| 49 | - * @param TableAnalysis $table_analysis |
|
| 50 | - */ |
|
| 51 | - public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
| 52 | - { |
|
| 53 | - $this->_migration_stages = array(); |
|
| 54 | - $this->_pretty_name = esc_html__("Fatal Uncatchable Error Occurred", "event_espresso"); |
|
| 55 | - parent::__construct($table_manager, $table_analysis); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - public function migration_page_hooks() |
|
| 59 | - { |
|
| 60 | - } |
|
| 21 | + /** |
|
| 22 | + * Returns whether or not this data migration script can operate on the given version of the database. |
|
| 23 | + * Eg, if this migration script can migrate from 3.1.26 or higher (but not anything after 4.0.0), and |
|
| 24 | + * it's passed a string like '3.1.38B', it should return true |
|
| 25 | + * |
|
| 26 | + * @param string $version_string |
|
| 27 | + * @return boolean |
|
| 28 | + */ |
|
| 29 | + public function can_migrate_from_version($version_string) |
|
| 30 | + { |
|
| 31 | + return false; |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + public function schema_changes_after_migration() |
|
| 35 | + { |
|
| 36 | + return; |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + public function schema_changes_before_migration() |
|
| 40 | + { |
|
| 41 | + return; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * All children of this must call parent::__construct() at the end of their constructor or suffer the consequences! |
|
| 47 | + * |
|
| 48 | + * @param TableManager $table_manager |
|
| 49 | + * @param TableAnalysis $table_analysis |
|
| 50 | + */ |
|
| 51 | + public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
| 52 | + { |
|
| 53 | + $this->_migration_stages = array(); |
|
| 54 | + $this->_pretty_name = esc_html__("Fatal Uncatchable Error Occurred", "event_espresso"); |
|
| 55 | + parent::__construct($table_manager, $table_analysis); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + public function migration_page_hooks() |
|
| 59 | + { |
|
| 60 | + } |
|
| 61 | 61 | } |
@@ -16,15 +16,13 @@ discard block |
||
| 16 | 16 | 'EQG_primary'=>new EE_Boolean_Field('EQG_primary', esc_html__('Flag indicating question is only for primary attendees','event_espresso'), false, false) |
| 17 | 17 | ) |
| 18 | 18 | ); |
| 19 | - |
|
| 20 | - |
|
| 21 | 19 | * |
| 22 | 20 | */ |
| 23 | 21 | class EE_DMS_4_1_0_event_question_group extends EE_Data_Migration_Script_Stage_Table |
| 24 | 22 | { |
| 25 | - private $_new_table; |
|
| 26 | - public function _migrate_old_row($old_row) |
|
| 27 | - { |
|
| 23 | + private $_new_table; |
|
| 24 | + public function _migrate_old_row($old_row) |
|
| 25 | + { |
|
| 28 | 26 | // $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $this->_new_transaction_table); |
| 29 | 27 | // if ( ! $txn_id ){ |
| 30 | 28 | // $this->add_error(sprintf(esc_html__("Could not find the transaction for the 3.1 attendee %d from row %s", "event_espresso"),$old_row['id'],$this->_json_encode($old_row))); |
@@ -34,8 +32,8 @@ discard block |
||
| 34 | 32 | // $new_line_items = $this->_insert_new_line_items($txn,$old_row); |
| 35 | 33 | // $this->get_migration_script()->set_mapping($this->_old_table,$old_row['id'],$this->_new_line_table,$new_line_items); |
| 36 | 34 | |
| 37 | - $this->_insert_new_event_question_groups($old_row); |
|
| 38 | - } |
|
| 35 | + $this->_insert_new_event_question_groups($old_row); |
|
| 36 | + } |
|
| 39 | 37 | // function _migration_step($num_items=50){ |
| 40 | 38 | // global $wpdb; |
| 41 | 39 | // $start_at_record = $this->count_records_migrated(); |
@@ -55,109 +53,109 @@ discard block |
||
| 55 | 53 | // $count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table); |
| 56 | 54 | // return $count; |
| 57 | 55 | // } |
| 58 | - public function __construct() |
|
| 59 | - { |
|
| 60 | - global $wpdb; |
|
| 61 | - $this->_old_table = $wpdb->prefix . "events_detail"; |
|
| 62 | - $this->_extra_where_sql = 'WHERE event_status!="D"'; |
|
| 63 | - $this->_new_table = $wpdb->prefix . "esp_event_question_group"; |
|
| 64 | - $this->_pretty_name = esc_html__("Question Groups in each Event", "event_espresso"); |
|
| 65 | - parent::__construct(); |
|
| 66 | - } |
|
| 56 | + public function __construct() |
|
| 57 | + { |
|
| 58 | + global $wpdb; |
|
| 59 | + $this->_old_table = $wpdb->prefix . "events_detail"; |
|
| 60 | + $this->_extra_where_sql = 'WHERE event_status!="D"'; |
|
| 61 | + $this->_new_table = $wpdb->prefix . "esp_event_question_group"; |
|
| 62 | + $this->_pretty_name = esc_html__("Question Groups in each Event", "event_espresso"); |
|
| 63 | + parent::__construct(); |
|
| 64 | + } |
|
| 67 | 65 | |
| 68 | - /** |
|
| 69 | - * Attempts to insert a new question group inthe new format given an old one |
|
| 70 | - * @global type $wpdb |
|
| 71 | - * @param array $old_event |
|
| 72 | - * @return void |
|
| 73 | - */ |
|
| 74 | - private function _insert_new_event_question_groups($old_event) |
|
| 75 | - { |
|
| 76 | - $new_event_question_group_ids = array(); |
|
| 77 | - $question_groups_for_primary = maybe_unserialize($old_event['question_groups']); |
|
| 78 | - if (is_array($question_groups_for_primary)) { |
|
| 79 | - foreach ($question_groups_for_primary as $old_question_group_id) { |
|
| 80 | - $new_id = $this->_insert_event_question_group($old_event, $old_question_group_id, true); |
|
| 81 | - if ($new_id) { |
|
| 82 | - $new_event_question_group_ids[] = $new_id; |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - } |
|
| 86 | - $event_meta = maybe_unserialize($old_event['event_meta']); |
|
| 87 | - if (isset($event_meta['add_attendee_question_groups'])) { |
|
| 88 | - if (is_array($event_meta['add_attendee_question_groups'])) { |
|
| 89 | - foreach ($event_meta['add_attendee_question_groups'] as $old_question_group_id) { |
|
| 90 | - $new_id = $this->_insert_event_question_group($old_event, $old_question_group_id, false); |
|
| 91 | - if ($new_id) { |
|
| 92 | - $new_event_question_group_ids[] = $new_id; |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - } |
|
| 96 | - } |
|
| 66 | + /** |
|
| 67 | + * Attempts to insert a new question group inthe new format given an old one |
|
| 68 | + * @global type $wpdb |
|
| 69 | + * @param array $old_event |
|
| 70 | + * @return void |
|
| 71 | + */ |
|
| 72 | + private function _insert_new_event_question_groups($old_event) |
|
| 73 | + { |
|
| 74 | + $new_event_question_group_ids = array(); |
|
| 75 | + $question_groups_for_primary = maybe_unserialize($old_event['question_groups']); |
|
| 76 | + if (is_array($question_groups_for_primary)) { |
|
| 77 | + foreach ($question_groups_for_primary as $old_question_group_id) { |
|
| 78 | + $new_id = $this->_insert_event_question_group($old_event, $old_question_group_id, true); |
|
| 79 | + if ($new_id) { |
|
| 80 | + $new_event_question_group_ids[] = $new_id; |
|
| 81 | + } |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + $event_meta = maybe_unserialize($old_event['event_meta']); |
|
| 85 | + if (isset($event_meta['add_attendee_question_groups'])) { |
|
| 86 | + if (is_array($event_meta['add_attendee_question_groups'])) { |
|
| 87 | + foreach ($event_meta['add_attendee_question_groups'] as $old_question_group_id) { |
|
| 88 | + $new_id = $this->_insert_event_question_group($old_event, $old_question_group_id, false); |
|
| 89 | + if ($new_id) { |
|
| 90 | + $new_event_question_group_ids[] = $new_id; |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + } |
|
| 97 | 95 | |
| 98 | 96 | |
| 99 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_event['id'], $this->_new_table, $new_event_question_group_ids); |
|
| 100 | - } |
|
| 97 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_event['id'], $this->_new_table, $new_event_question_group_ids); |
|
| 98 | + } |
|
| 101 | 99 | |
| 102 | - private function _insert_event_question_group($old_event, $old_question_group_id, $primary) |
|
| 103 | - { |
|
| 104 | - global $wpdb; |
|
| 105 | - $new_question_group_id = $this->get_migration_script()->get_mapping_new_pk( |
|
| 106 | - $wpdb->prefix . "events_qst_group", |
|
| 107 | - intval($old_question_group_id), |
|
| 108 | - $wpdb->prefix . "esp_question_group" |
|
| 109 | - ); |
|
| 100 | + private function _insert_event_question_group($old_event, $old_question_group_id, $primary) |
|
| 101 | + { |
|
| 102 | + global $wpdb; |
|
| 103 | + $new_question_group_id = $this->get_migration_script()->get_mapping_new_pk( |
|
| 104 | + $wpdb->prefix . "events_qst_group", |
|
| 105 | + intval($old_question_group_id), |
|
| 106 | + $wpdb->prefix . "esp_question_group" |
|
| 107 | + ); |
|
| 110 | 108 | |
| 111 | - if (! $new_question_group_id) { |
|
| 112 | - $this->add_error( |
|
| 113 | - sprintf( |
|
| 114 | - // translators: %s question ID, %s event ID |
|
| 115 | - esc_html__("Could not find 4.1 question ID for 3.1 question id #%s on event $%s", "event_espresso"), |
|
| 116 | - $old_question_group_id, |
|
| 117 | - $old_event['id'] |
|
| 118 | - ) |
|
| 119 | - ); |
|
| 120 | - return 0; |
|
| 121 | - } |
|
| 122 | - $new_event_id = $this->get_migration_script()->get_mapping_new_pk( |
|
| 123 | - $wpdb->prefix . "events_detail", |
|
| 124 | - intval($old_event['id']), |
|
| 125 | - $wpdb->posts |
|
| 126 | - ); |
|
| 127 | - if (! $new_question_group_id) { |
|
| 128 | - $this->add_error( |
|
| 129 | - sprintf( |
|
| 130 | - // translators: %s event ID |
|
| 131 | - esc_html__("Could not find 4.1 event 3.1 event id #%s", "event_espresso"), |
|
| 132 | - $old_event['id'] |
|
| 133 | - ) |
|
| 134 | - ); |
|
| 135 | - return 0; |
|
| 136 | - } |
|
| 137 | - $cols_n_values = array( |
|
| 138 | - 'EVT_ID' => $new_event_id, |
|
| 139 | - 'QSG_ID' => $new_question_group_id, |
|
| 140 | - 'EQG_primary' => $primary |
|
| 141 | - ); |
|
| 109 | + if (! $new_question_group_id) { |
|
| 110 | + $this->add_error( |
|
| 111 | + sprintf( |
|
| 112 | + // translators: %s question ID, %s event ID |
|
| 113 | + esc_html__("Could not find 4.1 question ID for 3.1 question id #%s on event $%s", "event_espresso"), |
|
| 114 | + $old_question_group_id, |
|
| 115 | + $old_event['id'] |
|
| 116 | + ) |
|
| 117 | + ); |
|
| 118 | + return 0; |
|
| 119 | + } |
|
| 120 | + $new_event_id = $this->get_migration_script()->get_mapping_new_pk( |
|
| 121 | + $wpdb->prefix . "events_detail", |
|
| 122 | + intval($old_event['id']), |
|
| 123 | + $wpdb->posts |
|
| 124 | + ); |
|
| 125 | + if (! $new_question_group_id) { |
|
| 126 | + $this->add_error( |
|
| 127 | + sprintf( |
|
| 128 | + // translators: %s event ID |
|
| 129 | + esc_html__("Could not find 4.1 event 3.1 event id #%s", "event_espresso"), |
|
| 130 | + $old_event['id'] |
|
| 131 | + ) |
|
| 132 | + ); |
|
| 133 | + return 0; |
|
| 134 | + } |
|
| 135 | + $cols_n_values = array( |
|
| 136 | + 'EVT_ID' => $new_event_id, |
|
| 137 | + 'QSG_ID' => $new_question_group_id, |
|
| 138 | + 'EQG_primary' => $primary |
|
| 139 | + ); |
|
| 142 | 140 | |
| 143 | - $datatypes = array( |
|
| 144 | - '%d',// EVT_ID |
|
| 145 | - '%d',// QSG_ID |
|
| 146 | - '%d',// EQG_primary |
|
| 147 | - ); |
|
| 148 | - $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
|
| 149 | - if (! $success) { |
|
| 150 | - $this->add_error( |
|
| 151 | - $this->get_migration_script()->_create_error_message_for_db_insertion( |
|
| 152 | - $this->_old_table, |
|
| 153 | - $old_event, |
|
| 154 | - $this->_new_table, |
|
| 155 | - $cols_n_values, |
|
| 156 | - $datatypes |
|
| 157 | - ) |
|
| 158 | - ); |
|
| 159 | - return 0; |
|
| 160 | - } |
|
| 161 | - return $wpdb->insert_id; |
|
| 162 | - } |
|
| 141 | + $datatypes = array( |
|
| 142 | + '%d',// EVT_ID |
|
| 143 | + '%d',// QSG_ID |
|
| 144 | + '%d',// EQG_primary |
|
| 145 | + ); |
|
| 146 | + $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
|
| 147 | + if (! $success) { |
|
| 148 | + $this->add_error( |
|
| 149 | + $this->get_migration_script()->_create_error_message_for_db_insertion( |
|
| 150 | + $this->_old_table, |
|
| 151 | + $old_event, |
|
| 152 | + $this->_new_table, |
|
| 153 | + $cols_n_values, |
|
| 154 | + $datatypes |
|
| 155 | + ) |
|
| 156 | + ); |
|
| 157 | + return 0; |
|
| 158 | + } |
|
| 159 | + return $wpdb->insert_id; |
|
| 160 | + } |
|
| 163 | 161 | } |
@@ -58,9 +58,9 @@ discard block |
||
| 58 | 58 | public function __construct() |
| 59 | 59 | { |
| 60 | 60 | global $wpdb; |
| 61 | - $this->_old_table = $wpdb->prefix . "events_detail"; |
|
| 61 | + $this->_old_table = $wpdb->prefix."events_detail"; |
|
| 62 | 62 | $this->_extra_where_sql = 'WHERE event_status!="D"'; |
| 63 | - $this->_new_table = $wpdb->prefix . "esp_event_question_group"; |
|
| 63 | + $this->_new_table = $wpdb->prefix."esp_event_question_group"; |
|
| 64 | 64 | $this->_pretty_name = esc_html__("Question Groups in each Event", "event_espresso"); |
| 65 | 65 | parent::__construct(); |
| 66 | 66 | } |
@@ -103,12 +103,12 @@ discard block |
||
| 103 | 103 | { |
| 104 | 104 | global $wpdb; |
| 105 | 105 | $new_question_group_id = $this->get_migration_script()->get_mapping_new_pk( |
| 106 | - $wpdb->prefix . "events_qst_group", |
|
| 106 | + $wpdb->prefix."events_qst_group", |
|
| 107 | 107 | intval($old_question_group_id), |
| 108 | - $wpdb->prefix . "esp_question_group" |
|
| 108 | + $wpdb->prefix."esp_question_group" |
|
| 109 | 109 | ); |
| 110 | 110 | |
| 111 | - if (! $new_question_group_id) { |
|
| 111 | + if ( ! $new_question_group_id) { |
|
| 112 | 112 | $this->add_error( |
| 113 | 113 | sprintf( |
| 114 | 114 | // translators: %s question ID, %s event ID |
@@ -120,11 +120,11 @@ discard block |
||
| 120 | 120 | return 0; |
| 121 | 121 | } |
| 122 | 122 | $new_event_id = $this->get_migration_script()->get_mapping_new_pk( |
| 123 | - $wpdb->prefix . "events_detail", |
|
| 123 | + $wpdb->prefix."events_detail", |
|
| 124 | 124 | intval($old_event['id']), |
| 125 | 125 | $wpdb->posts |
| 126 | 126 | ); |
| 127 | - if (! $new_question_group_id) { |
|
| 127 | + if ( ! $new_question_group_id) { |
|
| 128 | 128 | $this->add_error( |
| 129 | 129 | sprintf( |
| 130 | 130 | // translators: %s event ID |
@@ -141,12 +141,12 @@ discard block |
||
| 141 | 141 | ); |
| 142 | 142 | |
| 143 | 143 | $datatypes = array( |
| 144 | - '%d',// EVT_ID |
|
| 145 | - '%d',// QSG_ID |
|
| 146 | - '%d',// EQG_primary |
|
| 144 | + '%d', // EVT_ID |
|
| 145 | + '%d', // QSG_ID |
|
| 146 | + '%d', // EQG_primary |
|
| 147 | 147 | ); |
| 148 | 148 | $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
| 149 | - if (! $success) { |
|
| 149 | + if ( ! $success) { |
|
| 150 | 150 | $this->add_error( |
| 151 | 151 | $this->get_migration_script()->_create_error_message_for_db_insertion( |
| 152 | 152 | $this->_old_table, |
@@ -25,105 +25,102 @@ |
||
| 25 | 25 | |
| 26 | 26 | ) |
| 27 | 27 | ); |
| 28 | - |
|
| 29 | - |
|
| 30 | - |
|
| 31 | 28 | * |
| 32 | 29 | */ |
| 33 | 30 | class EE_DMS_4_1_0_event_venue extends EE_Data_Migration_Script_Stage |
| 34 | 31 | { |
| 35 | - private $_old_table; |
|
| 36 | - private $_new_table; |
|
| 37 | - public function _migration_step($num_items = 50) |
|
| 38 | - { |
|
| 32 | + private $_old_table; |
|
| 33 | + private $_new_table; |
|
| 34 | + public function _migration_step($num_items = 50) |
|
| 35 | + { |
|
| 39 | 36 | |
| 40 | - global $wpdb; |
|
| 41 | - $start_at_record = $this->count_records_migrated(); |
|
| 42 | - $rows = $wpdb->get_results( |
|
| 43 | - $wpdb->prepare( |
|
| 44 | - "SELECT * FROM $this->_old_table AS ev |
|
| 37 | + global $wpdb; |
|
| 38 | + $start_at_record = $this->count_records_migrated(); |
|
| 39 | + $rows = $wpdb->get_results( |
|
| 40 | + $wpdb->prepare( |
|
| 41 | + "SELECT * FROM $this->_old_table AS ev |
|
| 45 | 42 | INNER JOIN " . $wpdb->prefix . "events_detail AS e ON ev.event_id=e.id |
| 46 | 43 | WHERE e.event_status!='D' LIMIT %d,%d", |
| 47 | - $start_at_record, |
|
| 48 | - $num_items |
|
| 49 | - ), |
|
| 50 | - ARRAY_A |
|
| 51 | - ); |
|
| 52 | - $items_actually_migrated = 0; |
|
| 53 | - foreach ($rows as $event_venue_rel) { |
|
| 54 | - $this->_insert_new_event_to_venue_rel($event_venue_rel); |
|
| 55 | - $items_actually_migrated++; |
|
| 56 | - } |
|
| 57 | - if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
| 58 | - $this->set_completed(); |
|
| 59 | - } |
|
| 60 | - return $items_actually_migrated; |
|
| 61 | - } |
|
| 62 | - public function _count_records_to_migrate() |
|
| 63 | - { |
|
| 64 | - global $wpdb; |
|
| 65 | - $count = $wpdb->get_var( |
|
| 66 | - "SELECT COUNT(ev.id) FROM " . $this->_old_table . " AS ev |
|
| 44 | + $start_at_record, |
|
| 45 | + $num_items |
|
| 46 | + ), |
|
| 47 | + ARRAY_A |
|
| 48 | + ); |
|
| 49 | + $items_actually_migrated = 0; |
|
| 50 | + foreach ($rows as $event_venue_rel) { |
|
| 51 | + $this->_insert_new_event_to_venue_rel($event_venue_rel); |
|
| 52 | + $items_actually_migrated++; |
|
| 53 | + } |
|
| 54 | + if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
| 55 | + $this->set_completed(); |
|
| 56 | + } |
|
| 57 | + return $items_actually_migrated; |
|
| 58 | + } |
|
| 59 | + public function _count_records_to_migrate() |
|
| 60 | + { |
|
| 61 | + global $wpdb; |
|
| 62 | + $count = $wpdb->get_var( |
|
| 63 | + "SELECT COUNT(ev.id) FROM " . $this->_old_table . " AS ev |
|
| 67 | 64 | INNER JOIN " . $wpdb->prefix . 'events_detail AS e ON ev.event_id=e.id |
| 68 | 65 | WHERE e.event_status!="D"' |
| 69 | - ); |
|
| 70 | - return $count; |
|
| 71 | - } |
|
| 72 | - public function __construct() |
|
| 73 | - { |
|
| 74 | - global $wpdb; |
|
| 75 | - $this->_old_table = $wpdb->prefix . "events_venue_rel"; |
|
| 76 | - $this->_new_table = $wpdb->prefix . "esp_event_venue"; |
|
| 77 | - $this->_pretty_name = esc_html__("Event to Venue Relations", "event_espresso"); |
|
| 78 | - parent::__construct(); |
|
| 79 | - } |
|
| 66 | + ); |
|
| 67 | + return $count; |
|
| 68 | + } |
|
| 69 | + public function __construct() |
|
| 70 | + { |
|
| 71 | + global $wpdb; |
|
| 72 | + $this->_old_table = $wpdb->prefix . "events_venue_rel"; |
|
| 73 | + $this->_new_table = $wpdb->prefix . "esp_event_venue"; |
|
| 74 | + $this->_pretty_name = esc_html__("Event to Venue Relations", "event_espresso"); |
|
| 75 | + parent::__construct(); |
|
| 76 | + } |
|
| 80 | 77 | |
| 81 | - /** |
|
| 82 | - * Attempts to insert a new question group inthe new format given an old one |
|
| 83 | - * @global type $wpdb |
|
| 84 | - * @param array $old_event_venue_rel |
|
| 85 | - * @return int |
|
| 86 | - */ |
|
| 87 | - private function _insert_new_event_to_venue_rel($old_event_venue_rel) |
|
| 88 | - { |
|
| 89 | - global $wpdb; |
|
| 90 | - $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_detail", $old_event_venue_rel['event_id'], $wpdb->prefix . "posts"); |
|
| 91 | - $new_venue_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_venue", $old_event_venue_rel['venue_id'], $wpdb->prefix . "posts"); |
|
| 92 | - if (! $new_event_id) { |
|
| 93 | - $this->add_error(sprintf(esc_html__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $old_event_venue_rel['event_id'])); |
|
| 94 | - return 0; |
|
| 95 | - } |
|
| 96 | - if (! $new_venue_id) { |
|
| 97 | - $this->add_error(sprintf(esc_html__("Could not find 4.1 venue id for 3.1 venue #%d.", "event_espresso"), $old_event_venue_rel['venue_id'])); |
|
| 98 | - return 0; |
|
| 99 | - } |
|
| 100 | - // first ensure there are no other relation entries for this event |
|
| 101 | - // because although EE4 supports it, EE3 didn't really |
|
| 102 | - $wpdb->delete( |
|
| 103 | - $this->_new_table, |
|
| 104 | - array( |
|
| 105 | - 'EVT_ID' => $new_event_id, |
|
| 106 | - ), |
|
| 107 | - array( |
|
| 108 | - '%d',// EVT_ID |
|
| 109 | - ) |
|
| 110 | - ); |
|
| 78 | + /** |
|
| 79 | + * Attempts to insert a new question group inthe new format given an old one |
|
| 80 | + * @global type $wpdb |
|
| 81 | + * @param array $old_event_venue_rel |
|
| 82 | + * @return int |
|
| 83 | + */ |
|
| 84 | + private function _insert_new_event_to_venue_rel($old_event_venue_rel) |
|
| 85 | + { |
|
| 86 | + global $wpdb; |
|
| 87 | + $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_detail", $old_event_venue_rel['event_id'], $wpdb->prefix . "posts"); |
|
| 88 | + $new_venue_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_venue", $old_event_venue_rel['venue_id'], $wpdb->prefix . "posts"); |
|
| 89 | + if (! $new_event_id) { |
|
| 90 | + $this->add_error(sprintf(esc_html__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $old_event_venue_rel['event_id'])); |
|
| 91 | + return 0; |
|
| 92 | + } |
|
| 93 | + if (! $new_venue_id) { |
|
| 94 | + $this->add_error(sprintf(esc_html__("Could not find 4.1 venue id for 3.1 venue #%d.", "event_espresso"), $old_event_venue_rel['venue_id'])); |
|
| 95 | + return 0; |
|
| 96 | + } |
|
| 97 | + // first ensure there are no other relation entries for this event |
|
| 98 | + // because although EE4 supports it, EE3 didn't really |
|
| 99 | + $wpdb->delete( |
|
| 100 | + $this->_new_table, |
|
| 101 | + array( |
|
| 102 | + 'EVT_ID' => $new_event_id, |
|
| 103 | + ), |
|
| 104 | + array( |
|
| 105 | + '%d',// EVT_ID |
|
| 106 | + ) |
|
| 107 | + ); |
|
| 111 | 108 | // echo "last query". $wpdb->last_query;die; |
| 112 | - $cols_n_values = array( |
|
| 113 | - 'EVT_ID' => $new_event_id, |
|
| 114 | - 'VNU_ID' => $new_venue_id, |
|
| 115 | - 'EVV_primary' => true |
|
| 116 | - ); |
|
| 117 | - $datatypes = array( |
|
| 118 | - '%d',// EVT_ID |
|
| 119 | - '%d',// VNU_ID |
|
| 120 | - '%d',// EVT_primary |
|
| 121 | - ); |
|
| 122 | - $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
|
| 123 | - if (! $success) { |
|
| 124 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event_venue_rel, $this->_new_table, $cols_n_values, $datatypes)); |
|
| 125 | - return 0; |
|
| 126 | - } |
|
| 127 | - return $wpdb->insert_id; |
|
| 128 | - } |
|
| 109 | + $cols_n_values = array( |
|
| 110 | + 'EVT_ID' => $new_event_id, |
|
| 111 | + 'VNU_ID' => $new_venue_id, |
|
| 112 | + 'EVV_primary' => true |
|
| 113 | + ); |
|
| 114 | + $datatypes = array( |
|
| 115 | + '%d',// EVT_ID |
|
| 116 | + '%d',// VNU_ID |
|
| 117 | + '%d',// EVT_primary |
|
| 118 | + ); |
|
| 119 | + $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
|
| 120 | + if (! $success) { |
|
| 121 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event_venue_rel, $this->_new_table, $cols_n_values, $datatypes)); |
|
| 122 | + return 0; |
|
| 123 | + } |
|
| 124 | + return $wpdb->insert_id; |
|
| 125 | + } |
|
| 129 | 126 | } |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | $rows = $wpdb->get_results( |
| 43 | 43 | $wpdb->prepare( |
| 44 | 44 | "SELECT * FROM $this->_old_table AS ev |
| 45 | - INNER JOIN " . $wpdb->prefix . "events_detail AS e ON ev.event_id=e.id |
|
| 45 | + INNER JOIN ".$wpdb->prefix."events_detail AS e ON ev.event_id=e.id |
|
| 46 | 46 | WHERE e.event_status!='D' LIMIT %d,%d", |
| 47 | 47 | $start_at_record, |
| 48 | 48 | $num_items |
@@ -63,8 +63,8 @@ discard block |
||
| 63 | 63 | { |
| 64 | 64 | global $wpdb; |
| 65 | 65 | $count = $wpdb->get_var( |
| 66 | - "SELECT COUNT(ev.id) FROM " . $this->_old_table . " AS ev |
|
| 67 | - INNER JOIN " . $wpdb->prefix . 'events_detail AS e ON ev.event_id=e.id |
|
| 66 | + "SELECT COUNT(ev.id) FROM ".$this->_old_table." AS ev |
|
| 67 | + INNER JOIN " . $wpdb->prefix.'events_detail AS e ON ev.event_id=e.id |
|
| 68 | 68 | WHERE e.event_status!="D"' |
| 69 | 69 | ); |
| 70 | 70 | return $count; |
@@ -72,8 +72,8 @@ discard block |
||
| 72 | 72 | public function __construct() |
| 73 | 73 | { |
| 74 | 74 | global $wpdb; |
| 75 | - $this->_old_table = $wpdb->prefix . "events_venue_rel"; |
|
| 76 | - $this->_new_table = $wpdb->prefix . "esp_event_venue"; |
|
| 75 | + $this->_old_table = $wpdb->prefix."events_venue_rel"; |
|
| 76 | + $this->_new_table = $wpdb->prefix."esp_event_venue"; |
|
| 77 | 77 | $this->_pretty_name = esc_html__("Event to Venue Relations", "event_espresso"); |
| 78 | 78 | parent::__construct(); |
| 79 | 79 | } |
@@ -87,13 +87,13 @@ discard block |
||
| 87 | 87 | private function _insert_new_event_to_venue_rel($old_event_venue_rel) |
| 88 | 88 | { |
| 89 | 89 | global $wpdb; |
| 90 | - $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_detail", $old_event_venue_rel['event_id'], $wpdb->prefix . "posts"); |
|
| 91 | - $new_venue_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_venue", $old_event_venue_rel['venue_id'], $wpdb->prefix . "posts"); |
|
| 92 | - if (! $new_event_id) { |
|
| 90 | + $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_event_venue_rel['event_id'], $wpdb->prefix."posts"); |
|
| 91 | + $new_venue_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_venue", $old_event_venue_rel['venue_id'], $wpdb->prefix."posts"); |
|
| 92 | + if ( ! $new_event_id) { |
|
| 93 | 93 | $this->add_error(sprintf(esc_html__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $old_event_venue_rel['event_id'])); |
| 94 | 94 | return 0; |
| 95 | 95 | } |
| 96 | - if (! $new_venue_id) { |
|
| 96 | + if ( ! $new_venue_id) { |
|
| 97 | 97 | $this->add_error(sprintf(esc_html__("Could not find 4.1 venue id for 3.1 venue #%d.", "event_espresso"), $old_event_venue_rel['venue_id'])); |
| 98 | 98 | return 0; |
| 99 | 99 | } |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | 'EVT_ID' => $new_event_id, |
| 106 | 106 | ), |
| 107 | 107 | array( |
| 108 | - '%d',// EVT_ID |
|
| 108 | + '%d', // EVT_ID |
|
| 109 | 109 | ) |
| 110 | 110 | ); |
| 111 | 111 | // echo "last query". $wpdb->last_query;die; |
@@ -115,12 +115,12 @@ discard block |
||
| 115 | 115 | 'EVV_primary' => true |
| 116 | 116 | ); |
| 117 | 117 | $datatypes = array( |
| 118 | - '%d',// EVT_ID |
|
| 119 | - '%d',// VNU_ID |
|
| 120 | - '%d',// EVT_primary |
|
| 118 | + '%d', // EVT_ID |
|
| 119 | + '%d', // VNU_ID |
|
| 120 | + '%d', // EVT_primary |
|
| 121 | 121 | ); |
| 122 | 122 | $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
| 123 | - if (! $success) { |
|
| 123 | + if ( ! $success) { |
|
| 124 | 124 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event_venue_rel, $this->_new_table, $cols_n_values, $datatypes)); |
| 125 | 125 | return 0; |
| 126 | 126 | } |
@@ -12,8 +12,6 @@ discard block |
||
| 12 | 12 | KEY `group_id` (`group_id`), |
| 13 | 13 | KEY `question_id` (`question_id`) |
| 14 | 14 | ) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8$$ |
| 15 | - |
|
| 16 | - |
|
| 17 | 15 | * 4.1 question group question model's tables and fields: |
| 18 | 16 | $this->_tables = array( |
| 19 | 17 | 'Question_Group_Question'=>new EE_Primary_Table('esp_question_group_question','QGQ_ID') |
@@ -29,114 +27,114 @@ discard block |
||
| 29 | 27 | */ |
| 30 | 28 | class EE_DMS_4_1_0_question_group_question extends EE_Data_Migration_Script_Stage |
| 31 | 29 | { |
| 32 | - private $_old_table; |
|
| 33 | - private $_new_table; |
|
| 34 | - public function _migration_step($num_items = 50) |
|
| 35 | - { |
|
| 30 | + private $_old_table; |
|
| 31 | + private $_new_table; |
|
| 32 | + public function _migration_step($num_items = 50) |
|
| 33 | + { |
|
| 36 | 34 | |
| 37 | - global $wpdb; |
|
| 38 | - $start_at_record = $this->count_records_migrated(); |
|
| 39 | - $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A); |
|
| 40 | - $items_actually_migrated = 0; |
|
| 41 | - foreach ($rows as $question_group_question) { |
|
| 42 | - $this->_insert_new_question_group_question($question_group_question); |
|
| 43 | - $items_actually_migrated++; |
|
| 44 | - } |
|
| 45 | - if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
| 46 | - $this->set_completed(); |
|
| 47 | - } |
|
| 48 | - return $items_actually_migrated; |
|
| 49 | - } |
|
| 50 | - public function _count_records_to_migrate() |
|
| 51 | - { |
|
| 52 | - global $wpdb; |
|
| 53 | - $count = $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table); |
|
| 54 | - return $count; |
|
| 55 | - } |
|
| 56 | - public function __construct() |
|
| 57 | - { |
|
| 58 | - global $wpdb; |
|
| 59 | - $this->_old_table = $wpdb->prefix . "events_qst_group_rel"; |
|
| 60 | - $this->_new_table = $wpdb->prefix . "esp_question_group_question"; |
|
| 61 | - $this->_pretty_name = esc_html__("Question Group to Question Relations", "event_espresso"); |
|
| 62 | - parent::__construct(); |
|
| 63 | - } |
|
| 35 | + global $wpdb; |
|
| 36 | + $start_at_record = $this->count_records_migrated(); |
|
| 37 | + $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A); |
|
| 38 | + $items_actually_migrated = 0; |
|
| 39 | + foreach ($rows as $question_group_question) { |
|
| 40 | + $this->_insert_new_question_group_question($question_group_question); |
|
| 41 | + $items_actually_migrated++; |
|
| 42 | + } |
|
| 43 | + if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
| 44 | + $this->set_completed(); |
|
| 45 | + } |
|
| 46 | + return $items_actually_migrated; |
|
| 47 | + } |
|
| 48 | + public function _count_records_to_migrate() |
|
| 49 | + { |
|
| 50 | + global $wpdb; |
|
| 51 | + $count = $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table); |
|
| 52 | + return $count; |
|
| 53 | + } |
|
| 54 | + public function __construct() |
|
| 55 | + { |
|
| 56 | + global $wpdb; |
|
| 57 | + $this->_old_table = $wpdb->prefix . "events_qst_group_rel"; |
|
| 58 | + $this->_new_table = $wpdb->prefix . "esp_question_group_question"; |
|
| 59 | + $this->_pretty_name = esc_html__("Question Group to Question Relations", "event_espresso"); |
|
| 60 | + parent::__construct(); |
|
| 61 | + } |
|
| 64 | 62 | |
| 65 | - /** |
|
| 66 | - * Attempts to insert a new question group inthe new format given an old one |
|
| 67 | - * @global type $wpdb |
|
| 68 | - * @param array $old_question_group_question |
|
| 69 | - * @return int |
|
| 70 | - */ |
|
| 71 | - private function _insert_new_question_group_question($old_question_group_question) |
|
| 72 | - { |
|
| 73 | - global $wpdb; |
|
| 74 | - $new_question_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_question", $old_question_group_question['question_id'], $wpdb->prefix . "esp_question"); |
|
| 75 | - $new_question_group_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_qst_group", $old_question_group_question['group_id'], $wpdb->prefix . "esp_question_group"); |
|
| 76 | - if (! $new_question_id) { |
|
| 77 | - $this->add_error(sprintf(esc_html__("Could not find 4.1 question id for 3.1 question #%d.", "event_espresso"), $old_question_group_question['question_id'])); |
|
| 78 | - return 0; |
|
| 79 | - } |
|
| 80 | - if (! $new_question_group_id) { |
|
| 81 | - $this->add_error(sprintf(esc_html__("Could not find 4.1 question group id for 3.1 question group #%d.", "event_espresso"), $old_question_group_question['group_id'])); |
|
| 82 | - return 0; |
|
| 83 | - } |
|
| 84 | - // if it's a system question, it needs to be in the right system group. otherwise no dice! |
|
| 85 | - if ( |
|
| 86 | - ($this->_is_system_question_group($new_question_group_id) == $this->_is_system_question_for_question_group($new_question_id) ) |
|
| 87 | - || |
|
| 88 | - ! $this->_is_system_question_for_question_group($new_question_id) |
|
| 89 | - ) { |
|
| 90 | - $cols_n_values = array( |
|
| 91 | - 'QSG_ID' => $new_question_group_id, |
|
| 92 | - 'QST_ID' => $new_question_id |
|
| 93 | - ); |
|
| 94 | - $datatypes = array( |
|
| 95 | - '%d',// QSG_ID |
|
| 96 | - '%d',// QST_ID |
|
| 97 | - ); |
|
| 98 | - $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
|
| 99 | - if (! $success) { |
|
| 100 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_question_group_question, $this->_new_table, $cols_n_values, $datatypes)); |
|
| 101 | - return 0; |
|
| 102 | - } |
|
| 103 | - return $wpdb->insert_id; |
|
| 104 | - } else { |
|
| 105 | - return false; |
|
| 106 | - } |
|
| 107 | - } |
|
| 63 | + /** |
|
| 64 | + * Attempts to insert a new question group inthe new format given an old one |
|
| 65 | + * @global type $wpdb |
|
| 66 | + * @param array $old_question_group_question |
|
| 67 | + * @return int |
|
| 68 | + */ |
|
| 69 | + private function _insert_new_question_group_question($old_question_group_question) |
|
| 70 | + { |
|
| 71 | + global $wpdb; |
|
| 72 | + $new_question_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_question", $old_question_group_question['question_id'], $wpdb->prefix . "esp_question"); |
|
| 73 | + $new_question_group_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_qst_group", $old_question_group_question['group_id'], $wpdb->prefix . "esp_question_group"); |
|
| 74 | + if (! $new_question_id) { |
|
| 75 | + $this->add_error(sprintf(esc_html__("Could not find 4.1 question id for 3.1 question #%d.", "event_espresso"), $old_question_group_question['question_id'])); |
|
| 76 | + return 0; |
|
| 77 | + } |
|
| 78 | + if (! $new_question_group_id) { |
|
| 79 | + $this->add_error(sprintf(esc_html__("Could not find 4.1 question group id for 3.1 question group #%d.", "event_espresso"), $old_question_group_question['group_id'])); |
|
| 80 | + return 0; |
|
| 81 | + } |
|
| 82 | + // if it's a system question, it needs to be in the right system group. otherwise no dice! |
|
| 83 | + if ( |
|
| 84 | + ($this->_is_system_question_group($new_question_group_id) == $this->_is_system_question_for_question_group($new_question_id) ) |
|
| 85 | + || |
|
| 86 | + ! $this->_is_system_question_for_question_group($new_question_id) |
|
| 87 | + ) { |
|
| 88 | + $cols_n_values = array( |
|
| 89 | + 'QSG_ID' => $new_question_group_id, |
|
| 90 | + 'QST_ID' => $new_question_id |
|
| 91 | + ); |
|
| 92 | + $datatypes = array( |
|
| 93 | + '%d',// QSG_ID |
|
| 94 | + '%d',// QST_ID |
|
| 95 | + ); |
|
| 96 | + $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
|
| 97 | + if (! $success) { |
|
| 98 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_question_group_question, $this->_new_table, $cols_n_values, $datatypes)); |
|
| 99 | + return 0; |
|
| 100 | + } |
|
| 101 | + return $wpdb->insert_id; |
|
| 102 | + } else { |
|
| 103 | + return false; |
|
| 104 | + } |
|
| 105 | + } |
|
| 108 | 106 | |
| 109 | - /** |
|
| 110 | - * If this question is a system question, returns the QSG_system number that |
|
| 111 | - * indicates the question group its permitted in. |
|
| 112 | - * @global type $wpdb |
|
| 113 | - * @param type $new_question_id |
|
| 114 | - * @return int |
|
| 115 | - */ |
|
| 116 | - private function _is_system_question_for_question_group($new_question_id) |
|
| 117 | - { |
|
| 118 | - global $wpdb; |
|
| 119 | - $system_id = $wpdb->get_var($wpdb->prepare("SELECT QST_system FROM " . $wpdb->prefix . "esp_question WHERE QST_ID=%d", $new_question_id)); |
|
| 120 | - if (in_array($system_id, array('fname','lname','email'))) { |
|
| 121 | - return 1; |
|
| 122 | - } elseif ($system_id != '' && $system_id) { |
|
| 123 | - return 2; |
|
| 124 | - } else { |
|
| 125 | - return 0; |
|
| 126 | - } |
|
| 127 | - } |
|
| 107 | + /** |
|
| 108 | + * If this question is a system question, returns the QSG_system number that |
|
| 109 | + * indicates the question group its permitted in. |
|
| 110 | + * @global type $wpdb |
|
| 111 | + * @param type $new_question_id |
|
| 112 | + * @return int |
|
| 113 | + */ |
|
| 114 | + private function _is_system_question_for_question_group($new_question_id) |
|
| 115 | + { |
|
| 116 | + global $wpdb; |
|
| 117 | + $system_id = $wpdb->get_var($wpdb->prepare("SELECT QST_system FROM " . $wpdb->prefix . "esp_question WHERE QST_ID=%d", $new_question_id)); |
|
| 118 | + if (in_array($system_id, array('fname','lname','email'))) { |
|
| 119 | + return 1; |
|
| 120 | + } elseif ($system_id != '' && $system_id) { |
|
| 121 | + return 2; |
|
| 122 | + } else { |
|
| 123 | + return 0; |
|
| 124 | + } |
|
| 125 | + } |
|
| 128 | 126 | |
| 129 | - /** |
|
| 130 | - * Returns the questino group's QSG_system value (1 meaning personal info, 2 |
|
| 131 | - * being address info, and 0 being neither) |
|
| 132 | - * @global type $wpdb |
|
| 133 | - * @param type $new_question_group_id |
|
| 134 | - * @return boolean |
|
| 135 | - */ |
|
| 136 | - private function _is_system_question_group($new_question_group_id) |
|
| 137 | - { |
|
| 138 | - global $wpdb; |
|
| 139 | - $system_id = $wpdb->get_var($wpdb->prepare("SELECT QSG_system FROM " . $wpdb->prefix . "esp_question_group WHERE QSG_ID=%d", $new_question_group_id)); |
|
| 140 | - return intval($system_id); |
|
| 141 | - } |
|
| 127 | + /** |
|
| 128 | + * Returns the questino group's QSG_system value (1 meaning personal info, 2 |
|
| 129 | + * being address info, and 0 being neither) |
|
| 130 | + * @global type $wpdb |
|
| 131 | + * @param type $new_question_group_id |
|
| 132 | + * @return boolean |
|
| 133 | + */ |
|
| 134 | + private function _is_system_question_group($new_question_group_id) |
|
| 135 | + { |
|
| 136 | + global $wpdb; |
|
| 137 | + $system_id = $wpdb->get_var($wpdb->prepare("SELECT QSG_system FROM " . $wpdb->prefix . "esp_question_group WHERE QSG_ID=%d", $new_question_group_id)); |
|
| 138 | + return intval($system_id); |
|
| 139 | + } |
|
| 142 | 140 | } |
@@ -50,14 +50,14 @@ discard block |
||
| 50 | 50 | public function _count_records_to_migrate() |
| 51 | 51 | { |
| 52 | 52 | global $wpdb; |
| 53 | - $count = $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table); |
|
| 53 | + $count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table); |
|
| 54 | 54 | return $count; |
| 55 | 55 | } |
| 56 | 56 | public function __construct() |
| 57 | 57 | { |
| 58 | 58 | global $wpdb; |
| 59 | - $this->_old_table = $wpdb->prefix . "events_qst_group_rel"; |
|
| 60 | - $this->_new_table = $wpdb->prefix . "esp_question_group_question"; |
|
| 59 | + $this->_old_table = $wpdb->prefix."events_qst_group_rel"; |
|
| 60 | + $this->_new_table = $wpdb->prefix."esp_question_group_question"; |
|
| 61 | 61 | $this->_pretty_name = esc_html__("Question Group to Question Relations", "event_espresso"); |
| 62 | 62 | parent::__construct(); |
| 63 | 63 | } |
@@ -71,19 +71,19 @@ discard block |
||
| 71 | 71 | private function _insert_new_question_group_question($old_question_group_question) |
| 72 | 72 | { |
| 73 | 73 | global $wpdb; |
| 74 | - $new_question_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_question", $old_question_group_question['question_id'], $wpdb->prefix . "esp_question"); |
|
| 75 | - $new_question_group_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_qst_group", $old_question_group_question['group_id'], $wpdb->prefix . "esp_question_group"); |
|
| 76 | - if (! $new_question_id) { |
|
| 74 | + $new_question_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_question", $old_question_group_question['question_id'], $wpdb->prefix."esp_question"); |
|
| 75 | + $new_question_group_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_qst_group", $old_question_group_question['group_id'], $wpdb->prefix."esp_question_group"); |
|
| 76 | + if ( ! $new_question_id) { |
|
| 77 | 77 | $this->add_error(sprintf(esc_html__("Could not find 4.1 question id for 3.1 question #%d.", "event_espresso"), $old_question_group_question['question_id'])); |
| 78 | 78 | return 0; |
| 79 | 79 | } |
| 80 | - if (! $new_question_group_id) { |
|
| 80 | + if ( ! $new_question_group_id) { |
|
| 81 | 81 | $this->add_error(sprintf(esc_html__("Could not find 4.1 question group id for 3.1 question group #%d.", "event_espresso"), $old_question_group_question['group_id'])); |
| 82 | 82 | return 0; |
| 83 | 83 | } |
| 84 | 84 | // if it's a system question, it needs to be in the right system group. otherwise no dice! |
| 85 | 85 | if ( |
| 86 | - ($this->_is_system_question_group($new_question_group_id) == $this->_is_system_question_for_question_group($new_question_id) ) |
|
| 86 | + ($this->_is_system_question_group($new_question_group_id) == $this->_is_system_question_for_question_group($new_question_id)) |
|
| 87 | 87 | || |
| 88 | 88 | ! $this->_is_system_question_for_question_group($new_question_id) |
| 89 | 89 | ) { |
@@ -92,11 +92,11 @@ discard block |
||
| 92 | 92 | 'QST_ID' => $new_question_id |
| 93 | 93 | ); |
| 94 | 94 | $datatypes = array( |
| 95 | - '%d',// QSG_ID |
|
| 96 | - '%d',// QST_ID |
|
| 95 | + '%d', // QSG_ID |
|
| 96 | + '%d', // QST_ID |
|
| 97 | 97 | ); |
| 98 | 98 | $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
| 99 | - if (! $success) { |
|
| 99 | + if ( ! $success) { |
|
| 100 | 100 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_question_group_question, $this->_new_table, $cols_n_values, $datatypes)); |
| 101 | 101 | return 0; |
| 102 | 102 | } |
@@ -116,8 +116,8 @@ discard block |
||
| 116 | 116 | private function _is_system_question_for_question_group($new_question_id) |
| 117 | 117 | { |
| 118 | 118 | global $wpdb; |
| 119 | - $system_id = $wpdb->get_var($wpdb->prepare("SELECT QST_system FROM " . $wpdb->prefix . "esp_question WHERE QST_ID=%d", $new_question_id)); |
|
| 120 | - if (in_array($system_id, array('fname','lname','email'))) { |
|
| 119 | + $system_id = $wpdb->get_var($wpdb->prepare("SELECT QST_system FROM ".$wpdb->prefix."esp_question WHERE QST_ID=%d", $new_question_id)); |
|
| 120 | + if (in_array($system_id, array('fname', 'lname', 'email'))) { |
|
| 121 | 121 | return 1; |
| 122 | 122 | } elseif ($system_id != '' && $system_id) { |
| 123 | 123 | return 2; |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | private function _is_system_question_group($new_question_group_id) |
| 137 | 137 | { |
| 138 | 138 | global $wpdb; |
| 139 | - $system_id = $wpdb->get_var($wpdb->prepare("SELECT QSG_system FROM " . $wpdb->prefix . "esp_question_group WHERE QSG_ID=%d", $new_question_group_id)); |
|
| 139 | + $system_id = $wpdb->get_var($wpdb->prepare("SELECT QSG_system FROM ".$wpdb->prefix."esp_question_group WHERE QSG_ID=%d", $new_question_group_id)); |
|
| 140 | 140 | return intval($system_id); |
| 141 | 141 | } |
| 142 | 142 | } |
@@ -14,68 +14,68 @@ discard block |
||
| 14 | 14 | class EE_DMS_4_1_0_gateways extends EE_Data_Migration_Script_Stage |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - private $_converted_active_gateways = false; |
|
| 17 | + private $_converted_active_gateways = false; |
|
| 18 | 18 | |
| 19 | - public function _migration_step($num_items = 50) |
|
| 20 | - { |
|
| 21 | - // loads existing EE_CONfig from DB, if it exists |
|
| 22 | - $new_gateway_config_obj = EE_Config::instance()->gateway; |
|
| 23 | - $items_actually_migrated = 0; |
|
| 24 | - // convert settings |
|
| 25 | - $gateways_to_deal_with = array_merge($this->_gateways_we_know_how_to_migrate, $this->_gateways_we_leave_alone); |
|
| 26 | - // just do a part of them on this request |
|
| 27 | - $gateways_to_deal_with = array_slice($gateways_to_deal_with, $this->count_records_migrated(), $num_items);// $this->_gateways_we_know_how_to_migrate; |
|
| 28 | - foreach ($gateways_to_deal_with as $old_gateway_slug => $new_gateway_slug) { |
|
| 29 | - $old_gateway_wp_option_name = $this->_get_old_gateway_option_name($new_gateway_slug); |
|
| 30 | - if (isset($this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ])) { |
|
| 31 | - // determine the old option's name |
|
| 32 | - $old_gateway_settings = $this->_get_old_gateway_option($new_gateway_slug); |
|
| 33 | - if (! $old_gateway_settings) { |
|
| 34 | - // no settings existed for this gateway anyways... weird... |
|
| 35 | - $items_actually_migrated++; |
|
| 36 | - continue; |
|
| 37 | - } |
|
| 38 | - // now prepare the settings to make sure they're in the 4.1 format |
|
| 39 | - $new_gateway_settings = $this->_convert_gateway_settings($old_gateway_settings, $new_gateway_slug); |
|
| 40 | - $new_gateway_config_obj->payment_settings[ $new_gateway_slug ] = $new_gateway_settings; |
|
| 41 | - // and when we're done, remove the old option. Sometimes we'd prefer to do this in a different stage, but |
|
| 42 | - // I think it's ok to do right away this time (we wont need gateway settings elsewhere) |
|
| 43 | - delete_option($old_gateway_wp_option_name); |
|
| 44 | - } else {// it must be one of the ones we mostly leave alone |
|
| 45 | - global $wpdb; |
|
| 46 | - // yeah we could do this all in one query... and if you're reading this and would liek to, go ahead. Although you'll |
|
| 47 | - // only be saving users 50 milliseconds the one time this runs... |
|
| 48 | - $wpdb->query($wpdb->prepare("UPDATE " . $wpdb->options . " SET autoload='no' WHERE option_name=%s", $old_gateway_wp_option_name)); |
|
| 49 | - } |
|
| 19 | + public function _migration_step($num_items = 50) |
|
| 20 | + { |
|
| 21 | + // loads existing EE_CONfig from DB, if it exists |
|
| 22 | + $new_gateway_config_obj = EE_Config::instance()->gateway; |
|
| 23 | + $items_actually_migrated = 0; |
|
| 24 | + // convert settings |
|
| 25 | + $gateways_to_deal_with = array_merge($this->_gateways_we_know_how_to_migrate, $this->_gateways_we_leave_alone); |
|
| 26 | + // just do a part of them on this request |
|
| 27 | + $gateways_to_deal_with = array_slice($gateways_to_deal_with, $this->count_records_migrated(), $num_items);// $this->_gateways_we_know_how_to_migrate; |
|
| 28 | + foreach ($gateways_to_deal_with as $old_gateway_slug => $new_gateway_slug) { |
|
| 29 | + $old_gateway_wp_option_name = $this->_get_old_gateway_option_name($new_gateway_slug); |
|
| 30 | + if (isset($this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ])) { |
|
| 31 | + // determine the old option's name |
|
| 32 | + $old_gateway_settings = $this->_get_old_gateway_option($new_gateway_slug); |
|
| 33 | + if (! $old_gateway_settings) { |
|
| 34 | + // no settings existed for this gateway anyways... weird... |
|
| 35 | + $items_actually_migrated++; |
|
| 36 | + continue; |
|
| 37 | + } |
|
| 38 | + // now prepare the settings to make sure they're in the 4.1 format |
|
| 39 | + $new_gateway_settings = $this->_convert_gateway_settings($old_gateway_settings, $new_gateway_slug); |
|
| 40 | + $new_gateway_config_obj->payment_settings[ $new_gateway_slug ] = $new_gateway_settings; |
|
| 41 | + // and when we're done, remove the old option. Sometimes we'd prefer to do this in a different stage, but |
|
| 42 | + // I think it's ok to do right away this time (we wont need gateway settings elsewhere) |
|
| 43 | + delete_option($old_gateway_wp_option_name); |
|
| 44 | + } else {// it must be one of the ones we mostly leave alone |
|
| 45 | + global $wpdb; |
|
| 46 | + // yeah we could do this all in one query... and if you're reading this and would liek to, go ahead. Although you'll |
|
| 47 | + // only be saving users 50 milliseconds the one time this runs... |
|
| 48 | + $wpdb->query($wpdb->prepare("UPDATE " . $wpdb->options . " SET autoload='no' WHERE option_name=%s", $old_gateway_wp_option_name)); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - $items_actually_migrated++; |
|
| 52 | - } |
|
| 53 | - // if we can keep going, and it hasn' tbeen done yet, convert active gateways |
|
| 54 | - if ($items_actually_migrated < $num_items && ! $this->_converted_active_gateways) { |
|
| 55 | - $this->_convert_active_gateways(); |
|
| 56 | - $this->_converted_active_gateways = true; |
|
| 57 | - $items_actually_migrated++; |
|
| 58 | - } |
|
| 51 | + $items_actually_migrated++; |
|
| 52 | + } |
|
| 53 | + // if we can keep going, and it hasn' tbeen done yet, convert active gateways |
|
| 54 | + if ($items_actually_migrated < $num_items && ! $this->_converted_active_gateways) { |
|
| 55 | + $this->_convert_active_gateways(); |
|
| 56 | + $this->_converted_active_gateways = true; |
|
| 57 | + $items_actually_migrated++; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - EE_Config::instance()->update_espresso_config(false, false); |
|
| 61 | - if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
| 62 | - $this->set_completed(); |
|
| 63 | - } |
|
| 64 | - return $items_actually_migrated; |
|
| 65 | - } |
|
| 66 | - public function _count_records_to_migrate() |
|
| 67 | - { |
|
| 68 | - $count_of_gateways_to_convert = count($this->_gateways_we_know_how_to_migrate); |
|
| 69 | - $step_of_setting_active_gateways = 1; |
|
| 70 | - $count_of_gateways_to_leave_alone = count($this->_gateways_we_leave_alone); |
|
| 71 | - // $button_images_to_update = |
|
| 72 | - return $count_of_gateways_to_convert + $step_of_setting_active_gateways + $count_of_gateways_to_leave_alone; |
|
| 73 | - } |
|
| 74 | - public function __construct() |
|
| 75 | - { |
|
| 76 | - $this->_pretty_name = esc_html__("Gateways", "event_espresso"); |
|
| 77 | - parent::__construct(); |
|
| 78 | - } |
|
| 60 | + EE_Config::instance()->update_espresso_config(false, false); |
|
| 61 | + if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
| 62 | + $this->set_completed(); |
|
| 63 | + } |
|
| 64 | + return $items_actually_migrated; |
|
| 65 | + } |
|
| 66 | + public function _count_records_to_migrate() |
|
| 67 | + { |
|
| 68 | + $count_of_gateways_to_convert = count($this->_gateways_we_know_how_to_migrate); |
|
| 69 | + $step_of_setting_active_gateways = 1; |
|
| 70 | + $count_of_gateways_to_leave_alone = count($this->_gateways_we_leave_alone); |
|
| 71 | + // $button_images_to_update = |
|
| 72 | + return $count_of_gateways_to_convert + $step_of_setting_active_gateways + $count_of_gateways_to_leave_alone; |
|
| 73 | + } |
|
| 74 | + public function __construct() |
|
| 75 | + { |
|
| 76 | + $this->_pretty_name = esc_html__("Gateways", "event_espresso"); |
|
| 77 | + parent::__construct(); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | 80 | /** |
| 81 | 81 | * Takes the old array of 3.1 gateway settings for this gateway and converts it |
@@ -85,148 +85,148 @@ discard block |
||
| 85 | 85 | * @param string $new_gateway_slug |
| 86 | 86 | * @return array |
| 87 | 87 | */ |
| 88 | - private function _convert_gateway_settings($old_gateway_settings, $new_gateway_slug) |
|
| 89 | - { |
|
| 90 | - $new_gateway_settings = $old_gateway_settings; |
|
| 91 | - switch ($new_gateway_slug) { |
|
| 92 | - case 'Bank': |
|
| 93 | - $new_gateway_settings['account_number'] = $old_gateway_settings['bank_account']; |
|
| 94 | - $new_gateway_settings['page_title'] = $old_gateway_settings['bank_title']; |
|
| 95 | - break; |
|
| 96 | - case 'Invoice': |
|
| 97 | - $new_gateway_settings['invoice_logo_url'] = $old_gateway_settings['image_url']; |
|
| 98 | - // Dont' migrate the old invoice payee address. It was usually given dummy data. And in EE4 |
|
| 99 | - // it gets used in the receipts which are available to everyone. So usually it's best to not |
|
| 100 | - // migrate this. |
|
| 101 | - unset($new_gateway_settings['payment_address']); |
|
| 102 | - break; |
|
| 103 | - case 'Paypal_Pro': |
|
| 104 | - $new_gateway_settings['email'] = $old_gateway_settings['paypal_pro_email']; |
|
| 105 | - $new_gateway_settings['username'] = $old_gateway_settings['paypal_api_username']; |
|
| 106 | - $new_gateway_settings['password'] = $old_gateway_settings['paypal_api_password']; |
|
| 107 | - $new_gateway_settings['signature'] = $old_gateway_settings['paypal_api_signature']; |
|
| 108 | - $new_gateway_settings['credit_cards'] = explode(",", $old_gateway_settings['paypal_api_credit_cards']); |
|
| 109 | - $new_gateway_settings['use_sandbox'] = $old_gateway_settings['paypal_pro_use_sandbox']; |
|
| 110 | - break; |
|
| 111 | - } |
|
| 112 | - return $new_gateway_settings; |
|
| 113 | - } |
|
| 88 | + private function _convert_gateway_settings($old_gateway_settings, $new_gateway_slug) |
|
| 89 | + { |
|
| 90 | + $new_gateway_settings = $old_gateway_settings; |
|
| 91 | + switch ($new_gateway_slug) { |
|
| 92 | + case 'Bank': |
|
| 93 | + $new_gateway_settings['account_number'] = $old_gateway_settings['bank_account']; |
|
| 94 | + $new_gateway_settings['page_title'] = $old_gateway_settings['bank_title']; |
|
| 95 | + break; |
|
| 96 | + case 'Invoice': |
|
| 97 | + $new_gateway_settings['invoice_logo_url'] = $old_gateway_settings['image_url']; |
|
| 98 | + // Dont' migrate the old invoice payee address. It was usually given dummy data. And in EE4 |
|
| 99 | + // it gets used in the receipts which are available to everyone. So usually it's best to not |
|
| 100 | + // migrate this. |
|
| 101 | + unset($new_gateway_settings['payment_address']); |
|
| 102 | + break; |
|
| 103 | + case 'Paypal_Pro': |
|
| 104 | + $new_gateway_settings['email'] = $old_gateway_settings['paypal_pro_email']; |
|
| 105 | + $new_gateway_settings['username'] = $old_gateway_settings['paypal_api_username']; |
|
| 106 | + $new_gateway_settings['password'] = $old_gateway_settings['paypal_api_password']; |
|
| 107 | + $new_gateway_settings['signature'] = $old_gateway_settings['paypal_api_signature']; |
|
| 108 | + $new_gateway_settings['credit_cards'] = explode(",", $old_gateway_settings['paypal_api_credit_cards']); |
|
| 109 | + $new_gateway_settings['use_sandbox'] = $old_gateway_settings['paypal_pro_use_sandbox']; |
|
| 110 | + break; |
|
| 111 | + } |
|
| 112 | + return $new_gateway_settings; |
|
| 113 | + } |
|
| 114 | 114 | /** |
| 115 | - * Figures out the correct 3.1 gateway settings option name for the given 4.1 gateway |
|
| 116 | - * @param string $new_gateway_slug |
|
| 117 | - * @return string |
|
| 118 | - */ |
|
| 119 | - private function _get_old_gateway_option($new_gateway_slug) |
|
| 120 | - { |
|
| 121 | - $option_name = $this->_get_old_gateway_option_name($new_gateway_slug); |
|
| 122 | - $settings = get_option($option_name, null); |
|
| 123 | - // if( ! $settings){ |
|
| 124 | - // $this->add_error(sprintf(esc_html__("There is no wordpress option named %s for gateway %s", "event_espresso"),$option_name,$new_gateway_slug)); |
|
| 125 | - // } |
|
| 126 | - return $settings; |
|
| 127 | - } |
|
| 115 | + * Figures out the correct 3.1 gateway settings option name for the given 4.1 gateway |
|
| 116 | + * @param string $new_gateway_slug |
|
| 117 | + * @return string |
|
| 118 | + */ |
|
| 119 | + private function _get_old_gateway_option($new_gateway_slug) |
|
| 120 | + { |
|
| 121 | + $option_name = $this->_get_old_gateway_option_name($new_gateway_slug); |
|
| 122 | + $settings = get_option($option_name, null); |
|
| 123 | + // if( ! $settings){ |
|
| 124 | + // $this->add_error(sprintf(esc_html__("There is no wordpress option named %s for gateway %s", "event_espresso"),$option_name,$new_gateway_slug)); |
|
| 125 | + // } |
|
| 126 | + return $settings; |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | 129 | /** |
| 130 | 130 | * Just gets the old gateways slug |
| 131 | 131 | * @param string $new_gateway_slug |
| 132 | 132 | * @return string |
| 133 | 133 | */ |
| 134 | - private function _get_old_gateway_option_name($new_gateway_slug) |
|
| 135 | - { |
|
| 136 | - $new_gateway_slugs_to_new = array_flip(array_merge($this->_gateways_we_know_how_to_migrate, $this->_gateways_we_leave_alone)); |
|
| 137 | - $old_gateway_slug = $new_gateway_slugs_to_new[ $new_gateway_slug ]; |
|
| 138 | - $normal_option_prefix = 'event_espresso_'; |
|
| 139 | - $normal_option_postfix = '_settings'; |
|
| 140 | - switch ($new_gateway_slug) { |
|
| 141 | - case 'Bank': |
|
| 142 | - $option_name = $normal_option_prefix . 'bank_deposit' . $normal_option_postfix; |
|
| 143 | - break; |
|
| 144 | - case 'Aim': |
|
| 145 | - $option_name = $normal_option_prefix . 'authnet_aim' . $normal_option_postfix; |
|
| 146 | - break; |
|
| 147 | - case 'Check': |
|
| 148 | - $option_name = $normal_option_prefix . 'check_payment' . $normal_option_postfix; |
|
| 149 | - break; |
|
| 150 | - case 'Ideal': |
|
| 151 | - $option_name = $normal_option_prefix . 'ideal_mollie' . $normal_option_postfix; |
|
| 152 | - break; |
|
| 153 | - case 'Invoice': |
|
| 154 | - $option_name = $normal_option_prefix . 'invoice_payment' . $normal_option_postfix; |
|
| 155 | - break; |
|
| 156 | - case 'Purchase_Order': |
|
| 157 | - $option_name = $normal_option_prefix . 'purchase_order_payment' . $normal_option_postfix; |
|
| 158 | - break; |
|
| 159 | - case 'USAePay_Offsite': |
|
| 160 | - $option_name = 'espresso_usaepay_offsite' . $normal_option_postfix; |
|
| 161 | - break; |
|
| 162 | - case 'USAePay_Onsite': |
|
| 163 | - $option_name = 'espresso_usaepay_onsite' . $normal_option_postfix; |
|
| 164 | - break; |
|
| 165 | - default: |
|
| 166 | - $option_name = apply_filters('FHEE__EE_DMS_4_1_0_gateways__get_old_gateway_option', $normal_option_prefix . $old_gateway_slug . $normal_option_postfix); |
|
| 167 | - } |
|
| 168 | - return $option_name; |
|
| 169 | - } |
|
| 134 | + private function _get_old_gateway_option_name($new_gateway_slug) |
|
| 135 | + { |
|
| 136 | + $new_gateway_slugs_to_new = array_flip(array_merge($this->_gateways_we_know_how_to_migrate, $this->_gateways_we_leave_alone)); |
|
| 137 | + $old_gateway_slug = $new_gateway_slugs_to_new[ $new_gateway_slug ]; |
|
| 138 | + $normal_option_prefix = 'event_espresso_'; |
|
| 139 | + $normal_option_postfix = '_settings'; |
|
| 140 | + switch ($new_gateway_slug) { |
|
| 141 | + case 'Bank': |
|
| 142 | + $option_name = $normal_option_prefix . 'bank_deposit' . $normal_option_postfix; |
|
| 143 | + break; |
|
| 144 | + case 'Aim': |
|
| 145 | + $option_name = $normal_option_prefix . 'authnet_aim' . $normal_option_postfix; |
|
| 146 | + break; |
|
| 147 | + case 'Check': |
|
| 148 | + $option_name = $normal_option_prefix . 'check_payment' . $normal_option_postfix; |
|
| 149 | + break; |
|
| 150 | + case 'Ideal': |
|
| 151 | + $option_name = $normal_option_prefix . 'ideal_mollie' . $normal_option_postfix; |
|
| 152 | + break; |
|
| 153 | + case 'Invoice': |
|
| 154 | + $option_name = $normal_option_prefix . 'invoice_payment' . $normal_option_postfix; |
|
| 155 | + break; |
|
| 156 | + case 'Purchase_Order': |
|
| 157 | + $option_name = $normal_option_prefix . 'purchase_order_payment' . $normal_option_postfix; |
|
| 158 | + break; |
|
| 159 | + case 'USAePay_Offsite': |
|
| 160 | + $option_name = 'espresso_usaepay_offsite' . $normal_option_postfix; |
|
| 161 | + break; |
|
| 162 | + case 'USAePay_Onsite': |
|
| 163 | + $option_name = 'espresso_usaepay_onsite' . $normal_option_postfix; |
|
| 164 | + break; |
|
| 165 | + default: |
|
| 166 | + $option_name = apply_filters('FHEE__EE_DMS_4_1_0_gateways__get_old_gateway_option', $normal_option_prefix . $old_gateway_slug . $normal_option_postfix); |
|
| 167 | + } |
|
| 168 | + return $option_name; |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - private function _convert_active_gateways() |
|
| 172 | - { |
|
| 173 | - // just does it all one big swoop |
|
| 174 | - $old_active_gateways = get_option('event_espresso_active_gateways'); |
|
| 175 | - $new_active_gateways = EE_Config::instance()->gateway->active_gateways; |
|
| 176 | - foreach ($old_active_gateways as $old_gateway_slug => $filepath) { |
|
| 177 | - if (! isset($this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ])) { |
|
| 178 | - $this->add_error(sprintf(esc_html__("The %s gateway does not exist in EE 4.1", "event_espresso"), $old_gateway_slug)); |
|
| 179 | - continue; |
|
| 180 | - } |
|
| 181 | - $new_gateway_slug = $this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ]; |
|
| 171 | + private function _convert_active_gateways() |
|
| 172 | + { |
|
| 173 | + // just does it all one big swoop |
|
| 174 | + $old_active_gateways = get_option('event_espresso_active_gateways'); |
|
| 175 | + $new_active_gateways = EE_Config::instance()->gateway->active_gateways; |
|
| 176 | + foreach ($old_active_gateways as $old_gateway_slug => $filepath) { |
|
| 177 | + if (! isset($this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ])) { |
|
| 178 | + $this->add_error(sprintf(esc_html__("The %s gateway does not exist in EE 4.1", "event_espresso"), $old_gateway_slug)); |
|
| 179 | + continue; |
|
| 180 | + } |
|
| 181 | + $new_gateway_slug = $this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ]; |
|
| 182 | 182 | |
| 183 | - // in the new format we can also upload gateways to the uploads directory and |
|
| 184 | - $new_active_gateways[ $new_gateway_slug ] = false; |
|
| 185 | - } |
|
| 186 | - EE_Config::instance()->gateway->active_gateways = $new_active_gateways; |
|
| 187 | - } |
|
| 183 | + // in the new format we can also upload gateways to the uploads directory and |
|
| 184 | + $new_active_gateways[ $new_gateway_slug ] = false; |
|
| 185 | + } |
|
| 186 | + EE_Config::instance()->gateway->active_gateways = $new_active_gateways; |
|
| 187 | + } |
|
| 188 | 188 | |
| 189 | - protected $_gateways_we_know_how_to_migrate = array( |
|
| 190 | - 'aim' => 'Aim', |
|
| 191 | - 'bank' => 'Bank', |
|
| 192 | - 'check' => 'Check', |
|
| 193 | - 'invoice' => 'Invoice', |
|
| 194 | - 'paypal' => 'Paypal_Standard', |
|
| 195 | - 'paypal_pro' => 'Paypal_Pro', |
|
| 189 | + protected $_gateways_we_know_how_to_migrate = array( |
|
| 190 | + 'aim' => 'Aim', |
|
| 191 | + 'bank' => 'Bank', |
|
| 192 | + 'check' => 'Check', |
|
| 193 | + 'invoice' => 'Invoice', |
|
| 194 | + 'paypal' => 'Paypal_Standard', |
|
| 195 | + 'paypal_pro' => 'Paypal_Pro', |
|
| 196 | 196 | |
| 197 | - ); |
|
| 197 | + ); |
|
| 198 | 198 | |
| 199 | - protected $_gateways_we_leave_alone = array( |
|
| 200 | - '2checkout' => '2checkout', |
|
| 201 | - 'anz' => 'Anz', |
|
| 202 | - 'atos' => 'Atos', |
|
| 203 | - 'authnet' => 'Authnet', |
|
| 204 | - 'beanstream' => 'Beanstream', |
|
| 205 | - 'evertec' => 'Evertec', |
|
| 206 | - 'eway' => 'Eway', |
|
| 207 | - 'eway_rapid3' => 'Eway_Rapid3', |
|
| 208 | - 'exact' => 'Exact', |
|
| 209 | - 'firstdata' => 'Firstdata', |
|
| 210 | - 'firstdat_e4' => 'Firstdata_E4', |
|
| 211 | - 'ideal' => 'Ideal', |
|
| 212 | - 'infusion_payment' => 'InfusionSoft', |
|
| 213 | - 'luottokunta' => 'Luottokunta', |
|
| 214 | - 'megasoft' => 'Megasoft', |
|
| 215 | - 'moneris_hpp' => 'Moneris_HPP', |
|
| 216 | - 'mwarrior' => 'Mwarrior', |
|
| 217 | - 'nab' => 'NAB', |
|
| 218 | - 'paychoice' => 'Paychoice', |
|
| 219 | - 'paytrace' => 'Paytrace', |
|
| 220 | - 'psigate' => 'Psigate', |
|
| 221 | - 'purchase_order' => 'Purchase_Order', |
|
| 222 | - 'qbms' => 'QBMS', |
|
| 223 | - 'quickpay' => 'Quickpay', |
|
| 224 | - 'realauth' => 'Realauth', |
|
| 225 | - 'securepay_aus' => 'Securepay_Aus', |
|
| 226 | - 'stripe' => 'Stripe', |
|
| 227 | - 'usaepay_offsite' => 'USAePay_Offsite', |
|
| 228 | - 'usaepay_onsite' => 'USAePay_Onsite', |
|
| 229 | - 'wepay' => 'Wepay', |
|
| 230 | - 'worldpay' => 'Worldpay' |
|
| 231 | - ); |
|
| 199 | + protected $_gateways_we_leave_alone = array( |
|
| 200 | + '2checkout' => '2checkout', |
|
| 201 | + 'anz' => 'Anz', |
|
| 202 | + 'atos' => 'Atos', |
|
| 203 | + 'authnet' => 'Authnet', |
|
| 204 | + 'beanstream' => 'Beanstream', |
|
| 205 | + 'evertec' => 'Evertec', |
|
| 206 | + 'eway' => 'Eway', |
|
| 207 | + 'eway_rapid3' => 'Eway_Rapid3', |
|
| 208 | + 'exact' => 'Exact', |
|
| 209 | + 'firstdata' => 'Firstdata', |
|
| 210 | + 'firstdat_e4' => 'Firstdata_E4', |
|
| 211 | + 'ideal' => 'Ideal', |
|
| 212 | + 'infusion_payment' => 'InfusionSoft', |
|
| 213 | + 'luottokunta' => 'Luottokunta', |
|
| 214 | + 'megasoft' => 'Megasoft', |
|
| 215 | + 'moneris_hpp' => 'Moneris_HPP', |
|
| 216 | + 'mwarrior' => 'Mwarrior', |
|
| 217 | + 'nab' => 'NAB', |
|
| 218 | + 'paychoice' => 'Paychoice', |
|
| 219 | + 'paytrace' => 'Paytrace', |
|
| 220 | + 'psigate' => 'Psigate', |
|
| 221 | + 'purchase_order' => 'Purchase_Order', |
|
| 222 | + 'qbms' => 'QBMS', |
|
| 223 | + 'quickpay' => 'Quickpay', |
|
| 224 | + 'realauth' => 'Realauth', |
|
| 225 | + 'securepay_aus' => 'Securepay_Aus', |
|
| 226 | + 'stripe' => 'Stripe', |
|
| 227 | + 'usaepay_offsite' => 'USAePay_Offsite', |
|
| 228 | + 'usaepay_onsite' => 'USAePay_Onsite', |
|
| 229 | + 'wepay' => 'Wepay', |
|
| 230 | + 'worldpay' => 'Worldpay' |
|
| 231 | + ); |
|
| 232 | 232 | } |
@@ -24,20 +24,20 @@ discard block |
||
| 24 | 24 | // convert settings |
| 25 | 25 | $gateways_to_deal_with = array_merge($this->_gateways_we_know_how_to_migrate, $this->_gateways_we_leave_alone); |
| 26 | 26 | // just do a part of them on this request |
| 27 | - $gateways_to_deal_with = array_slice($gateways_to_deal_with, $this->count_records_migrated(), $num_items);// $this->_gateways_we_know_how_to_migrate; |
|
| 27 | + $gateways_to_deal_with = array_slice($gateways_to_deal_with, $this->count_records_migrated(), $num_items); // $this->_gateways_we_know_how_to_migrate; |
|
| 28 | 28 | foreach ($gateways_to_deal_with as $old_gateway_slug => $new_gateway_slug) { |
| 29 | 29 | $old_gateway_wp_option_name = $this->_get_old_gateway_option_name($new_gateway_slug); |
| 30 | - if (isset($this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ])) { |
|
| 30 | + if (isset($this->_gateways_we_know_how_to_migrate[$old_gateway_slug])) { |
|
| 31 | 31 | // determine the old option's name |
| 32 | 32 | $old_gateway_settings = $this->_get_old_gateway_option($new_gateway_slug); |
| 33 | - if (! $old_gateway_settings) { |
|
| 33 | + if ( ! $old_gateway_settings) { |
|
| 34 | 34 | // no settings existed for this gateway anyways... weird... |
| 35 | 35 | $items_actually_migrated++; |
| 36 | 36 | continue; |
| 37 | 37 | } |
| 38 | 38 | // now prepare the settings to make sure they're in the 4.1 format |
| 39 | 39 | $new_gateway_settings = $this->_convert_gateway_settings($old_gateway_settings, $new_gateway_slug); |
| 40 | - $new_gateway_config_obj->payment_settings[ $new_gateway_slug ] = $new_gateway_settings; |
|
| 40 | + $new_gateway_config_obj->payment_settings[$new_gateway_slug] = $new_gateway_settings; |
|
| 41 | 41 | // and when we're done, remove the old option. Sometimes we'd prefer to do this in a different stage, but |
| 42 | 42 | // I think it's ok to do right away this time (we wont need gateway settings elsewhere) |
| 43 | 43 | delete_option($old_gateway_wp_option_name); |
@@ -45,13 +45,13 @@ discard block |
||
| 45 | 45 | global $wpdb; |
| 46 | 46 | // yeah we could do this all in one query... and if you're reading this and would liek to, go ahead. Although you'll |
| 47 | 47 | // only be saving users 50 milliseconds the one time this runs... |
| 48 | - $wpdb->query($wpdb->prepare("UPDATE " . $wpdb->options . " SET autoload='no' WHERE option_name=%s", $old_gateway_wp_option_name)); |
|
| 48 | + $wpdb->query($wpdb->prepare("UPDATE ".$wpdb->options." SET autoload='no' WHERE option_name=%s", $old_gateway_wp_option_name)); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | $items_actually_migrated++; |
| 52 | 52 | } |
| 53 | 53 | // if we can keep going, and it hasn' tbeen done yet, convert active gateways |
| 54 | - if ($items_actually_migrated < $num_items && ! $this->_converted_active_gateways) { |
|
| 54 | + if ($items_actually_migrated < $num_items && ! $this->_converted_active_gateways) { |
|
| 55 | 55 | $this->_convert_active_gateways(); |
| 56 | 56 | $this->_converted_active_gateways = true; |
| 57 | 57 | $items_actually_migrated++; |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | $step_of_setting_active_gateways = 1; |
| 70 | 70 | $count_of_gateways_to_leave_alone = count($this->_gateways_we_leave_alone); |
| 71 | 71 | // $button_images_to_update = |
| 72 | - return $count_of_gateways_to_convert + $step_of_setting_active_gateways + $count_of_gateways_to_leave_alone; |
|
| 72 | + return $count_of_gateways_to_convert + $step_of_setting_active_gateways + $count_of_gateways_to_leave_alone; |
|
| 73 | 73 | } |
| 74 | 74 | public function __construct() |
| 75 | 75 | { |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | private function _get_old_gateway_option($new_gateway_slug) |
| 120 | 120 | { |
| 121 | 121 | $option_name = $this->_get_old_gateway_option_name($new_gateway_slug); |
| 122 | - $settings = get_option($option_name, null); |
|
| 122 | + $settings = get_option($option_name, null); |
|
| 123 | 123 | // if( ! $settings){ |
| 124 | 124 | // $this->add_error(sprintf(esc_html__("There is no wordpress option named %s for gateway %s", "event_espresso"),$option_name,$new_gateway_slug)); |
| 125 | 125 | // } |
@@ -134,36 +134,36 @@ discard block |
||
| 134 | 134 | private function _get_old_gateway_option_name($new_gateway_slug) |
| 135 | 135 | { |
| 136 | 136 | $new_gateway_slugs_to_new = array_flip(array_merge($this->_gateways_we_know_how_to_migrate, $this->_gateways_we_leave_alone)); |
| 137 | - $old_gateway_slug = $new_gateway_slugs_to_new[ $new_gateway_slug ]; |
|
| 137 | + $old_gateway_slug = $new_gateway_slugs_to_new[$new_gateway_slug]; |
|
| 138 | 138 | $normal_option_prefix = 'event_espresso_'; |
| 139 | 139 | $normal_option_postfix = '_settings'; |
| 140 | 140 | switch ($new_gateway_slug) { |
| 141 | 141 | case 'Bank': |
| 142 | - $option_name = $normal_option_prefix . 'bank_deposit' . $normal_option_postfix; |
|
| 142 | + $option_name = $normal_option_prefix.'bank_deposit'.$normal_option_postfix; |
|
| 143 | 143 | break; |
| 144 | 144 | case 'Aim': |
| 145 | - $option_name = $normal_option_prefix . 'authnet_aim' . $normal_option_postfix; |
|
| 145 | + $option_name = $normal_option_prefix.'authnet_aim'.$normal_option_postfix; |
|
| 146 | 146 | break; |
| 147 | 147 | case 'Check': |
| 148 | - $option_name = $normal_option_prefix . 'check_payment' . $normal_option_postfix; |
|
| 148 | + $option_name = $normal_option_prefix.'check_payment'.$normal_option_postfix; |
|
| 149 | 149 | break; |
| 150 | 150 | case 'Ideal': |
| 151 | - $option_name = $normal_option_prefix . 'ideal_mollie' . $normal_option_postfix; |
|
| 151 | + $option_name = $normal_option_prefix.'ideal_mollie'.$normal_option_postfix; |
|
| 152 | 152 | break; |
| 153 | 153 | case 'Invoice': |
| 154 | - $option_name = $normal_option_prefix . 'invoice_payment' . $normal_option_postfix; |
|
| 154 | + $option_name = $normal_option_prefix.'invoice_payment'.$normal_option_postfix; |
|
| 155 | 155 | break; |
| 156 | 156 | case 'Purchase_Order': |
| 157 | - $option_name = $normal_option_prefix . 'purchase_order_payment' . $normal_option_postfix; |
|
| 157 | + $option_name = $normal_option_prefix.'purchase_order_payment'.$normal_option_postfix; |
|
| 158 | 158 | break; |
| 159 | 159 | case 'USAePay_Offsite': |
| 160 | - $option_name = 'espresso_usaepay_offsite' . $normal_option_postfix; |
|
| 160 | + $option_name = 'espresso_usaepay_offsite'.$normal_option_postfix; |
|
| 161 | 161 | break; |
| 162 | 162 | case 'USAePay_Onsite': |
| 163 | - $option_name = 'espresso_usaepay_onsite' . $normal_option_postfix; |
|
| 163 | + $option_name = 'espresso_usaepay_onsite'.$normal_option_postfix; |
|
| 164 | 164 | break; |
| 165 | 165 | default: |
| 166 | - $option_name = apply_filters('FHEE__EE_DMS_4_1_0_gateways__get_old_gateway_option', $normal_option_prefix . $old_gateway_slug . $normal_option_postfix); |
|
| 166 | + $option_name = apply_filters('FHEE__EE_DMS_4_1_0_gateways__get_old_gateway_option', $normal_option_prefix.$old_gateway_slug.$normal_option_postfix); |
|
| 167 | 167 | } |
| 168 | 168 | return $option_name; |
| 169 | 169 | } |
@@ -174,14 +174,14 @@ discard block |
||
| 174 | 174 | $old_active_gateways = get_option('event_espresso_active_gateways'); |
| 175 | 175 | $new_active_gateways = EE_Config::instance()->gateway->active_gateways; |
| 176 | 176 | foreach ($old_active_gateways as $old_gateway_slug => $filepath) { |
| 177 | - if (! isset($this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ])) { |
|
| 177 | + if ( ! isset($this->_gateways_we_know_how_to_migrate[$old_gateway_slug])) { |
|
| 178 | 178 | $this->add_error(sprintf(esc_html__("The %s gateway does not exist in EE 4.1", "event_espresso"), $old_gateway_slug)); |
| 179 | 179 | continue; |
| 180 | 180 | } |
| 181 | - $new_gateway_slug = $this->_gateways_we_know_how_to_migrate[ $old_gateway_slug ]; |
|
| 181 | + $new_gateway_slug = $this->_gateways_we_know_how_to_migrate[$old_gateway_slug]; |
|
| 182 | 182 | |
| 183 | 183 | // in the new format we can also upload gateways to the uploads directory and |
| 184 | - $new_active_gateways[ $new_gateway_slug ] = false; |
|
| 184 | + $new_active_gateways[$new_gateway_slug] = false; |
|
| 185 | 185 | } |
| 186 | 186 | EE_Config::instance()->gateway->active_gateways = $new_active_gateways; |
| 187 | 187 | } |
@@ -24,87 +24,85 @@ |
||
| 24 | 24 | 'term_taxonomy_id'=>new EE_Foreign_Key_Int_Field('term_taxonomy_id', esc_html__('Term (in context of a taxonomy) ID','event_espresso'), false, 0, 'Term_Taxonomy'), |
| 25 | 25 | 'term_order'=>new EE_Integer_Field('term_order', esc_html__('Term Order','event_espresso'), false, 0) |
| 26 | 26 | )); |
| 27 | - |
|
| 28 | - |
|
| 29 | 27 | * |
| 30 | 28 | */ |
| 31 | 29 | class EE_DMS_4_1_0_event_category extends EE_Data_Migration_Script_Stage |
| 32 | 30 | { |
| 33 | - private $_old_table; |
|
| 34 | - private $_new_table; |
|
| 35 | - public function _migration_step($num_items = 50) |
|
| 36 | - { |
|
| 37 | - global $wpdb; |
|
| 38 | - $start_at_record = $this->count_records_migrated(); |
|
| 39 | - $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A); |
|
| 40 | - $items_actually_migrated = 0; |
|
| 41 | - foreach ($rows as $event_venue_rel) { |
|
| 42 | - $term_relation_id = $this->_add_relation_from_event_to_term_taxonomy($event_venue_rel); |
|
| 43 | - if ($term_relation_id) { |
|
| 44 | - $this->get_migration_script()->set_mapping($this->_old_table, $event_venue_rel['id'], $this->_new_table, $term_relation_id); |
|
| 45 | - } |
|
| 46 | - $items_actually_migrated++; |
|
| 47 | - } |
|
| 48 | - if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
| 49 | - $this->set_completed(); |
|
| 50 | - } |
|
| 51 | - return $items_actually_migrated; |
|
| 52 | - } |
|
| 53 | - public function _count_records_to_migrate() |
|
| 54 | - { |
|
| 55 | - global $wpdb; |
|
| 56 | - $count = $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table); |
|
| 57 | - return $count; |
|
| 58 | - } |
|
| 59 | - public function __construct() |
|
| 60 | - { |
|
| 61 | - global $wpdb; |
|
| 62 | - $this->_old_table = $wpdb->prefix . "events_category_rel"; |
|
| 63 | - $this->_new_table = $wpdb->prefix . "term_relationships"; |
|
| 64 | - $this->_pretty_name = esc_html__("Event to Category (4.1 Term Relationships)", "event_espresso"); |
|
| 65 | - parent::__construct(); |
|
| 66 | - } |
|
| 31 | + private $_old_table; |
|
| 32 | + private $_new_table; |
|
| 33 | + public function _migration_step($num_items = 50) |
|
| 34 | + { |
|
| 35 | + global $wpdb; |
|
| 36 | + $start_at_record = $this->count_records_migrated(); |
|
| 37 | + $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A); |
|
| 38 | + $items_actually_migrated = 0; |
|
| 39 | + foreach ($rows as $event_venue_rel) { |
|
| 40 | + $term_relation_id = $this->_add_relation_from_event_to_term_taxonomy($event_venue_rel); |
|
| 41 | + if ($term_relation_id) { |
|
| 42 | + $this->get_migration_script()->set_mapping($this->_old_table, $event_venue_rel['id'], $this->_new_table, $term_relation_id); |
|
| 43 | + } |
|
| 44 | + $items_actually_migrated++; |
|
| 45 | + } |
|
| 46 | + if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
| 47 | + $this->set_completed(); |
|
| 48 | + } |
|
| 49 | + return $items_actually_migrated; |
|
| 50 | + } |
|
| 51 | + public function _count_records_to_migrate() |
|
| 52 | + { |
|
| 53 | + global $wpdb; |
|
| 54 | + $count = $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table); |
|
| 55 | + return $count; |
|
| 56 | + } |
|
| 57 | + public function __construct() |
|
| 58 | + { |
|
| 59 | + global $wpdb; |
|
| 60 | + $this->_old_table = $wpdb->prefix . "events_category_rel"; |
|
| 61 | + $this->_new_table = $wpdb->prefix . "term_relationships"; |
|
| 62 | + $this->_pretty_name = esc_html__("Event to Category (4.1 Term Relationships)", "event_espresso"); |
|
| 63 | + parent::__construct(); |
|
| 64 | + } |
|
| 67 | 65 | |
| 68 | - /** |
|
| 69 | - * Attempts to insert a new question group inthe new format given an old one |
|
| 70 | - * @global type $wpdb |
|
| 71 | - * @param array $old_event_cat_relation |
|
| 72 | - * @return int |
|
| 73 | - */ |
|
| 74 | - private function _add_relation_from_event_to_term_taxonomy($old_event_cat_relation) |
|
| 75 | - { |
|
| 76 | - global $wpdb; |
|
| 77 | - $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_detail", intval($old_event_cat_relation['event_id']), $wpdb->prefix . "posts"); |
|
| 78 | - $new_term_taxonomy_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_category_detail", intval($old_event_cat_relation['cat_id']), $wpdb->prefix . "term_taxonomy"); |
|
| 79 | - if (! $new_event_id) { |
|
| 80 | - $this->add_error(sprintf(esc_html__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $old_event_cat_relation['event_id'])); |
|
| 81 | - return 0; |
|
| 82 | - } |
|
| 83 | - if (! $new_term_taxonomy_id) { |
|
| 84 | - $this->add_error(sprintf(esc_html__("Could not find 4.1 term-taxonomy id for 3.1 category #%d.", "event_espresso"), $old_event_cat_relation['cat_id'])); |
|
| 85 | - return 0; |
|
| 86 | - } |
|
| 87 | - $cols_n_values = array( |
|
| 88 | - 'object_id' => $new_event_id, |
|
| 89 | - 'term_taxonomy_id' => $new_term_taxonomy_id, |
|
| 90 | - 'term_order' => 0 |
|
| 91 | - ); |
|
| 92 | - $datatypes = array( |
|
| 93 | - '%d',// object_id |
|
| 94 | - '%d',// term_taxonomy_id |
|
| 95 | - '%d',// term_order |
|
| 96 | - ); |
|
| 97 | - $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
|
| 98 | - if (! $success) { |
|
| 99 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event_cat_relation, $this->_new_table, $cols_n_values, $datatypes)); |
|
| 100 | - return 0; |
|
| 101 | - } else { |
|
| 102 | - // increment the term-taxonomie's count |
|
| 103 | - $success = $wpdb->query($wpdb->prepare("UPDATE {$wpdb->term_taxonomy} SET count = count +1 WHERE term_taxonomy_id=%d", $new_term_taxonomy_id)); |
|
| 104 | - if (! $success) { |
|
| 105 | - $this->add_error(sprintf(esc_html__('Could not increment term_taxonomy\'s count because %s', 'event_espresso'), $wpdb->last_error)); |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - return $wpdb->insert_id; |
|
| 109 | - } |
|
| 66 | + /** |
|
| 67 | + * Attempts to insert a new question group inthe new format given an old one |
|
| 68 | + * @global type $wpdb |
|
| 69 | + * @param array $old_event_cat_relation |
|
| 70 | + * @return int |
|
| 71 | + */ |
|
| 72 | + private function _add_relation_from_event_to_term_taxonomy($old_event_cat_relation) |
|
| 73 | + { |
|
| 74 | + global $wpdb; |
|
| 75 | + $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_detail", intval($old_event_cat_relation['event_id']), $wpdb->prefix . "posts"); |
|
| 76 | + $new_term_taxonomy_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_category_detail", intval($old_event_cat_relation['cat_id']), $wpdb->prefix . "term_taxonomy"); |
|
| 77 | + if (! $new_event_id) { |
|
| 78 | + $this->add_error(sprintf(esc_html__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $old_event_cat_relation['event_id'])); |
|
| 79 | + return 0; |
|
| 80 | + } |
|
| 81 | + if (! $new_term_taxonomy_id) { |
|
| 82 | + $this->add_error(sprintf(esc_html__("Could not find 4.1 term-taxonomy id for 3.1 category #%d.", "event_espresso"), $old_event_cat_relation['cat_id'])); |
|
| 83 | + return 0; |
|
| 84 | + } |
|
| 85 | + $cols_n_values = array( |
|
| 86 | + 'object_id' => $new_event_id, |
|
| 87 | + 'term_taxonomy_id' => $new_term_taxonomy_id, |
|
| 88 | + 'term_order' => 0 |
|
| 89 | + ); |
|
| 90 | + $datatypes = array( |
|
| 91 | + '%d',// object_id |
|
| 92 | + '%d',// term_taxonomy_id |
|
| 93 | + '%d',// term_order |
|
| 94 | + ); |
|
| 95 | + $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
|
| 96 | + if (! $success) { |
|
| 97 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event_cat_relation, $this->_new_table, $cols_n_values, $datatypes)); |
|
| 98 | + return 0; |
|
| 99 | + } else { |
|
| 100 | + // increment the term-taxonomie's count |
|
| 101 | + $success = $wpdb->query($wpdb->prepare("UPDATE {$wpdb->term_taxonomy} SET count = count +1 WHERE term_taxonomy_id=%d", $new_term_taxonomy_id)); |
|
| 102 | + if (! $success) { |
|
| 103 | + $this->add_error(sprintf(esc_html__('Could not increment term_taxonomy\'s count because %s', 'event_espresso'), $wpdb->last_error)); |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + return $wpdb->insert_id; |
|
| 107 | + } |
|
| 110 | 108 | } |
@@ -53,14 +53,14 @@ discard block |
||
| 53 | 53 | public function _count_records_to_migrate() |
| 54 | 54 | { |
| 55 | 55 | global $wpdb; |
| 56 | - $count = $wpdb->get_var("SELECT COUNT(id) FROM " . $this->_old_table); |
|
| 56 | + $count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table); |
|
| 57 | 57 | return $count; |
| 58 | 58 | } |
| 59 | 59 | public function __construct() |
| 60 | 60 | { |
| 61 | 61 | global $wpdb; |
| 62 | - $this->_old_table = $wpdb->prefix . "events_category_rel"; |
|
| 63 | - $this->_new_table = $wpdb->prefix . "term_relationships"; |
|
| 62 | + $this->_old_table = $wpdb->prefix."events_category_rel"; |
|
| 63 | + $this->_new_table = $wpdb->prefix."term_relationships"; |
|
| 64 | 64 | $this->_pretty_name = esc_html__("Event to Category (4.1 Term Relationships)", "event_espresso"); |
| 65 | 65 | parent::__construct(); |
| 66 | 66 | } |
@@ -74,13 +74,13 @@ discard block |
||
| 74 | 74 | private function _add_relation_from_event_to_term_taxonomy($old_event_cat_relation) |
| 75 | 75 | { |
| 76 | 76 | global $wpdb; |
| 77 | - $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_detail", intval($old_event_cat_relation['event_id']), $wpdb->prefix . "posts"); |
|
| 78 | - $new_term_taxonomy_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_category_detail", intval($old_event_cat_relation['cat_id']), $wpdb->prefix . "term_taxonomy"); |
|
| 79 | - if (! $new_event_id) { |
|
| 77 | + $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", intval($old_event_cat_relation['event_id']), $wpdb->prefix."posts"); |
|
| 78 | + $new_term_taxonomy_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_category_detail", intval($old_event_cat_relation['cat_id']), $wpdb->prefix."term_taxonomy"); |
|
| 79 | + if ( ! $new_event_id) { |
|
| 80 | 80 | $this->add_error(sprintf(esc_html__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $old_event_cat_relation['event_id'])); |
| 81 | 81 | return 0; |
| 82 | 82 | } |
| 83 | - if (! $new_term_taxonomy_id) { |
|
| 83 | + if ( ! $new_term_taxonomy_id) { |
|
| 84 | 84 | $this->add_error(sprintf(esc_html__("Could not find 4.1 term-taxonomy id for 3.1 category #%d.", "event_espresso"), $old_event_cat_relation['cat_id'])); |
| 85 | 85 | return 0; |
| 86 | 86 | } |
@@ -90,18 +90,18 @@ discard block |
||
| 90 | 90 | 'term_order' => 0 |
| 91 | 91 | ); |
| 92 | 92 | $datatypes = array( |
| 93 | - '%d',// object_id |
|
| 94 | - '%d',// term_taxonomy_id |
|
| 95 | - '%d',// term_order |
|
| 93 | + '%d', // object_id |
|
| 94 | + '%d', // term_taxonomy_id |
|
| 95 | + '%d', // term_order |
|
| 96 | 96 | ); |
| 97 | 97 | $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
| 98 | - if (! $success) { |
|
| 98 | + if ( ! $success) { |
|
| 99 | 99 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event_cat_relation, $this->_new_table, $cols_n_values, $datatypes)); |
| 100 | 100 | return 0; |
| 101 | 101 | } else { |
| 102 | 102 | // increment the term-taxonomie's count |
| 103 | 103 | $success = $wpdb->query($wpdb->prepare("UPDATE {$wpdb->term_taxonomy} SET count = count +1 WHERE term_taxonomy_id=%d", $new_term_taxonomy_id)); |
| 104 | - if (! $success) { |
|
| 104 | + if ( ! $success) { |
|
| 105 | 105 | $this->add_error(sprintf(esc_html__('Could not increment term_taxonomy\'s count because %s', 'event_espresso'), $wpdb->last_error)); |
| 106 | 106 | } |
| 107 | 107 | } |
@@ -32,102 +32,102 @@ |
||
| 32 | 32 | |
| 33 | 33 | class EE_DMS_4_1_0_answers extends EE_Data_Migration_Script_Stage_Table |
| 34 | 34 | { |
| 35 | - private $_new_answer_table; |
|
| 36 | - private $_new_question_table; |
|
| 37 | - public function __construct() |
|
| 38 | - { |
|
| 39 | - global $wpdb; |
|
| 40 | - $this->_pretty_name = esc_html__("Answers", "event_espresso"); |
|
| 41 | - $this->_old_table = $wpdb->prefix . "events_answer"; |
|
| 42 | - // join to attendee and then join to events table |
|
| 43 | - $this->select_expression = 'ans.*, e.event_status'; |
|
| 44 | - $this->_extra_where_sql = ' AS ans |
|
| 35 | + private $_new_answer_table; |
|
| 36 | + private $_new_question_table; |
|
| 37 | + public function __construct() |
|
| 38 | + { |
|
| 39 | + global $wpdb; |
|
| 40 | + $this->_pretty_name = esc_html__("Answers", "event_espresso"); |
|
| 41 | + $this->_old_table = $wpdb->prefix . "events_answer"; |
|
| 42 | + // join to attendee and then join to events table |
|
| 43 | + $this->select_expression = 'ans.*, e.event_status'; |
|
| 44 | + $this->_extra_where_sql = ' AS ans |
|
| 45 | 45 | INNER JOIN ' . $wpdb->prefix . 'events_attendee AS att ON ans.attendee_id = att.id |
| 46 | 46 | INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id = e.id |
| 47 | 47 | WHERE e.event_status !="D"'; |
| 48 | - $this->_new_answer_table = $wpdb->prefix . "esp_answer"; |
|
| 49 | - $this->_new_question_table = $wpdb->prefix . "esp_question"; |
|
| 50 | - parent::__construct(); |
|
| 51 | - } |
|
| 52 | - protected function _migrate_old_row($old_row) |
|
| 53 | - { |
|
| 54 | - // get the new REGs for the old answer |
|
| 55 | - global $wpdb; |
|
| 56 | - $old_attendee_table = $wpdb->prefix . "events_attendee"; |
|
| 57 | - $new_reg_table = $wpdb->prefix . "esp_registration"; |
|
| 58 | - $regs = $this->get_migration_script()->get_mapping_new_pk($old_attendee_table, $old_row['attendee_id'], $new_reg_table); |
|
| 59 | - if (! $regs) { |
|
| 60 | - $this->add_error(sprintf(esc_html__("Could not find new registrations for old attendee %d when creating answer %s", "event_espresso"), $old_row['attendee_id'], $this->_json_encode($old_row))); |
|
| 61 | - return false; |
|
| 62 | - } |
|
| 63 | - // as inefficient as this sounds, we create an answer per REGISTRATION, (even if the registrations use the same attendee) |
|
| 64 | - foreach ($regs as $new_reg_id) { |
|
| 65 | - $this->_insert_new_answer($old_row, $new_reg_id); |
|
| 66 | - } |
|
| 67 | - } |
|
| 68 | - /** |
|
| 69 | - * Creates a 4.1 price base type |
|
| 70 | - * @global type $wpdb |
|
| 71 | - * @param array $old_price |
|
| 72 | - * @param int $new_reg_id |
|
| 73 | - * @return int |
|
| 74 | - */ |
|
| 75 | - private function _insert_new_answer($old_answer, $new_reg_id) |
|
| 76 | - { |
|
| 77 | - global $wpdb; |
|
| 78 | - $old_question_table = $wpdb->prefix . "events_question"; |
|
| 79 | - $new_question_id = $this->get_migration_script()->get_mapping_new_pk($old_question_table, $old_answer['question_id'], $this->_new_question_table); |
|
| 48 | + $this->_new_answer_table = $wpdb->prefix . "esp_answer"; |
|
| 49 | + $this->_new_question_table = $wpdb->prefix . "esp_question"; |
|
| 50 | + parent::__construct(); |
|
| 51 | + } |
|
| 52 | + protected function _migrate_old_row($old_row) |
|
| 53 | + { |
|
| 54 | + // get the new REGs for the old answer |
|
| 55 | + global $wpdb; |
|
| 56 | + $old_attendee_table = $wpdb->prefix . "events_attendee"; |
|
| 57 | + $new_reg_table = $wpdb->prefix . "esp_registration"; |
|
| 58 | + $regs = $this->get_migration_script()->get_mapping_new_pk($old_attendee_table, $old_row['attendee_id'], $new_reg_table); |
|
| 59 | + if (! $regs) { |
|
| 60 | + $this->add_error(sprintf(esc_html__("Could not find new registrations for old attendee %d when creating answer %s", "event_espresso"), $old_row['attendee_id'], $this->_json_encode($old_row))); |
|
| 61 | + return false; |
|
| 62 | + } |
|
| 63 | + // as inefficient as this sounds, we create an answer per REGISTRATION, (even if the registrations use the same attendee) |
|
| 64 | + foreach ($regs as $new_reg_id) { |
|
| 65 | + $this->_insert_new_answer($old_row, $new_reg_id); |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | + /** |
|
| 69 | + * Creates a 4.1 price base type |
|
| 70 | + * @global type $wpdb |
|
| 71 | + * @param array $old_price |
|
| 72 | + * @param int $new_reg_id |
|
| 73 | + * @return int |
|
| 74 | + */ |
|
| 75 | + private function _insert_new_answer($old_answer, $new_reg_id) |
|
| 76 | + { |
|
| 77 | + global $wpdb; |
|
| 78 | + $old_question_table = $wpdb->prefix . "events_question"; |
|
| 79 | + $new_question_id = $this->get_migration_script()->get_mapping_new_pk($old_question_table, $old_answer['question_id'], $this->_new_question_table); |
|
| 80 | 80 | |
| 81 | - $question_row = $this->_get_question_type_and_system($new_question_id); |
|
| 82 | - if ($question_row['QST_system']) { |
|
| 83 | - // It's an answer to a system question? EE3 used to store that on both the attendee and the answers column, |
|
| 84 | - // but not EE4! It's just stored in the attendee meta table. The answers table is ONLY for answers to custom |
|
| 85 | - // questions. |
|
| 86 | - return 0; |
|
| 87 | - } |
|
| 88 | - if (in_array($question_row['QST_type'], array('MULTIPLE'))) { |
|
| 89 | - $ans_value = serialize(explode(",", stripslashes($old_answer['answer']))); |
|
| 90 | - } else { |
|
| 91 | - $ans_value = stripslashes($old_answer['answer']); |
|
| 92 | - } |
|
| 93 | - $cols_n_values = array( |
|
| 94 | - 'REG_ID' => $new_reg_id, |
|
| 95 | - 'QST_ID' => $new_question_id, |
|
| 96 | - 'ANS_value' => $ans_value |
|
| 97 | - ); |
|
| 98 | - $datatypes = array( |
|
| 99 | - '%d',// REG_ID |
|
| 100 | - '%d',// QST_ID |
|
| 101 | - '%s',// ANS_value |
|
| 102 | - ); |
|
| 103 | - $success = $wpdb->insert($this->_new_answer_table, $cols_n_values, $datatypes); |
|
| 104 | - if (! $success) { |
|
| 105 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_answer, $this->_new_answer_table, $cols_n_values, $datatypes)); |
|
| 106 | - return 0; |
|
| 107 | - } |
|
| 108 | - $new_id = $wpdb->insert_id; |
|
| 109 | - return $new_id; |
|
| 110 | - } |
|
| 81 | + $question_row = $this->_get_question_type_and_system($new_question_id); |
|
| 82 | + if ($question_row['QST_system']) { |
|
| 83 | + // It's an answer to a system question? EE3 used to store that on both the attendee and the answers column, |
|
| 84 | + // but not EE4! It's just stored in the attendee meta table. The answers table is ONLY for answers to custom |
|
| 85 | + // questions. |
|
| 86 | + return 0; |
|
| 87 | + } |
|
| 88 | + if (in_array($question_row['QST_type'], array('MULTIPLE'))) { |
|
| 89 | + $ans_value = serialize(explode(",", stripslashes($old_answer['answer']))); |
|
| 90 | + } else { |
|
| 91 | + $ans_value = stripslashes($old_answer['answer']); |
|
| 92 | + } |
|
| 93 | + $cols_n_values = array( |
|
| 94 | + 'REG_ID' => $new_reg_id, |
|
| 95 | + 'QST_ID' => $new_question_id, |
|
| 96 | + 'ANS_value' => $ans_value |
|
| 97 | + ); |
|
| 98 | + $datatypes = array( |
|
| 99 | + '%d',// REG_ID |
|
| 100 | + '%d',// QST_ID |
|
| 101 | + '%s',// ANS_value |
|
| 102 | + ); |
|
| 103 | + $success = $wpdb->insert($this->_new_answer_table, $cols_n_values, $datatypes); |
|
| 104 | + if (! $success) { |
|
| 105 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_answer, $this->_new_answer_table, $cols_n_values, $datatypes)); |
|
| 106 | + return 0; |
|
| 107 | + } |
|
| 108 | + $new_id = $wpdb->insert_id; |
|
| 109 | + return $new_id; |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - /** |
|
| 113 | - * Gets the question's type |
|
| 114 | - * @global type $wpdb |
|
| 115 | - * @param type $question_id |
|
| 116 | - * @return array { |
|
| 117 | - * @type string $QST_type |
|
| 118 | - * @type string $QST_system |
|
| 119 | - * } |
|
| 120 | - */ |
|
| 121 | - private function _get_question_type_and_system($question_id) |
|
| 122 | - { |
|
| 123 | - global $wpdb; |
|
| 124 | - $row = $wpdb->get_row( |
|
| 125 | - $wpdb->prepare( |
|
| 126 | - "SELECT QST_type, QST_system FROM " . $this->_new_question_table . " WHERE QST_ID=%d LIMIT 1", |
|
| 127 | - $question_id |
|
| 128 | - ), |
|
| 129 | - ARRAY_A |
|
| 130 | - ); |
|
| 131 | - return $row; |
|
| 132 | - } |
|
| 112 | + /** |
|
| 113 | + * Gets the question's type |
|
| 114 | + * @global type $wpdb |
|
| 115 | + * @param type $question_id |
|
| 116 | + * @return array { |
|
| 117 | + * @type string $QST_type |
|
| 118 | + * @type string $QST_system |
|
| 119 | + * } |
|
| 120 | + */ |
|
| 121 | + private function _get_question_type_and_system($question_id) |
|
| 122 | + { |
|
| 123 | + global $wpdb; |
|
| 124 | + $row = $wpdb->get_row( |
|
| 125 | + $wpdb->prepare( |
|
| 126 | + "SELECT QST_type, QST_system FROM " . $this->_new_question_table . " WHERE QST_ID=%d LIMIT 1", |
|
| 127 | + $question_id |
|
| 128 | + ), |
|
| 129 | + ARRAY_A |
|
| 130 | + ); |
|
| 131 | + return $row; |
|
| 132 | + } |
|
| 133 | 133 | } |
@@ -38,25 +38,25 @@ discard block |
||
| 38 | 38 | { |
| 39 | 39 | global $wpdb; |
| 40 | 40 | $this->_pretty_name = esc_html__("Answers", "event_espresso"); |
| 41 | - $this->_old_table = $wpdb->prefix . "events_answer"; |
|
| 41 | + $this->_old_table = $wpdb->prefix."events_answer"; |
|
| 42 | 42 | // join to attendee and then join to events table |
| 43 | 43 | $this->select_expression = 'ans.*, e.event_status'; |
| 44 | 44 | $this->_extra_where_sql = ' AS ans |
| 45 | - INNER JOIN ' . $wpdb->prefix . 'events_attendee AS att ON ans.attendee_id = att.id |
|
| 46 | - INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id = e.id |
|
| 45 | + INNER JOIN ' . $wpdb->prefix.'events_attendee AS att ON ans.attendee_id = att.id |
|
| 46 | + INNER JOIN ' . $wpdb->prefix.'events_detail AS e ON att.event_id = e.id |
|
| 47 | 47 | WHERE e.event_status !="D"'; |
| 48 | - $this->_new_answer_table = $wpdb->prefix . "esp_answer"; |
|
| 49 | - $this->_new_question_table = $wpdb->prefix . "esp_question"; |
|
| 48 | + $this->_new_answer_table = $wpdb->prefix."esp_answer"; |
|
| 49 | + $this->_new_question_table = $wpdb->prefix."esp_question"; |
|
| 50 | 50 | parent::__construct(); |
| 51 | 51 | } |
| 52 | 52 | protected function _migrate_old_row($old_row) |
| 53 | 53 | { |
| 54 | 54 | // get the new REGs for the old answer |
| 55 | 55 | global $wpdb; |
| 56 | - $old_attendee_table = $wpdb->prefix . "events_attendee"; |
|
| 57 | - $new_reg_table = $wpdb->prefix . "esp_registration"; |
|
| 56 | + $old_attendee_table = $wpdb->prefix."events_attendee"; |
|
| 57 | + $new_reg_table = $wpdb->prefix."esp_registration"; |
|
| 58 | 58 | $regs = $this->get_migration_script()->get_mapping_new_pk($old_attendee_table, $old_row['attendee_id'], $new_reg_table); |
| 59 | - if (! $regs) { |
|
| 59 | + if ( ! $regs) { |
|
| 60 | 60 | $this->add_error(sprintf(esc_html__("Could not find new registrations for old attendee %d when creating answer %s", "event_espresso"), $old_row['attendee_id'], $this->_json_encode($old_row))); |
| 61 | 61 | return false; |
| 62 | 62 | } |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | private function _insert_new_answer($old_answer, $new_reg_id) |
| 76 | 76 | { |
| 77 | 77 | global $wpdb; |
| 78 | - $old_question_table = $wpdb->prefix . "events_question"; |
|
| 78 | + $old_question_table = $wpdb->prefix."events_question"; |
|
| 79 | 79 | $new_question_id = $this->get_migration_script()->get_mapping_new_pk($old_question_table, $old_answer['question_id'], $this->_new_question_table); |
| 80 | 80 | |
| 81 | 81 | $question_row = $this->_get_question_type_and_system($new_question_id); |
@@ -96,12 +96,12 @@ discard block |
||
| 96 | 96 | 'ANS_value' => $ans_value |
| 97 | 97 | ); |
| 98 | 98 | $datatypes = array( |
| 99 | - '%d',// REG_ID |
|
| 100 | - '%d',// QST_ID |
|
| 101 | - '%s',// ANS_value |
|
| 99 | + '%d', // REG_ID |
|
| 100 | + '%d', // QST_ID |
|
| 101 | + '%s', // ANS_value |
|
| 102 | 102 | ); |
| 103 | 103 | $success = $wpdb->insert($this->_new_answer_table, $cols_n_values, $datatypes); |
| 104 | - if (! $success) { |
|
| 104 | + if ( ! $success) { |
|
| 105 | 105 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_answer, $this->_new_answer_table, $cols_n_values, $datatypes)); |
| 106 | 106 | return 0; |
| 107 | 107 | } |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | global $wpdb; |
| 124 | 124 | $row = $wpdb->get_row( |
| 125 | 125 | $wpdb->prepare( |
| 126 | - "SELECT QST_type, QST_system FROM " . $this->_new_question_table . " WHERE QST_ID=%d LIMIT 1", |
|
| 126 | + "SELECT QST_type, QST_system FROM ".$this->_new_question_table." WHERE QST_ID=%d LIMIT 1", |
|
| 127 | 127 | $question_id |
| 128 | 128 | ), |
| 129 | 129 | ARRAY_A |
@@ -85,8 +85,6 @@ discard block |
||
| 85 | 85 | KEY `submitted` (`submitted`), |
| 86 | 86 | KEY `likes` (`likes`) |
| 87 | 87 | ) ENGINE=InnoDB AUTO_INCREMENT=63 DEFAULT CHARSET=utf8$$ |
| 88 | - |
|
| 89 | - |
|
| 90 | 88 | * |
| 91 | 89 | * 4.1 Event model: |
| 92 | 90 | * $this->_tables = array( |
@@ -125,7 +123,6 @@ discard block |
||
| 125 | 123 | 'EVT_donations'=>new EE_Boolean_Field('EVT_donations', esc_html__("Accept Donations?", "event_espresso"), false, false) |
| 126 | 124 | |
| 127 | 125 | )); |
| 128 | - |
|
| 129 | 126 | * |
| 130 | 127 | * 3.1's start end table |
| 131 | 128 | * |
@@ -138,8 +135,6 @@ discard block |
||
| 138 | 135 | PRIMARY KEY (`id`), |
| 139 | 136 | KEY `event_id` (`event_id`) |
| 140 | 137 | ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8$$ |
| 141 | - |
|
| 142 | - |
|
| 143 | 138 | * |
| 144 | 139 | * and 4.1 Datetime model's tables and fields: |
| 145 | 140 | * $this->_tables = array( |
@@ -161,172 +156,172 @@ discard block |
||
| 161 | 156 | */ |
| 162 | 157 | class EE_DMS_4_1_0_events extends EE_Data_Migration_Script_Stage |
| 163 | 158 | { |
| 164 | - private $_old_table; |
|
| 165 | - private $_old_start_end_table; |
|
| 166 | - private $_new_table; |
|
| 167 | - private $_new_meta_table; |
|
| 168 | - private $_new_datetime_table; |
|
| 169 | - |
|
| 170 | - |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * Just initializes the status of the migration |
|
| 174 | - * @throws EE_Error |
|
| 175 | - */ |
|
| 176 | - public function __construct() |
|
| 177 | - { |
|
| 178 | - global $wpdb; |
|
| 179 | - $this->_old_table = $wpdb->prefix . "events_detail"; |
|
| 180 | - $this->_old_start_end_table = $wpdb->prefix . "events_start_end"; |
|
| 181 | - $this->_new_table = $wpdb->prefix . "posts"; |
|
| 182 | - $this->_new_meta_table = $wpdb->prefix . "esp_event_meta"; |
|
| 183 | - $this->_new_datetime_table = $wpdb->prefix . "esp_datetime"; |
|
| 184 | - $this->_pretty_name = esc_html__("Events", "event_espresso"); |
|
| 185 | - parent::__construct(); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * Counts the records to migrate; the public version may cache it |
|
| 192 | - * @return int |
|
| 193 | - */ |
|
| 194 | - public function _count_records_to_migrate() |
|
| 195 | - { |
|
| 196 | - global $wpdb; |
|
| 197 | - $count = $wpdb->get_var("SELECT COUNT(*) FROM " . $this->_old_table . ' WHERE event_status !="D"'); |
|
| 198 | - return intval($count); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * IMPORTANT: if an error is encountered, or everything is finished, this stage should update its status property accordingly. |
|
| 205 | - * Note: it should not alter the count of items migrated. That is done in the public function that calls this. |
|
| 206 | - * IMPORTANT: The count of items migrated should ONLY be less than $num_items_to_migrate when it's the last migration step, otherwise it |
|
| 207 | - * should always return $num_items_to_migrate. (Eg, if we're migrating attendees rows from the database, and $num_items_to_migrate is set to 50, |
|
| 208 | - * then we SHOULD actually migrate 50 rows,but at very least we MUST report/return 50 items migrated) |
|
| 209 | - * @param int $num_items_to_migrate |
|
| 210 | - * @return int number of items ACTUALLY migrated |
|
| 211 | - */ |
|
| 212 | - protected function _migration_step($num_items_to_migrate = 50) |
|
| 213 | - { |
|
| 214 | - global $wpdb; |
|
| 215 | - // because the migration of each event can be a LOT more work, make each step smaller |
|
| 216 | - $num_items_to_migrate = max(1, $num_items_to_migrate / 5); |
|
| 217 | - $events = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table WHERE event_status!='D' LIMIT %d,%d", $this->count_records_migrated(), $num_items_to_migrate), ARRAY_A); |
|
| 218 | - $items_migrated_this_step = 0; |
|
| 219 | - |
|
| 220 | - foreach ($events as $event_row) { |
|
| 221 | - $guid = null; |
|
| 222 | - // insert new 4.1 Attendee object using $wpdb |
|
| 223 | - $post_id = $this->_insert_cpt($event_row); |
|
| 224 | - if ($post_id) { |
|
| 225 | - $this->get_migration_script()->set_mapping($this->_old_table, $event_row['id'], $this->_new_table, $post_id); |
|
| 226 | - $meta_id = $this->_insert_event_meta($event_row, $post_id); |
|
| 227 | - if ($meta_id) { |
|
| 228 | - $this->get_migration_script()->set_mapping($this->_old_table, $event_row['id'], $this->_new_meta_table, $meta_id); |
|
| 229 | - } |
|
| 230 | - $this->_convert_start_end_times($event_row, $post_id); |
|
| 231 | - $event_meta = maybe_unserialize($event_row['event_meta']); |
|
| 232 | - $guid = isset($event_meta['event_thumbnail_url']) ? $event_meta['event_thumbnail_url'] : null; |
|
| 233 | - $this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $post_id, $this); |
|
| 234 | - |
|
| 235 | - // maybe create a venue from info on the event? |
|
| 236 | - $new_venue_id = $this->_maybe_create_venue($event_row); |
|
| 237 | - if ($new_venue_id) { |
|
| 238 | - $this->_insert_new_venue_to_event($post_id, $new_venue_id); |
|
| 239 | - } |
|
| 240 | - $this->_add_post_metas($event_row, $post_id); |
|
| 241 | - } |
|
| 242 | - $items_migrated_this_step++; |
|
| 243 | - if ($guid) { |
|
| 244 | - // if we had to check for an image attachment |
|
| 245 | - // then let's call it a day (avoid timing out, because this took a long time) |
|
| 246 | - break; |
|
| 247 | - } |
|
| 248 | - } |
|
| 249 | - if ($this->count_records_migrated() + $items_migrated_this_step >= $this->count_records_to_migrate()) { |
|
| 250 | - $this->set_status(EE_Data_Migration_Manager::status_completed); |
|
| 251 | - } |
|
| 252 | - return $items_migrated_this_step; |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * Stores any extra 3.1 "event_meta" column things as post meta |
|
| 257 | - * @param array $old_event |
|
| 258 | - * @param int $post_id |
|
| 259 | - * @return void |
|
| 260 | - */ |
|
| 261 | - private function _add_post_metas($old_event, $post_id) |
|
| 262 | - { |
|
| 263 | - $event_meta = maybe_unserialize($old_event['event_meta']); |
|
| 264 | - if (! $event_meta || ! is_array($event_meta)) { |
|
| 265 | - return; |
|
| 266 | - } |
|
| 267 | - unset($event_meta['date_submitted']);// factored into CPT |
|
| 268 | - unset($event_meta['additional_attendee_reg_info']);// factored into event meta table |
|
| 269 | - unset($event_meta['default_payment_status']);// dido |
|
| 270 | - unset($event_meta['event_thumbnail_url']);// used to find post featured image |
|
| 271 | - foreach ($event_meta as $meta_key => $meta_value) { |
|
| 272 | - if ($meta_key) {// if the meta key is just an empty string, ignore it |
|
| 273 | - $success = add_post_meta($post_id, $meta_key, $meta_value, true); |
|
| 274 | - if (! $success) { |
|
| 275 | - $this->add_error(sprintf(esc_html__("Could not add post meta for CPT with ID #%d. Meta key: '%s',meta value:'%d' for 3.1 event: %s", "event_espresso"), $post_id, $meta_key, $meta_value, implode(",", $old_event))); |
|
| 276 | - } |
|
| 277 | - } |
|
| 278 | - } |
|
| 279 | - if ($old_event['alt_email']) { |
|
| 280 | - add_post_meta($post_id, 'alt_email', $old_event['alt_email']); |
|
| 281 | - } |
|
| 282 | - if ($old_event['recurrence_id']) { |
|
| 283 | - add_post_meta($post_id, 'recurrence_id', $old_event['recurrence_id']); |
|
| 284 | - } |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * Finds a unique slug for this event, given its name (we could have simply used |
|
| 291 | - * the old unique_identifier column, but it added a long string of seemingly random characters onto the end |
|
| 292 | - * and really wasn't that pretty for a slug, so we decided we'd make our own slug again) |
|
| 293 | - * @param string $event_name (the name of the event for reading by humans) |
|
| 294 | - * @param string $old_identifier the old EE3 identifier (a long unique string) |
|
| 295 | - * @param string $new_post_status a post status |
|
| 296 | - * @return string |
|
| 297 | - */ |
|
| 298 | - private function _find_unique_slug($event_name, $old_identifier = '', $new_post_status = 'publish') |
|
| 299 | - { |
|
| 300 | - $count = 0; |
|
| 301 | - $original_name = $event_name ? sanitize_title($event_name) : $old_identifier; |
|
| 302 | - return wp_unique_post_slug($original_name, 0, $new_post_status, 'espresso_events', 0); |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * returns whether or not there is a post that has this same slug (post_title) |
|
| 307 | - * @global wpdb $wpdb |
|
| 308 | - * @param string $slug |
|
| 309 | - * @return boolean |
|
| 310 | - */ |
|
| 311 | - private function _other_post_exists_with_that_slug($slug) |
|
| 312 | - { |
|
| 313 | - global $wpdb; |
|
| 314 | - $query = $wpdb->prepare("SELECT COUNT(ID) FROM {$this->_new_table} WHERE event_status != 'D' AND post_name = %s", $slug); |
|
| 315 | - $count = $wpdb->get_var($query); |
|
| 316 | - return (bool) intval($count); |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - |
|
| 320 | - |
|
| 321 | - /** |
|
| 322 | - * @param $old_event |
|
| 323 | - * @return int |
|
| 324 | - */ |
|
| 325 | - private function _insert_cpt($old_event) |
|
| 326 | - { |
|
| 327 | - global $wpdb; |
|
| 328 | - // convert 3.1 event status to 4.1 CPT status |
|
| 329 | - // for reference, 3.1 event stati available for setting are: |
|
| 159 | + private $_old_table; |
|
| 160 | + private $_old_start_end_table; |
|
| 161 | + private $_new_table; |
|
| 162 | + private $_new_meta_table; |
|
| 163 | + private $_new_datetime_table; |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Just initializes the status of the migration |
|
| 169 | + * @throws EE_Error |
|
| 170 | + */ |
|
| 171 | + public function __construct() |
|
| 172 | + { |
|
| 173 | + global $wpdb; |
|
| 174 | + $this->_old_table = $wpdb->prefix . "events_detail"; |
|
| 175 | + $this->_old_start_end_table = $wpdb->prefix . "events_start_end"; |
|
| 176 | + $this->_new_table = $wpdb->prefix . "posts"; |
|
| 177 | + $this->_new_meta_table = $wpdb->prefix . "esp_event_meta"; |
|
| 178 | + $this->_new_datetime_table = $wpdb->prefix . "esp_datetime"; |
|
| 179 | + $this->_pretty_name = esc_html__("Events", "event_espresso"); |
|
| 180 | + parent::__construct(); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * Counts the records to migrate; the public version may cache it |
|
| 187 | + * @return int |
|
| 188 | + */ |
|
| 189 | + public function _count_records_to_migrate() |
|
| 190 | + { |
|
| 191 | + global $wpdb; |
|
| 192 | + $count = $wpdb->get_var("SELECT COUNT(*) FROM " . $this->_old_table . ' WHERE event_status !="D"'); |
|
| 193 | + return intval($count); |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * IMPORTANT: if an error is encountered, or everything is finished, this stage should update its status property accordingly. |
|
| 200 | + * Note: it should not alter the count of items migrated. That is done in the public function that calls this. |
|
| 201 | + * IMPORTANT: The count of items migrated should ONLY be less than $num_items_to_migrate when it's the last migration step, otherwise it |
|
| 202 | + * should always return $num_items_to_migrate. (Eg, if we're migrating attendees rows from the database, and $num_items_to_migrate is set to 50, |
|
| 203 | + * then we SHOULD actually migrate 50 rows,but at very least we MUST report/return 50 items migrated) |
|
| 204 | + * @param int $num_items_to_migrate |
|
| 205 | + * @return int number of items ACTUALLY migrated |
|
| 206 | + */ |
|
| 207 | + protected function _migration_step($num_items_to_migrate = 50) |
|
| 208 | + { |
|
| 209 | + global $wpdb; |
|
| 210 | + // because the migration of each event can be a LOT more work, make each step smaller |
|
| 211 | + $num_items_to_migrate = max(1, $num_items_to_migrate / 5); |
|
| 212 | + $events = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table WHERE event_status!='D' LIMIT %d,%d", $this->count_records_migrated(), $num_items_to_migrate), ARRAY_A); |
|
| 213 | + $items_migrated_this_step = 0; |
|
| 214 | + |
|
| 215 | + foreach ($events as $event_row) { |
|
| 216 | + $guid = null; |
|
| 217 | + // insert new 4.1 Attendee object using $wpdb |
|
| 218 | + $post_id = $this->_insert_cpt($event_row); |
|
| 219 | + if ($post_id) { |
|
| 220 | + $this->get_migration_script()->set_mapping($this->_old_table, $event_row['id'], $this->_new_table, $post_id); |
|
| 221 | + $meta_id = $this->_insert_event_meta($event_row, $post_id); |
|
| 222 | + if ($meta_id) { |
|
| 223 | + $this->get_migration_script()->set_mapping($this->_old_table, $event_row['id'], $this->_new_meta_table, $meta_id); |
|
| 224 | + } |
|
| 225 | + $this->_convert_start_end_times($event_row, $post_id); |
|
| 226 | + $event_meta = maybe_unserialize($event_row['event_meta']); |
|
| 227 | + $guid = isset($event_meta['event_thumbnail_url']) ? $event_meta['event_thumbnail_url'] : null; |
|
| 228 | + $this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $post_id, $this); |
|
| 229 | + |
|
| 230 | + // maybe create a venue from info on the event? |
|
| 231 | + $new_venue_id = $this->_maybe_create_venue($event_row); |
|
| 232 | + if ($new_venue_id) { |
|
| 233 | + $this->_insert_new_venue_to_event($post_id, $new_venue_id); |
|
| 234 | + } |
|
| 235 | + $this->_add_post_metas($event_row, $post_id); |
|
| 236 | + } |
|
| 237 | + $items_migrated_this_step++; |
|
| 238 | + if ($guid) { |
|
| 239 | + // if we had to check for an image attachment |
|
| 240 | + // then let's call it a day (avoid timing out, because this took a long time) |
|
| 241 | + break; |
|
| 242 | + } |
|
| 243 | + } |
|
| 244 | + if ($this->count_records_migrated() + $items_migrated_this_step >= $this->count_records_to_migrate()) { |
|
| 245 | + $this->set_status(EE_Data_Migration_Manager::status_completed); |
|
| 246 | + } |
|
| 247 | + return $items_migrated_this_step; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * Stores any extra 3.1 "event_meta" column things as post meta |
|
| 252 | + * @param array $old_event |
|
| 253 | + * @param int $post_id |
|
| 254 | + * @return void |
|
| 255 | + */ |
|
| 256 | + private function _add_post_metas($old_event, $post_id) |
|
| 257 | + { |
|
| 258 | + $event_meta = maybe_unserialize($old_event['event_meta']); |
|
| 259 | + if (! $event_meta || ! is_array($event_meta)) { |
|
| 260 | + return; |
|
| 261 | + } |
|
| 262 | + unset($event_meta['date_submitted']);// factored into CPT |
|
| 263 | + unset($event_meta['additional_attendee_reg_info']);// factored into event meta table |
|
| 264 | + unset($event_meta['default_payment_status']);// dido |
|
| 265 | + unset($event_meta['event_thumbnail_url']);// used to find post featured image |
|
| 266 | + foreach ($event_meta as $meta_key => $meta_value) { |
|
| 267 | + if ($meta_key) {// if the meta key is just an empty string, ignore it |
|
| 268 | + $success = add_post_meta($post_id, $meta_key, $meta_value, true); |
|
| 269 | + if (! $success) { |
|
| 270 | + $this->add_error(sprintf(esc_html__("Could not add post meta for CPT with ID #%d. Meta key: '%s',meta value:'%d' for 3.1 event: %s", "event_espresso"), $post_id, $meta_key, $meta_value, implode(",", $old_event))); |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + if ($old_event['alt_email']) { |
|
| 275 | + add_post_meta($post_id, 'alt_email', $old_event['alt_email']); |
|
| 276 | + } |
|
| 277 | + if ($old_event['recurrence_id']) { |
|
| 278 | + add_post_meta($post_id, 'recurrence_id', $old_event['recurrence_id']); |
|
| 279 | + } |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + |
|
| 283 | + |
|
| 284 | + /** |
|
| 285 | + * Finds a unique slug for this event, given its name (we could have simply used |
|
| 286 | + * the old unique_identifier column, but it added a long string of seemingly random characters onto the end |
|
| 287 | + * and really wasn't that pretty for a slug, so we decided we'd make our own slug again) |
|
| 288 | + * @param string $event_name (the name of the event for reading by humans) |
|
| 289 | + * @param string $old_identifier the old EE3 identifier (a long unique string) |
|
| 290 | + * @param string $new_post_status a post status |
|
| 291 | + * @return string |
|
| 292 | + */ |
|
| 293 | + private function _find_unique_slug($event_name, $old_identifier = '', $new_post_status = 'publish') |
|
| 294 | + { |
|
| 295 | + $count = 0; |
|
| 296 | + $original_name = $event_name ? sanitize_title($event_name) : $old_identifier; |
|
| 297 | + return wp_unique_post_slug($original_name, 0, $new_post_status, 'espresso_events', 0); |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * returns whether or not there is a post that has this same slug (post_title) |
|
| 302 | + * @global wpdb $wpdb |
|
| 303 | + * @param string $slug |
|
| 304 | + * @return boolean |
|
| 305 | + */ |
|
| 306 | + private function _other_post_exists_with_that_slug($slug) |
|
| 307 | + { |
|
| 308 | + global $wpdb; |
|
| 309 | + $query = $wpdb->prepare("SELECT COUNT(ID) FROM {$this->_new_table} WHERE event_status != 'D' AND post_name = %s", $slug); |
|
| 310 | + $count = $wpdb->get_var($query); |
|
| 311 | + return (bool) intval($count); |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * @param $old_event |
|
| 318 | + * @return int |
|
| 319 | + */ |
|
| 320 | + private function _insert_cpt($old_event) |
|
| 321 | + { |
|
| 322 | + global $wpdb; |
|
| 323 | + // convert 3.1 event status to 4.1 CPT status |
|
| 324 | + // for reference, 3.1 event stati available for setting are: |
|
| 330 | 325 | // $status = array(array('id' => 'A', 'text' => esc_html__('Public', 'event_espresso')), array('id' => 'S', 'text' => esc_html__('Waitlist', 'event_espresso')), array('id' => 'O', 'text' => esc_html__('Ongoing', 'event_espresso')), array('id' => 'R', 'text' => esc_html__('Draft', 'event_espresso')), array('id' => 'D', 'text' => esc_html__('Deleted', 'event_espresso'))); |
| 331 | 326 | // and the json api uses the following to convert from 3.1 to 4.0 |
| 332 | 327 | // 'S'=>'secondary/waitlist', |
@@ -340,487 +335,487 @@ discard block |
||
| 340 | 335 | // 4.1 Event Post stati are the normal post statis |
| 341 | 336 | // (publish,future,draft,pending,private,trash,auto-draft,inherit) |
| 342 | 337 | // and 3 custom ones: cancelled,postponed,sold_out |
| 343 | - $status_conversions = array( |
|
| 344 | - 'R' => 'draft', |
|
| 345 | - 'X' => 'draft',// 4.1 doesn't have a "not approved for publishing" status. this is what posts are set to that aren't approved |
|
| 346 | - 'P' => 'pending', |
|
| 347 | - 'IA' => 'draft',// draft and in the past |
|
| 338 | + $status_conversions = array( |
|
| 339 | + 'R' => 'draft', |
|
| 340 | + 'X' => 'draft',// 4.1 doesn't have a "not approved for publishing" status. this is what posts are set to that aren't approved |
|
| 341 | + 'P' => 'pending', |
|
| 342 | + 'IA' => 'draft',// draft and in the past |
|
| 348 | 343 | // IA=inactive in 3.1: events were switched to this when they expired. in 4.1 that's just calculated |
| 349 | - 'O' => 'publish',// @todo: will be an event type later; if this is the status, set the end date WAAAY later; and add term for 'ongoing' |
|
| 350 | - 'A' => 'publish', |
|
| 351 | - 'S' => 'draft',// @todo: is it ok to just mark secondary/waitlist events as DRAFTS? |
|
| 352 | - 'D' => 'trash', |
|
| 353 | - ); |
|
| 354 | - $post_status = $status_conversions[ $old_event['event_status'] ]; |
|
| 355 | - // check if we've sold out |
|
| 356 | - if (intval($old_event['reg_limit']) <= self::count_registrations($old_event['id'])) { |
|
| 357 | - $post_status = 'sold_out'; |
|
| 358 | - } |
|
| 344 | + 'O' => 'publish',// @todo: will be an event type later; if this is the status, set the end date WAAAY later; and add term for 'ongoing' |
|
| 345 | + 'A' => 'publish', |
|
| 346 | + 'S' => 'draft',// @todo: is it ok to just mark secondary/waitlist events as DRAFTS? |
|
| 347 | + 'D' => 'trash', |
|
| 348 | + ); |
|
| 349 | + $post_status = $status_conversions[ $old_event['event_status'] ]; |
|
| 350 | + // check if we've sold out |
|
| 351 | + if (intval($old_event['reg_limit']) <= self::count_registrations($old_event['id'])) { |
|
| 352 | + $post_status = 'sold_out'; |
|
| 353 | + } |
|
| 359 | 354 | // FYI postponed and cancelled don't exist in 3.1 |
| 360 | - $cols_n_values = array( |
|
| 361 | - 'post_title' => stripslashes($old_event['event_name']),// EVT_name |
|
| 362 | - 'post_content' => stripslashes($old_event['event_desc']),// EVT_desc |
|
| 363 | - 'post_name' => $this->_find_unique_slug($old_event['event_name'], $old_event['event_identifier'], $post_status),// EVT_slug |
|
| 364 | - 'post_date' => $old_event['submitted'],// EVT_created NOT |
|
| 365 | - 'post_date_gmt' => get_gmt_from_date($old_event['submitted']), |
|
| 366 | - 'post_excerpt' => '',// EVT_short_desc |
|
| 367 | - 'post_modified' => $old_event['submitted'],// EVT_modified |
|
| 368 | - 'post_modified_gmt' => get_gmt_from_date($old_event['submitted']), |
|
| 369 | - 'post_author' => $old_event['wp_user'],// EVT_wp_user |
|
| 370 | - 'post_parent' => 0,// parent maybe get this from some REM field? |
|
| 371 | - 'menu_order' => 0,// EVT_order |
|
| 372 | - 'post_type' => 'espresso_events',// post_type |
|
| 373 | - 'post_status' => $post_status,// status |
|
| 374 | - ); |
|
| 375 | - $cols_n_values_with_no_invalid_text = array(); |
|
| 376 | - foreach ($cols_n_values as $col => $value) { |
|
| 377 | - $value_sans_invalid_chars = $wpdb->strip_invalid_text_for_column($this->_new_table, $col, $value); |
|
| 378 | - if (! is_wp_error($value_sans_invalid_chars)) { |
|
| 379 | - $cols_n_values_with_no_invalid_text[ $col ] = $value_sans_invalid_chars; |
|
| 380 | - } else { |
|
| 381 | - // otherwise leave it as-is. It will blow everything up and stop the migration |
|
| 382 | - $cols_n_values_with_no_invalid_text[ $col ] = $value; |
|
| 383 | - } |
|
| 384 | - } |
|
| 385 | - $cols_n_values = $cols_n_values_with_no_invalid_text; |
|
| 386 | - $datatypes = array( |
|
| 387 | - '%s',// EVT_name |
|
| 388 | - '%s',// EVT_desc |
|
| 389 | - '%s',// EVT_slug |
|
| 390 | - '%s',// EVT_created |
|
| 391 | - '%s', |
|
| 392 | - '%s',// EVT_short_desc |
|
| 393 | - '%s',// EVT_modified |
|
| 394 | - '%s', |
|
| 395 | - '%s',// EVT_wp_user |
|
| 396 | - '%d',// post_parent |
|
| 397 | - '%d',// EVT_order |
|
| 398 | - '%s',// post_type |
|
| 399 | - '%s',// status |
|
| 400 | - ); |
|
| 401 | - $success = $wpdb->insert( |
|
| 402 | - $this->_new_table, |
|
| 403 | - $cols_n_values, |
|
| 404 | - $datatypes |
|
| 405 | - ); |
|
| 406 | - if (! $success) { |
|
| 407 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_table, $cols_n_values, $datatypes)); |
|
| 408 | - return 0; |
|
| 409 | - } |
|
| 410 | - return $wpdb->insert_id; |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - /** |
|
| 414 | - * Counts all the registrations for the event in the 3.1 DB. (takes into account attendee rows which represent various registrations) |
|
| 415 | - * @global wpdb $wpdb |
|
| 416 | - * @param int $event_id |
|
| 417 | - * @return int |
|
| 418 | - */ |
|
| 419 | - public static function count_registrations($event_id) |
|
| 420 | - { |
|
| 421 | - global $wpdb; |
|
| 422 | - $count = $wpdb->get_var($wpdb->prepare("SELECT sum(quantity) FROM {$wpdb->prefix}events_attendee WHERE event_id=%d", $event_id)); |
|
| 423 | - return intval($count); |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - |
|
| 427 | - |
|
| 428 | - /** |
|
| 429 | - * @param $old_event |
|
| 430 | - * @param $new_cpt_id |
|
| 431 | - * @return int |
|
| 432 | - */ |
|
| 433 | - private function _insert_event_meta($old_event, $new_cpt_id) |
|
| 434 | - { |
|
| 435 | - global $wpdb; |
|
| 436 | - $event_meta = maybe_unserialize($old_event['event_meta']); |
|
| 355 | + $cols_n_values = array( |
|
| 356 | + 'post_title' => stripslashes($old_event['event_name']),// EVT_name |
|
| 357 | + 'post_content' => stripslashes($old_event['event_desc']),// EVT_desc |
|
| 358 | + 'post_name' => $this->_find_unique_slug($old_event['event_name'], $old_event['event_identifier'], $post_status),// EVT_slug |
|
| 359 | + 'post_date' => $old_event['submitted'],// EVT_created NOT |
|
| 360 | + 'post_date_gmt' => get_gmt_from_date($old_event['submitted']), |
|
| 361 | + 'post_excerpt' => '',// EVT_short_desc |
|
| 362 | + 'post_modified' => $old_event['submitted'],// EVT_modified |
|
| 363 | + 'post_modified_gmt' => get_gmt_from_date($old_event['submitted']), |
|
| 364 | + 'post_author' => $old_event['wp_user'],// EVT_wp_user |
|
| 365 | + 'post_parent' => 0,// parent maybe get this from some REM field? |
|
| 366 | + 'menu_order' => 0,// EVT_order |
|
| 367 | + 'post_type' => 'espresso_events',// post_type |
|
| 368 | + 'post_status' => $post_status,// status |
|
| 369 | + ); |
|
| 370 | + $cols_n_values_with_no_invalid_text = array(); |
|
| 371 | + foreach ($cols_n_values as $col => $value) { |
|
| 372 | + $value_sans_invalid_chars = $wpdb->strip_invalid_text_for_column($this->_new_table, $col, $value); |
|
| 373 | + if (! is_wp_error($value_sans_invalid_chars)) { |
|
| 374 | + $cols_n_values_with_no_invalid_text[ $col ] = $value_sans_invalid_chars; |
|
| 375 | + } else { |
|
| 376 | + // otherwise leave it as-is. It will blow everything up and stop the migration |
|
| 377 | + $cols_n_values_with_no_invalid_text[ $col ] = $value; |
|
| 378 | + } |
|
| 379 | + } |
|
| 380 | + $cols_n_values = $cols_n_values_with_no_invalid_text; |
|
| 381 | + $datatypes = array( |
|
| 382 | + '%s',// EVT_name |
|
| 383 | + '%s',// EVT_desc |
|
| 384 | + '%s',// EVT_slug |
|
| 385 | + '%s',// EVT_created |
|
| 386 | + '%s', |
|
| 387 | + '%s',// EVT_short_desc |
|
| 388 | + '%s',// EVT_modified |
|
| 389 | + '%s', |
|
| 390 | + '%s',// EVT_wp_user |
|
| 391 | + '%d',// post_parent |
|
| 392 | + '%d',// EVT_order |
|
| 393 | + '%s',// post_type |
|
| 394 | + '%s',// status |
|
| 395 | + ); |
|
| 396 | + $success = $wpdb->insert( |
|
| 397 | + $this->_new_table, |
|
| 398 | + $cols_n_values, |
|
| 399 | + $datatypes |
|
| 400 | + ); |
|
| 401 | + if (! $success) { |
|
| 402 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_table, $cols_n_values, $datatypes)); |
|
| 403 | + return 0; |
|
| 404 | + } |
|
| 405 | + return $wpdb->insert_id; |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + /** |
|
| 409 | + * Counts all the registrations for the event in the 3.1 DB. (takes into account attendee rows which represent various registrations) |
|
| 410 | + * @global wpdb $wpdb |
|
| 411 | + * @param int $event_id |
|
| 412 | + * @return int |
|
| 413 | + */ |
|
| 414 | + public static function count_registrations($event_id) |
|
| 415 | + { |
|
| 416 | + global $wpdb; |
|
| 417 | + $count = $wpdb->get_var($wpdb->prepare("SELECT sum(quantity) FROM {$wpdb->prefix}events_attendee WHERE event_id=%d", $event_id)); |
|
| 418 | + return intval($count); |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + |
|
| 422 | + |
|
| 423 | + /** |
|
| 424 | + * @param $old_event |
|
| 425 | + * @param $new_cpt_id |
|
| 426 | + * @return int |
|
| 427 | + */ |
|
| 428 | + private function _insert_event_meta($old_event, $new_cpt_id) |
|
| 429 | + { |
|
| 430 | + global $wpdb; |
|
| 431 | + $event_meta = maybe_unserialize($old_event['event_meta']); |
|
| 437 | 432 | // for reference, 3.1 'default_payment_status' are: $default_payment_status = array( |
| 438 | 433 | // array('id' => "", 'text' => 'No Change'), |
| 439 | 434 | // array('id' => 'Incomplete', 'text' => 'Incomplete'), |
| 440 | 435 | // array('id' => 'Pending', 'text' => 'Pending'), |
| 441 | 436 | // //array('id' => 'Completed', 'text' => 'Completed') |
| 442 | 437 | // ); |
| 443 | - $default_reg_status = $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID(isset($event_meta['default_payment_status']) ? $event_meta['default_payment_status'] : '', intval($old_event['require_pre_approval'])); |
|
| 444 | - $cols_n_values = array( |
|
| 445 | - 'EVT_ID' => $new_cpt_id,// EVT_ID_fk |
|
| 446 | - 'EVT_display_desc' => 'Y' == $old_event['display_desc'], |
|
| 447 | - 'EVT_display_ticket_selector' => 'Y' == $old_event['display_reg_form'], |
|
| 448 | - 'EVT_visible_on' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_event, current_time('mysql'), $old_event['timezone_string']),// don't use the old 'visible_on', as it wasn't ever used |
|
| 449 | - 'EVT_additional_limit' => $old_event['allow_multiple'] == 'N' ? 1 : $old_event['additional_limit'], |
|
| 450 | - 'EVT_default_registration_status' => $default_reg_status, |
|
| 451 | - 'EVT_member_only' => $old_event['member_only'], |
|
| 452 | - 'EVT_phone' => $old_event['phone'], |
|
| 453 | - 'EVT_allow_overflow' => 'Y' == $old_event['allow_overflow'], |
|
| 454 | - 'EVT_timezone_string' => $old_event['timezone_string'], |
|
| 455 | - 'EVT_external_URL' => $old_event['externalURL'], |
|
| 456 | - 'EVT_donations' => false// doesnt exist in 3.1 |
|
| 457 | - |
|
| 458 | - ); |
|
| 459 | - $datatypes = array( |
|
| 460 | - '%s',// EVT_ID |
|
| 461 | - '%d',// EVT_display_desc |
|
| 462 | - '%d',// EVT_display_ticket_selector |
|
| 463 | - '%s',// EVT_visible_on |
|
| 464 | - '%d',// EVT_additional_limit |
|
| 465 | - '%s',// EVT_default_registration_status |
|
| 466 | - '%d',// EVT_member_only |
|
| 467 | - '%s',// EVT_phone |
|
| 468 | - '%d',// EVT_allow_overflow |
|
| 469 | - '%s',// EVT_timezone_string |
|
| 470 | - '%s',// EVT_external_URL |
|
| 471 | - '%d',// EVT_donations |
|
| 472 | - ); |
|
| 473 | - $success = $wpdb->insert( |
|
| 474 | - $this->_new_meta_table, |
|
| 475 | - $cols_n_values, |
|
| 476 | - $datatypes |
|
| 477 | - ); |
|
| 478 | - if (! $success) { |
|
| 479 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_meta_table, $cols_n_values, $datatypes)); |
|
| 480 | - return 0; |
|
| 481 | - } |
|
| 482 | - return $wpdb->insert_id; |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * @param $old_event |
|
| 489 | - * @return int |
|
| 490 | - */ |
|
| 491 | - private function _maybe_create_venue($old_event) |
|
| 492 | - { |
|
| 493 | - if ( |
|
| 494 | - $old_event['address'] || |
|
| 495 | - $old_event['address2'] || |
|
| 496 | - $old_event['city'] || |
|
| 497 | - $old_event['state'] || |
|
| 498 | - $old_event['zip'] || |
|
| 499 | - $old_event['venue_title'] || |
|
| 500 | - $old_event['venue_url'] || |
|
| 501 | - $old_event['venue_image'] || |
|
| 502 | - $old_event['venue_phone'] || |
|
| 503 | - $old_event['virtual_url'] || |
|
| 504 | - $old_event['virtual_phone'] |
|
| 505 | - ) { |
|
| 506 | - $old_id = $this->_duplicate_venue_exists($old_event); |
|
| 507 | - if ($old_id) { |
|
| 508 | - return $old_id; |
|
| 509 | - } |
|
| 510 | - $new_id = $this->_insert_venue_into_posts($old_event); |
|
| 511 | - if ($new_id) { |
|
| 512 | - $this->_insert_venue_into_meta_table($new_id, $old_event); |
|
| 513 | - $guid = isset($old_event['venue_image']) ? $old_event['venue_image'] : null; |
|
| 514 | - $this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $new_id, $this); |
|
| 515 | - } |
|
| 516 | - // we don't bother recording the conversion from old events to venues as that |
|
| 517 | - // will complicate finding the conversion from old venues to new events |
|
| 518 | - return $new_id; |
|
| 519 | - } else { |
|
| 520 | - return 0; |
|
| 521 | - } |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - /** |
|
| 525 | - * Assuming there is venue data on this event, check if there is a duplicate venue already in the system for it. |
|
| 526 | - * If so, return it. Otherwise return NULL. |
|
| 527 | - * @param array $old_event |
|
| 528 | - * @return int duplicate venue id |
|
| 529 | - */ |
|
| 530 | - private function _duplicate_venue_exists($old_event) |
|
| 531 | - { |
|
| 532 | - global $wpdb; |
|
| 533 | - $conditions = array( |
|
| 534 | - 'VNU_address' => $old_event ['address'], |
|
| 535 | - 'VNU_address2' => $old_event['address2'], |
|
| 536 | - 'VNU_city' => $old_event['city'], |
|
| 537 | - 'VNU_zip' => $old_event['zip'], |
|
| 538 | - 'post_title' => $this->_get_venue_title_for_event($old_event), |
|
| 539 | - 'VNU_phone' => $old_event['venue_phone'],// VNU_phone |
|
| 540 | - 'VNU_url' => $old_event['venue_url'],// VNU_url |
|
| 541 | - 'VNU_virtual_phone' => $old_event['virtual_phone'],// VNU_virtual_phone |
|
| 542 | - 'VNU_virtual_url' => $old_event['virtual_url'],// VNU_virtual_url |
|
| 543 | - ); |
|
| 544 | - $sql_conditions = array(); |
|
| 545 | - foreach ($conditions as $column => $value) { |
|
| 546 | - $sql_conditions [] = $wpdb->prepare("$column = %s", $value); |
|
| 547 | - } |
|
| 548 | - $query = "SELECT VNU_ID |
|
| 438 | + $default_reg_status = $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID(isset($event_meta['default_payment_status']) ? $event_meta['default_payment_status'] : '', intval($old_event['require_pre_approval'])); |
|
| 439 | + $cols_n_values = array( |
|
| 440 | + 'EVT_ID' => $new_cpt_id,// EVT_ID_fk |
|
| 441 | + 'EVT_display_desc' => 'Y' == $old_event['display_desc'], |
|
| 442 | + 'EVT_display_ticket_selector' => 'Y' == $old_event['display_reg_form'], |
|
| 443 | + 'EVT_visible_on' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_event, current_time('mysql'), $old_event['timezone_string']),// don't use the old 'visible_on', as it wasn't ever used |
|
| 444 | + 'EVT_additional_limit' => $old_event['allow_multiple'] == 'N' ? 1 : $old_event['additional_limit'], |
|
| 445 | + 'EVT_default_registration_status' => $default_reg_status, |
|
| 446 | + 'EVT_member_only' => $old_event['member_only'], |
|
| 447 | + 'EVT_phone' => $old_event['phone'], |
|
| 448 | + 'EVT_allow_overflow' => 'Y' == $old_event['allow_overflow'], |
|
| 449 | + 'EVT_timezone_string' => $old_event['timezone_string'], |
|
| 450 | + 'EVT_external_URL' => $old_event['externalURL'], |
|
| 451 | + 'EVT_donations' => false// doesnt exist in 3.1 |
|
| 452 | + |
|
| 453 | + ); |
|
| 454 | + $datatypes = array( |
|
| 455 | + '%s',// EVT_ID |
|
| 456 | + '%d',// EVT_display_desc |
|
| 457 | + '%d',// EVT_display_ticket_selector |
|
| 458 | + '%s',// EVT_visible_on |
|
| 459 | + '%d',// EVT_additional_limit |
|
| 460 | + '%s',// EVT_default_registration_status |
|
| 461 | + '%d',// EVT_member_only |
|
| 462 | + '%s',// EVT_phone |
|
| 463 | + '%d',// EVT_allow_overflow |
|
| 464 | + '%s',// EVT_timezone_string |
|
| 465 | + '%s',// EVT_external_URL |
|
| 466 | + '%d',// EVT_donations |
|
| 467 | + ); |
|
| 468 | + $success = $wpdb->insert( |
|
| 469 | + $this->_new_meta_table, |
|
| 470 | + $cols_n_values, |
|
| 471 | + $datatypes |
|
| 472 | + ); |
|
| 473 | + if (! $success) { |
|
| 474 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_meta_table, $cols_n_values, $datatypes)); |
|
| 475 | + return 0; |
|
| 476 | + } |
|
| 477 | + return $wpdb->insert_id; |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * @param $old_event |
|
| 484 | + * @return int |
|
| 485 | + */ |
|
| 486 | + private function _maybe_create_venue($old_event) |
|
| 487 | + { |
|
| 488 | + if ( |
|
| 489 | + $old_event['address'] || |
|
| 490 | + $old_event['address2'] || |
|
| 491 | + $old_event['city'] || |
|
| 492 | + $old_event['state'] || |
|
| 493 | + $old_event['zip'] || |
|
| 494 | + $old_event['venue_title'] || |
|
| 495 | + $old_event['venue_url'] || |
|
| 496 | + $old_event['venue_image'] || |
|
| 497 | + $old_event['venue_phone'] || |
|
| 498 | + $old_event['virtual_url'] || |
|
| 499 | + $old_event['virtual_phone'] |
|
| 500 | + ) { |
|
| 501 | + $old_id = $this->_duplicate_venue_exists($old_event); |
|
| 502 | + if ($old_id) { |
|
| 503 | + return $old_id; |
|
| 504 | + } |
|
| 505 | + $new_id = $this->_insert_venue_into_posts($old_event); |
|
| 506 | + if ($new_id) { |
|
| 507 | + $this->_insert_venue_into_meta_table($new_id, $old_event); |
|
| 508 | + $guid = isset($old_event['venue_image']) ? $old_event['venue_image'] : null; |
|
| 509 | + $this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $new_id, $this); |
|
| 510 | + } |
|
| 511 | + // we don't bother recording the conversion from old events to venues as that |
|
| 512 | + // will complicate finding the conversion from old venues to new events |
|
| 513 | + return $new_id; |
|
| 514 | + } else { |
|
| 515 | + return 0; |
|
| 516 | + } |
|
| 517 | + } |
|
| 518 | + |
|
| 519 | + /** |
|
| 520 | + * Assuming there is venue data on this event, check if there is a duplicate venue already in the system for it. |
|
| 521 | + * If so, return it. Otherwise return NULL. |
|
| 522 | + * @param array $old_event |
|
| 523 | + * @return int duplicate venue id |
|
| 524 | + */ |
|
| 525 | + private function _duplicate_venue_exists($old_event) |
|
| 526 | + { |
|
| 527 | + global $wpdb; |
|
| 528 | + $conditions = array( |
|
| 529 | + 'VNU_address' => $old_event ['address'], |
|
| 530 | + 'VNU_address2' => $old_event['address2'], |
|
| 531 | + 'VNU_city' => $old_event['city'], |
|
| 532 | + 'VNU_zip' => $old_event['zip'], |
|
| 533 | + 'post_title' => $this->_get_venue_title_for_event($old_event), |
|
| 534 | + 'VNU_phone' => $old_event['venue_phone'],// VNU_phone |
|
| 535 | + 'VNU_url' => $old_event['venue_url'],// VNU_url |
|
| 536 | + 'VNU_virtual_phone' => $old_event['virtual_phone'],// VNU_virtual_phone |
|
| 537 | + 'VNU_virtual_url' => $old_event['virtual_url'],// VNU_virtual_url |
|
| 538 | + ); |
|
| 539 | + $sql_conditions = array(); |
|
| 540 | + foreach ($conditions as $column => $value) { |
|
| 541 | + $sql_conditions [] = $wpdb->prepare("$column = %s", $value); |
|
| 542 | + } |
|
| 543 | + $query = "SELECT VNU_ID |
|
| 549 | 544 | FROM |
| 550 | 545 | {$wpdb->posts} as p INNER JOIN |
| 551 | 546 | {$wpdb->prefix}esp_venue_meta as v ON p.ID = v.VNU_ID |
| 552 | 547 | WHERE " . implode(" AND ", $sql_conditions) . " LIMIT 1"; |
| 553 | - $id = $wpdb->get_var($query); |
|
| 554 | - return $id; |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - /** |
|
| 558 | - * Gets teh venue's title or makes one up if there is none |
|
| 559 | - * @param array $event_data_array keys are events_details columns and values are their values |
|
| 560 | - * @return string |
|
| 561 | - */ |
|
| 562 | - protected function _get_venue_title_for_event($event_data_array) |
|
| 563 | - { |
|
| 564 | - return $event_data_array['venue_title'] ? stripslashes($event_data_array['venue_title']) : stripslashes(sprintf(esc_html__('Venue of %s', 'event_espresso'), $event_data_array['event_name'])); |
|
| 565 | - } |
|
| 566 | - |
|
| 567 | - /** |
|
| 568 | - * Inserts the CPT |
|
| 569 | - * |
|
| 570 | - * @param array $old_event keys are cols, values are col values |
|
| 571 | - * @return int |
|
| 572 | - */ |
|
| 573 | - private function _insert_venue_into_posts($old_event) |
|
| 574 | - { |
|
| 575 | - global $wpdb; |
|
| 576 | - $insertion_array = array( |
|
| 577 | - 'post_title' => $this->_get_venue_title_for_event($old_event),// VNU_name |
|
| 578 | - 'post_content' => '',// VNU_desc |
|
| 579 | - 'post_name' => $this->_find_unique_slug($old_event['venue_title'], sanitize_title('venue-of-' . $old_event['event_name'])),// VNU_identifier |
|
| 580 | - 'post_date' => current_time('mysql'),// VNU_created |
|
| 581 | - 'post_date_gmt' => get_gmt_from_date(current_time('mysql')), |
|
| 582 | - 'post_excerpt' => '',// VNU_short_desc arbitrary only 50 characters |
|
| 583 | - 'post_modified' => current_time('mysql'),// VNU_modified |
|
| 584 | - 'post_modified_gmt' => get_gmt_from_date(current_time('mysql')), |
|
| 585 | - 'post_author' => $old_event['wp_user'],// VNU_wp_user |
|
| 586 | - 'post_parent' => 0,// parent |
|
| 587 | - 'menu_order' => 0,// VNU_order |
|
| 588 | - 'post_type' => 'espresso_venues'// post_type |
|
| 589 | - ); |
|
| 590 | - $datatypes_array = array( |
|
| 591 | - '%s',// VNU_name |
|
| 592 | - '%s',// VNU_desc |
|
| 593 | - '%s',// VNU_identifier |
|
| 594 | - '%s',// VNU_created |
|
| 595 | - '%s', |
|
| 596 | - '%s',// VNU_short_desc |
|
| 597 | - '%s',// VNU_modified |
|
| 598 | - '%s', |
|
| 599 | - '%d',// VNU_wp_user |
|
| 600 | - '%d',// parent |
|
| 601 | - '%d',// VNU_order |
|
| 602 | - '%s',// post_type |
|
| 603 | - ); |
|
| 604 | - $success = $wpdb->insert( |
|
| 605 | - $wpdb->posts, |
|
| 606 | - $insertion_array, |
|
| 607 | - $datatypes_array |
|
| 608 | - ); |
|
| 609 | - if (! $success) { |
|
| 610 | - $this->add_error( |
|
| 611 | - $this->get_migration_script()->_create_error_message_for_db_insertion( |
|
| 612 | - $this->_old_table, |
|
| 613 | - $old_event, |
|
| 614 | - $this->_new_table, |
|
| 615 | - $insertion_array, |
|
| 616 | - $datatypes_array |
|
| 617 | - ) |
|
| 618 | - ); |
|
| 619 | - return 0; |
|
| 620 | - } |
|
| 621 | - return $wpdb->insert_id; |
|
| 622 | - } |
|
| 623 | - |
|
| 624 | - /** |
|
| 625 | - * Inserts into the venue_meta table |
|
| 626 | - * @param int $cpt_id |
|
| 627 | - * @param array $old_event |
|
| 628 | - * @return int |
|
| 629 | - */ |
|
| 630 | - private function _insert_venue_into_meta_table($cpt_id, $old_event) |
|
| 631 | - { |
|
| 632 | - global $wpdb; |
|
| 633 | - |
|
| 634 | - // assume the country is the same as the organization's old settings |
|
| 635 | - $country_iso = $this->get_migration_script()->get_default_country_iso(); |
|
| 636 | - // find the state from the venue, or the organization, or just guess california |
|
| 637 | - if (! $old_event['state']) { |
|
| 638 | - $old_org_options = get_option('events_organization_settings'); |
|
| 639 | - $state_name = stripslashes($old_org_options['organization_state']); |
|
| 640 | - } else { |
|
| 641 | - $state_name = $old_event['state']; |
|
| 642 | - } |
|
| 643 | - if (! $state_name) { |
|
| 644 | - $state_name = 'CA'; |
|
| 645 | - } |
|
| 646 | - // get a state ID with the same name, if possible |
|
| 647 | - try { |
|
| 648 | - $state = $this->get_migration_script()->get_or_create_state($state_name, $country_iso); |
|
| 649 | - $state_id = $state['STA_ID']; |
|
| 650 | - } catch (EE_Error $e) { |
|
| 651 | - $this->add_error($e->getMessage()); |
|
| 652 | - $state_id = 0; |
|
| 653 | - } |
|
| 654 | - // now insert into meta table |
|
| 655 | - $insertion_array = array( |
|
| 656 | - 'VNU_ID' => $cpt_id,// VNU_ID_fk |
|
| 657 | - 'VNU_address' => stripslashes($old_event['address']),// VNU_address |
|
| 658 | - 'VNU_address2' => stripslashes($old_event['address2']),// VNU_address2 |
|
| 659 | - 'VNU_city' => stripslashes($old_event['city']),// VNU_city |
|
| 660 | - 'STA_ID' => $state_id,// STA_ID |
|
| 661 | - 'CNT_ISO' => $country_iso,// CNT_ISO |
|
| 662 | - 'VNU_zip' => $old_event['zip'],// VNU_zip |
|
| 663 | - 'VNU_phone' => $old_event['venue_phone'],// VNU_phone |
|
| 664 | - 'VNU_capacity' => -1,// VNU_capacity |
|
| 665 | - 'VNU_url' => $old_event['venue_url'],// VNU_url |
|
| 666 | - 'VNU_virtual_phone' => $old_event['virtual_phone'],// VNU_virtual_phone |
|
| 667 | - 'VNU_virtual_url' => $old_event['virtual_url'],// VNU_virtual_url |
|
| 668 | - 'VNU_google_map_link' => '',// VNU_google_map_link |
|
| 669 | - 'VNU_enable_for_gmap' => true // VNU_enable_for_gmap |
|
| 670 | - ); |
|
| 671 | - $datatypes = array( |
|
| 672 | - '%d',// VNU_ID_fk |
|
| 673 | - '%s',// VNU_address |
|
| 674 | - '%s',// VNU_address2 |
|
| 675 | - '%s',// VNU_city |
|
| 676 | - '%d',// STA_ID |
|
| 677 | - '%s',// CNT_ISO |
|
| 678 | - '%s',// VNU_zip |
|
| 679 | - '%s',// VNU_phone |
|
| 680 | - '%d',// VNU_capacity |
|
| 681 | - '%s',// VNU_url |
|
| 682 | - '%s',// VNU_virtual_phone |
|
| 683 | - '%s',// VNU_virtual_url |
|
| 684 | - '%s',// VNU_google_map_link |
|
| 685 | - '%d',// VNU_enable_for_gmap |
|
| 686 | - ); |
|
| 687 | - $success = $wpdb->insert($wpdb->prefix . "esp_venue_meta", $insertion_array, $datatypes); |
|
| 688 | - if (! $success) { |
|
| 689 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_meta_table, $insertion_array, $datatypes)); |
|
| 690 | - return 0; |
|
| 691 | - } |
|
| 692 | - return $wpdb->insert_id; |
|
| 693 | - } |
|
| 694 | - |
|
| 695 | - |
|
| 696 | - |
|
| 697 | - /** |
|
| 698 | - * @param $new_event_id |
|
| 699 | - * @param $new_venue_id |
|
| 700 | - * @return int |
|
| 701 | - */ |
|
| 702 | - private function _insert_new_venue_to_event($new_event_id, $new_venue_id) |
|
| 703 | - { |
|
| 704 | - global $wpdb; |
|
| 705 | - if (! $new_event_id) { |
|
| 706 | - $this->add_error(sprintf(esc_html__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $new_event_id)); |
|
| 707 | - return 0; |
|
| 708 | - } |
|
| 709 | - if (! $new_venue_id) { |
|
| 710 | - $this->add_error(sprintf(esc_html__("Could not find 4.1 venue id for 3.1 venue #%d.", "event_espresso"), $new_venue_id)); |
|
| 711 | - return 0; |
|
| 712 | - } |
|
| 713 | - $cols_n_values = array( |
|
| 714 | - 'EVT_ID' => $new_event_id, |
|
| 715 | - 'VNU_ID' => $new_venue_id, |
|
| 716 | - 'EVV_primary' => true |
|
| 717 | - ); |
|
| 718 | - $datatypes = array( |
|
| 719 | - '%d',// EVT_ID |
|
| 720 | - '%d',// VNU_ID |
|
| 721 | - '%d',// EVT_primary |
|
| 722 | - ); |
|
| 723 | - $success = $wpdb->insert($wpdb->prefix . "esp_event_venue", $cols_n_values, $datatypes); |
|
| 724 | - if (! $success) { |
|
| 725 | - $this->add_error( |
|
| 726 | - $this->get_migration_script()->_create_error_message_for_db_insertion( |
|
| 727 | - $this->_old_table, |
|
| 728 | - array(), |
|
| 729 | - $this->_new_table, |
|
| 730 | - $cols_n_values, |
|
| 731 | - $datatypes |
|
| 732 | - ) |
|
| 733 | - ); |
|
| 734 | - return 0; |
|
| 735 | - } |
|
| 736 | - return $wpdb->insert_id; |
|
| 737 | - } |
|
| 738 | - /** |
|
| 739 | - * Converts all the 3.1 start-end times for the event to 4.1 datetimes |
|
| 740 | - * @global wpdb $wpdb |
|
| 741 | - * @param array $old_event results of get_results(...,ARRAY_A) |
|
| 742 | - * @param int $new_cpt_id new post ID |
|
| 743 | - * @return void (if there are errors though, adds them to the stage's error list |
|
| 744 | - */ |
|
| 745 | - private function _convert_start_end_times($old_event, $new_cpt_id) |
|
| 746 | - { |
|
| 747 | - $start_end_times = $this->_get_old_start_end_times($old_event['id']); |
|
| 748 | - foreach ($start_end_times as $start_end_time) { |
|
| 749 | - $datetime_id = $this->_insert_new_datetime($start_end_time, $old_event, $new_cpt_id); |
|
| 750 | - if ($datetime_id) { |
|
| 751 | - $this->get_migration_script()->set_mapping($this->_old_start_end_table, $start_end_time['id'], $this->_new_datetime_table, $datetime_id); |
|
| 752 | - } |
|
| 753 | - } |
|
| 754 | - } |
|
| 755 | - /** |
|
| 756 | - * Queries the 3.1 wp_events_start_end table to get all the start and end times for the event |
|
| 757 | - * @global wpdb $wpdb |
|
| 758 | - * @param int $old_event_id |
|
| 759 | - * @return array |
|
| 760 | - */ |
|
| 761 | - private function _get_old_start_end_times($old_event_id) |
|
| 762 | - { |
|
| 763 | - global $wpdb; |
|
| 764 | - return $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_start_end_table WHERE event_id=%d", $old_event_id), ARRAY_A); |
|
| 765 | - } |
|
| 766 | - /** |
|
| 767 | - * Inserts a 4.1 datetime given the 3.1 start_end db row and event_details row |
|
| 768 | - * @param array $start_end_time_row |
|
| 769 | - * @param array $old_event_row |
|
| 770 | - * @param int $new_cpt_id |
|
| 771 | - * @return int ID of new datetime |
|
| 772 | - */ |
|
| 773 | - private function _insert_new_datetime($start_end_time_row, $old_event_row, $new_cpt_id) |
|
| 774 | - { |
|
| 775 | - global $wpdb; |
|
| 776 | - $start_date = $old_event_row['start_date']; |
|
| 777 | - $start_time = $this->get_migration_script()->convertTimeFromAMPM($start_end_time_row['start_time']); |
|
| 778 | - $end_date = $old_event_row['end_date']; |
|
| 779 | - $end_time = $this->get_migration_script()->convertTimeFromAMPM($start_end_time_row['end_time']); |
|
| 780 | - $existing_datetimes = $this->_count_other_datetimes_exist_for_new_event($new_cpt_id); |
|
| 781 | - $start_datetime_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $start_end_time_row, "$start_date $start_time:00", $old_event_row['timezone_string']); |
|
| 782 | - $end_datetime_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $start_end_time_row, "$end_date $end_time:00", $old_event_row['timezone_string']); |
|
| 783 | - $cols_n_values = array( |
|
| 784 | - 'EVT_ID' => $new_cpt_id,// EVT_ID |
|
| 785 | - 'DTT_EVT_start' => $start_datetime_utc,// DTT_EVT_start |
|
| 786 | - 'DTT_EVT_end' => $end_datetime_utc,// DTT_EVT_end |
|
| 787 | - 'DTT_reg_limit' => intval($start_end_time_row['reg_limit']) ? $start_end_time_row['reg_limit'] : $old_event_row['reg_limit'],// DTT_reg_limit |
|
| 788 | - 'DTT_sold' => 0,// note: we will increment this as registrations are added during the migration |
|
| 548 | + $id = $wpdb->get_var($query); |
|
| 549 | + return $id; |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + /** |
|
| 553 | + * Gets teh venue's title or makes one up if there is none |
|
| 554 | + * @param array $event_data_array keys are events_details columns and values are their values |
|
| 555 | + * @return string |
|
| 556 | + */ |
|
| 557 | + protected function _get_venue_title_for_event($event_data_array) |
|
| 558 | + { |
|
| 559 | + return $event_data_array['venue_title'] ? stripslashes($event_data_array['venue_title']) : stripslashes(sprintf(esc_html__('Venue of %s', 'event_espresso'), $event_data_array['event_name'])); |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + /** |
|
| 563 | + * Inserts the CPT |
|
| 564 | + * |
|
| 565 | + * @param array $old_event keys are cols, values are col values |
|
| 566 | + * @return int |
|
| 567 | + */ |
|
| 568 | + private function _insert_venue_into_posts($old_event) |
|
| 569 | + { |
|
| 570 | + global $wpdb; |
|
| 571 | + $insertion_array = array( |
|
| 572 | + 'post_title' => $this->_get_venue_title_for_event($old_event),// VNU_name |
|
| 573 | + 'post_content' => '',// VNU_desc |
|
| 574 | + 'post_name' => $this->_find_unique_slug($old_event['venue_title'], sanitize_title('venue-of-' . $old_event['event_name'])),// VNU_identifier |
|
| 575 | + 'post_date' => current_time('mysql'),// VNU_created |
|
| 576 | + 'post_date_gmt' => get_gmt_from_date(current_time('mysql')), |
|
| 577 | + 'post_excerpt' => '',// VNU_short_desc arbitrary only 50 characters |
|
| 578 | + 'post_modified' => current_time('mysql'),// VNU_modified |
|
| 579 | + 'post_modified_gmt' => get_gmt_from_date(current_time('mysql')), |
|
| 580 | + 'post_author' => $old_event['wp_user'],// VNU_wp_user |
|
| 581 | + 'post_parent' => 0,// parent |
|
| 582 | + 'menu_order' => 0,// VNU_order |
|
| 583 | + 'post_type' => 'espresso_venues'// post_type |
|
| 584 | + ); |
|
| 585 | + $datatypes_array = array( |
|
| 586 | + '%s',// VNU_name |
|
| 587 | + '%s',// VNU_desc |
|
| 588 | + '%s',// VNU_identifier |
|
| 589 | + '%s',// VNU_created |
|
| 590 | + '%s', |
|
| 591 | + '%s',// VNU_short_desc |
|
| 592 | + '%s',// VNU_modified |
|
| 593 | + '%s', |
|
| 594 | + '%d',// VNU_wp_user |
|
| 595 | + '%d',// parent |
|
| 596 | + '%d',// VNU_order |
|
| 597 | + '%s',// post_type |
|
| 598 | + ); |
|
| 599 | + $success = $wpdb->insert( |
|
| 600 | + $wpdb->posts, |
|
| 601 | + $insertion_array, |
|
| 602 | + $datatypes_array |
|
| 603 | + ); |
|
| 604 | + if (! $success) { |
|
| 605 | + $this->add_error( |
|
| 606 | + $this->get_migration_script()->_create_error_message_for_db_insertion( |
|
| 607 | + $this->_old_table, |
|
| 608 | + $old_event, |
|
| 609 | + $this->_new_table, |
|
| 610 | + $insertion_array, |
|
| 611 | + $datatypes_array |
|
| 612 | + ) |
|
| 613 | + ); |
|
| 614 | + return 0; |
|
| 615 | + } |
|
| 616 | + return $wpdb->insert_id; |
|
| 617 | + } |
|
| 618 | + |
|
| 619 | + /** |
|
| 620 | + * Inserts into the venue_meta table |
|
| 621 | + * @param int $cpt_id |
|
| 622 | + * @param array $old_event |
|
| 623 | + * @return int |
|
| 624 | + */ |
|
| 625 | + private function _insert_venue_into_meta_table($cpt_id, $old_event) |
|
| 626 | + { |
|
| 627 | + global $wpdb; |
|
| 628 | + |
|
| 629 | + // assume the country is the same as the organization's old settings |
|
| 630 | + $country_iso = $this->get_migration_script()->get_default_country_iso(); |
|
| 631 | + // find the state from the venue, or the organization, or just guess california |
|
| 632 | + if (! $old_event['state']) { |
|
| 633 | + $old_org_options = get_option('events_organization_settings'); |
|
| 634 | + $state_name = stripslashes($old_org_options['organization_state']); |
|
| 635 | + } else { |
|
| 636 | + $state_name = $old_event['state']; |
|
| 637 | + } |
|
| 638 | + if (! $state_name) { |
|
| 639 | + $state_name = 'CA'; |
|
| 640 | + } |
|
| 641 | + // get a state ID with the same name, if possible |
|
| 642 | + try { |
|
| 643 | + $state = $this->get_migration_script()->get_or_create_state($state_name, $country_iso); |
|
| 644 | + $state_id = $state['STA_ID']; |
|
| 645 | + } catch (EE_Error $e) { |
|
| 646 | + $this->add_error($e->getMessage()); |
|
| 647 | + $state_id = 0; |
|
| 648 | + } |
|
| 649 | + // now insert into meta table |
|
| 650 | + $insertion_array = array( |
|
| 651 | + 'VNU_ID' => $cpt_id,// VNU_ID_fk |
|
| 652 | + 'VNU_address' => stripslashes($old_event['address']),// VNU_address |
|
| 653 | + 'VNU_address2' => stripslashes($old_event['address2']),// VNU_address2 |
|
| 654 | + 'VNU_city' => stripslashes($old_event['city']),// VNU_city |
|
| 655 | + 'STA_ID' => $state_id,// STA_ID |
|
| 656 | + 'CNT_ISO' => $country_iso,// CNT_ISO |
|
| 657 | + 'VNU_zip' => $old_event['zip'],// VNU_zip |
|
| 658 | + 'VNU_phone' => $old_event['venue_phone'],// VNU_phone |
|
| 659 | + 'VNU_capacity' => -1,// VNU_capacity |
|
| 660 | + 'VNU_url' => $old_event['venue_url'],// VNU_url |
|
| 661 | + 'VNU_virtual_phone' => $old_event['virtual_phone'],// VNU_virtual_phone |
|
| 662 | + 'VNU_virtual_url' => $old_event['virtual_url'],// VNU_virtual_url |
|
| 663 | + 'VNU_google_map_link' => '',// VNU_google_map_link |
|
| 664 | + 'VNU_enable_for_gmap' => true // VNU_enable_for_gmap |
|
| 665 | + ); |
|
| 666 | + $datatypes = array( |
|
| 667 | + '%d',// VNU_ID_fk |
|
| 668 | + '%s',// VNU_address |
|
| 669 | + '%s',// VNU_address2 |
|
| 670 | + '%s',// VNU_city |
|
| 671 | + '%d',// STA_ID |
|
| 672 | + '%s',// CNT_ISO |
|
| 673 | + '%s',// VNU_zip |
|
| 674 | + '%s',// VNU_phone |
|
| 675 | + '%d',// VNU_capacity |
|
| 676 | + '%s',// VNU_url |
|
| 677 | + '%s',// VNU_virtual_phone |
|
| 678 | + '%s',// VNU_virtual_url |
|
| 679 | + '%s',// VNU_google_map_link |
|
| 680 | + '%d',// VNU_enable_for_gmap |
|
| 681 | + ); |
|
| 682 | + $success = $wpdb->insert($wpdb->prefix . "esp_venue_meta", $insertion_array, $datatypes); |
|
| 683 | + if (! $success) { |
|
| 684 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_meta_table, $insertion_array, $datatypes)); |
|
| 685 | + return 0; |
|
| 686 | + } |
|
| 687 | + return $wpdb->insert_id; |
|
| 688 | + } |
|
| 689 | + |
|
| 690 | + |
|
| 691 | + |
|
| 692 | + /** |
|
| 693 | + * @param $new_event_id |
|
| 694 | + * @param $new_venue_id |
|
| 695 | + * @return int |
|
| 696 | + */ |
|
| 697 | + private function _insert_new_venue_to_event($new_event_id, $new_venue_id) |
|
| 698 | + { |
|
| 699 | + global $wpdb; |
|
| 700 | + if (! $new_event_id) { |
|
| 701 | + $this->add_error(sprintf(esc_html__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $new_event_id)); |
|
| 702 | + return 0; |
|
| 703 | + } |
|
| 704 | + if (! $new_venue_id) { |
|
| 705 | + $this->add_error(sprintf(esc_html__("Could not find 4.1 venue id for 3.1 venue #%d.", "event_espresso"), $new_venue_id)); |
|
| 706 | + return 0; |
|
| 707 | + } |
|
| 708 | + $cols_n_values = array( |
|
| 709 | + 'EVT_ID' => $new_event_id, |
|
| 710 | + 'VNU_ID' => $new_venue_id, |
|
| 711 | + 'EVV_primary' => true |
|
| 712 | + ); |
|
| 713 | + $datatypes = array( |
|
| 714 | + '%d',// EVT_ID |
|
| 715 | + '%d',// VNU_ID |
|
| 716 | + '%d',// EVT_primary |
|
| 717 | + ); |
|
| 718 | + $success = $wpdb->insert($wpdb->prefix . "esp_event_venue", $cols_n_values, $datatypes); |
|
| 719 | + if (! $success) { |
|
| 720 | + $this->add_error( |
|
| 721 | + $this->get_migration_script()->_create_error_message_for_db_insertion( |
|
| 722 | + $this->_old_table, |
|
| 723 | + array(), |
|
| 724 | + $this->_new_table, |
|
| 725 | + $cols_n_values, |
|
| 726 | + $datatypes |
|
| 727 | + ) |
|
| 728 | + ); |
|
| 729 | + return 0; |
|
| 730 | + } |
|
| 731 | + return $wpdb->insert_id; |
|
| 732 | + } |
|
| 733 | + /** |
|
| 734 | + * Converts all the 3.1 start-end times for the event to 4.1 datetimes |
|
| 735 | + * @global wpdb $wpdb |
|
| 736 | + * @param array $old_event results of get_results(...,ARRAY_A) |
|
| 737 | + * @param int $new_cpt_id new post ID |
|
| 738 | + * @return void (if there are errors though, adds them to the stage's error list |
|
| 739 | + */ |
|
| 740 | + private function _convert_start_end_times($old_event, $new_cpt_id) |
|
| 741 | + { |
|
| 742 | + $start_end_times = $this->_get_old_start_end_times($old_event['id']); |
|
| 743 | + foreach ($start_end_times as $start_end_time) { |
|
| 744 | + $datetime_id = $this->_insert_new_datetime($start_end_time, $old_event, $new_cpt_id); |
|
| 745 | + if ($datetime_id) { |
|
| 746 | + $this->get_migration_script()->set_mapping($this->_old_start_end_table, $start_end_time['id'], $this->_new_datetime_table, $datetime_id); |
|
| 747 | + } |
|
| 748 | + } |
|
| 749 | + } |
|
| 750 | + /** |
|
| 751 | + * Queries the 3.1 wp_events_start_end table to get all the start and end times for the event |
|
| 752 | + * @global wpdb $wpdb |
|
| 753 | + * @param int $old_event_id |
|
| 754 | + * @return array |
|
| 755 | + */ |
|
| 756 | + private function _get_old_start_end_times($old_event_id) |
|
| 757 | + { |
|
| 758 | + global $wpdb; |
|
| 759 | + return $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_start_end_table WHERE event_id=%d", $old_event_id), ARRAY_A); |
|
| 760 | + } |
|
| 761 | + /** |
|
| 762 | + * Inserts a 4.1 datetime given the 3.1 start_end db row and event_details row |
|
| 763 | + * @param array $start_end_time_row |
|
| 764 | + * @param array $old_event_row |
|
| 765 | + * @param int $new_cpt_id |
|
| 766 | + * @return int ID of new datetime |
|
| 767 | + */ |
|
| 768 | + private function _insert_new_datetime($start_end_time_row, $old_event_row, $new_cpt_id) |
|
| 769 | + { |
|
| 770 | + global $wpdb; |
|
| 771 | + $start_date = $old_event_row['start_date']; |
|
| 772 | + $start_time = $this->get_migration_script()->convertTimeFromAMPM($start_end_time_row['start_time']); |
|
| 773 | + $end_date = $old_event_row['end_date']; |
|
| 774 | + $end_time = $this->get_migration_script()->convertTimeFromAMPM($start_end_time_row['end_time']); |
|
| 775 | + $existing_datetimes = $this->_count_other_datetimes_exist_for_new_event($new_cpt_id); |
|
| 776 | + $start_datetime_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $start_end_time_row, "$start_date $start_time:00", $old_event_row['timezone_string']); |
|
| 777 | + $end_datetime_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $start_end_time_row, "$end_date $end_time:00", $old_event_row['timezone_string']); |
|
| 778 | + $cols_n_values = array( |
|
| 779 | + 'EVT_ID' => $new_cpt_id,// EVT_ID |
|
| 780 | + 'DTT_EVT_start' => $start_datetime_utc,// DTT_EVT_start |
|
| 781 | + 'DTT_EVT_end' => $end_datetime_utc,// DTT_EVT_end |
|
| 782 | + 'DTT_reg_limit' => intval($start_end_time_row['reg_limit']) ? $start_end_time_row['reg_limit'] : $old_event_row['reg_limit'],// DTT_reg_limit |
|
| 783 | + 'DTT_sold' => 0,// note: we will increment this as registrations are added during the migration |
|
| 789 | 784 | // 'DTT_is_primary'=> 0 == $existing_datetimes ,//DTT_is_primary... if count==0, then we'll call it the 'primary' |
| 790 | - 'DTT_order' => $existing_datetimes,// DTT_order, just give it the same order as the count of how many datetimes already exist |
|
| 791 | - 'DTT_parent' => 0, |
|
| 792 | - 'DTT_deleted' => false |
|
| 793 | - ); |
|
| 794 | - $datatypes = array( |
|
| 795 | - '%d',// EVT_Id |
|
| 796 | - '%s',// DTT_EVT_start |
|
| 797 | - '%s',// DTT_EVT_end |
|
| 798 | - '%d',// DTT_reg_limit |
|
| 799 | - '%d',// DTT_sold |
|
| 785 | + 'DTT_order' => $existing_datetimes,// DTT_order, just give it the same order as the count of how many datetimes already exist |
|
| 786 | + 'DTT_parent' => 0, |
|
| 787 | + 'DTT_deleted' => false |
|
| 788 | + ); |
|
| 789 | + $datatypes = array( |
|
| 790 | + '%d',// EVT_Id |
|
| 791 | + '%s',// DTT_EVT_start |
|
| 792 | + '%s',// DTT_EVT_end |
|
| 793 | + '%d',// DTT_reg_limit |
|
| 794 | + '%d',// DTT_sold |
|
| 800 | 795 | // '%d',//DTT_is_primary |
| 801 | - '%d',// DTT_order |
|
| 802 | - '%d',// DTT_parent |
|
| 803 | - '%d',// DTT_deleted |
|
| 804 | - ); |
|
| 805 | - $success = $wpdb->insert($this->_new_datetime_table, $cols_n_values, $datatypes); |
|
| 806 | - if (! $success) { |
|
| 807 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_start_end_table, array_merge($old_event_row, $start_end_time_row), $this->_new_datetime_table, $cols_n_values, $datatypes)); |
|
| 808 | - return 0; |
|
| 809 | - } |
|
| 810 | - return $wpdb->insert_id; |
|
| 811 | - } |
|
| 812 | - |
|
| 813 | - /** |
|
| 814 | - * Checks if there's a 4.1 datetime for this event already. This is mostly only handy |
|
| 815 | - * when deciding whether a datetime we're about ot insert should be the 'primary' or not |
|
| 816 | - * @global wpdb $wpdb |
|
| 817 | - * @param int $cpt_event_id |
|
| 818 | - * @return int |
|
| 819 | - */ |
|
| 820 | - private function _count_other_datetimes_exist_for_new_event($cpt_event_id) |
|
| 821 | - { |
|
| 822 | - global $wpdb; |
|
| 823 | - $count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $this->_new_datetime_table WHERE EVT_ID=%d", $cpt_event_id)); |
|
| 824 | - return intval($count); |
|
| 825 | - } |
|
| 796 | + '%d',// DTT_order |
|
| 797 | + '%d',// DTT_parent |
|
| 798 | + '%d',// DTT_deleted |
|
| 799 | + ); |
|
| 800 | + $success = $wpdb->insert($this->_new_datetime_table, $cols_n_values, $datatypes); |
|
| 801 | + if (! $success) { |
|
| 802 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_start_end_table, array_merge($old_event_row, $start_end_time_row), $this->_new_datetime_table, $cols_n_values, $datatypes)); |
|
| 803 | + return 0; |
|
| 804 | + } |
|
| 805 | + return $wpdb->insert_id; |
|
| 806 | + } |
|
| 807 | + |
|
| 808 | + /** |
|
| 809 | + * Checks if there's a 4.1 datetime for this event already. This is mostly only handy |
|
| 810 | + * when deciding whether a datetime we're about ot insert should be the 'primary' or not |
|
| 811 | + * @global wpdb $wpdb |
|
| 812 | + * @param int $cpt_event_id |
|
| 813 | + * @return int |
|
| 814 | + */ |
|
| 815 | + private function _count_other_datetimes_exist_for_new_event($cpt_event_id) |
|
| 816 | + { |
|
| 817 | + global $wpdb; |
|
| 818 | + $count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $this->_new_datetime_table WHERE EVT_ID=%d", $cpt_event_id)); |
|
| 819 | + return intval($count); |
|
| 820 | + } |
|
| 826 | 821 | } |
@@ -176,11 +176,11 @@ discard block |
||
| 176 | 176 | public function __construct() |
| 177 | 177 | { |
| 178 | 178 | global $wpdb; |
| 179 | - $this->_old_table = $wpdb->prefix . "events_detail"; |
|
| 180 | - $this->_old_start_end_table = $wpdb->prefix . "events_start_end"; |
|
| 181 | - $this->_new_table = $wpdb->prefix . "posts"; |
|
| 182 | - $this->_new_meta_table = $wpdb->prefix . "esp_event_meta"; |
|
| 183 | - $this->_new_datetime_table = $wpdb->prefix . "esp_datetime"; |
|
| 179 | + $this->_old_table = $wpdb->prefix."events_detail"; |
|
| 180 | + $this->_old_start_end_table = $wpdb->prefix."events_start_end"; |
|
| 181 | + $this->_new_table = $wpdb->prefix."posts"; |
|
| 182 | + $this->_new_meta_table = $wpdb->prefix."esp_event_meta"; |
|
| 183 | + $this->_new_datetime_table = $wpdb->prefix."esp_datetime"; |
|
| 184 | 184 | $this->_pretty_name = esc_html__("Events", "event_espresso"); |
| 185 | 185 | parent::__construct(); |
| 186 | 186 | } |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | public function _count_records_to_migrate() |
| 195 | 195 | { |
| 196 | 196 | global $wpdb; |
| 197 | - $count = $wpdb->get_var("SELECT COUNT(*) FROM " . $this->_old_table . ' WHERE event_status !="D"'); |
|
| 197 | + $count = $wpdb->get_var("SELECT COUNT(*) FROM ".$this->_old_table.' WHERE event_status !="D"'); |
|
| 198 | 198 | return intval($count); |
| 199 | 199 | } |
| 200 | 200 | |
@@ -261,17 +261,17 @@ discard block |
||
| 261 | 261 | private function _add_post_metas($old_event, $post_id) |
| 262 | 262 | { |
| 263 | 263 | $event_meta = maybe_unserialize($old_event['event_meta']); |
| 264 | - if (! $event_meta || ! is_array($event_meta)) { |
|
| 264 | + if ( ! $event_meta || ! is_array($event_meta)) { |
|
| 265 | 265 | return; |
| 266 | 266 | } |
| 267 | - unset($event_meta['date_submitted']);// factored into CPT |
|
| 268 | - unset($event_meta['additional_attendee_reg_info']);// factored into event meta table |
|
| 269 | - unset($event_meta['default_payment_status']);// dido |
|
| 270 | - unset($event_meta['event_thumbnail_url']);// used to find post featured image |
|
| 267 | + unset($event_meta['date_submitted']); // factored into CPT |
|
| 268 | + unset($event_meta['additional_attendee_reg_info']); // factored into event meta table |
|
| 269 | + unset($event_meta['default_payment_status']); // dido |
|
| 270 | + unset($event_meta['event_thumbnail_url']); // used to find post featured image |
|
| 271 | 271 | foreach ($event_meta as $meta_key => $meta_value) { |
| 272 | 272 | if ($meta_key) {// if the meta key is just an empty string, ignore it |
| 273 | 273 | $success = add_post_meta($post_id, $meta_key, $meta_value, true); |
| 274 | - if (! $success) { |
|
| 274 | + if ( ! $success) { |
|
| 275 | 275 | $this->add_error(sprintf(esc_html__("Could not add post meta for CPT with ID #%d. Meta key: '%s',meta value:'%d' for 3.1 event: %s", "event_espresso"), $post_id, $meta_key, $meta_value, implode(",", $old_event))); |
| 276 | 276 | } |
| 277 | 277 | } |
@@ -342,68 +342,68 @@ discard block |
||
| 342 | 342 | // and 3 custom ones: cancelled,postponed,sold_out |
| 343 | 343 | $status_conversions = array( |
| 344 | 344 | 'R' => 'draft', |
| 345 | - 'X' => 'draft',// 4.1 doesn't have a "not approved for publishing" status. this is what posts are set to that aren't approved |
|
| 345 | + 'X' => 'draft', // 4.1 doesn't have a "not approved for publishing" status. this is what posts are set to that aren't approved |
|
| 346 | 346 | 'P' => 'pending', |
| 347 | - 'IA' => 'draft',// draft and in the past |
|
| 347 | + 'IA' => 'draft', // draft and in the past |
|
| 348 | 348 | // IA=inactive in 3.1: events were switched to this when they expired. in 4.1 that's just calculated |
| 349 | - 'O' => 'publish',// @todo: will be an event type later; if this is the status, set the end date WAAAY later; and add term for 'ongoing' |
|
| 349 | + 'O' => 'publish', // @todo: will be an event type later; if this is the status, set the end date WAAAY later; and add term for 'ongoing' |
|
| 350 | 350 | 'A' => 'publish', |
| 351 | - 'S' => 'draft',// @todo: is it ok to just mark secondary/waitlist events as DRAFTS? |
|
| 351 | + 'S' => 'draft', // @todo: is it ok to just mark secondary/waitlist events as DRAFTS? |
|
| 352 | 352 | 'D' => 'trash', |
| 353 | 353 | ); |
| 354 | - $post_status = $status_conversions[ $old_event['event_status'] ]; |
|
| 354 | + $post_status = $status_conversions[$old_event['event_status']]; |
|
| 355 | 355 | // check if we've sold out |
| 356 | 356 | if (intval($old_event['reg_limit']) <= self::count_registrations($old_event['id'])) { |
| 357 | 357 | $post_status = 'sold_out'; |
| 358 | 358 | } |
| 359 | 359 | // FYI postponed and cancelled don't exist in 3.1 |
| 360 | 360 | $cols_n_values = array( |
| 361 | - 'post_title' => stripslashes($old_event['event_name']),// EVT_name |
|
| 362 | - 'post_content' => stripslashes($old_event['event_desc']),// EVT_desc |
|
| 363 | - 'post_name' => $this->_find_unique_slug($old_event['event_name'], $old_event['event_identifier'], $post_status),// EVT_slug |
|
| 364 | - 'post_date' => $old_event['submitted'],// EVT_created NOT |
|
| 361 | + 'post_title' => stripslashes($old_event['event_name']), // EVT_name |
|
| 362 | + 'post_content' => stripslashes($old_event['event_desc']), // EVT_desc |
|
| 363 | + 'post_name' => $this->_find_unique_slug($old_event['event_name'], $old_event['event_identifier'], $post_status), // EVT_slug |
|
| 364 | + 'post_date' => $old_event['submitted'], // EVT_created NOT |
|
| 365 | 365 | 'post_date_gmt' => get_gmt_from_date($old_event['submitted']), |
| 366 | - 'post_excerpt' => '',// EVT_short_desc |
|
| 367 | - 'post_modified' => $old_event['submitted'],// EVT_modified |
|
| 366 | + 'post_excerpt' => '', // EVT_short_desc |
|
| 367 | + 'post_modified' => $old_event['submitted'], // EVT_modified |
|
| 368 | 368 | 'post_modified_gmt' => get_gmt_from_date($old_event['submitted']), |
| 369 | - 'post_author' => $old_event['wp_user'],// EVT_wp_user |
|
| 370 | - 'post_parent' => 0,// parent maybe get this from some REM field? |
|
| 371 | - 'menu_order' => 0,// EVT_order |
|
| 372 | - 'post_type' => 'espresso_events',// post_type |
|
| 373 | - 'post_status' => $post_status,// status |
|
| 369 | + 'post_author' => $old_event['wp_user'], // EVT_wp_user |
|
| 370 | + 'post_parent' => 0, // parent maybe get this from some REM field? |
|
| 371 | + 'menu_order' => 0, // EVT_order |
|
| 372 | + 'post_type' => 'espresso_events', // post_type |
|
| 373 | + 'post_status' => $post_status, // status |
|
| 374 | 374 | ); |
| 375 | 375 | $cols_n_values_with_no_invalid_text = array(); |
| 376 | 376 | foreach ($cols_n_values as $col => $value) { |
| 377 | 377 | $value_sans_invalid_chars = $wpdb->strip_invalid_text_for_column($this->_new_table, $col, $value); |
| 378 | - if (! is_wp_error($value_sans_invalid_chars)) { |
|
| 379 | - $cols_n_values_with_no_invalid_text[ $col ] = $value_sans_invalid_chars; |
|
| 378 | + if ( ! is_wp_error($value_sans_invalid_chars)) { |
|
| 379 | + $cols_n_values_with_no_invalid_text[$col] = $value_sans_invalid_chars; |
|
| 380 | 380 | } else { |
| 381 | 381 | // otherwise leave it as-is. It will blow everything up and stop the migration |
| 382 | - $cols_n_values_with_no_invalid_text[ $col ] = $value; |
|
| 382 | + $cols_n_values_with_no_invalid_text[$col] = $value; |
|
| 383 | 383 | } |
| 384 | 384 | } |
| 385 | 385 | $cols_n_values = $cols_n_values_with_no_invalid_text; |
| 386 | 386 | $datatypes = array( |
| 387 | - '%s',// EVT_name |
|
| 388 | - '%s',// EVT_desc |
|
| 389 | - '%s',// EVT_slug |
|
| 390 | - '%s',// EVT_created |
|
| 387 | + '%s', // EVT_name |
|
| 388 | + '%s', // EVT_desc |
|
| 389 | + '%s', // EVT_slug |
|
| 390 | + '%s', // EVT_created |
|
| 391 | 391 | '%s', |
| 392 | - '%s',// EVT_short_desc |
|
| 393 | - '%s',// EVT_modified |
|
| 392 | + '%s', // EVT_short_desc |
|
| 393 | + '%s', // EVT_modified |
|
| 394 | 394 | '%s', |
| 395 | - '%s',// EVT_wp_user |
|
| 396 | - '%d',// post_parent |
|
| 397 | - '%d',// EVT_order |
|
| 398 | - '%s',// post_type |
|
| 399 | - '%s',// status |
|
| 395 | + '%s', // EVT_wp_user |
|
| 396 | + '%d', // post_parent |
|
| 397 | + '%d', // EVT_order |
|
| 398 | + '%s', // post_type |
|
| 399 | + '%s', // status |
|
| 400 | 400 | ); |
| 401 | 401 | $success = $wpdb->insert( |
| 402 | 402 | $this->_new_table, |
| 403 | 403 | $cols_n_values, |
| 404 | 404 | $datatypes |
| 405 | 405 | ); |
| 406 | - if (! $success) { |
|
| 406 | + if ( ! $success) { |
|
| 407 | 407 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_table, $cols_n_values, $datatypes)); |
| 408 | 408 | return 0; |
| 409 | 409 | } |
@@ -442,10 +442,10 @@ discard block |
||
| 442 | 442 | // ); |
| 443 | 443 | $default_reg_status = $this->get_migration_script()->convert_3_1_payment_status_to_4_1_STS_ID(isset($event_meta['default_payment_status']) ? $event_meta['default_payment_status'] : '', intval($old_event['require_pre_approval'])); |
| 444 | 444 | $cols_n_values = array( |
| 445 | - 'EVT_ID' => $new_cpt_id,// EVT_ID_fk |
|
| 445 | + 'EVT_ID' => $new_cpt_id, // EVT_ID_fk |
|
| 446 | 446 | 'EVT_display_desc' => 'Y' == $old_event['display_desc'], |
| 447 | 447 | 'EVT_display_ticket_selector' => 'Y' == $old_event['display_reg_form'], |
| 448 | - 'EVT_visible_on' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_event, current_time('mysql'), $old_event['timezone_string']),// don't use the old 'visible_on', as it wasn't ever used |
|
| 448 | + 'EVT_visible_on' => $this->get_migration_script()->convert_date_string_to_utc($this, $old_event, current_time('mysql'), $old_event['timezone_string']), // don't use the old 'visible_on', as it wasn't ever used |
|
| 449 | 449 | 'EVT_additional_limit' => $old_event['allow_multiple'] == 'N' ? 1 : $old_event['additional_limit'], |
| 450 | 450 | 'EVT_default_registration_status' => $default_reg_status, |
| 451 | 451 | 'EVT_member_only' => $old_event['member_only'], |
@@ -457,25 +457,25 @@ discard block |
||
| 457 | 457 | |
| 458 | 458 | ); |
| 459 | 459 | $datatypes = array( |
| 460 | - '%s',// EVT_ID |
|
| 461 | - '%d',// EVT_display_desc |
|
| 462 | - '%d',// EVT_display_ticket_selector |
|
| 463 | - '%s',// EVT_visible_on |
|
| 464 | - '%d',// EVT_additional_limit |
|
| 465 | - '%s',// EVT_default_registration_status |
|
| 466 | - '%d',// EVT_member_only |
|
| 467 | - '%s',// EVT_phone |
|
| 468 | - '%d',// EVT_allow_overflow |
|
| 469 | - '%s',// EVT_timezone_string |
|
| 470 | - '%s',// EVT_external_URL |
|
| 471 | - '%d',// EVT_donations |
|
| 460 | + '%s', // EVT_ID |
|
| 461 | + '%d', // EVT_display_desc |
|
| 462 | + '%d', // EVT_display_ticket_selector |
|
| 463 | + '%s', // EVT_visible_on |
|
| 464 | + '%d', // EVT_additional_limit |
|
| 465 | + '%s', // EVT_default_registration_status |
|
| 466 | + '%d', // EVT_member_only |
|
| 467 | + '%s', // EVT_phone |
|
| 468 | + '%d', // EVT_allow_overflow |
|
| 469 | + '%s', // EVT_timezone_string |
|
| 470 | + '%s', // EVT_external_URL |
|
| 471 | + '%d', // EVT_donations |
|
| 472 | 472 | ); |
| 473 | 473 | $success = $wpdb->insert( |
| 474 | 474 | $this->_new_meta_table, |
| 475 | 475 | $cols_n_values, |
| 476 | 476 | $datatypes |
| 477 | 477 | ); |
| 478 | - if (! $success) { |
|
| 478 | + if ( ! $success) { |
|
| 479 | 479 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_meta_table, $cols_n_values, $datatypes)); |
| 480 | 480 | return 0; |
| 481 | 481 | } |
@@ -510,7 +510,7 @@ discard block |
||
| 510 | 510 | $new_id = $this->_insert_venue_into_posts($old_event); |
| 511 | 511 | if ($new_id) { |
| 512 | 512 | $this->_insert_venue_into_meta_table($new_id, $old_event); |
| 513 | - $guid = isset($old_event['venue_image']) ? $old_event['venue_image'] : null; |
|
| 513 | + $guid = isset($old_event['venue_image']) ? $old_event['venue_image'] : null; |
|
| 514 | 514 | $this->get_migration_script()->convert_image_url_to_attachment_and_attach_to_post($guid, $new_id, $this); |
| 515 | 515 | } |
| 516 | 516 | // we don't bother recording the conversion from old events to venues as that |
@@ -536,10 +536,10 @@ discard block |
||
| 536 | 536 | 'VNU_city' => $old_event['city'], |
| 537 | 537 | 'VNU_zip' => $old_event['zip'], |
| 538 | 538 | 'post_title' => $this->_get_venue_title_for_event($old_event), |
| 539 | - 'VNU_phone' => $old_event['venue_phone'],// VNU_phone |
|
| 540 | - 'VNU_url' => $old_event['venue_url'],// VNU_url |
|
| 541 | - 'VNU_virtual_phone' => $old_event['virtual_phone'],// VNU_virtual_phone |
|
| 542 | - 'VNU_virtual_url' => $old_event['virtual_url'],// VNU_virtual_url |
|
| 539 | + 'VNU_phone' => $old_event['venue_phone'], // VNU_phone |
|
| 540 | + 'VNU_url' => $old_event['venue_url'], // VNU_url |
|
| 541 | + 'VNU_virtual_phone' => $old_event['virtual_phone'], // VNU_virtual_phone |
|
| 542 | + 'VNU_virtual_url' => $old_event['virtual_url'], // VNU_virtual_url |
|
| 543 | 543 | ); |
| 544 | 544 | $sql_conditions = array(); |
| 545 | 545 | foreach ($conditions as $column => $value) { |
@@ -549,7 +549,7 @@ discard block |
||
| 549 | 549 | FROM |
| 550 | 550 | {$wpdb->posts} as p INNER JOIN |
| 551 | 551 | {$wpdb->prefix}esp_venue_meta as v ON p.ID = v.VNU_ID |
| 552 | - WHERE " . implode(" AND ", $sql_conditions) . " LIMIT 1"; |
|
| 552 | + WHERE ".implode(" AND ", $sql_conditions)." LIMIT 1"; |
|
| 553 | 553 | $id = $wpdb->get_var($query); |
| 554 | 554 | return $id; |
| 555 | 555 | } |
@@ -574,39 +574,39 @@ discard block |
||
| 574 | 574 | { |
| 575 | 575 | global $wpdb; |
| 576 | 576 | $insertion_array = array( |
| 577 | - 'post_title' => $this->_get_venue_title_for_event($old_event),// VNU_name |
|
| 578 | - 'post_content' => '',// VNU_desc |
|
| 579 | - 'post_name' => $this->_find_unique_slug($old_event['venue_title'], sanitize_title('venue-of-' . $old_event['event_name'])),// VNU_identifier |
|
| 580 | - 'post_date' => current_time('mysql'),// VNU_created |
|
| 577 | + 'post_title' => $this->_get_venue_title_for_event($old_event), // VNU_name |
|
| 578 | + 'post_content' => '', // VNU_desc |
|
| 579 | + 'post_name' => $this->_find_unique_slug($old_event['venue_title'], sanitize_title('venue-of-'.$old_event['event_name'])), // VNU_identifier |
|
| 580 | + 'post_date' => current_time('mysql'), // VNU_created |
|
| 581 | 581 | 'post_date_gmt' => get_gmt_from_date(current_time('mysql')), |
| 582 | - 'post_excerpt' => '',// VNU_short_desc arbitrary only 50 characters |
|
| 583 | - 'post_modified' => current_time('mysql'),// VNU_modified |
|
| 582 | + 'post_excerpt' => '', // VNU_short_desc arbitrary only 50 characters |
|
| 583 | + 'post_modified' => current_time('mysql'), // VNU_modified |
|
| 584 | 584 | 'post_modified_gmt' => get_gmt_from_date(current_time('mysql')), |
| 585 | - 'post_author' => $old_event['wp_user'],// VNU_wp_user |
|
| 586 | - 'post_parent' => 0,// parent |
|
| 587 | - 'menu_order' => 0,// VNU_order |
|
| 585 | + 'post_author' => $old_event['wp_user'], // VNU_wp_user |
|
| 586 | + 'post_parent' => 0, // parent |
|
| 587 | + 'menu_order' => 0, // VNU_order |
|
| 588 | 588 | 'post_type' => 'espresso_venues'// post_type |
| 589 | 589 | ); |
| 590 | 590 | $datatypes_array = array( |
| 591 | - '%s',// VNU_name |
|
| 592 | - '%s',// VNU_desc |
|
| 593 | - '%s',// VNU_identifier |
|
| 594 | - '%s',// VNU_created |
|
| 591 | + '%s', // VNU_name |
|
| 592 | + '%s', // VNU_desc |
|
| 593 | + '%s', // VNU_identifier |
|
| 594 | + '%s', // VNU_created |
|
| 595 | 595 | '%s', |
| 596 | - '%s',// VNU_short_desc |
|
| 597 | - '%s',// VNU_modified |
|
| 596 | + '%s', // VNU_short_desc |
|
| 597 | + '%s', // VNU_modified |
|
| 598 | 598 | '%s', |
| 599 | - '%d',// VNU_wp_user |
|
| 600 | - '%d',// parent |
|
| 601 | - '%d',// VNU_order |
|
| 602 | - '%s',// post_type |
|
| 599 | + '%d', // VNU_wp_user |
|
| 600 | + '%d', // parent |
|
| 601 | + '%d', // VNU_order |
|
| 602 | + '%s', // post_type |
|
| 603 | 603 | ); |
| 604 | 604 | $success = $wpdb->insert( |
| 605 | 605 | $wpdb->posts, |
| 606 | 606 | $insertion_array, |
| 607 | 607 | $datatypes_array |
| 608 | 608 | ); |
| 609 | - if (! $success) { |
|
| 609 | + if ( ! $success) { |
|
| 610 | 610 | $this->add_error( |
| 611 | 611 | $this->get_migration_script()->_create_error_message_for_db_insertion( |
| 612 | 612 | $this->_old_table, |
@@ -634,13 +634,13 @@ discard block |
||
| 634 | 634 | // assume the country is the same as the organization's old settings |
| 635 | 635 | $country_iso = $this->get_migration_script()->get_default_country_iso(); |
| 636 | 636 | // find the state from the venue, or the organization, or just guess california |
| 637 | - if (! $old_event['state']) { |
|
| 637 | + if ( ! $old_event['state']) { |
|
| 638 | 638 | $old_org_options = get_option('events_organization_settings'); |
| 639 | 639 | $state_name = stripslashes($old_org_options['organization_state']); |
| 640 | 640 | } else { |
| 641 | 641 | $state_name = $old_event['state']; |
| 642 | 642 | } |
| 643 | - if (! $state_name) { |
|
| 643 | + if ( ! $state_name) { |
|
| 644 | 644 | $state_name = 'CA'; |
| 645 | 645 | } |
| 646 | 646 | // get a state ID with the same name, if possible |
@@ -653,39 +653,39 @@ discard block |
||
| 653 | 653 | } |
| 654 | 654 | // now insert into meta table |
| 655 | 655 | $insertion_array = array( |
| 656 | - 'VNU_ID' => $cpt_id,// VNU_ID_fk |
|
| 657 | - 'VNU_address' => stripslashes($old_event['address']),// VNU_address |
|
| 658 | - 'VNU_address2' => stripslashes($old_event['address2']),// VNU_address2 |
|
| 659 | - 'VNU_city' => stripslashes($old_event['city']),// VNU_city |
|
| 660 | - 'STA_ID' => $state_id,// STA_ID |
|
| 661 | - 'CNT_ISO' => $country_iso,// CNT_ISO |
|
| 662 | - 'VNU_zip' => $old_event['zip'],// VNU_zip |
|
| 663 | - 'VNU_phone' => $old_event['venue_phone'],// VNU_phone |
|
| 664 | - 'VNU_capacity' => -1,// VNU_capacity |
|
| 665 | - 'VNU_url' => $old_event['venue_url'],// VNU_url |
|
| 666 | - 'VNU_virtual_phone' => $old_event['virtual_phone'],// VNU_virtual_phone |
|
| 667 | - 'VNU_virtual_url' => $old_event['virtual_url'],// VNU_virtual_url |
|
| 668 | - 'VNU_google_map_link' => '',// VNU_google_map_link |
|
| 656 | + 'VNU_ID' => $cpt_id, // VNU_ID_fk |
|
| 657 | + 'VNU_address' => stripslashes($old_event['address']), // VNU_address |
|
| 658 | + 'VNU_address2' => stripslashes($old_event['address2']), // VNU_address2 |
|
| 659 | + 'VNU_city' => stripslashes($old_event['city']), // VNU_city |
|
| 660 | + 'STA_ID' => $state_id, // STA_ID |
|
| 661 | + 'CNT_ISO' => $country_iso, // CNT_ISO |
|
| 662 | + 'VNU_zip' => $old_event['zip'], // VNU_zip |
|
| 663 | + 'VNU_phone' => $old_event['venue_phone'], // VNU_phone |
|
| 664 | + 'VNU_capacity' => -1, // VNU_capacity |
|
| 665 | + 'VNU_url' => $old_event['venue_url'], // VNU_url |
|
| 666 | + 'VNU_virtual_phone' => $old_event['virtual_phone'], // VNU_virtual_phone |
|
| 667 | + 'VNU_virtual_url' => $old_event['virtual_url'], // VNU_virtual_url |
|
| 668 | + 'VNU_google_map_link' => '', // VNU_google_map_link |
|
| 669 | 669 | 'VNU_enable_for_gmap' => true // VNU_enable_for_gmap |
| 670 | 670 | ); |
| 671 | 671 | $datatypes = array( |
| 672 | - '%d',// VNU_ID_fk |
|
| 673 | - '%s',// VNU_address |
|
| 674 | - '%s',// VNU_address2 |
|
| 675 | - '%s',// VNU_city |
|
| 676 | - '%d',// STA_ID |
|
| 677 | - '%s',// CNT_ISO |
|
| 678 | - '%s',// VNU_zip |
|
| 679 | - '%s',// VNU_phone |
|
| 680 | - '%d',// VNU_capacity |
|
| 681 | - '%s',// VNU_url |
|
| 682 | - '%s',// VNU_virtual_phone |
|
| 683 | - '%s',// VNU_virtual_url |
|
| 684 | - '%s',// VNU_google_map_link |
|
| 685 | - '%d',// VNU_enable_for_gmap |
|
| 672 | + '%d', // VNU_ID_fk |
|
| 673 | + '%s', // VNU_address |
|
| 674 | + '%s', // VNU_address2 |
|
| 675 | + '%s', // VNU_city |
|
| 676 | + '%d', // STA_ID |
|
| 677 | + '%s', // CNT_ISO |
|
| 678 | + '%s', // VNU_zip |
|
| 679 | + '%s', // VNU_phone |
|
| 680 | + '%d', // VNU_capacity |
|
| 681 | + '%s', // VNU_url |
|
| 682 | + '%s', // VNU_virtual_phone |
|
| 683 | + '%s', // VNU_virtual_url |
|
| 684 | + '%s', // VNU_google_map_link |
|
| 685 | + '%d', // VNU_enable_for_gmap |
|
| 686 | 686 | ); |
| 687 | - $success = $wpdb->insert($wpdb->prefix . "esp_venue_meta", $insertion_array, $datatypes); |
|
| 688 | - if (! $success) { |
|
| 687 | + $success = $wpdb->insert($wpdb->prefix."esp_venue_meta", $insertion_array, $datatypes); |
|
| 688 | + if ( ! $success) { |
|
| 689 | 689 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_event, $this->_new_meta_table, $insertion_array, $datatypes)); |
| 690 | 690 | return 0; |
| 691 | 691 | } |
@@ -702,11 +702,11 @@ discard block |
||
| 702 | 702 | private function _insert_new_venue_to_event($new_event_id, $new_venue_id) |
| 703 | 703 | { |
| 704 | 704 | global $wpdb; |
| 705 | - if (! $new_event_id) { |
|
| 705 | + if ( ! $new_event_id) { |
|
| 706 | 706 | $this->add_error(sprintf(esc_html__("Could not find 4.1 event id for 3.1 event #%d.", "event_espresso"), $new_event_id)); |
| 707 | 707 | return 0; |
| 708 | 708 | } |
| 709 | - if (! $new_venue_id) { |
|
| 709 | + if ( ! $new_venue_id) { |
|
| 710 | 710 | $this->add_error(sprintf(esc_html__("Could not find 4.1 venue id for 3.1 venue #%d.", "event_espresso"), $new_venue_id)); |
| 711 | 711 | return 0; |
| 712 | 712 | } |
@@ -716,12 +716,12 @@ discard block |
||
| 716 | 716 | 'EVV_primary' => true |
| 717 | 717 | ); |
| 718 | 718 | $datatypes = array( |
| 719 | - '%d',// EVT_ID |
|
| 720 | - '%d',// VNU_ID |
|
| 721 | - '%d',// EVT_primary |
|
| 719 | + '%d', // EVT_ID |
|
| 720 | + '%d', // VNU_ID |
|
| 721 | + '%d', // EVT_primary |
|
| 722 | 722 | ); |
| 723 | - $success = $wpdb->insert($wpdb->prefix . "esp_event_venue", $cols_n_values, $datatypes); |
|
| 724 | - if (! $success) { |
|
| 723 | + $success = $wpdb->insert($wpdb->prefix."esp_event_venue", $cols_n_values, $datatypes); |
|
| 724 | + if ( ! $success) { |
|
| 725 | 725 | $this->add_error( |
| 726 | 726 | $this->get_migration_script()->_create_error_message_for_db_insertion( |
| 727 | 727 | $this->_old_table, |
@@ -781,29 +781,29 @@ discard block |
||
| 781 | 781 | $start_datetime_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $start_end_time_row, "$start_date $start_time:00", $old_event_row['timezone_string']); |
| 782 | 782 | $end_datetime_utc = $this->get_migration_script()->convert_date_string_to_utc($this, $start_end_time_row, "$end_date $end_time:00", $old_event_row['timezone_string']); |
| 783 | 783 | $cols_n_values = array( |
| 784 | - 'EVT_ID' => $new_cpt_id,// EVT_ID |
|
| 785 | - 'DTT_EVT_start' => $start_datetime_utc,// DTT_EVT_start |
|
| 786 | - 'DTT_EVT_end' => $end_datetime_utc,// DTT_EVT_end |
|
| 787 | - 'DTT_reg_limit' => intval($start_end_time_row['reg_limit']) ? $start_end_time_row['reg_limit'] : $old_event_row['reg_limit'],// DTT_reg_limit |
|
| 788 | - 'DTT_sold' => 0,// note: we will increment this as registrations are added during the migration |
|
| 784 | + 'EVT_ID' => $new_cpt_id, // EVT_ID |
|
| 785 | + 'DTT_EVT_start' => $start_datetime_utc, // DTT_EVT_start |
|
| 786 | + 'DTT_EVT_end' => $end_datetime_utc, // DTT_EVT_end |
|
| 787 | + 'DTT_reg_limit' => intval($start_end_time_row['reg_limit']) ? $start_end_time_row['reg_limit'] : $old_event_row['reg_limit'], // DTT_reg_limit |
|
| 788 | + 'DTT_sold' => 0, // note: we will increment this as registrations are added during the migration |
|
| 789 | 789 | // 'DTT_is_primary'=> 0 == $existing_datetimes ,//DTT_is_primary... if count==0, then we'll call it the 'primary' |
| 790 | - 'DTT_order' => $existing_datetimes,// DTT_order, just give it the same order as the count of how many datetimes already exist |
|
| 790 | + 'DTT_order' => $existing_datetimes, // DTT_order, just give it the same order as the count of how many datetimes already exist |
|
| 791 | 791 | 'DTT_parent' => 0, |
| 792 | 792 | 'DTT_deleted' => false |
| 793 | 793 | ); |
| 794 | 794 | $datatypes = array( |
| 795 | - '%d',// EVT_Id |
|
| 796 | - '%s',// DTT_EVT_start |
|
| 797 | - '%s',// DTT_EVT_end |
|
| 798 | - '%d',// DTT_reg_limit |
|
| 799 | - '%d',// DTT_sold |
|
| 795 | + '%d', // EVT_Id |
|
| 796 | + '%s', // DTT_EVT_start |
|
| 797 | + '%s', // DTT_EVT_end |
|
| 798 | + '%d', // DTT_reg_limit |
|
| 799 | + '%d', // DTT_sold |
|
| 800 | 800 | // '%d',//DTT_is_primary |
| 801 | - '%d',// DTT_order |
|
| 802 | - '%d',// DTT_parent |
|
| 803 | - '%d',// DTT_deleted |
|
| 801 | + '%d', // DTT_order |
|
| 802 | + '%d', // DTT_parent |
|
| 803 | + '%d', // DTT_deleted |
|
| 804 | 804 | ); |
| 805 | 805 | $success = $wpdb->insert($this->_new_datetime_table, $cols_n_values, $datatypes); |
| 806 | - if (! $success) { |
|
| 806 | + if ( ! $success) { |
|
| 807 | 807 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_start_end_table, array_merge($old_event_row, $start_end_time_row), $this->_new_datetime_table, $cols_n_values, $datatypes)); |
| 808 | 808 | return 0; |
| 809 | 809 | } |
@@ -8,53 +8,53 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | class EE_DMS_4_1_0_category_details extends EE_Data_Migration_Script_Stage |
| 10 | 10 | { |
| 11 | - private $_old_table; |
|
| 12 | - private $_new_table; |
|
| 13 | - private $_new_term_table; |
|
| 14 | - public function _migration_step($num_items = 50) |
|
| 15 | - { |
|
| 16 | - global $wpdb; |
|
| 17 | - $start_at_record = $this->count_records_migrated(); |
|
| 18 | - $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A); |
|
| 19 | - $items_actually_migrated = 0; |
|
| 20 | - foreach ($rows as $category_detail_row) { |
|
| 21 | - $term_and_taxonomy_ids = wp_insert_term( |
|
| 22 | - stripslashes($category_detail_row['category_name']), |
|
| 23 | - 'espresso_event_categories', |
|
| 24 | - array( |
|
| 25 | - 'description' => stripslashes($category_detail_row['category_desc']), |
|
| 26 | - 'slug' => $category_detail_row['category_identifier'] |
|
| 27 | - ) |
|
| 28 | - ); |
|
| 29 | - if ($term_and_taxonomy_ids instanceof WP_Error) { |
|
| 30 | - $this->add_error(sprintf(esc_html__("Could not create WP Term_Taxonomy from old category: %s. The Error was: %s", "event_espresso"), $this->_json_encode($category_detail_row), $term_and_taxonomy_ids->get_error_message())); |
|
| 31 | - $items_actually_migrated++; |
|
| 32 | - continue; |
|
| 33 | - } |
|
| 34 | - $term_id = $term_and_taxonomy_ids['term_id']; |
|
| 35 | - $term_taxonomy_id = $term_and_taxonomy_ids['term_taxonomy_id']; |
|
| 36 | - $this->get_migration_script()->set_mapping($this->_old_table, $category_detail_row['id'], $this->_new_term_table, $term_id); |
|
| 37 | - $this->get_migration_script()->set_mapping($this->_old_table, $category_detail_row['id'], $this->_new_table, $term_taxonomy_id); |
|
| 38 | - $items_actually_migrated++; |
|
| 39 | - } |
|
| 40 | - if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
| 41 | - $this->set_completed(); |
|
| 42 | - } |
|
| 43 | - return $items_actually_migrated; |
|
| 44 | - } |
|
| 45 | - public function _count_records_to_migrate() |
|
| 46 | - { |
|
| 47 | - global $wpdb; |
|
| 48 | - $count = $wpdb->get_var("SELECT COUNT(id) FROM $this->_old_table"); |
|
| 49 | - return $count; |
|
| 50 | - } |
|
| 51 | - public function __construct() |
|
| 52 | - { |
|
| 53 | - $this->_pretty_name = esc_html__("Category Details", "event_espresso"); |
|
| 54 | - global $wpdb; |
|
| 55 | - $this->_old_table = $wpdb->prefix . "events_category_detail"; |
|
| 56 | - $this->_new_table = $wpdb->prefix . "term_taxonomy"; |
|
| 57 | - $this->_new_term_table = $wpdb->prefix . "terms"; |
|
| 58 | - parent::__construct(); |
|
| 59 | - } |
|
| 11 | + private $_old_table; |
|
| 12 | + private $_new_table; |
|
| 13 | + private $_new_term_table; |
|
| 14 | + public function _migration_step($num_items = 50) |
|
| 15 | + { |
|
| 16 | + global $wpdb; |
|
| 17 | + $start_at_record = $this->count_records_migrated(); |
|
| 18 | + $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A); |
|
| 19 | + $items_actually_migrated = 0; |
|
| 20 | + foreach ($rows as $category_detail_row) { |
|
| 21 | + $term_and_taxonomy_ids = wp_insert_term( |
|
| 22 | + stripslashes($category_detail_row['category_name']), |
|
| 23 | + 'espresso_event_categories', |
|
| 24 | + array( |
|
| 25 | + 'description' => stripslashes($category_detail_row['category_desc']), |
|
| 26 | + 'slug' => $category_detail_row['category_identifier'] |
|
| 27 | + ) |
|
| 28 | + ); |
|
| 29 | + if ($term_and_taxonomy_ids instanceof WP_Error) { |
|
| 30 | + $this->add_error(sprintf(esc_html__("Could not create WP Term_Taxonomy from old category: %s. The Error was: %s", "event_espresso"), $this->_json_encode($category_detail_row), $term_and_taxonomy_ids->get_error_message())); |
|
| 31 | + $items_actually_migrated++; |
|
| 32 | + continue; |
|
| 33 | + } |
|
| 34 | + $term_id = $term_and_taxonomy_ids['term_id']; |
|
| 35 | + $term_taxonomy_id = $term_and_taxonomy_ids['term_taxonomy_id']; |
|
| 36 | + $this->get_migration_script()->set_mapping($this->_old_table, $category_detail_row['id'], $this->_new_term_table, $term_id); |
|
| 37 | + $this->get_migration_script()->set_mapping($this->_old_table, $category_detail_row['id'], $this->_new_table, $term_taxonomy_id); |
|
| 38 | + $items_actually_migrated++; |
|
| 39 | + } |
|
| 40 | + if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
| 41 | + $this->set_completed(); |
|
| 42 | + } |
|
| 43 | + return $items_actually_migrated; |
|
| 44 | + } |
|
| 45 | + public function _count_records_to_migrate() |
|
| 46 | + { |
|
| 47 | + global $wpdb; |
|
| 48 | + $count = $wpdb->get_var("SELECT COUNT(id) FROM $this->_old_table"); |
|
| 49 | + return $count; |
|
| 50 | + } |
|
| 51 | + public function __construct() |
|
| 52 | + { |
|
| 53 | + $this->_pretty_name = esc_html__("Category Details", "event_espresso"); |
|
| 54 | + global $wpdb; |
|
| 55 | + $this->_old_table = $wpdb->prefix . "events_category_detail"; |
|
| 56 | + $this->_new_table = $wpdb->prefix . "term_taxonomy"; |
|
| 57 | + $this->_new_term_table = $wpdb->prefix . "terms"; |
|
| 58 | + parent::__construct(); |
|
| 59 | + } |
|
| 60 | 60 | } |
@@ -52,9 +52,9 @@ |
||
| 52 | 52 | { |
| 53 | 53 | $this->_pretty_name = esc_html__("Category Details", "event_espresso"); |
| 54 | 54 | global $wpdb; |
| 55 | - $this->_old_table = $wpdb->prefix . "events_category_detail"; |
|
| 56 | - $this->_new_table = $wpdb->prefix . "term_taxonomy"; |
|
| 57 | - $this->_new_term_table = $wpdb->prefix . "terms"; |
|
| 55 | + $this->_old_table = $wpdb->prefix."events_category_detail"; |
|
| 56 | + $this->_new_table = $wpdb->prefix."term_taxonomy"; |
|
| 57 | + $this->_new_term_table = $wpdb->prefix."terms"; |
|
| 58 | 58 | parent::__construct(); |
| 59 | 59 | } |
| 60 | 60 | } |