Move mod/maintenance to src/Module/Maintenance
authorPhilipp Holzer <admin@philipp.info>
Sat, 4 May 2019 11:42:26 +0000 (13:42 +0200)
committerPhilipp Holzer <admin@philipp.info>
Sun, 5 May 2019 08:06:50 +0000 (10:06 +0200)
mod/maintenance.php [deleted file]
src/App.php
src/App/Router.php
src/Core/System.php
src/Module/Maintenance.php [new file with mode: 0644]

diff --git a/mod/maintenance.php b/mod/maintenance.php
deleted file mode 100644 (file)
index 8e0197b..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-<?php
-/**
- * @file mod/maintenance.php
- */
-use Friendica\App;
-use Friendica\Core\Config;
-use Friendica\Core\L10n;
-use Friendica\Core\Renderer;
-use Friendica\Util\Strings;
-
-function maintenance_content(App $a)
-{
-       $reason = Config::get('system', 'maintenance_reason');
-
-       if (substr(Strings::normaliseLink($reason), 0, 7) == 'http://') {
-               header("HTTP/1.1 307 Temporary Redirect");
-               header("Location:".$reason);
-               return;
-       }
-
-       header('HTTP/1.1 503 Service Temporarily Unavailable');
-       header('Status: 503 Service Temporarily Unavailable');
-       header('Retry-After: 600');
-
-       return Renderer::replaceMacros(Renderer::getMarkupTemplate('maintenance.tpl'), [
-               '$sysdown' => L10n::t('System down for maintenance'),
-               '$reason' => $reason
-       ]);
-}
index 017661c..32e9fa8 100644 (file)
@@ -1077,10 +1077,10 @@ class App
 
                // in install mode, any url loads install module
                // but we need "view" module for stylesheet
-               if ($this->getMode()->isInstall() && $this->module != 'view') {
-                       $this->module = 'install';
-               } elseif (!$this->getMode()->has(App\Mode::MAINTENANCEDISABLED) && $this->module != 'view') {
-                       $this->module = 'maintenance';
+               if ($this->getMode()->isInstall() && $this->module !== 'install') {
+                       $this->internalRedirect('install');
+               } elseif (!$this->getMode()->has(App\Mode::MAINTENANCEDISABLED) && $this->module !== 'maintenance') {
+                       $this->internalRedirect('maintenance');
                } else {
                        $this->checkURL();
                        Core\Update::check($this->getBasePath(), false, $this->getMode());
index b94c0bb..ac701a0 100644 (file)
@@ -138,6 +138,7 @@ class Router
                $this->routeCollector->addRoute(['GET', 'POST'], '/login',               Module\Login::class);
                $this->routeCollector->addRoute(['GET', 'POST'], '/logout',              Module\Logout::class);
                $this->routeCollector->addRoute(['GET'],         '/magic',               Module\Magic::class);
+               $this->routeCollector->addRoute(['GET'],         '/maintenance',         Module\Maintenance::class);
                $this->routeCollector->addRoute(['GET'],         '/manifest',            Module\Manifest::class);
                $this->routeCollector->addRoute(['GET'],         '/nodeinfo/1.0',        Module\NodeInfo::class);
                $this->routeCollector->addRoute(['GET'],         '/nogroup',             Module\Group::class);
index 31934af..4258757 100644 (file)
@@ -242,6 +242,9 @@ class System extends BaseObject
                        case 301:
                                header('HTTP/1.1 301 Moved Permanently');
                                break;
+                       case 307:
+                               header('HTTP/1.1 307 Temporary Redirect');
+                               break;
                }
 
                header("Location: $url");
diff --git a/src/Module/Maintenance.php b/src/Module/Maintenance.php
new file mode 100644 (file)
index 0000000..e7dc5a0
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+
+namespace Friendica\Module;
+
+use Friendica\BaseModule;
+use Friendica\Core\L10n;
+use Friendica\Core\Renderer;
+use Friendica\Core\System;
+use Friendica\Util\Strings;
+
+/**
+ * Shows the maintenance reason
+ * or redirects to the alternate location
+ */
+class Maintenance extends BaseModule
+{
+       public static function content()
+       {
+               $config = self::getApp()->getConfig();
+
+               $reason = $config->get('system', 'maintenance_reason');
+
+               if ((substr(Strings::normaliseLink($reason), 0, 7) === 'http://') ||
+                       (substr(Strings::normaliseLink($reason), 0, 8) === 'https://')) {
+                       System::externalRedirect($reason, 307);
+               }
+
+               header('HTTP/1.1 503 Service Temporarily Unavailable');
+               header('Status: 503 Service Temporarily Unavailable');
+               header('Retry-After: 600');
+
+               return Renderer::replaceMacros(Renderer::getMarkupTemplate('maintenance.tpl'), [
+                       '$sysdown' => L10n::t('System down for maintenance'),
+                       '$reason' => $reason
+               ]);
+       }
+}