Merge pull request #7086 from nupplaphil/task/mod_maintenance

Move mod/maintenance to src/Module/Maintenance
This commit is contained in:
Hypolite Petovan 2019-05-05 20:36:12 -04:00 committed by GitHub
commit fbf36d6e7f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 42 additions and 35 deletions

View file

@ -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
]);
}

View file

@ -988,7 +988,7 @@ class App
header('Refresh: 120; url=' . $this->getBaseURL() . "/" . $this->query_string); header('Refresh: 120; url=' . $this->getBaseURL() . "/" . $this->query_string);
Module\Special\HTTPException::rawContent( Module\Special\HTTPException::rawContent(
new HTTPException\ServiceUnavaiableException('The node is currently overloaded. Please try again later.') new HTTPException\ServiceUnavailableException('The node is currently overloaded. Please try again later.')
); );
} }
@ -1077,10 +1077,10 @@ class App
// in install mode, any url loads install module // in install mode, any url loads install module
// but we need "view" module for stylesheet // but we need "view" module for stylesheet
if ($this->getMode()->isInstall() && $this->module != 'view') { if ($this->getMode()->isInstall() && $this->module !== 'install') {
$this->module = 'install'; $this->internalRedirect('install');
} elseif (!$this->getMode()->has(App\Mode::MAINTENANCEDISABLED) && $this->module != 'view') { } elseif (!$this->getMode()->has(App\Mode::MAINTENANCEDISABLED) && $this->module !== 'maintenance') {
$this->module = 'maintenance'; $this->internalRedirect('maintenance');
} else { } else {
$this->checkURL(); $this->checkURL();
Core\Update::check($this->getBasePath(), false, $this->getMode()); Core\Update::check($this->getBasePath(), false, $this->getMode());

View file

@ -139,6 +139,7 @@ class Router
$this->routeCollector->addRoute(['GET', 'POST'], '/login', Module\Login::class); $this->routeCollector->addRoute(['GET', 'POST'], '/login', Module\Login::class);
$this->routeCollector->addRoute(['GET', 'POST'], '/logout', Module\Logout::class); $this->routeCollector->addRoute(['GET', 'POST'], '/logout', Module\Logout::class);
$this->routeCollector->addRoute(['GET'], '/magic', Module\Magic::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'], '/manifest', Module\Manifest::class);
$this->routeCollector->addRoute(['GET'], '/modexp/{nick}', Module\PublicRSAKey::class); $this->routeCollector->addRoute(['GET'], '/modexp/{nick}', Module\PublicRSAKey::class);
$this->routeCollector->addRoute(['GET'], '/nodeinfo/1.0', Module\NodeInfo::class); $this->routeCollector->addRoute(['GET'], '/nodeinfo/1.0', Module\NodeInfo::class);

View file

@ -242,6 +242,9 @@ class System extends BaseObject
case 301: case 301:
header('HTTP/1.1 301 Moved Permanently'); header('HTTP/1.1 301 Moved Permanently');
break; break;
case 307:
header('HTTP/1.1 307 Temporary Redirect');
break;
} }
header("Location: $url"); header("Location: $url");

View file

@ -0,0 +1,32 @@
<?php
namespace Friendica\Module;
use Friendica\BaseModule;
use Friendica\Core\L10n;
use Friendica\Core\System;
use Friendica\Network\HTTPException;
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);
}
$exception = new HTTPException\ServiceUnavailableException($reason);
$exception->httpdesc = L10n::t('System down for maintenance');
throw $exception;
}
}

View file

@ -4,7 +4,7 @@ namespace Friendica\Network\HTTPException;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
class ServiceUnavaiableException extends HTTPException class ServiceUnavailableException extends HTTPException
{ {
protected $code = 503; protected $code = 503;
} }