From 7e65c8a106b7abdfd84d38dcb1de3db9a8b8d364 Mon Sep 17 00:00:00 2001 From: kato Date: Thu, 5 Dec 2024 11:30:36 +0900 Subject: [PATCH] =?UTF-8?q?fix=20#15=20baserCMS5=E7=B3=BB=E2=86=924?= =?UTF-8?q?=E7=B3=BB=E3=81=AE=E3=83=91=E3=82=B9=E3=83=AF=E3=83=BC=E3=83=89?= =?UTF-8?q?=E5=BC=95=E3=81=8D=E7=B6=99=E3=81=8E=E3=81=8C=E3=81=A7=E3=81=8D?= =?UTF-8?q?=E3=81=AA=E3=81=84=E5=95=8F=E9=A1=8C=E3=82=92=E8=A7=A3=E6=B1=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controller/Admin/MigratorController.php | 2 ++ .../Component/BcDbMigrator5Component.php | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Controller/Admin/MigratorController.php b/src/Controller/Admin/MigratorController.php index be909d3..34f6823 100644 --- a/src/Controller/Admin/MigratorController.php +++ b/src/Controller/Admin/MigratorController.php @@ -53,6 +53,8 @@ public function index() $password = $this->{$this->migrator}->getNewPassword(); if ($password) { $this->BcMessage->setInfo('残念ながらパスワードの移行はできません。すべてのユーザーのパスワードは、「' . $password . '」にセットされています。ログイン後のパスワードの変更をお願いします。'); + } elseif (env('HASH_TYPE') === 'sha1') { + $this->BcMessage->setInfo('baserCMSの設定を引き継いでユーザーのパスワードは以前のものを保存しております。データ復旧後、シークレットウィンドウなどでログイン確認をお願いします。'); } $this->redirect(['action' => 'index']); } else { diff --git a/src/Controller/Component/BcDbMigrator5Component.php b/src/Controller/Component/BcDbMigrator5Component.php index 6a22e39..7f180d2 100755 --- a/src/Controller/Component/BcDbMigrator5Component.php +++ b/src/Controller/Component/BcDbMigrator5Component.php @@ -19,6 +19,7 @@ use CakephpFixtureFactories\Error\PersistenceException; use Cake\Core\Configure; use Psr\Log\LogLevel; +use ReflectionClass; /** * include files @@ -626,12 +627,27 @@ protected function _updateUser() foreach($records as $record) { $record['status'] = true; $record['user_groups']['_ids'] = [$record['user_group_id']]; - $this->newPassword = $record['password'] = Security::randomString(10); + // HASH_TYPE が sha1 の場合はパスワードをそのまま移行する + if (env('HASH_TYPE') === 'sha1' && !empty($record['password'])) { + $this->newPassword = ''; + } else { + $this->newPassword = $record['password'] = Security::randomString(10); + } unset($record['user_group_id']); try { $entity = $table->newEmptyEntity(); $entity->setAccess('id', true); $entity = $table->patchEntity($entity, $record, ['validate' => false]); + // HASH_TYPE が sha1 の場合はパスワードをそのまま移行する + if (env('HASH_TYPE') === 'sha1' && !empty($record['password'])) { + // Entityの構造を無視して値を書き換える + $reflection = new ReflectionClass($entity); + $property = $reflection->getProperty('_fields'); + $property->setAccessible(true); + $fields = $property->getValue($entity); + $fields['password'] = $record['password']; + $property->setValue($entity, $fields); + } $table->saveOrFail($entity); } catch (PersistenceException $e) { $this->log('users: ' . $e->getEntity()->getMessage(), LogLevel::ERROR, 'migrate_db');