From 30bd49f4490402639b5c4f56a31a76017fce513a Mon Sep 17 00:00:00 2001 From: RikaFujiwara Date: Thu, 18 Mar 2021 10:50:19 +0900 Subject: [PATCH] refs: /NetCommons3/NetCommons3/issues/1631 --- .../1616031325_modify_clean_up_records.php | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 Config/Migration/1616031325_modify_clean_up_records.php diff --git a/Config/Migration/1616031325_modify_clean_up_records.php b/Config/Migration/1616031325_modify_clean_up_records.php new file mode 100644 index 0000000..280b539 --- /dev/null +++ b/Config/Migration/1616031325_modify_clean_up_records.php @@ -0,0 +1,103 @@ + + * @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'); + +/** + * clean up records migration + * + * @package NetCommons\CleanUp\Config\Migration + */ +class ModifyCleanUpRecordsColumn extends NetCommonsMigration { + +/** + * Migration description + * + * @var string + */ + public $description = 'modify_clean_up_records'; + +/** + * Actions to be performed + * + * @var array $migration + */ + public $migration = array( + 'up' => array( + ), + 'down' => array( + ), + ); + +/** + * records
+ * ファイルクリーンアップの対象にしたい場合、当マイグレーションを参考にマイグレーション作成して、
+ * 対象プラグインのデータをclean_upsテーブルに書き込む + * + * @var array $migration + */ + public $records = array( + 'CleanUp' => array( + //登録フォーム + array ( + 'plugin_key' => 'registrations', + 'model' => 'RegistrationQuestion', + 'class' => 'Registrations.RegistrationQuestion', + 'fields' => 'description', + 'alive_func' => 'getAliveCondition', + 'created_user' => '1', + 'modified_user' => '1', + ), + ), + ); + +/** + * Before migration callback + * + * @param string $direction Direction of migration process (up or down) + * @return bool Should process continue + */ + public function before($direction) { + 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 === 'down') { + return true; + } + + foreach ($this->records as $model => $records) { + $CleanUp = $this->generateModel('CleanUp'); + foreach ($records as &$record) { + $targetRecord = $CleanUp->find('first', array( + 'recursive' => -1, + 'conditions' => array( + 'class' => $record['class'] + ) + )); + if (! $targetRecord) { + CakeLog::info('Not Found ' . $record['class'] . ' in clean_ups'); + continue; + } + $record['id'] = $targetRecord['CleanUp']['id']; + } + if (!$this->updateRecords($model, $records)) { + return false; + } + } + return true; + } +}