From d10de1362651f7d73783f12dcb4a3e9f57a78c45 Mon Sep 17 00:00:00 2001
From: ivan <ivan@opensupports.com>
Date: Thu, 30 Mar 2017 20:37:55 -0300
Subject: [PATCH] Ivan - Fix installation issues [skip ci]

---
 client/gulp/tasks/copyIndex.js                |  2 +
 client/src/.htaccess                          |  5 ++
 client/src/app/App.js                         |  8 ++++
 client/src/app/install/install-layout.js      | 47 ++++++++++---------
 .../install/install-step-4-user-system.scss   |  3 +-
 .../src/app/install/install-step-5-admin.js   |  6 ---
 .../src/app/install/install-step-5-admin.scss |  8 +---
 server/.htaccess                              |  4 ++
 server/controllers/system/init-database.php   |  2 +-
 9 files changed, 48 insertions(+), 37 deletions(-)
 create mode 100644 client/src/.htaccess
 create mode 100644 server/.htaccess

diff --git a/client/gulp/tasks/copyIndex.js b/client/gulp/tasks/copyIndex.js
index c69d0353..d526e3c6 100644
--- a/client/gulp/tasks/copyIndex.js
+++ b/client/gulp/tasks/copyIndex.js
@@ -6,5 +6,7 @@ var config = require('../config');
 gulp.task('copyIndex', function() {
 
   gulp.src(config.sourceDir + 'index.html').pipe(gulp.dest(config.buildDir));
+  gulp.src(config.sourceDir + 'index.php').pipe(gulp.dest(config.buildDir));
+  gulp.src(config.sourceDir + '.htaccess').pipe(gulp.dest(config.buildDir));
 
 });
\ No newline at end of file
diff --git a/client/src/.htaccess b/client/src/.htaccess
new file mode 100644
index 00000000..87e9334a
--- /dev/null
+++ b/client/src/.htaccess
@@ -0,0 +1,5 @@
+RewriteEngine on
+RewriteCond %{REQUEST_FILENAME} !-f
+RewriteCond %{REQUEST_FILENAME} !-d
+RewriteCond %{REQUEST_URI} !^/?(api)/
+RewriteRule .* index.php [PT,L]
\ No newline at end of file
diff --git a/client/src/app/App.js b/client/src/app/App.js
index 20227002..ace0982b 100644
--- a/client/src/app/App.js
+++ b/client/src/app/App.js
@@ -102,6 +102,14 @@ class App extends React.Component {
         if(props.config['user-system-enabled'] && _.includes(props.location.pathname, '/check-ticket')) {
             browserHistory.push('/');
         }
+
+        if(props.config.installedDone && !props.config.installed && !_.includes(props.location.pathname, '/install')) {
+            browserHistory.push('/install');
+        }
+
+        if(props.config.installedDone && props.config.installed && _.includes(props.location.pathname, '/install')) {
+            browserHistory.push('/');
+        }
     }
 
     isPathAvailableForStaff(props) {
diff --git a/client/src/app/install/install-layout.js b/client/src/app/install/install-layout.js
index 884fc0e3..1cfd151d 100644
--- a/client/src/app/install/install-layout.js
+++ b/client/src/app/install/install-layout.js
@@ -2,6 +2,7 @@ import React from 'react';
 import classNames from 'classnames';
 import _ from 'lodash';
 import {browserHistory} from 'react-router';
+import DocumentTitle from 'react-document-title';
 
 import i18n from 'lib-app/i18n';
 import API from 'lib-app/api-call';
@@ -33,32 +34,34 @@ class InstallLayout extends React.Component {
 
     render() {
         return (
-            <Widget className="install-layout">
-                <div className="install-layout__header">
-                    <div className="install-layout__header-logo">
-                        <img width="100%" src="../../images/logo.png" alt="OpenSupports Installation"/>
-                    </div>
-                    <div className="install-layout__header-text">
-                        <div className="install-layout__header-title">
-                            {i18n('INSTALL_HEADER_TITLE')}
+            <DocumentTitle title="OpenSupports Installation">
+                <Widget className="install-layout">
+                    <div className="install-layout__header">
+                        <div className="install-layout__header-logo">
+                            <img width="100%" src="../../images/logo.png" alt="OpenSupports Installation"/>
                         </div>
-                        <div className="install-layout__header-description">
-                            {i18n('INSTALL_HEADER_DESCRIPTION')}
+                        <div className="install-layout__header-text">
+                            <div className="install-layout__header-title">
+                                {i18n('INSTALL_HEADER_TITLE')}
+                            </div>
+                            <div className="install-layout__header-description">
+                                {i18n('INSTALL_HEADER_DESCRIPTION')}
+                            </div>
                         </div>
                     </div>
-                </div>
-                <span className="separator"/>
-                <div className="install-layout__body row">
-                    <div className="col-md-3">
-                        <ul className="install-layout__steps">
-                            {steps.map(this.renderStep.bind(this))}
-                        </ul>
+                    <span className="separator"/>
+                    <div className="install-layout__body row">
+                        <div className="col-md-3">
+                            <ul className="install-layout__steps">
+                                {steps.map(this.renderStep.bind(this))}
+                            </ul>
+                        </div>
+                        <div className="install-layout__content col-md-9">
+                            {this.props.children}
+                        </div>
                     </div>
-                    <div className="install-layout__content col-md-9">
-                        {this.props.children}
-                    </div>
-                </div>
-            </Widget>
+                </Widget>
+            </DocumentTitle>
         );
     }
 
diff --git a/client/src/app/install/install-step-4-user-system.scss b/client/src/app/install/install-step-4-user-system.scss
index 92e326bb..ad8ac7c7 100644
--- a/client/src/app/install/install-step-4-user-system.scss
+++ b/client/src/app/install/install-step-4-user-system.scss
@@ -9,6 +9,7 @@
     &__next {
         float: left;
         position: absolute;
-        margin-left: 286px;
+        margin-left: 230px;
+        min-width: 70px;
     }
 }
\ No newline at end of file
diff --git a/client/src/app/install/install-step-5-admin.js b/client/src/app/install/install-step-5-admin.js
index 0c5c1903..112fc190 100644
--- a/client/src/app/install/install-step-5-admin.js
+++ b/client/src/app/install/install-step-5-admin.js
@@ -30,7 +30,6 @@ class InstallStep5Admin extends React.Component {
                     <FormField name="password" validation="PASSWORD" label={i18n('ADMIN_PASSWORD')} infoMessage={i18n('ADMIN_PASSWORD_DESCRIPTION')} fieldProps={{size: 'large', autoComplete: 'off'}} required/>
                     <div className="install-step-5__buttons">
                         <SubmitButton className="install-step-5__next" size="medium" type="secondary">{i18n('NEXT')}</SubmitButton>
-                        <Button className="install-step-5__previous" size="medium" onClick={this.onPreviousClick.bind(this)}>{i18n('PREVIOUS')}</Button>
                     </div>
                 </Form>
             </div>
@@ -50,11 +49,6 @@ class InstallStep5Admin extends React.Component {
 
         return message;
     }
-    
-    onPreviousClick(event) {
-        event.preventDefault();
-        browserHistory.push('/install/step-4');
-    }
 
     onSubmit(form) {
         this.setState({
diff --git a/client/src/app/install/install-step-5-admin.scss b/client/src/app/install/install-step-5-admin.scss
index 2b8eb92d..668d5326 100644
--- a/client/src/app/install/install-step-5-admin.scss
+++ b/client/src/app/install/install-step-5-admin.scss
@@ -6,13 +6,7 @@
         margin-bottom: 20px;
     }
 
-    &__previous {
-        margin-right: 20px;
-    }
-
     &__next {
-        float: left;
-        position: absolute;
-        margin-left: 286px;
+        min-width: 70px;
     }
 }
\ No newline at end of file
diff --git a/server/.htaccess b/server/.htaccess
new file mode 100644
index 00000000..945b7599
--- /dev/null
+++ b/server/.htaccess
@@ -0,0 +1,4 @@
+RewriteEngine on
+RewriteCond %{REQUEST_FILENAME} !-f
+RewriteCond %{REQUEST_FILENAME} !-d
+RewriteRule .* index.php [PT,L]
\ No newline at end of file
diff --git a/server/controllers/system/init-database.php b/server/controllers/system/init-database.php
index a360bff5..1d811964 100644
--- a/server/controllers/system/init-database.php
+++ b/server/controllers/system/init-database.php
@@ -14,7 +14,7 @@ class InitDatabaseController extends Controller {
     }
 
     public function handler() {
-        if(InstallationDoneController::isInstallationDone()) {
+        if(defined('MYSQL_HOST')) {
             throw new Exception(ERRORS::INIT_SETTINGS_DONE);
         }