public function template()
    {
        global $wpdb;
        if (isset($_REQUEST['pull_the_trigger'])) {
            $args = array('post_type' => 'podcast', 'posts_per_page' => -1);
            $query = new \WP_Query($args);
            while ($query->have_posts()) {
                $query->the_post();
                $post = get_post();
                // publicize episode
                wp_update_post(array('ID' => $post->ID, 'post_status' => 'publish'));
                // put legacy post in trash
                wp_delete_post($post->post_parent);
            }
            wp_reset_postdata();
            // cleanup temporary migration settings
            // delete_option( 'podlove_module_migration' );
            delete_option('podlove_migration');
            delete_option('podlove_migration_validation_cache');
            delete_option('podlove_migrated_posts_cache');
        }
        $unpublished_episodes = $wpdb->get_var("\n\t\t\tSELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type = 'podcast' AND post_status = 'pending'\n\t\t");
        ?>

		<?php 
        if ($unpublished_episodes > 0) {
            ?>
			<div class="hero-unit">
				<h1>
					<?php 
            echo __('Nearly done!', 'podlove');
            ?>
				</h1>
				<p>
					All your episodes are migrated and marked as <em>pending</em>. Your original posts are still <em>published</em>.
					You can now <a href="<?php 
            echo admin_url('edit.php?post_type=podcast');
            ?>
">preview your episodes</a> and adjust them to your liking. Then it's time to pull the trigger.
				</p>
				<p>
					Pushing this button depublicizes all migrated posts and publishes all episodes at once.
				</p>
				<p>
					Ready?
				</p>
				<p>
					<form method="GET">
						<input type="submit" name="pull_the_trigger" class="btn btn-danger" value="Switch to Podlove Publisher Episodes">
						<input type="hidden" name="page" value="podlove_settings_migration_handle" />
						<input type="hidden" name="step" value="<?php 
            echo Migration::instance()->get_module_option('current_step', 1);
            ?>
" />
					</form>
				</p>
			</div>
		<?php 
        } else {
            ?>
			<img src="<?php 
            echo \Podlove\Modules\Migration\Migration::instance()->get_module_url();
            ?>
/success.jpg" class="img-polaroid">
		<?php 
        }
        ?>
		<?php 
    }
    public function page()
    {
        set_time_limit(1800);
        // increase max_execution_time for migration actions
        $wizard = array(new Wizard\StepWelcome(), new Wizard\StepBasics(), new Wizard\StepPosts(), new Wizard\StepMigrate(), new Wizard\StepFinalize());
        // start-index must be 1, not 0
        array_unshift($wizard, "whatever");
        unset($wizard[0]);
        $this->process_request();
        $steps = array_map(function ($step) {
            return $step->title;
        }, $wizard);
        if (isset($_REQUEST['prev']) || isset($_REQUEST['next']) || isset($_REQUEST['stay'])) {
            $current_step = Migration::instance()->get_module_option('current_step', 1);
            if (isset($_REQUEST['next'])) {
                $current_step++;
                Migration::instance()->update_module_option('current_step', $current_step);
            } elseif (isset($_REQUEST['prev'])) {
                $current_step--;
                Migration::instance()->update_module_option('current_step', $current_step);
            }
        } elseif (isset($_REQUEST['step']) && $_REQUEST['step'] > 0 && $_REQUEST['step'] <= count($steps)) {
            $current_step = (int) $_REQUEST['step'];
            Migration::instance()->update_module_option('current_step', $current_step);
        } else {
            $current_step = Migration::instance()->get_module_option('current_step', 1);
        }
        if ($current_step < 1) {
            $current_step = 1;
        }
        ?>

		<script type="text/javascript">
		jQuery(function($) {
			$('[data-toggle="tooltip"]').tooltip();
		});
		</script>

		<div class="wrap bootstrap">
			<h2 id="migration_header">
				<?php 
        echo __('Migration Assistant');
        ?>
				<p class="lead">
					Migrate your existing episodes to the Podlove Publisher.
					<br>
					If you get stuck, feel free to reset the migration and
					<span class="btn-group">
						<a href="<?php 
        echo admin_url('admin.php?page=' . $_REQUEST['page'] . '&step=1&reset_migration=1');
        ?>
"
						   class="btn btn-small"
						   data-placement="bottom"
						   data-toggle="tooltip"
						   title="<?php 
        echo __("Deletes all episodes, assets, feeds and migration settings.", 'podlove');
        ?>
"
						   >
							<?php 
        echo __('start from scratch', 'podlove');
        ?>
						</a>
					</span>.
					<br>
					There's also <a href="http://podlove.github.com/publisher/migration/" target="_blank">documentation</a> if you'd like to get into details.
				</p>
			</h2>

			<hr>

			<ul class="nav nav-pills">
				<?php 
        foreach ($steps as $index => $title) {
            ?>
					<?php 
            $class = $index === $current_step ? 'active' : ($current_step < $index ? 'disabled' : '');
            if ($index > 1) {
                $title = sprintf(__('Step %s:', 'podlove'), $index - 1) . ' ' . $title;
            }
            $link = $class == 'disabled' ? "#" : self::get_page_link($index);
            ?>
					<li class="<?php 
            echo $class;
            ?>
">
						<a href="<?php 
            echo $link;
            ?>
"><?php 
            echo $title;
            ?>
</a>
					</li>
				<?php 
        }
        ?>
			</ul>

			<?php 
        $wizard[$current_step]->template();
        ?>
		</div>	
		<?php 
    }