flagFile = $flagFile ? $flagFile : MAGENTO_BP . '/var/.maintenance.flag'; $this->ipFile = $ipFile ? $ipFile : MAGENTO_BP . '/var/.maintenance.ip'; $this->status = $status ? $status : new Status(); } /** * Check whether Magento maintenance mode is on. * * @return bool */ public function isOn() { return file_exists($this->flagFile); } /** * Set maintenance mode. * * @param bool $isOn * @return $this * @throws \RuntimeException */ public function set($isOn) { if ($isOn) { if (touch($this->flagFile)) { $this->status->add("Magento maintenance mode is enabled.", \Psr\Log\LogLevel::INFO); } else { throw new \RuntimeException("Magento maintenance mode cannot be enabled."); } } else if (file_exists($this->flagFile)) { if (file_exists($this->ipFile)) { /** Maintenance mode should not be unset from updater application if it was set manually by the admin */ $this->status->add( "Magento maintenance mode was not disabled. It can be disabled from the Magento Backend.", \Psr\Log\LogLevel::INFO ); } else if (unlink($this->flagFile)) { $this->status->add("Magento maintenance mode is disabled.", \Psr\Log\LogLevel::INFO); } else { throw new \RuntimeException("Magento maintenance mode cannot be disabled."); } } return $this; } }