/** * MaintenanceLibTest::testStatus() * * @return void */ public function testStatus() { $status = $this->Maintenance->isMaintenanceMode(); $this->assertFalse($status); $this->Maintenance->setMaintenanceMode(0); $status = $this->Maintenance->isMaintenanceMode(); $this->assertTrue($status); $this->Maintenance->setMaintenanceMode(1); $status = $this->Maintenance->isMaintenanceMode(); $this->assertTrue($status); $content = file_get_contents(TMP . 'maintenance.txt'); $this->assertWithinRange(time() + MINUTE, $content, 2); }
/** * Set maintance mode for everybody except for the own IP which will * be whitelisted. * * Alternatively, this can and should be done using the CLI shell. * * URL Options: * - `duration` query string can be used to set a timeout maintenance window * * @param mixed $maintenance * @return bool Success */ public function setMaintenance($maintenance) { $ip = env('REMOTE_ADDR'); // optional length in minutes $length = (int) $this->Controller->request->query('duration'); $Maintenance = new Maintenance(); if (!$Maintenance->setMaintenanceMode($maintenance ? $length : false)) { return false; } if (!$Maintenance->whitelist([$ip])) { return false; } return true; }