From 8b2ba8cb8bfd0a1376a9dc91feec9e172f8782ac Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Thu, 28 Mar 2024 14:14:32 +0900 Subject: [PATCH] =?UTF-8?q?fix:=202024=E5=B9=B49=E6=9C=8823=E6=97=A5?= =?UTF-8?q?=E3=82=92=E7=A5=9D=E6=97=A5=E3=81=AB=E4=BF=AE=E6=AD=A3=20https:?= =?UTF-8?q?//github.com/NetCommons3/NetCommons3/issues/1720?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../1711535474_update_2024_holidays.php | 136 ++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 Config/Migration/1711535474_update_2024_holidays.php diff --git a/Config/Migration/1711535474_update_2024_holidays.php b/Config/Migration/1711535474_update_2024_holidays.php new file mode 100644 index 0000000..57a3312 --- /dev/null +++ b/Config/Migration/1711535474_update_2024_holidays.php @@ -0,0 +1,136 @@ + + * @link http://www.netcommons.org NetCommons Project + * @license http://www.netcommons.org/license.txt NetCommons License + * @copyright Copyright 2014, NetCommons Project + */ + +App::uses('NetCommonsMigration', 'NetCommons.Config/Migration'); +App::uses('CurrentLib', 'NetCommons.Lib'); + +/** + * 令和3年の祝日の修正 + * + * @author Shohei Nakajima + * @package NetCommons\Holidays\Config\Migration + * @see https://github.com/NetCommons3/NetCommons3/issues/1621 + */ +class Update2024Holidays extends NetCommonsMigration { + +/** + * Migration description + * + * @var string + */ + public $description = 'update_2024_holidays'; + +/** + * Actions to be performed + * + * @var array $migration + */ + public $migration = array( + 'up' => array( + ), + 'down' => array( + ), + ); + +/** + * HolidayRruleモデル + * + * @var HolidayRrule + */ + private $__HolidayRrule; + +/** + * Holidayモデル + * + * @var HolidayRrule + */ + private $__Holiday; + +/** + * Before migration callback + * + * @param string $direction Direction of migration process (up or down) + * @return bool Should process continue + */ + public function before($direction) { + $this->__HolidayRrule = ClassRegistry::init('Holidays.HolidayRrule'); + $this->__Holiday = ClassRegistry::init('Holidays.Holiday'); + return true; + } + +/** + * After migration callback + * + * @param string $direction Direction of migration process (up or down) + * @return bool Should process continue + */ + public function after($direction) { + if ($direction === 'up') { + CurrentLib::write('Language.id', 2); + //秋分日の更新 + $this->__updateAutumnalEquinoxDay(); + } + return true; + } + +/** + * 秋分日の更新 + * + * @return void + */ + private function __updateAutumnalEquinoxDay() { + $count = $this->__Holiday->find('count', array( + 'conditions' => array( + 'holiday' => '2024-09-23', + ), + 'recursive' => -1, + )); + if ($count > 0) { + return; + } + + $params = [ + 'HolidayRrule' => [ + 'id' => '146', + 'input_month_day' => [ + 'day' => '22', + 'month' => '9', + ], + 'can_substitute' => '1', + 'is_variable' => '0', + 'week' => '1', + 'day_of_the_week' => 'SU', + 'start_year' => '2024', + 'end_year' => '2024', + ], + 'Holiday' => [ + 2 => [ + 'id' => '', + 'key' => '', + 'language_id' => '2', + 'title' => '秋分の日', + 'is_origin' => true, + 'is_translation' => true, + ], + 1 => [ + 'id' => '', + 'key' => '', + 'language_id' => '1', + 'title' => 'Autumnal Equinox Day', + 'is_origin' => false, + 'is_translation' => true, + ], + ], + ]; + $this->__HolidayRrule->create(null); + $this->__HolidayRrule->saveHolidayRrule($params); + } + +}