Lock the site during migrations to avoid dumb errors.

This commit is contained in:
flash 2019-02-05 14:39:22 +01:00
parent cdd7f8d9d7
commit 5d36e24fc7
3 changed files with 66 additions and 3 deletions

View file

@ -178,6 +178,8 @@ if (PHP_SAPI === 'cli') {
break;
case 'migrate':
touch(MSZ_ROOT . '/.migrating');
$migrationTargets = [
'mysql-main' => MSZ_ROOT . '/database',
];
@ -217,6 +219,8 @@ if (PHP_SAPI === 'cli') {
}
}
}
unlink(MSZ_ROOT . '/.migrating');
break;
case 'new-mig':
@ -306,6 +310,15 @@ MIG;
exit;
}
if (file_exists(MSZ_ROOT . '/.migrating')) {
http_response_code(503);
echo tpl_render('auth.lockdown', [
'message' => "The site is currently updating, this shouldn't take long.<br><a href='javascript:location.reload(true)' class='link'>Retry</a>",
'message_title' => '<i class="fas fa-wrench"></i> Updating',
]);
exit;
}
if (isset($_COOKIE['msz_uid'], $_COOKIE['msz_sid'])
&& user_session_start((int)$_COOKIE['msz_uid'], $_COOKIE['msz_sid'])) {
$mszUserId = (int)$_COOKIE['msz_uid'];

View file

@ -1,12 +1,12 @@
{% extends 'auth/master.twig' %}
{% extends 'master_minimal.twig' %}
{% from 'macros.twig' import container_title %}
{% block content %}
<div class="container auth">
{{ container_title('<i class="fas fa-lock fa-fw"></i> Unavailable') }}
{{ container_title(message_title|default('<i class="fas fa-lock fa-fw"></i> Unavailable')) }}
<div class="container__content">
{{ message|default('The site is currently unavailable, try again later.') }}
{{ message|default('The site is currently unavailable, try again later.')|raw }}
</div>
</div>
{% endblock %}

View file

@ -0,0 +1,50 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{ title|default(globals.site_name) }}</title>
<link href="{{ '/css/libraries.css'|asset_url }}" rel="stylesheet">
<link href="{{ '/css/style.css'|asset_url }}" rel="stylesheet">
</head>
<body class="main">
<nav class="header">
<div class="header__background"></div>
<div class="header__desktop">
<a class="header__desktop__logo" href="{{ url('index') }}" title="{{ globals.site_name }}">
{{ globals.site_name }}
</a>
</div>
<div class="header__mobile">
<div class="header__mobile__icons">
<a class="header__mobile__logo header__mobile__icon" href="{{ url('index') }}">
{{ globals.site_name }}
</a>
</div>
</div>
</nav>
<div class="main__wrapper">
{% block content %}
This page has no content!
{% endblock %}
</div>
<footer class="footer">
<div class="footer__background"></div>
<div class="footer__wrapper">
{% autoescape false %}
<div class="footer__copyright">
{{ 'https://flash.moe'|html_link('Flashwave', 'footer__link') }} 2013-{{
''|date('Y') }} /
{{ ('https://github.com/flashwave/misuzu/tree/' ~ git_tag())|html_link(git_tag(), 'footer__link') }}
# {{ ('https://github.com/flashwave/misuzu/commit/' ~ git_commit_hash(true))|html_link(git_commit_hash(), 'footer__link') }}
</div>
{% endautoescape %}
</div>
</footer>
</body>
</html>