<?php
/**
 * This file contain all functions tha manage the udpdates
 *
 * @package YITH\PayPalPayouts\Functions
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( ! function_exists( 'yith_paypal_payouts_update_1_1_0' ) ) {
	/**
	 * Update db to version 1.1.0
	 *
	 * @author YITH <plugins@yithemes.com>
	 * @since 2.0.0
	 */
	function yith_paypal_payouts_update_1_1_0() {

		$db = get_option( 'yith_payouts_db_version', '1.1.0' );
		if ( version_compare( $db, '1.1.0', '<' ) ) {
			$gdpr_user_data    = get_option( 'yith_payouts_eraser_user_data', 'no' );
			$gdpr_payouts_data = get_option( 'yith_payouts_eraser_payout', 'no' );
			$new_option        = array();

			if ( 'yes' === $gdpr_user_data ) {
				$new_option[] = 'profile';
			}
			if ( 'yes' === $gdpr_payouts_data ) {
				$new_option[] = 'payouts_user_id';
			}
			update_option( 'yith_payouts_privacy_options_eraser', $new_option );
			update_option( 'yith_payouts_db_version', '1.1.0' );
		}
	}
}
add_action( 'admin_init', 'yith_paypal_payouts_update_1_1_0' );
