/** * Check that legacy data exists before doing anything * * @return void */ public static function load() { // Exit early if there is no option holding the DB version if (false === get_site_option('wp_stream_db')) { return; } global $wpdb; // If there are no legacy tables found, then attempt to clear all legacy data and exit early if (null === $wpdb->get_var("SHOW TABLES LIKE '{$wpdb->base_prefix}stream'")) { self::drop_legacy_data(false); return; } self::$site_id = is_multisite() ? get_current_site()->id : 1; self::$blog_id = get_current_blog_id(); $since = WP_Stream::$api->get_plan_retention_max_date(); self::$record_count = $wpdb->get_var($wpdb->prepare("\n\t\t\t\tSELECT COUNT(*)\n\t\t\t\tFROM {$wpdb->base_prefix}stream AS s, {$wpdb->base_prefix}stream_context AS sc\n\t\t\t\tWHERE s.site_id = %d\n\t\t\t\t\tAND s.blog_id = %d\n\t\t\t\t\tAND s.type = 'stream'\n\t\t\t\t\tAND s.created > %s\n\t\t\t\t\tAND sc.record_id = s.ID\n\t\t\t\t", self::$site_id, self::$blog_id, $since)); // If there are no legacy records for this site/blog, then attempt to clear all legacy data and exit early if (0 === self::$record_count) { self::drop_legacy_data(); return; } self::$limit = apply_filters('wp_stream_migrate_chunk_size', 100); add_action('admin_notices', array(__CLASS__, 'migrate_notice'), 9); add_action('wp_ajax_wp_stream_migrate_action', array(__CLASS__, 'process_migrate_action')); }