Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Does updates, flushes the rewrite rules, etc, if we're in the
- * admin area, and if they need it.
- *
- * @return void
- * @author Simon Wheatley
- **/
- protected function do_update() {
- global $wpdb;
- if ( ! is_admin() )
- return;
- $version_option = $this->name . '_version';
- $version = get_option( $version_option, 0 );
- if ( $version == $this->version )
- return;
- if ( $version < 4 ) {
- wp_clear_scheduled_hook( 'sie_events_expire_events' );
- wp_schedule_event( gmmktime( 2 ), 'daily', 'sie_events_expire_events' );
- error_log( "SI Events Venue: Setup Cron" );
- }
- if ( $version < 4 ) {
- flush_rewrite_rules();
- error_log( "SI Events Venue: Flush rewrite rules" );
- }
- if ( $version < 6 ) {
- $venue_ids = $wpdb->get_col( " SELECT ID from $wpdb->posts WHERE post_type = 'venue' AND post_status = 'publish' " );
- $postgeo = $wpdb->prefix . 'postgeo';
- $postgeo_sql = " INSERT INTO $postgeo VALUES( %d, %s, %s ) ON DUPLICATE KEY UPDATE lng = %s, lat = %s ";
- foreach ( $venue_ids as $venue_id ) {
- $venue_term_id = (int) get_post_meta( $venue_id, '_venue_term_id', true );
- $venue_geo = $wpdb->get_row( $wpdb->prepare( " SELECT lng, lat FROM $postgeo WHERE post_id = %s ", $venue_id ) );
- $event_ids = get_objects_in_term( $venue_term_id, 'venue' );
- error_log( "Updating postgeo on EVENTS " . join( ',', $event_ids ) . " for VENUE $venue_id" );
- foreach ( $event_ids as $event_id ) {
- $prepared_sql = $wpdb->prepare( $postgeo_sql, $event_id, $venue_geo->lng, $venue_geo->lat, $venue_geo->lng, $venue_geo->lat );
- if ( false === $wpdb->query( $prepared_sql ) )
- error_log( "DB error on do_update creating postgeo $postgeo for event $event_id" );
- }
- }
- error_log( "SI Events Venue: reset all events coords from their venue" );
- }
- error_log( "Updating version ($version_option) to $this->version (was $version)" );
- update_option( $version_option, $this->version );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement