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 = []; $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' => '---', ]; try { //Unnecessary // $versions = $update->listVersions(); $versions = []; } catch (\Exception $exception) { $update->doLog("can not fetch versions from github: " . $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; } try { $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'), ]; } catch (\Exception $exception) { $update->doLog("can not fetch latest commit from github: " . $exception->getMessage()); } 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']; $mysqlInfo = $update->getMysqlVersionInfo(); $redisInfo = $update->getRedisVersionInfo(); while ($isPost) { set_time_limit(300); try { // $update->updateDependencies(); $update->createSymbolicLinks($symbolicLinks); //new setting should add in extraQueries(), this step only do when install // $update->saveSettings($settings); $update->runExtraQueries(); $update->runMigrate(); $update->runExtraMigrate(); $update->nextStep(); } catch (\Exception $e) { $error = $e->getMessage(); break; } break; } } if ( !empty($error) || (isset($mysqlInfo) && !$mysqlInfo['match']) || (isset($redisInfo) && !$redisInfo['match']) ) { $pass = false; } ?>