/** * Upgrade from version 1.7.1 and older * */ function activation_171() { global $wpdb; // Read all posts with map metadata $sql = "SELECT m.post_id, p.post_title FROM {$wpdb->postmeta} m, {$wpdb->posts} p " . " WHERE m.meta_key = '_mapp_pois' AND m.post_id = p.id AND m.meta_value != ''"; $results = $wpdb->get_results($sql); // Convert maps and pois foreach ((array) $results as $post) { // Get original metadata $mapdata = get_post_meta($post->post_id, '_mapp_map', true); $poidata = get_post_meta($post->post_id, '_mapp_pois', true); // For some reason, some folks had serialized strings in metadata. Fix if we're forcing upgrade. if (isset($_GET['mp_force_upgrade'])) { if (!is_array($mapdata)) { $mapdata = unserialize($mapdata); } if (!is_array($poidata)) { $poidata = unserialize($poidata); } echo "MAP for post {$post->post_id} ({$post->post_title}): " . print_r($mapdata, true) . "<br/>"; echo "POIS for post {$post->post_id} ({$post->post_title}): " . print_r($poidata, true) . "<br/>"; if (!$mapdata || !$poidata) { continue; } } $pois = array(); if ($poidata) { foreach ((array) $poidata as $poi) { // New POI format $pois[] = new Mappress_Poi(array('point' => array('lat' => $poi['lat'], 'lng' => $poi['lng']), 'title' => isset($poi['caption']) ? $poi['caption'] : '', 'body' => isset($poi['body']) ? $poi['body'] : '', 'address' => $poi['address'], 'correctedAddress' => $poi['corrected_address'], 'iconid' => null, 'viewport' => array('sw' => array('lat' => $poi['boundsbox']['south'], 'lng' => $poi['boundsbox']['west']), 'ne' => array('lat' => $poi['boundsbox']['north'], 'lng' => $poi['boundsbox']['east'])))); } } // Convert map types $mapTypeId = $mapdata['maptype']; if ($mapTypeId != 'roadmap' && $mapTypeId != 'satellite' && $mapTypeId != 'terrain' && $mapTypeId != 'hybrid') { $mapTypeId = 'roadmap'; } else { $mapTypeId = strtolower($mapTypeId); } // Create map object $map = new Mappress_Map(array('id' => null, 'width' => $mapdata['width'], 'height' => $mapdata['height'], 'zoom' => $mapdata['zoom'], 'center' => array('lat' => $mapdata['center_lat'], 'lng' => $mapdata['center_lng']), 'mapTypeId' => $mapTypeId, 'pois' => $pois)); // Only save maps that have pois $result = $map->save($post->post_id); if (!$result) { die("Unable to save new maps data"); } } // Convert options $options = get_option('mappress'); if ($options && isset($options['map_options'])) { $options = $options['map_options']; $new_options = new Mappress_Options(array('directions' => isset($options['directions']) && $options['directions'] ? 'inline' : 'none', 'mapTypeControl' => isset($options['maptypes']) && $options['maptypes'] ? true : false, 'scrollwheel' => isset($options['scrollwheel_zoom']) && $options['scrollwheel_zoom'] ? true : false, 'initialOpenInfo' => isset($options['open_info']) && $options['open_info'] ? true : false, 'country' => isset($options['country']) && !empty($options['country']) ? $options['country'] : null, 'language' => isset($options['language']) && !empty($options['language']) ? $options['language'] : null)); } else { $new_options = new Mappress_Options(); } // Save under new key $new_options->save(); }