From b1cacf00bcd6c3e937b3203c28dabf705e288449 Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Thu, 10 Feb 2022 10:17:03 +0900 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E5=88=A5=E3=81=AE=E3=83=9A=E3=83=BC?= =?UTF-8?q?=E3=82=B8=E3=81=AE=E4=B8=8B=E3=81=AB=E7=A7=BB=E5=8B=95=E3=81=97?= =?UTF-8?q?=E3=81=9F=E9=9A=9B=E3=81=AB=E3=83=91=E3=83=BC=E3=83=9E=E3=83=AA?= =?UTF-8?q?=E3=83=B3=E3=82=AF=E3=81=8C=E6=9B=B4=E6=96=B0=E3=81=95=E3=82=8C?= =?UTF-8?q?=E3=81=AA=E3=81=84=E3=83=90=E3=82=B0=E4=BF=AE=E6=AD=A3=20https:?= =?UTF-8?q?//github.com/NetCommons3/NetCommons3/issues/1683?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Model/Behavior/SavePageBehavior.php | 15 +++++++++++++-- Model/Page.php | 16 +++++++--------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/Model/Behavior/SavePageBehavior.php b/Model/Behavior/SavePageBehavior.php index 3751edb..d5c5b76 100644 --- a/Model/Behavior/SavePageBehavior.php +++ b/Model/Behavior/SavePageBehavior.php @@ -243,8 +243,19 @@ public function saveMove(Model $model, $data) { $result = $model->moveDown($model->id, $childCount); } elseif ($data[$model->alias]['type'] === 'move') { //callbacksは必要 - $result = - $model->saveField('parent_id', $data[$model->alias]['parent_id'], ['callbacks' => true]); + $permalink = + $model->getParentPermalink($data['Page']) . '/' . Current::read('Page.slug'); + if (substr($permalink, 0, 1) === '/') { + $permalink = substr($permalink, 1); + } + $data[$model->alias]['permalink'] = $permalink; + $model->create(false); + $options = [ + 'validate' => false, + 'fieldList' => ['parent_id', 'permalink'], + 'callbacks' => true + ]; + $result = $model->save($data, $options); } else { $result = false; } diff --git a/Model/Page.php b/Model/Page.php index d364210..bf5f250 100644 --- a/Model/Page.php +++ b/Model/Page.php @@ -344,9 +344,9 @@ public function isUniquePermalink($fields) { */ public function afterSave($created, $options = array()) { if (Hash::get($this->data, 'Page.id') && - Hash::get($this->data, 'Page.slug') !== Current::read('Page.slug')) { + Hash::get($this->data, 'Page.permalink')) { $chidren = $this->children( - Hash::get($this->data, 'Page.id'), false, array('Page.id', 'Page.permalink') + Hash::get($this->data, 'Page.id'), false, array('Page.id', 'Page.permalink', 'Page.slug') ); $data = $this->data; @@ -354,13 +354,11 @@ public function afterSave($created, $options = array()) { foreach ($chidren as $child) { $this->id = $child[$this->alias]['id']; - $pattern = '/^' . preg_quote(Current::read('Page.permalink') . '/', '/') . '/'; - $permalink = preg_replace( - $pattern, Hash::get($data, 'Page.permalink') . '/', $child[$this->alias]['permalink'] - ); - - if (! $this->saveField('permalink', $permalink, array('callbacks' => false))) { - throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); + $permalink = Hash::get($data, 'Page.permalink') . '/' . $child[$this->alias]['slug']; + if ($permalink !== $child[$this->alias]['permalink']) { + if (! $this->saveField('permalink', $permalink, array('callbacks' => false))) { + throw new InternalErrorException(__d('net_commons', 'Internal Server Error')); + } } } From 792c43e86b547fc8b47369fe8a77d3f463b1970a Mon Sep 17 00:00:00 2001 From: s-nakajima Date: Thu, 10 Feb 2022 10:24:09 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20phpmd=E3=82=A8=E3=83=A9=E3=83=BC?= =?UTF-8?q?=E5=9B=9E=E9=81=BF=20https://github.com/NetCommons3/NetCommons3?= =?UTF-8?q?/issues/1683?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Model/Behavior/SavePageBehavior.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Model/Behavior/SavePageBehavior.php b/Model/Behavior/SavePageBehavior.php index d5c5b76..f079e0b 100644 --- a/Model/Behavior/SavePageBehavior.php +++ b/Model/Behavior/SavePageBehavior.php @@ -219,6 +219,7 @@ public function saveTheme(Model $model, $data) { * @param array $data request data * @return bool * @throws InternalErrorException + * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function saveMove(Model $model, $data) { //トランザクションBegin