protected function _migrate_old_row($old_row) { //foreach ticket row we add the id for the current logged in user. global $wpdb; $user_id = EEH_Activation::get_default_creator_id(); $updated = $wpdb->update($this->_old_table, array('PRC_wp_user' => $user_id), array('PRC_ID' => $old_row['PRC_ID']), array('%d'), array('%d')); if (FALSE === $updated) { $this->add_error(sprintf(__("Error in updating table {$this->_old_table} setting PRC_wp_user = %d where PRC_ID = %d", 'event_espresso'), $user_id, $old_row['PRC_ID'])); } }
public function add_default_admin_only_payments() { global $wpdb; $table_name = $wpdb->prefix . "esp_payment_method"; $user_id = EEH_Activation::get_default_creator_id(); if ($wpdb->get_var("SHOW TABLES LIKE '" . $table_name . "'") == $table_name) { $SQL = "SELECT COUNT( * ) FROM {$table_name}"; $existing_payment_methods = $wpdb->get_var($SQL); $default_admin_only_payment_methods = apply_filters('FHEE__EEH_Activation__add_default_admin_only_payments__default_admin_only_payment_methods', array(__("Bank", 'event_espresso') => __("Bank Draft", 'event_espresso'), __("Cash", 'event_espresso') => __("Cash Delivered Physically", 'event_espresso'), __("Check", 'event_espresso') => __("Paper Check", 'event_espresso'), __("Credit Card", 'event_espresso') => __("Offline Credit Card Payment", 'event_espresso'), __("Debit Card", 'event_espresso') => __("Offline Debit Payment", 'event_espresso'), __("Invoice", 'event_espresso') => __("Invoice received with monies included", 'event_espresso'), __("Money Order", 'event_espresso') => '', __("Paypal", 'event_espresso') => __("Paypal eCheck, Invoice, etc", 'event_espresso'), __('Other', 'event_espresso') => __('Other method of payment', 'event_espresso'))); //make sure we hae payment method records for the following //so admins can record payments for them from the admin page foreach ($default_admin_only_payment_methods as $nicename => $description) { $slug = sanitize_key($nicename); //check that such a payment method exists $exists = $wpdb->get_var($wpdb->prepare("SELECT count(*) FROM {$table_name} WHERE PMD_slug = %s", $slug)); if (!$exists) { $values = array('PMD_type' => 'Admin_Only', 'PMD_name' => $nicename, 'PMD_admin_name' => $nicename, 'PMD_admin_desc' => $description, 'PMD_slug' => $slug, 'PMD_wp_user' => $user_id, 'PMD_scope' => serialize(array('ADMIN'))); $success = $wpdb->insert($table_name, $values, array('%s', '%s', '%s', '%s', '%s', '%d', '%s')); if (!$success) { $this->add_error(sprintf(__("Could not insert new admin-only payment method with values %s during migration", "event_espresso"), $this->_json_encode($values))); } } } } }
/** * Ensure getting default creator works as expected * @since 4.6.0 */ public function test_get_default_creator_id() { //clear out any previous users that may be lurking in teh system foreach (get_users() as $wp_user) { wp_delete_user($wp_user->ID); } //set some users; and just make it interesting by having the first user NOT be an admin $non_admin_users = $this->factory->user->create_many(2); $users = $this->factory->user->create_many(2); //make users administrators. foreach ($users as $user_id) { $user = $this->factory->user->get_object_by_id($user_id); //verify $this->assertInstanceOf('WP_User', $user); //add role $user->add_role('administrator'); } //get all users so we know who is the first one that we should be expecting. $expected_id = reset($users); $this->assertEquals(EEH_Activation::get_default_creator_id(), $expected_id); /** * ok now let's verify EEH_Activation::reset() properly clears the cache * on EEH_Activation. This is important for subsequent unit tests (because * EEH_Activation::reset() is called beween unit tests), but also when an admin * resets their EE database, or when anyone wants to reset that cache) * clear out any previous users that may be lurking in teh system */ EEH_Activation::reset(); foreach (get_users() as $wp_user) { wp_delete_user($wp_user->ID); } //set some users; and just make it interesting by having the first user NOT be an admin $this->factory->user->create_many(2); $users_created_after_reset = $this->factory->user->create_many(2); //make users administrators. foreach ($users_created_after_reset as $user_id) { $user = $this->factory->user->get_object_by_id($user_id); //verify $this->assertInstanceOf('WP_User', $user); //add role $user->add_role('administrator'); } //get all users so we know who is the first one that we should be expecting. $new_expected_id = reset($users_created_after_reset); $this->assertEquals(EEH_Activation::get_default_creator_id(), $new_expected_id); }
/** * insert DEFAULT ticket * Almost identical to EE_DMS_Core_4_3_0::insert_default_tickets, except is aware of the TKT_wp_user field * * @since 4.5.0 * * @return void */ public function insert_default_tickets() { global $wpdb; $ticket_table = $wpdb->prefix . "esp_ticket"; if (EEH_Activation::table_exists($ticket_table)) { $SQL = 'SELECT COUNT(TKT_ID) FROM ' . $ticket_table; $tickets_exist = $wpdb->get_var($SQL); if (!$tickets_exist) { $user_id = EEH_Activation::get_default_creator_id(); $SQL = "INSERT INTO {$ticket_table}\n\t\t\t\t\t( TKT_ID, TTM_ID, TKT_name, TKT_description, TKT_qty, TKT_sold, TKT_uses, TKT_required, TKT_min, TKT_max, TKT_price, TKT_start_date, TKT_end_date, TKT_taxable, TKT_order, TKT_row, TKT_is_default, TKT_parent, TKT_wp_user, TKT_deleted ) VALUES\n\t\t\t\t\t( 1, 0, '" . __("Free Ticket", "event_espresso") . "', '', 100, 0, -1, 0, 0, -1, 0.00, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 0, 0, 1, 1, 0, {$user_id}, 0);"; $SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_tickets__SQL', $SQL); $wpdb->query($SQL); } } $ticket_price_table = $wpdb->prefix . "esp_ticket_price"; if (EEH_Activation::table_exists($ticket_price_table)) { $SQL = 'SELECT COUNT(TKP_ID) FROM ' . $ticket_price_table; $ticket_prc_exist = $wpdb->get_var($SQL); if (!$ticket_prc_exist) { $SQL = "INSERT INTO {$ticket_price_table}\n\t\t\t\t( TKP_ID, TKT_ID, PRC_ID ) VALUES\n\t\t\t\t( 1, 1, 1 )\n\t\t\t\t"; $SQL = apply_filters('FHEE__EE_DMS_4_5_0__insert_default_tickets__SQL__ticket_price', $SQL); $wpdb->query($SQL); } } }
/** * Handles creating new default templates. * * @param string $template_pack This corresponds to a template pack class reference * which will contain information about where to obtain the templates. * @return mixed (array|bool) success array or false. */ protected function _create_new_templates($template_pack) { $this->_set_templates($template_pack); //necessary properties are set, let's save the default templates if (empty($this->_GRP_ID)) { $main_template_data = array('MTP_messenger' => $this->_messenger->name, 'MTP_message_type' => $this->_message_type->name, 'MTP_is_override' => 0, 'MTP_deleted' => 0, 'MTP_is_global' => 1, 'MTP_user_id' => EEH_Activation::get_default_creator_id(), 'MTP_is_active' => 1); //let's insert the above and get our GRP_ID, then reset the template data array to just include the GRP_ID $grp_id = $this->_message_template_group_model->insert($main_template_data); if (empty($grp_id)) { return $grp_id; } $this->_GRP_ID = $grp_id; } $template_data = array('GRP_ID' => $this->_GRP_ID); foreach ($this->_contexts as $context => $details) { foreach ($this->_fields as $field => $field_type) { if ($field != 'extra') { $template_data['MTP_context'] = $context; $template_data['MTP_template_field'] = $field; $template_data['MTP_content'] = $this->_templates[$context][$field]; $MTP = $this->_message_template_model->insert($template_data); if (!$MTP) { EE_Error::add_error(sprintf(__('There was an error in saving new template data for %1$s messenger, %2$s message type, %3$s context and %4$s template field.', 'event_espresso'), $this->_messenger->name, $this->_message_type->name, $context, $field), __FILE__, __FUNCTION__, __LINE__); return false; } } } } return array('GRP_ID' => $this->_GRP_ID, 'MTP_context' => key($this->_contexts)); }