From: Steve Sutton Date: Tue, 31 May 2016 20:56:24 +0000 (-0400) Subject: Working on the Event Import from Time.ly X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=dca6a1dd8a816d563940bb2578c4692bd66da3b4;p=WP-Plugins%2Fglm-member-db-events.git Working on the Event Import from Time.ly --- diff --git a/models/admin/management/events.php b/models/admin/management/events.php index cdeb99b..eff01d8 100644 --- a/models/admin/management/events.php +++ b/models/admin/management/events.php @@ -1024,17 +1024,110 @@ class GlmMembersAdmin_management_events extends GlmDataEventsManagement return $return; } public function importFromTimely() { - $sql = "SELECT * FROM " . $this->wpdb->prefix . "posts WHERE post_type = 'ai1ec_event'"; + // clear the events tables first + $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "events" ); + $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "recurrences" ); + $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times" ); + $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "event_categories" ); + $this->wpdb->query( "DELETE FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "locations" ); + $Recurrences = new GlmDataEventsRecurrences($this->wpdb, $this->config); + + $sql = " + SELECT * + FROM " . $this->wpdb->prefix . "posts + WHERE post_type = 'ai1ec_event' + AND post_status = 'publish'"; $results = $this->wpdb->get_results( $sql, ARRAY_A ); + echo '

Total events: ' . count( $results ) . '

'; + if ( !empty( $results ) ) { foreach ( $results as $post ) { + echo '
$post: ' . print_r($post, true) . '
'; + $sql = " + SELECT * + FROM " . $this->wpdb->prefix . "ai1ec_events + WHERE post_id = {$post['ID']}"; + $event_data = $this->wpdb->get_row( $sql, ARRAY_A ); + echo '
$event_data: ' . print_r($event_data, true) . '
'; + $cost_data = unserialize( $event_data ); + $cost = $cost_data['cost']; + $is_free = $cost_data['is_free']; + // use the posts table data if ( has_post_thumbnail( $post['ID'] ) ) { $thumbnail_id = get_post_thumbnail_id( $post['ID'] ); $thumb_src = wp_get_attachment_image_src( $thumbnail_id, 'large' ); - echo '
$thumbnail: ' . print_r($thumb_src, true) . '
'; - var_dump( $thumb_src[0] ); + //echo '
$thumbnail: ' . print_r($thumb_src, true) . '
'; + } + // Insert the event data + $event_import_data = array( + 'status' => $this->config['status_numb']['Active'], + 'created' => $post['post_date'], + 'updated' => $post['post_modified'], + 'approved' => $post['post_modified'], + 'name' => $post['post_title'], + 'intro' => $intro, + 'descr' => $post['post_content'], + 'image' => $image, + 'file1' => null, + 'file1_descr' => null, + 'cost' => $cost, + 'free' => $is_free, + 'url' => $event_data['contact_url'], + 'old_event_id' => $post['ID'], + 'ref_type' => null, + 'ref_dest' => null, + 'admin_name' => null, + 'admin_org' => null, + 'admin_email' => null, + 'admin_phone' => null, + 'contact_email' => $event_data['contact_email'], + 'contact_name' => $event_data['contact_name'], + 'contact_phone' => $event_data['contact_phone'], + 'notes' => null, + 'hide_address' => null, + 'use_member_location' => 0, + ); + $event_data_format = array( + '%d', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + '%s', + ); + $this->wpdb->insert( + GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . 'events', + $event_import_data, + $event_data_format + ); + $eventId = $this->wpdb->insert_id; + var_dump( $eventId ); + if ( !$eventId ) { + echo '
SQL Error: ' . $this->wpdb->last_error . '
'; + echo '
SQL Error: ' . $this->wpdb->print_error() . '
'; + die('something is wrong no eventId'); } } }