2021-01-27 16:26:37 +08:00
< ? php
$rootpath = dirname ( dirname ( __DIR__ )) . '/' ;
define ( 'ROOT_PATH' , $rootpath );
2021-06-08 20:43:47 +08:00
require ROOT_PATH . 'nexus/Install/install_update_start.php' ;
2021-01-27 16:26:37 +08:00
2021-06-08 20:43:47 +08:00
$isPost = $_SERVER [ 'REQUEST_METHOD' ] == 'POST' ;
2021-01-27 16:26:37 +08:00
$install = new \Nexus\Install\Install ();
$currentStep = $install -> currentStep ();
$maxStep = $install -> maxStep ();
2021-01-30 13:53:15 +08:00
if ( ! $install -> canAccessStep ( $currentStep )) {
$install -> gotoStep ( 1 );
}
$error = $copy = '' ;
2021-06-05 17:04:53 +08:00
$pass = true ;
2021-01-27 16:26:37 +08:00
//step 1
if ( $currentStep == 1 ) {
$requirements = $install -> listRequirementTableRows ();
$pass = $requirements [ 'pass' ];
if ( $isPost ) {
$install -> nextStep ();
}
}
if ( $currentStep == 2 ) {
2021-04-30 15:10:31 +08:00
$envExampleFile = $rootpath . " .env.example " ;
2021-01-27 16:26:37 +08:00
$envExampleData = readEnvFile ( $envExampleFile );
$envFormControls = $install -> listEnvFormControls ();
$newData = array_column ( $envFormControls , 'value' , 'name' );
while ( $isPost ) {
try {
2021-01-27 17:50:24 +08:00
$install -> createEnvFile ( $_POST );
$install -> nextStep ();
} catch ( \Exception $exception ) {
2021-01-30 13:53:15 +08:00
$error = $exception -> getMessage ();
2021-01-27 16:26:37 +08:00
break ;
}
break ;
}
$tableRows = [
[
2021-04-30 15:10:31 +08:00
'label' => basename ( $envExampleFile ),
2021-01-27 16:26:37 +08:00
'required' => 'exists && readable' ,
'current' => $envExampleFile ,
'result' => $install -> yesOrNo ( file_exists ( $envExampleFile ) && is_readable ( $envExampleFile )),
],
];
$fails = array_filter ( $tableRows , function ( $value ) { return $value [ 'result' ] == 'NO' ;});
$pass = empty ( $fails );
}
if ( $currentStep == 3 ) {
2021-01-27 17:50:24 +08:00
$shouldCreateTable = $install -> listShouldCreateTable ();
while ( $isPost ) {
try {
2021-06-08 20:43:47 +08:00
// $install->createTable($shouldCreateTable);
2021-06-22 13:49:54 +08:00
$install -> runMigrate ();
2021-01-27 16:26:37 +08:00
$install -> nextStep ();
2021-01-27 17:50:24 +08:00
} catch ( \Exception $exception ) {
2021-01-30 13:53:15 +08:00
$error = $exception -> getMessage ();
2021-01-27 17:50:24 +08:00
break ;
2021-01-27 16:26:37 +08:00
}
break ;
}
}
//if ($currentStep == 4) {
// $pass = true;
// while (true) {
// $shouldAlterTable = listShouldAlterTable();
// if ($isPost) {
// if (!empty($shouldAlterTable)) {
// try {
// sql_query('SET sql_mode=(SELECT REPLACE(@@sql_mode,"NO_ZERO_DATE", ""));');
// foreach ($shouldAlterTable as $table => $fields) {
// $sqlAlter = "alter table $table";
// $sqlUpdate = "update $table";
// $updateWhere = [];
// foreach ($fields as $field) {
// $sqlAlter .= " modify $field datetime default null,";
// $sqlUpdate .= " set $field = null,";
// $updateWhere[] = "$field = '0000-00-00 00:00:00'";
// }
// $sqlAlter = rtrim($sqlAlter, ',');
// $sqlUpdate = rtrim($sqlUpdate, ',') . " where " . implode(' or ', $updateWhere);
// sql_query($sqlUpdate);
// sql_query($sqlAlter);
// }
// } catch (\Exception $e) {
2021-01-30 13:53:15 +08:00
// $error = $e->getMessage();
2021-01-27 16:26:37 +08:00
// break;
// }
// }
// goStep($currentStep + 1);
// }
// break;
// }
//}
if ( $currentStep == 4 ) {
$settingTableRows = $install -> listSettingTableRows ();
$settings = $settingTableRows [ 'settings' ];
$symbolicLinks = $settingTableRows [ 'symbolic_links' ];
$tableRows = $settingTableRows [ 'table_rows' ];
$pass = $settingTableRows [ 'pass' ];
2022-04-17 16:38:44 +08:00
$mysqlInfo = $install -> getMysqlVersionInfo ();
2022-07-18 15:13:03 +08:00
$redisInfo = $install -> getREdisVersionInfo ();
2021-01-27 17:50:24 +08:00
while ( $isPost ) {
2022-03-10 21:45:23 +08:00
set_time_limit ( 300 );
2021-01-27 16:26:37 +08:00
try {
2021-01-27 17:50:24 +08:00
$install -> createSymbolicLinks ( $symbolicLinks );
2021-06-22 13:49:54 +08:00
$install -> runDatabaseSeeder ();
2021-01-29 01:47:26 +08:00
$install -> saveSettings ( $settings );
2022-12-01 00:45:22 +08:00
$install -> migrateSearchBoxModeRelated ();
2021-01-27 17:50:24 +08:00
$install -> nextStep ();
2021-01-27 16:26:37 +08:00
} catch ( \Exception $e ) {
2021-01-30 13:53:15 +08:00
$error = $e -> getMessage ();
2021-01-27 16:26:37 +08:00
break ;
}
break ;
}
}
if ( $currentStep == 5 ) {
if ( $isPost ) {
try {
$install -> createAdministrator ( $_POST [ 'username' ], $_POST [ 'email' ], $_POST [ 'password' ], $_POST [ 'confirm_password' ]);
$install -> nextStep ();
} catch ( \Exception $exception ) {
2021-01-30 13:53:15 +08:00
$error = $exception -> getMessage ();
2021-01-27 16:26:37 +08:00
}
}
$userFormControls = [
2022-03-08 15:08:56 +08:00
[ 'label' => 'Username' , 'name' => 'username' , 'value' => $_POST [ 'username' ] ? ? '' ],
[ 'label' => 'Email' , 'name' => 'email' , 'value' => $_POST [ 'email' ] ? ? '' ],
[ 'label' => 'Password' , 'name' => 'password' , 'value' => $_POST [ 'password' ] ? ? '' ],
[ 'label' => 'Re-password' , 'name' => 'confirm_password' , 'value' => $_POST [ 'confirm_password' ] ? ? '' ],
2021-01-27 16:26:37 +08:00
];
}
2021-06-04 10:26:34 +08:00
2022-07-18 15:13:03 +08:00
if (
! empty ( $error )
|| ( isset ( $mysqlInfo ) && ! $mysqlInfo [ 'match' ])
|| ( isset ( $redisInfo ) && ! $redisInfo [ 'match' ])
) {
2021-06-04 10:26:34 +08:00
$pass = false ;
}
2021-01-27 16:26:37 +08:00
?>
<! doctype html >
< html lang = " en " >
< head >
<!-- Required meta tags -->
< meta charset = " utf-8 " >
< meta name = " viewport " content = " width=device-width, initial-scale=1 " >
< link href = " https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css " rel = " stylesheet " >
2021-01-27 16:46:39 +08:00
< title > Install NexusPHP | step < ? php echo $currentStep ?> </title>
2021-01-27 16:26:37 +08:00
</ head >
< body >
< div class = " container mx-auto " >
< ? php echo $install -> renderSteps () ?>
< div class = " mt-10 " >
< form method = " post " action = " <?php echo getBaseUrl() . '?step=' . $currentStep ?> " >
< input type = " hidden " name = " step " value = " <?php echo $currentStep ?> " >
< ? php
echo '<div class="step-' . $currentStep . ' text-center">' ;
2021-06-22 13:49:54 +08:00
$header = [
2022-03-08 15:08:56 +08:00
'label' => 'Item' ,
'required' => 'Require' ,
'current' => 'Current' ,
'result' => 'Result'
2021-06-22 13:49:54 +08:00
];
2021-01-27 16:26:37 +08:00
if ( $currentStep == 1 ) {
echo $install -> renderTable ( $header , $requirements [ 'table_rows' ]);
} elseif ( $currentStep == 2 ) {
echo $install -> renderTable ( $header , $tableRows );
echo $install -> renderForm ( $envFormControls );
} elseif ( $currentStep == 3 ) {
2022-03-10 18:16:10 +08:00
echo '<h1 class="mb-4 text-lg font-bold">The following tables will be created</h1>' ;
2021-01-27 16:26:37 +08:00
if ( empty ( $shouldCreateTable )) {
2022-03-08 15:08:56 +08:00
echo '<div class="text-green-600 text-center">Congratulations, all the required tables have been created!</div>' ;
2021-01-27 16:26:37 +08:00
} else {
echo sprintf ( '<div class="h-64 text-left inline-block w-2/3"><code class="bolck w-px-100">%s</code></div>' , implode ( ', ' , array_keys ( $shouldCreateTable )));
}
} elseif ( $currentStep == 4 ) {
echo $install -> renderTable ( $header , $tableRows );
echo '<div class="text-blue-500 pt-10">' ;
2022-03-08 15:08:56 +08:00
echo sprintf ( 'This step will merge <code>%s</code> to <code>%s</code>, then insert into database' , $tableRows [ 1 ][ 'label' ], $tableRows [ 0 ][ 'label' ]);
2021-01-27 16:26:37 +08:00
echo '</div>' ;
2022-04-17 16:38:44 +08:00
if ( ! $mysqlInfo [ 'match' ]) {
echo sprintf ( '<div class="text-red-700 pt-10">MySQL version: %s is too low, please use the newest version of 5.7 or above.</div>' , $mysqlInfo [ 'version' ]);
}
2022-07-18 15:13:03 +08:00
if ( ! $redisInfo [ 'match' ]) {
echo sprintf ( '<div class="text-red-700 pt-10">Redis version: %s is too low, please use 2.0.0 or above.</div>' , $redisInfo [ 'version' ]);
}
2021-01-27 16:26:37 +08:00
} elseif ( $currentStep == 5 ) {
2022-03-10 18:16:10 +08:00
echo $install -> renderForm ( $userFormControls , '1/2' , '1/4' , '3/4' );
2021-01-27 16:26:37 +08:00
} elseif ( $currentStep > $maxStep ) {
2022-03-08 15:08:56 +08:00
echo '<div class="text-green-900 text-6xl p-10">Congratulations, everything is ready!</div>' ;
echo '<div class="mb-6">For questions, consult the installation log at: <code>' . $install -> getLogFile () . '</code></div>' ;
echo '<div class="text-red-500">For security reasons, please delete the following directories</div>' ;
2021-01-27 16:26:37 +08:00
echo '<div class="text-red-500"><code>' . $install -> getInsallDirectory () . '</code></div>' ;
2022-04-25 02:30:15 +08:00
$install -> setLock ();
2021-01-27 16:26:37 +08:00
}
echo '</div>' ;
2021-01-30 13:53:15 +08:00
if ( ! empty ( $error )) {
echo sprintf ( '<div class="text-center text-red-500 p-4">Error: %s</div>' , nl2br ( $error ));
unset ( $error );
2021-01-27 16:26:37 +08:00
}
2021-01-30 13:53:15 +08:00
if ( ! empty ( $copy )) {
echo sprintf ( '<div class="text-center"><textarea class="w-1/2 h-40 border">%s</textarea></div>' , $copy );
unset ( $copy );
2021-01-27 16:26:37 +08:00
}
?>
2022-04-19 16:27:30 +08:00
< div class = " mt-2 text-center " >
2022-03-08 15:08:56 +08:00
< button class = " bg-blue-500 p-2 m-4 text-white rounded " type = " button " onclick = " goBack() " > Prev </ button >
2021-01-27 16:26:37 +08:00
< ? php if ( $currentStep <= $maxStep ) { ?>
2022-03-08 15:08:56 +08:00
< button class = " bg-blue-<?php echo $pass ? 500 : 200;?> p-2 m-4 text-white rounded " type = " submit " < ? php echo $pass ? '' : 'disabled' ; ?> >Next</button>
2021-01-27 16:26:37 +08:00
< ? php } else { ?>
2022-03-08 15:08:56 +08:00
< a class = " bg-blue-500 p-2 m-4 text-white rounded " href = " <?php echo getSchemeAndHttpHost()?> " > Go to homepage </ a >
2021-01-27 16:26:37 +08:00
< ? php } ?>
</ div >
</ form >
</ div >
</ div >
2022-04-19 16:27:30 +08:00
< div class = " m-2 text-center " >
2022-03-08 15:08:56 +08:00
Welcome to the NexusPHP installer , if you have any questions , click < a href = " https://nexusphp.org/ " target = " _blank " class = " text-blue-500 p-1 " > here </ a > for help .
2021-01-28 18:00:54 +08:00
</ div >
2021-01-27 16:26:37 +08:00
</ body >
< script >
function goBack () {
window . location . search = " step=<?php echo $currentStep == 1 ? 1 : $currentStep - 1?> "
}
</ script >
2021-04-30 01:27:29 +08:00
</ html >