55use App \Lib \Environment ;
66use Cake \Controller \Component ;
77use Cake \Controller \ComponentRegistry ;
8+ use Cake \Http \Cookie \Cookie ;
89
910/**
1011 * Maintenance component
11- *
12- * @property \App\Lib\Environment
1312 */
1413class MaintenanceComponent extends Component
1514{
@@ -21,8 +20,8 @@ class MaintenanceComponent extends Component
2120 /**
2221 * Constructor
2322 *
24- * @param \Cake\Controller\ComponentRegistry; $registry A ComponentRegistry object.
25- * @param string:mixed[] $config Array of configuration settings.
23+ * @param \Cake\Controller\ComponentRegistry $registry A ComponentRegistry object.
24+ * @param array $config Array of configuration settings.
2625 */
2726 public function __construct (ComponentRegistry $ registry , array $ config = [])
2827 {
@@ -59,7 +58,10 @@ public function beforeFilter()
5958
6059 if (!self ::isMaintenanceActive ()) {
6160 // if maintenance is not active but maintenance page is requested -> redirect to default page
62- if (in_array ($ currentUrl , $ accessibleUrls ) && substr ($ maintenancePage , -strlen ($ currentUrl )) === $ currentUrl ) {
61+ if (
62+ in_array ($ currentUrl , $ accessibleUrls )
63+ && substr ($ maintenancePage , -strlen ($ currentUrl )) === $ currentUrl
64+ ) {
6365 $ maintenanceBasePage = Environment::read ('MAINTENANCE_BASE_URL ' );
6466
6567 return $ this ->_controller ->redirect ($ maintenanceBasePage );
@@ -69,18 +71,21 @@ public function beforeFilter()
6971 }
7072
7173 $ cookieName = Environment::read ('MAINTENANCE_COOKIE_NAME ' );
72- $ cookieExists = ($ this ->_controller ->Cookie -> read ($ cookieName ) !== null );
74+ $ cookieExists = ($ this ->_controller ->getRequest ()-> getCookie ($ cookieName ) !== null );
7375 if ($ cookieExists ) {
7476 return ;
7577 }
7678 $ headerActive = Environment::read ('MAINTENANCE_HEADER_ACTIVE ' );
7779 $ headerName = Environment::read ('MAINTENANCE_HEADER_NAME ' );
7880 $ headerValue = Environment::read ('MAINTENANCE_HEADER_VALUE ' );
7981 $ successUrl = Environment::read ('MAINTENANCE_PASSWORD_SUCCESS_URL ' );
80- if ($ headerActive && !empty ($ this ->_controller ->request ->getHeader ($ headerName ))
81- && $ this ->_controller ->request ->getHeader ($ headerName ) === $ headerValue
82+ $ cookie = new Cookie ($ cookieName , '1 ' );
83+ if (
84+ $ headerActive
85+ && !empty ($ this ->_controller ->getRequest ()->getHeader ($ headerName ))
86+ && $ this ->_controller ->getRequest ()->getHeader ($ headerName ) === $ headerValue
8287 ) {
83- $ this ->_controller ->Cookie -> write ( $ cookieName , true );
88+ $ this ->_controller ->getRequest ()-> getCookieCollection ()-> add ( $ cookie );
8489
8590 return $ this ->_controller ->redirect ($ successUrl );
8691 }
@@ -104,7 +109,7 @@ public function beforeFilter()
104109 }
105110
106111 if ($ _SERVER ['PHP_AUTH_USER ' ] === $ user && $ _SERVER ['PHP_AUTH_PW ' ] === $ password ) {
107- $ this ->_controller ->Cookie -> write ( $ cookieName , true );
112+ $ this ->_controller ->getRequest ()-> getCookieCollection ()-> add ( $ cookie );
108113
109114 return $ this ->_controller ->redirect ($ successUrl );
110115 }
0 commit comments