Browse Source

Maintenance template, migration

Vova Tkach 5 years ago
parent
commit
b98bad7b64

+ 28 - 0
engine/assets/template/maintenance_html_file.go

@@ -0,0 +1,28 @@
+package template
+
+var VarMaintenanceHtmlFile = []byte(`<!DOCTYPE html>
+<html lang="en">
+	<head>
+		<meta charset="utf-8" />
+		<meta name="theme-color" content="#205081" />
+		<title>Maintenance</title>
+		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
+		<meta name="viewport" content="width=device-width, initial-scale=0.8, maximum-scale=0.8" />
+		<link rel="shortcut icon" href="{{$.System.PathIcoFav}}" type="image/x-icon" />
+		<link rel="stylesheet" type="text/css" media="all" href="{{$.System.PathCssStyles}}" />
+	</head>
+	<body>
+		<div class="wrapper">
+			<div class="logo">
+				<div class="svg">
+					<img src="{{$.System.PathSvgLogo}}" width="150" height="150" />
+				</div>
+			</div>
+			<h1>We are currently down for maintenance</h1>
+			<h2>
+				<script>document.write(document.location.host);</script>
+				<noscript>fave.pro</noscript>
+			</h2>
+		</div>
+	</body>
+</html>`)

+ 1 - 0
engine/assets/template/template.go

@@ -11,6 +11,7 @@ var AllData = map[string][]byte{
 	"blog.html":                  VarBlogHtmlFile,
 	"shop-product.html":          VarShopProductHtmlFile,
 	"index.html":                 VarIndexHtmlFile,
+	"maintenance.html":           VarMaintenanceHtmlFile,
 	"email-new-order-admin.html": VarEmailNewOrderAdminHtmlFile,
 	"robots.txt":                 VarRobotsTxtFile,
 	"page.html":                  VarPageHtmlFile,

+ 20 - 0
engine/engine.go

@@ -64,6 +64,26 @@ func (this *Engine) Process() bool {
 
 	// Separated logic
 	if !this.Wrap.IsBackend {
+		// Maintenance mode
+		if this.Wrap.Config.Engine.Maintenance != 0 {
+			if this.Wrap.User == nil {
+				this.Wrap.UseDatabase()
+				this.Wrap.LoadSessionUser()
+			}
+			if this.Wrap.User == nil {
+				this.Wrap.RenderFrontEnd("maintenance", nil, http.StatusServiceUnavailable)
+				return true
+			}
+			if this.Wrap.User.A_id <= 0 {
+				this.Wrap.RenderFrontEnd("maintenance", nil, http.StatusServiceUnavailable)
+				return true
+			}
+			if this.Wrap.User.A_admin <= 0 {
+				this.Wrap.RenderFrontEnd("maintenance", nil, http.StatusServiceUnavailable)
+				return true
+			}
+		}
+
 		// Render frontend
 		return this.Mods.XXXFrontEnd(this.Wrap)
 	}

+ 1 - 1
engine/modules/module_index_act_mysql_setup.go

@@ -561,7 +561,7 @@ func (this *Modules) RegisterAction_IndexMysqlSetup() *Action {
 		}
 		if _, err = tx.Exec(
 			wrap.R.Context(),
-			`INSERT INTO fave_settings (name, value) VALUES ('database_version', '000000021');`,
+			`INSERT INTO fave_settings (name, value) VALUES ('database_version', '000000022');`,
 		); err != nil {
 			tx.Rollback()
 			wrap.MsgError(err.Error())

+ 26 - 0
hosts/localhost/template/maintenance.html

@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html lang="en">
+	<head>
+		<meta charset="utf-8" />
+		<meta name="theme-color" content="#205081" />
+		<title>Maintenance</title>
+		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
+		<meta name="viewport" content="width=device-width, initial-scale=0.8, maximum-scale=0.8" />
+		<link rel="shortcut icon" href="{{$.System.PathIcoFav}}" type="image/x-icon" />
+		<link rel="stylesheet" type="text/css" media="all" href="{{$.System.PathCssStyles}}" />
+	</head>
+	<body>
+		<div class="wrapper">
+			<div class="logo">
+				<div class="svg">
+					<img src="{{$.System.PathSvgLogo}}" width="150" height="150" />
+				</div>
+			</div>
+			<h1>We are currently down for maintenance</h1>
+			<h2>
+				<script>document.write(document.location.host);</script>
+				<noscript>fave.pro</noscript>
+			</h2>
+		</div>
+	</body>
+</html>

+ 1 - 0
support/migrate/000000001.go

@@ -29,4 +29,5 @@ var Migrations = map[string]func(context.Context, *sqlw.DB, string) error{
 	"000000019": Migrate_000000019,
 	"000000020": Migrate_000000020,
 	"000000021": Migrate_000000021,
+	"000000022": Migrate_000000022,
 }

+ 18 - 0
support/migrate/000000022.go

@@ -0,0 +1,18 @@
+package migrate
+
+import (
+	"context"
+	"io/ioutil"
+	"os"
+
+	ThemeFiles "golang-fave/engine/assets/template"
+	"golang-fave/engine/sqlw"
+)
+
+func Migrate_000000022(ctx context.Context, db *sqlw.DB, host string) error {
+	if err := ioutil.WriteFile(host+string(os.PathSeparator)+"/template/maintenance.html", ThemeFiles.AllData["maintenance.html"], 0664); err != nil {
+		return err
+	}
+
+	return nil
+}