Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions Model/Behavior/SavePageBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -243,8 +244,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;
}
Expand Down
16 changes: 7 additions & 9 deletions Model/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,23 +344,21 @@ 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;

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'));
}
}
}

Expand Down