currentStep(); $maxStep = $update->maxStep(); if (!$update->canAccessStep($currentStep)) { $update->gotoStep(1); } $error = $copy = ''; $pass = true; //step 1 if ($currentStep == 1) { $requirements = $update->listRequirementTableRows(); $pass = $requirements['pass']; if ($isPost) { $update->nextStep(); } } if ($currentStep == 2) { $tableRows = []; $versionTable = $versions = []; $cacheKkey = '__versions_' . date('Ymd_H'); try { $versions = $update->listVersions(); // if (!empty($_SESSION[$cacheKkey])) { // $update->doLog("get versions from session."); // $versions = $_SESSION[$cacheKkey]; // } else { // $_SESSION[$cacheKkey] = $versions; // } } catch (\Exception $exception) { $error = $exception->getMessage(); } if (!$isPost) { $versionHeader = [ 'checkbox' => 'Check', 'tag_name' => 'Version(tag)', 'name' => 'Description', 'published_at' => 'Release at', ]; try { $timezone = nexus_env('TIMEZONE'); } catch (\Exception $exception) { $update->doLog("no .env file, release time is github original"); $timezone = null; } $tableRows[] = [ 'checkbox' => sprintf(''), 'tag_name' => 'Manual', 'name' => 'If there are changes that are not suitable for full coverage, please check this box and make sure you have updated the code manually', 'published_at' => '---', ]; $latestCommit = $update->getLatestCommit(); $time = \Carbon\Carbon::parse($latestCommit['commit']['committer']['date']); if ($timezone) { $time->tz = $timezone; } $tableRows[] = [ 'checkbox' => sprintf('', $latestCommit['sha']), 'tag_name' => 'Latest development code', 'name' => "Development testing only! Latest commit:" . $latestCommit['commit']['message'], 'published_at' => $time->format('Y-m-d H:i:s'), ]; foreach ($versions as $version) { if ($version['draft']) { continue; } $time = \Carbon\Carbon::parse($version['published_at']); if ($timezone) { $time->tz = $timezone; } $versionUrl = $version['tag_name'] . '|' . $version['tarball_url']; $checked = !empty($_REQUEST['version_url']) && $_REQUEST['version_url'] == $versionUrl ? ' checked' : ''; $tableRows[] = [ 'checkbox' => sprintf('', $versionUrl, $checked), 'tag_name' => $version['tag_name'], 'name' => $version['name'], 'published_at' => $time->format('Y-m-d H:i:s'), ]; } } // dd($tableRows); while ($isPost) { try { if (empty($_REQUEST['version_url'])) { throw new \RuntimeException("No version selected yet"); } $downloadUrl = ''; if ($_REQUEST['version_url'] == 'manual') { $update->nextStep(); } elseif (\Illuminate\Support\Str::startsWith($_REQUEST['version_url'], 'development')) { $downloadUrlArr = explode('|', $_REQUEST['version_url']); $downloadUrl = sprintf('https://github.com/xiaomlove/nexusphp/archive/%s.zip', $downloadUrlArr[1]); } else { $versionUrlArr = explode('|', $_REQUEST['version_url']); $version = strtolower($versionUrlArr[0]); $downloadUrl = $versionUrlArr[1]; if (\Illuminate\Support\Str::startsWith($version, 'v')) { $version = substr($version, 1); } $update->doLog("version: $version, downloadUrl: $downloadUrl, currentVersion: " . VERSION_NUMBER); if (version_compare($version, VERSION_NUMBER, '<=')) { throw new \RuntimeException("Must select a version higher than the current one(" . VERSION_NUMBER . ")"); } } $update->downAndExtractCode($downloadUrl); $update->nextStep(); } catch (\Exception $exception) { $update->doLog($exception->getMessage() . $exception->getTraceAsString()); $error = $exception->getMessage(); break; } break; } } if ($currentStep == 3) { $envExampleFile = $rootpath . ".env.example"; $envExampleData = readEnvFile($envExampleFile); $envFormControls = $update->listEnvFormControls(); $newData = array_column($envFormControls, 'value', 'name'); while ($isPost) { try { $update->createEnvFile($_POST, 'update'); $update->nextStep(); } catch (\Exception $exception) { $error = $exception->getMessage(); break; } break; } $tableRows = [ [ 'label' => basename($envExampleFile), 'required' => 'exists && readable', 'current' => $envExampleFile, 'result' => $update->yesOrNo(file_exists($envExampleFile) && is_readable($envExampleFile)), ], ]; $fails = array_filter($tableRows, function ($value) {return $value['result'] == 'NO';}); $pass = empty($fails); } if ($currentStep == 4) { $settingTableRows = $update->listSettingTableRows(); $settings = $settingTableRows['settings']; $symbolicLinks = $settingTableRows['symbolic_links']; $tableRows = $settingTableRows['table_rows']; $pass = $settingTableRows['pass']; while ($isPost) { try { // $update->updateDependencies(); $update->createSymbolicLinks($symbolicLinks); $update->saveSettings($settings); $update->runExtraQueries(); $update->runMigrate(); $update->runExtraMigrate(); $update->nextStep(); } catch (\Exception $e) { $error = $e->getMessage(); break; } break; } } if (!empty($error)) { $pass = false; } ?> Update NexusPHP | step <?php echo $currentStep?>
renderSteps()?>
'; $header = [ 'label' => 'Item', 'required' => 'Require', 'current'=> 'Current', 'result'=> 'Result' ]; if ($currentStep == 1) { echo $update->renderTable($header, $requirements['table_rows']); } elseif ($currentStep == 3) { echo $update->renderTable($header, $tableRows); echo '
Before the next step, make sure that you have executed composer install in the root directory to update the dependencies.
'; echo $update->renderForm($envFormControls); } elseif ($currentStep == 2) { if (empty($tableRows)) { echo '
Sorry, there is no version to choose from at this time!
'; } else { echo $update->renderTable($versionHeader, $tableRows); } } elseif ($currentStep == 4) { echo $update->renderTable($header, $tableRows); echo '
'; echo sprintf('This step will merge %s to %s, then insert into database.', $tableRows[1]['label'], $tableRows[0]['label']); echo '
'; } elseif ($currentStep > $maxStep) { echo '
Congratulations, everything is ready!
'; echo '
For questions, consult the upgrade log at: ' . $update->getLogFile() . '
'; echo '
For security reasons, please delete the following directories
'; echo '
' . $update->getUpdateDirectory() . '
'; } echo'
'; if (!empty($error)) { echo sprintf('
Error: %s
', nl2br($error)); unset($error); } if (!empty($copy)) { echo sprintf('
', $copy); unset($copy); } ?>
Go to homepage
Welcome to the NexusPHP updater, if you have any questions, clickherefor help.