@@ -5,38 +5,137 @@ class MaintenanceController extends AppController
55
66 public $ components = ['Session ' ];
77
8- public function index ($ banned = false )
8+ public function index ($ url = "" )
99 {
10- if ($ this ->Configuration ->getKey ('maintenance ' ) != '0 ' ) {
11- $ msg = $ this ->Configuration ->getKey ('maintenance ' );
12- } else if ($ banned ) {
13- $ msg = $ this ->Lang ->get ('USER__BANNED_MSG ' );
14- } else {
15- $ this ->redirect ('/ ' );
16- }
10+ $ this ->loadModel ("Maintenance " );
11+
12+ if ($ this ->Permissions ->can ("BYPASS_MAINTENANCE " ) || !$ this ->Maintenance ->checkMaintenance ("/ " . $ url ))
13+ $ this ->redirect ("/ " );
14+
15+ $ msg = $ this ->Maintenance ->checkMaintenance ("/ " . $ url )["Maintenance " ]["reason " ];
1716 $ this ->set (compact ('msg ' ));
1817 }
1918
2019 public function admin_index ()
2120 {
22- if ($ this ->isConnected and $ this ->Permissions ->can ('MANAGE_MAINTENANCE ' )) {
23- $ this ->layout = "admin " ;
24-
25- $ this ->set ('title_for_layout ' , $ this ->Lang ->get ('MAINTENANCE__TITLE ' ));
26- if ($ this ->request ->is ('post ' )) {
27- if ($ this ->request ->data ['state ' ] == 'enabled ' ) {
28- $ maintenance = $ this ->request ->data ['reason ' ];
29- $ this ->History ->set ('ADD_MAINTENANCE ' , 'maintenance ' );
30- } else if ($ this ->request ->data ['state ' ] == 'disabled ' ) {
31- $ maintenance = '0 ' ;
32- $ this ->History ->set ('DELETE_MAINTENANCE ' , 'maintenance ' );
33- }
34- $ this ->Configuration ->setKey ('maintenance ' , $ maintenance );
35- $ this ->Session ->setFlash ($ this ->Lang ->get ('MAINTENANCE__EDIT_SUCCESS ' ), 'default.success ' );
36- }
37- } else {
38- $ this ->redirect ('/ ' );
21+ if (!$ this ->isConnected and !$ this ->Permissions ->can ('MANAGE_MAINTENANCE ' ))
22+ throw new ForbiddenException ();
23+
24+ $ this ->layout = "admin " ;
25+ $ this ->set ('title_for_layout ' , $ this ->Lang ->get ('MAINTENANCE__TITLE ' ));
26+
27+ $ this ->loadModel ("Maintenance " );
28+ $ pagesInMaintenance = $ this ->Maintenance ->find ("all " );
29+
30+ $ this ->set ("pages " , $ pagesInMaintenance );
31+ }
32+
33+ public function admin_add ()
34+ {
35+ if (!$ this ->isConnected and !$ this ->Permissions ->can ('MANAGE_MAINTENANCE ' ))
36+ throw new ForbiddenException ();
37+
38+ $ this ->layout = "admin " ;
39+ $ this ->set ('title_for_layout ' , $ this ->Lang ->get ('MAINTENANCE__TITLE ' ));
40+
41+ if ($ this ->request ->is ("post " )) {
42+ $ this ->autoRender = false ;
43+ $ this ->response ->type ('json ' );
44+
45+ if (empty ($ this ->request ->data ["reason " ]))
46+ return $ this ->response ->body (json_encode (['statut ' => false , 'msg ' => $ this ->Lang ->get ('MAINTENANCE__ADD_REASON_EMPTY ' )]));
47+
48+ $ this ->loadModel ("Maintenance " );
49+
50+ $ this ->Maintenance ->create ();
51+ $ this ->Maintenance ->set ($ this ->request ->data );
52+ $ this ->Maintenance ->save ();
53+
54+ return $ this ->response ->body (json_encode (['statut ' => true , 'msg ' => $ this ->Lang ->get ('MAINTENANCE__ADD_SUCCESS ' )]));
3955 }
4056 }
4157
58+ public function admin_edit ($ id = false )
59+ {
60+ if (!$ this ->isConnected and !$ this ->Permissions ->can ('MANAGE_MAINTENANCE ' ) | !$ id )
61+ throw new ForbiddenException ();
62+
63+ $ this ->layout = "admin " ;
64+ $ this ->set ('title_for_layout ' , $ this ->Lang ->get ('MAINTENANCE__TITLE ' ));
65+
66+ $ this ->loadModel ("Maintenance " );
67+ $ page = $ this ->Maintenance ->find ("first " , ["conditions " => ["id " => $ id ]])["Maintenance " ];
68+
69+ $ this ->set ("page " , $ page );
70+
71+ if ($ this ->request ->is ("post " )) {
72+ $ this ->autoRender = false ;
73+ $ this ->response ->type ('json ' );
74+
75+ if (empty ($ this ->request ->data ["reason " ]))
76+ return $ this ->response ->body (json_encode (['statut ' => false , 'msg ' => $ this ->Lang ->get ('MAINTENANCE__ADD_REASON_EMPTY ' )]));
77+
78+ $ this ->Maintenance ->read (null , $ id );
79+ $ this ->Maintenance ->set ([
80+ "url " => $ this ->request ->data ["url " ],
81+ "reason " => $ this ->request ->data ["reason " ]
82+ ]);
83+ $ this ->Maintenance ->save ();
84+
85+ return $ this ->response ->body (json_encode (['statut ' => true , 'msg ' => $ this ->Lang ->get ('MAINTENANCE__EDIT_SUCCESS ' )]));
86+ }
87+ }
88+
89+ public function admin_disable ($ id = false )
90+ {
91+ $ this ->autoRender = false ;
92+ if (!$ this ->isConnected || !$ this ->Permissions ->can ('MANAGE_MAINTENANCE ' ) || !$ id )
93+ throw new ForbiddenException ();
94+
95+ $ this ->loadModel ('Maintenance ' );
96+ $ this ->Maintenance ->read (null , $ id );
97+ $ this ->Maintenance ->set (["active " => "0 " ]);
98+ $ this ->Maintenance ->save ();
99+
100+ $ pageUrl = $ this ->Maintenance ->find ('first ' , ["conditions " => ['id ' => $ id ]])["Maintenance " ]["url " ];
101+ $ this ->Session ->setFlash ($ this ->Lang ->get ('MAINTENANCE__DISABLED_PAGE ' , [
102+ '{PAGE} ' => $ pageUrl ,
103+ ]), 'default.success ' );
104+ $ this ->redirect (['controller ' => 'maintenance ' , 'action ' => 'index ' , 'admin ' => true ]);
105+ }
106+
107+ public function admin_enable ($ id = false )
108+ {
109+ $ this ->autoRender = false ;
110+ if (!$ this ->isConnected || !$ this ->Permissions ->can ('MANAGE_MAINTENANCE ' ) || !$ id )
111+ throw new ForbiddenException ();
112+
113+ $ this ->loadModel ('Maintenance ' );
114+ $ this ->Maintenance ->read (null , $ id );
115+ $ this ->Maintenance ->set (["active " => "1 " ]);
116+ $ this ->Maintenance ->save ();
117+
118+ $ pageUrl = $ this ->Maintenance ->find ('first ' , ["conditions " => ['id ' => $ id ]])["Maintenance " ]["url " ];
119+ $ this ->Session ->setFlash ($ this ->Lang ->get ('MAINTENANCE__ENABLED_PAGE ' , [
120+ '{PAGE} ' => $ pageUrl ,
121+ ]), 'default.success ' );
122+ $ this ->redirect (['controller ' => 'maintenance ' , 'action ' => 'index ' , 'admin ' => true ]);
123+ }
124+
125+ public function admin_delete ($ id = false )
126+ {
127+ $ this ->autoRender = false ;
128+ if (!$ this ->isConnected || !$ this ->Permissions ->can ('MANAGE_MAINTENANCE ' ) || !$ id )
129+ throw new ForbiddenException ();
130+
131+ $ this ->loadModel ('Maintenance ' );
132+ $ pageUrl = $ this ->Maintenance ->find ('first ' , ["conditions " => ['id ' => $ id ]])["Maintenance " ]["url " ];
133+
134+ $ this ->Maintenance ->delete ($ id );
135+
136+ $ this ->Session ->setFlash ($ this ->Lang ->get ('MAINTENANCE__DELETED_PAGE ' , [
137+ '{PAGE} ' => $ pageUrl ,
138+ ]), 'default.success ' );
139+ $ this ->redirect (['controller ' => 'maintenance ' , 'action ' => 'index ' , 'admin ' => true ]);
140+ }
42141}
0 commit comments