Skip to content

Commit 753e85a

Browse files
committed
bugfix: ページ管理, 同じ固定リンクを登録できないように重複チェックを追加
1 parent e030efd commit 753e85a

File tree

1 file changed

+25
-28
lines changed

1 file changed

+25
-28
lines changed

app/Plugins/Manage/PageManage/PageManage.php

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,26 @@
33
namespace App\Plugins\Manage\PageManage;
44

55
use App\Enums\WebsiteType;
6-
use Illuminate\Support\Facades\Storage;
7-
use Illuminate\Support\Facades\Validator;
8-
use Carbon\Carbon;
9-
10-
use DB;
11-
12-
use App\User;
136
use App\Models\Common\Buckets;
147
use App\Models\Common\Frame;
158
use App\Models\Common\Group;
169
use App\Models\Common\GroupUser;
1710
use App\Models\Common\Page;
1811
use App\Models\Common\PageRole;
1912
use App\Models\User\Contents\Contents;
20-
13+
use App\Plugins\Manage\ManagePluginBase;
2114
use App\Rules\CustomValiTextMax;
2215
use App\Rules\CustomValiUrlMax;
23-
2416
use App\Traits\Migration\MigrationTrait;
2517
use App\Traits\Migration\MigrationExportNc3PageTrait;
2618
use App\Traits\Migration\MigrationExportHtmlPageTrait;
27-
28-
use App\Plugins\Manage\ManagePluginBase;
29-
19+
use App\User;
3020
use App\Utilities\Csv\CsvUtils;
21+
use Carbon\Carbon;
22+
use Illuminate\Support\Facades\DB;
23+
use Illuminate\Support\Facades\Storage;
24+
use Illuminate\Support\Facades\Validator;
25+
use Illuminate\Validation\Rule;
3126

3227
/**
3328
* ページ管理クラス
@@ -183,12 +178,12 @@ public function edit($request, $page_id = null)
183178
/**
184179
* ページ登録・変更時のエラーチェック
185180
*/
186-
private function pageValidator($request)
181+
private function pageValidator($request, $page_id = null)
187182
{
188183
// 項目のエラーチェック
189184
$validator = Validator::make($request->all(), [
190185
'page_name' => ['required', 'max:255'],
191-
'permanent_link' => ['nullable', new CustomValiUrlMax(true)],
186+
'permanent_link' => ['nullable', new CustomValiUrlMax(true), Rule::unique('pages')->ignore($page_id)],
192187
'password' => ['nullable', 'max:255'],
193188
'background_color' => ['nullable', 'max:255'],
194189
'header_color' => ['nullable', 'max:255'],
@@ -214,25 +209,25 @@ private function pageValidator($request)
214209
*/
215210
public function store($request)
216211
{
212+
// 固定リンクの先頭に / がない場合、追加する。
213+
if (strncmp($request->permanent_link, '/', 1) !== 0) {
214+
$request->merge([
215+
"permanent_link" => '/' . $request->permanent_link,
216+
]);
217+
}
218+
217219
// ページ登録・変更時のエラーチェック
218220
$validator = $this->pageValidator($request);
219221

220222
// エラーがあった場合は入力画面に戻る。
221223
if ($validator->fails()) {
222-
// return ( $this->index($request, null, $validator->errors()) );
223224
return redirect()->back()->withErrors($validator)->withInput();
224225
}
225226

226-
// 固定リンクの先頭に / がない場合、追加する。(php8.1対応)stringにキャストする。
227-
$permanent_link = (string)$request->permanent_link;
228-
if (strncmp($permanent_link, '/', 1) !== 0) {
229-
$permanent_link = '/' . $permanent_link;
230-
}
231-
232227
// ページデータの登録
233228
$page = new Page;
234229
$page->page_name = $request->page_name;
235-
$page->permanent_link = $permanent_link;
230+
$page->permanent_link = $request->permanent_link;
236231
$page->password = $request->password;
237232
$page->background_color = $request->background_color;
238233
$page->header_color = $request->header_color;
@@ -257,19 +252,21 @@ public function store($request)
257252
*/
258253
public function update($request, $page_id)
259254
{
255+
// 固定リンクの先頭に / がない場合、追加する。
256+
if (strncmp($request->permanent_link, '/', 1) !== 0) {
257+
$request->merge([
258+
"permanent_link" => '/' . $request->permanent_link,
259+
]);
260+
}
261+
260262
// ページ登録・変更時のエラーチェック
261-
$validator = $this->pageValidator($request);
263+
$validator = $this->pageValidator($request, $page_id);
262264

263265
// エラーがあった場合は入力画面に戻る。
264266
if ($validator->fails()) {
265267
return redirect()->back()->withErrors($validator)->withInput();
266268
}
267269

268-
// 固定リンクの先頭に / がない場合、追加する。
269-
if (strncmp($request->permanent_link, '/', 1) !== 0) {
270-
$request->permanent_link = '/' . $request->permanent_link;
271-
}
272-
273270
// ページデータの更新
274271
Page::where('id', $page_id)
275272
->update([

0 commit comments

Comments
 (0)