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 '<p>Total events: ' . count( $results ) . '</p>';
+
if ( !empty( $results ) ) {
foreach ( $results as $post ) {
+ echo '<pre>$post: ' . print_r($post, true) . '</pre>';
+ $sql = "
+ SELECT *
+ FROM " . $this->wpdb->prefix . "ai1ec_events
+ WHERE post_id = {$post['ID']}";
+ $event_data = $this->wpdb->get_row( $sql, ARRAY_A );
+ echo '<pre>$event_data: ' . print_r($event_data, true) . '</pre>';
+ $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 '<pre>$thumbnail: ' . print_r($thumb_src, true) . '</pre>';
- var_dump( $thumb_src[0] );
+ //echo '<pre>$thumbnail: ' . print_r($thumb_src, true) . '</pre>';
+ }
+ // 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 '<pre>SQL Error: ' . $this->wpdb->last_error . '</pre>';
+ echo '<pre>SQL Error: ' . $this->wpdb->print_error() . '</pre>';
+ die('something is wrong no eventId');
}
}
}