7
7
use DateTimeImmutable ;
8
8
use DateTimeZone ;
9
9
use RuntimeException ;
10
+ use Wcms \Exception \Databaseexception ;
10
11
use Wcms \Exception \Filesystemexception ;
11
12
12
13
class Controllerpage extends Controller
@@ -46,6 +47,8 @@ protected function setpage(string $id, string $route): void
46
47
* Try yo import by multiple way the called page
47
48
*
48
49
* @return bool If a page is found and stored in `$this->page`
50
+ *
51
+ * @todo maybe throw error instead of logging to let the upper code choose what to do
49
52
*/
50
53
protected function importpage (): bool
51
54
{
@@ -59,7 +62,7 @@ protected function importpage(): bool
59
62
return true ;
60
63
}
61
64
} catch (RuntimeException $ e ) {
62
- Logger::errorex ($ e );
65
+ Logger::warningex ($ e );
63
66
return false ;
64
67
}
65
68
}
@@ -191,18 +194,19 @@ public function read(string $page): void
191
194
}
192
195
193
196
$ this ->pagemanager ->templaterender ($ this ->page , $ this ->router );
197
+
198
+ $ this ->page ->adddisplaycount ();
199
+ if ($ this ->user ->isvisitor ()) {
200
+ $ this ->page ->addvisitcount ();
201
+ }
202
+ $ this ->pagemanager ->update ($ this ->page );
194
203
} catch (RuntimeException $ e ) {
195
- $ msg = $ e ->getMessage ();
196
- Logger::error ("Error while trying to read page ' $ page': $ msg " );
204
+ Logger::error ("Error while trying to read page ' $ page': " . $ e ->getMessage ());
197
205
}
198
206
199
- $ this ->page ->adddisplaycount ();
200
- if ($ this ->user ->isvisitor ()) {
201
- $ this ->page ->addvisitcount ();
202
- }
203
- $ this ->pagemanager ->update ($ this ->page );
204
207
205
208
// redirection using Location and 302
209
+ // If redirecting to a dead page or an invalid URL, redirection is canceled
206
210
if (!empty ($ this ->page ->redirection ()) && $ this ->page ->refresh () === 0 && $ this ->page ->sleep () === 0 ) {
207
211
try {
208
212
if (Model::idcheck ($ this ->page ->redirection ())) {
@@ -212,8 +216,7 @@ public function read(string $page): void
212
216
$ this ->redirect ($ url );
213
217
}
214
218
} catch (RuntimeException $ e ) {
215
- // This mean the redirect field did'nt contain an existing page or URL
216
- // TODO : send syntax error to editor
219
+ Logger::warning ("Page ' $ page' redirect to existing page or a valid URL " );
217
220
}
218
221
}
219
222
@@ -481,16 +484,28 @@ public function delete(string $page): void
481
484
}
482
485
}
483
486
487
+ /**
488
+ * @todo maybe show an error view if deletion failed
489
+ */
484
490
public function confirmdelete (string $ page ): void
485
491
{
486
492
$ this ->setpage ($ page , 'pageconfirmdelete ' );
487
- if ($ this ->user ->iseditor () && $ this ->importpage ()) {
488
- $ this ->pagemanager ->delete ($ this ->page );
489
- $ this ->routedirect ('pageread ' , ['page ' => $ this ->page ->id ()]);
490
- } else {
493
+ if (!$ this ->importpage () || !$ this ->candelete ($ this ->page )) {
491
494
http_response_code (403 );
492
495
$ this ->showtemplate ('forbidden ' , ['route ' => 'pageread ' , 'id ' => $ this ->page ->id ()]);
496
+ exit ;
493
497
}
498
+
499
+ try {
500
+ $ this ->pagemanager ->delete ($ this ->page );
501
+ $ user = $ this ->user ->id ();
502
+ Logger::info ("User ' $ user' uccessfully deleted Page ' $ page' " );
503
+ } catch (Filesystemexception $ e ) {
504
+ Logger::warning ("Error while deleting Page ' $ page' " . $ e ->getMessage ());
505
+ } catch (Databaseexception $ e ) {
506
+ Logger::error ("Could not delete Page $ page: " . $ e ->getMessage ());
507
+ }
508
+ $ this ->routedirect ('pageread ' , ['page ' => $ this ->page ->id ()]);
494
509
}
495
510
496
511
public function duplicate (string $ page , string $ duplicate ): void
@@ -547,9 +562,14 @@ public function update(string $page): void
547
562
$ _SESSION ['pageupdate ' ]['id ' ] = $ this ->page ->id ();
548
563
$ this ->routedirect ('pageedit ' , ['page ' => $ this ->page ->id ()]);
549
564
} else {
550
- $ this ->page ->updateedited ();
551
-
552
- $ this ->pagemanager ->update ($ this ->page );
565
+ try {
566
+ $ this ->page ->updateedited ();
567
+ $ this ->pagemanager ->update ($ this ->page );
568
+ $ this ->sendflashmessage ('Page succesfully updated ' , self ::FLASH_SUCCESS );
569
+ } catch (RuntimeException $ e ) {
570
+ $ this ->sendflashmessage ('Error while trying to update ' , self ::FLASH_ERROR );
571
+ Logger::error ("Error while trying to update Page ' $ page': " . $ e ->getMessage ());
572
+ }
553
573
}
554
574
} else {
555
575
// If the editor session finished during the editing, let's try to reconnect to save the editing
@@ -575,8 +595,6 @@ public function pagepermanentredirect(string $page): void
575
595
576
596
/**
577
597
* Send a `404` HTTP code and display 'Command not found'
578
- *
579
- * @todo use a dedicated view and suggest a list of W URL based command.
580
598
*/
581
599
public function commandnotfound (string $ page , string $ command ): void
582
600
{
0 commit comments