<?php
$_db_migration_to = '28.04'; // 8.2.0-rc
if (!isset($migrations) || !is_object($migrations))
	die("This file cannot be executed directly");
$migrations->CheckValid($_db_migration_to);
//===========================================================================================



$migrations->Run('02_hp_config.php', <<<'DB_UPDATE_FILE'
<?php

/** @var $migrations \Claromentis\Setup\SetupFacade */
$db = $migrations->GetDb();

$config = $migrations->GetConfigFull();

$res = @$db->query("SELECT year_start, common_year, ical_notification FROM hpl_config");
if ($res->hasData())
{
	list($year_start, $common_year, $ical_notification) = $res->fetchRow();
	$config->Set('cfg_holidays_year_start', (int) $year_start);
	$config->Set('cfg_holidays_common_year', (int) $common_year);
	$config->Set('cfg_holidays_ical_notification', (int) $ical_notification);
}

$hp_config = $migrations->GetConfigFull('holidays');

$config->Set('holidays_bradford_half_day', $hp_config->Get('half_day'));
$config->Set('holidays_bradford_enabled', $hp_config->Get('bradford_formula_enabled'));
$config->Set('holidays_bradford_days', $hp_config->Get('bradford_allowed_types'));

$config->Save();

$db->query("DROP TABLE hpl_config");

DB_UPDATE_FILE
);


//===========================================================================================
$migrations->SetVersion('28.04');
