<?php

/**
 * In version 2.3.0 the shortcode CSS options were changed to be dynamic. Some of the old
 * options keys changed because the previous ones were manual and not all of them match up
 * to the new dynamic options. This migration will map the old to the new. The following are
 * the old shortcode CSS option keys and the new keys they are mapped to.
 *
 * old: posts
 * new: 
 *  blog
 *  books
 *  clients
 *  coupons
 *  custom_post
 *  events
 *  jobs
 *  locations
 *  movies
 *  news
 *  pages
 *  portfolio
 *  project
 *  quotes
 *  recipes
 *  team
 *  testimonials
 *  recent_books
 *  recent_clients
 *  recent_coupons
 *  recent_events
 *  recent_jobs
 *  recent_locations
 *  recent_movies
 *  recent_news
 *  recent_pages
 *  recent_portfolios
 *  recent_posts
 *  recent_projects
 *  recent_quotes
 *  recent_recipes
 *  recent_team
 *  recent_tesimonials
 *
 * old: image
 * new:
 *  image
 *  gallery
 *
 * old: layout
 * new: 
 *  row
 *
 * old: promo
 * new: 
 *  promo_box
 *
 * old: testimony
 * new:
 *  testimonies 
 */
class Intense_Migration_2_2_2 extends Intense_Migration {
	public function up(){
		parent::up();

		$intense_visions_options = get_option( 'intense_visions_options' );

		if ( isset( $intense_visions_options['intense_shortcode_css']['posts'] ) && $intense_visions_options['intense_shortcode_css']['posts'] ) {
			$intense_visions_options['intense_shortcode_css']['blog'] = 1;
			$intense_visions_options['intense_shortcode_css']['books'] = 1;
			$intense_visions_options['intense_shortcode_css']['clients'] = 1;
			$intense_visions_options['intense_shortcode_css']['coupons'] = 1;
			$intense_visions_options['intense_shortcode_css']['custom_post'] = 1;
			$intense_visions_options['intense_shortcode_css']['events'] = 1;
			$intense_visions_options['intense_shortcode_css']['jobs'] = 1;
			$intense_visions_options['intense_shortcode_css']['locations'] = 1;
			$intense_visions_options['intense_shortcode_css']['movies'] = 1;
			$intense_visions_options['intense_shortcode_css']['news'] = 1;
			$intense_visions_options['intense_shortcode_css']['pages'] = 1;
			$intense_visions_options['intense_shortcode_css']['portfolio'] = 1;
			$intense_visions_options['intense_shortcode_css']['project'] = 1;
			$intense_visions_options['intense_shortcode_css']['quotes'] = 1;
			$intense_visions_options['intense_shortcode_css']['recipes'] = 1;
			$intense_visions_options['intense_shortcode_css']['team'] = 1;
			$intense_visions_options['intense_shortcode_css']['testimonials'] = 1;
			$intense_visions_options['intense_shortcode_css']['recent_books'] = 1;
			$intense_visions_options['intense_shortcode_css']['recent_clients'] = 1;
			$intense_visions_options['intense_shortcode_css']['recent_coupons'] = 1;
			$intense_visions_options['intense_shortcode_css']['recent_events'] = 1;
			$intense_visions_options['intense_shortcode_css']['recent_jobs'] = 1;
			$intense_visions_options['intense_shortcode_css']['recent_locations'] = 1;
			$intense_visions_options['intense_shortcode_css']['recent_movies'] = 1;
			$intense_visions_options['intense_shortcode_css']['recent_news'] = 1;
			$intense_visions_options['intense_shortcode_css']['recent_pages'] = 1;
			$intense_visions_options['intense_shortcode_css']['recent_portfolios'] = 1;
			$intense_visions_options['intense_shortcode_css']['recent_posts'] = 1;
			$intense_visions_options['intense_shortcode_css']['recent_projects'] = 1;
			$intense_visions_options['intense_shortcode_css']['recent_quotes'] = 1;
			$intense_visions_options['intense_shortcode_css']['recent_recipes'] = 1;
			$intense_visions_options['intense_shortcode_css']['recent_team'] = 1;
			$intense_visions_options['intense_shortcode_css']['recent_tesimonials'] = 1;
		}

		if ( isset( $intense_visions_options['intense_shortcode_css']['image'] ) && $intense_visions_options['intense_shortcode_css']['image'] ) {
			$intense_visions_options['intense_shortcode_css']['gallery'] = 1;
		}

		if ( isset( $intense_visions_options['intense_shortcode_css']['layout'] ) && $intense_visions_options['intense_shortcode_css']['layout'] ) {
			$intense_visions_options['intense_shortcode_css']['row'] = 1;
		}

		if ( isset( $intense_visions_options['intense_shortcode_css']['promo'] ) && $intense_visions_options['intense_shortcode_css']['promo'] ) {
			$intense_visions_options['intense_shortcode_css']['promo_box'] = 1;
		}

		if ( isset( $intense_visions_options['intense_shortcode_css']['testimony'] ) && $intense_visions_options['intense_shortcode_css']['testimony'] ) {
			$intense_visions_options['intense_shortcode_css']['testimonies'] = 1;
		}

		update_option( 'intense_visions_options', $intense_visions_options );
	}

	public function down() {
		parent::down();

		$intense_visions_options = get_option( 'intense_visions_options' );

		if (!empty( $intense_visions_options['intense_shortcode_css']['blog'] ) ||
			!empty( $intense_visions_options['intense_shortcode_css']['books'] ) ||
			!empty( $intense_visions_options['intense_shortcode_css']['clients'] ) ||
			!empty( $intense_visions_options['intense_shortcode_css']['coupons'] ) ||
			!empty( $intense_visions_options['intense_shortcode_css']['custom_post'] ) ||
			!empty( $intense_visions_options['intense_shortcode_css']['events'] ) ||
			!empty( $intense_visions_options['intense_shortcode_css']['jobs'] ) ||
			!empty( $intense_visions_options['intense_shortcode_css']['locations'] ) ||
			!empty( $intense_visions_options['intense_shortcode_css']['movies'] ) ||
			!empty( $intense_visions_options['intense_shortcode_css']['news'] ) ||
			!empty( $intense_visions_options['intense_shortcode_css']['pages'] ) ||
			!empty( $intense_visions_options['intense_shortcode_css']['portfolio'] ) ||
			!empty( $intense_visions_options['intense_shortcode_css']['project'] ) ||
			!empty( $intense_visions_options['intense_shortcode_css']['quotes'] ) ||
			!empty( $intense_visions_options['intense_shortcode_css']['recipes'] ) ||
			!empty( $intense_visions_options['intense_shortcode_css']['team'] ) ||
			!empty( $intense_visions_options['intense_shortcode_css']['testimonials'] ) ||
			!empty( $intense_visions_options['intense_shortcode_css']['recent_books'] ) ||
			!empty( $intense_visions_options['intense_shortcode_css']['recent_clients'] ) ||
			!empty( $intense_visions_options['intense_shortcode_css']['recent_coupons'] ) ||
			!empty( $intense_visions_options['intense_shortcode_css']['recent_events'] ) ||
			!empty( $intense_visions_options['intense_shortcode_css']['recent_jobs'] ) ||
			!empty( $intense_visions_options['intense_shortcode_css']['recent_locations'] ) ||
			!empty( $intense_visions_options['intense_shortcode_css']['recent_movies'] ) ||
			!empty( $intense_visions_options['intense_shortcode_css']['recent_news'] ) ||
			!empty( $intense_visions_options['intense_shortcode_css']['recent_pages'] ) ||
			!empty( $intense_visions_options['intense_shortcode_css']['recent_portfolios'] ) ||
			!empty( $intense_visions_options['intense_shortcode_css']['recent_posts'] ) ||
			!empty( $intense_visions_options['intense_shortcode_css']['recent_projects'] ) ||
			!empty( $intense_visions_options['intense_shortcode_css']['recent_quotes'] ) ||
			!empty( $intense_visions_options['intense_shortcode_css']['recent_recipes'] ) ||
			!empty( $intense_visions_options['intense_shortcode_css']['recent_team'] ) ||
			!empty( $intense_visions_options['intense_shortcode_css']['recent_tesimonials'] ) ) {

			$intense_visions_options['intense_shortcode_css']['posts'] = 1;
		}

		if ( isset( $intense_visions_options['intense_shortcode_css']['image'] ) && $intense_visions_options['intense_shortcode_css']['image'] ) {
			$intense_visions_options['intense_shortcode_css']['gallery'] = 1;
		}

		if ( isset( $intense_visions_options['intense_shortcode_css']['row'] ) && $intense_visions_options['intense_shortcode_css']['row'] ) {
			$intense_visions_options['intense_shortcode_css']['layout'] = 1;
		}

		if ( isset( $intense_visions_options['intense_shortcode_css']['promo_box'] ) && $intense_visions_options['intense_shortcode_css']['promo_box'] ) {
			$intense_visions_options['intense_shortcode_css']['promo'] = 1;
		}

		if ( isset( $intense_visions_options['intense_shortcode_css']['testimonies'] ) && $intense_visions_options['intense_shortcode_css']['testimonies'] ) {
			$intense_visions_options['intense_shortcode_css']['testimony'] = 1;
		}

		update_option( 'intense_visions_options', $intense_visions_options );
	}
}