#25: Updated the installer layout for BS4-beta. Added a redirect when the vendor autoload file doesn't exist to install.php, which can download and install Composer.

This commit is contained in:
Andy Heathershaw 2017-09-05 14:59:18 +01:00
parent 2b011b6384
commit 280768d001
6 changed files with 138 additions and 62 deletions

View File

@ -7,6 +7,14 @@
* @author Taylor Otwell <taylor@laravel.com>
*/
/* Added by Andy - check to see if Composer/vendors are installed */
if (!file_exists(__DIR__.'/../vendor/autoload.php'))
{
header('Location: install.php');
exit();
}
/* End Added by Andy */
/*
|--------------------------------------------------------------------------
| Register The Auto Loader

View File

@ -2,96 +2,168 @@
namespace BtwInstaller;
use Illuminate\Support\Facades\Artisan;
use Symfony\Component\Translation\Loader\PhpFileLoader;
use Symfony\Component\Translation\Translator;
class BlueTwilightInstaller
{
private $baseDirectory;
private $licenseInfo;
private $composerSignature;
public function __construct()
{
$this->baseDirectory = dirname(__DIR__);
chdir($this->baseDirectory);
// Display errors so installer never gets a WSOD!
ini_set('display_errors', true);
require $this->baseDirectory . '/vendor/autoload.php';
}
public function run()
{
$licenseFile = new \SplFileInfo(sprintf('%s/blue-twilight.lic', $this->baseDirectory));
if (!$licenseFile->isReadable())
if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST')
{
return $this->needLicense();
// Handle post
$this->runInstall();
exit();
}
?>
<h1>Blue Twilight Setup</h1>
<p>We need to download a few things - namely <a href="http://getcomposer.org" target="_blank">Composer</a> and related packages - before we can kick off the Blue Twilight installer.</p>
<p>We can do this for you - simply click the button below.</p>
<form method="post">
<button type="submit">Install Composer and dependencies for me</button>
</form>
try
{
$this->licenseInfo = $this->verifyLicense();
}
catch (\Exception $ex)
{
unlink($licenseFile->getRealPath());
return $this->needLicense();
}
<hr/>
<h2>Got Composer?</h2>
$environmentFile = new \SplFileInfo(sprintf('%s/.env', $this->baseDirectory));
if (!$environmentFile->isReadable())
{
return $this->needEnvironmentSetup();
}
<p>If you already have Composer installed, however, you may want to use that instead. Just run the below commands on your server, changing the path to Composer as appropriate:</p>
<p><em>Please note: &quot;composer.phar&quot; may actually be &quot;composer&quot; on your system.</em></p>
<pre>cd <?php echo $this->baseDirectory; ?><br/>/path/to/composer.phar install</pre>
<?php
}
private function needEnvironmentSetup()
private function runInstall()
{
if ($_SERVER['REQUEST_METHOD'] != 'POST')
?>
<h1>Installing Blue Twilight Setup Files</h1>
<ul>
<?php
$steps = [
['Fetching Composer signature', 'fetchComposerSignature'],
['Installing Composer', 'installComposer'],
['Installing dependencies using Composer', 'runComposer']
];
foreach ($steps as $step)
{
return $this->render('database-connection');
echo sprintf("<li>%s...</li>%s", $step[0], PHP_EOL);
$result = call_user_func([$this, $step[1]]);
if (!$result)
{
break;
}
}
?>
</ul>
<?php
}
private function echoError($message)
{
echo sprintf("<span style=\"color: #ff0000;\">%s.</span>%s", $message, PHP_EOL);
}
private function echoOK($message = '')
{
echo "<span style=\"color: #008800;\">OK";
if (strlen($message) > 0)
{
echo sprintf('... %s', $message);
}
echo '</span>' . PHP_EOL;
}
private function fetchComposerSignature()
{
$signatureUrl = 'https://composer.github.io/installer.sig';
$this->composerSignature = trim(file_get_contents($signatureUrl));
if (strlen($this->composerSignature) == 0)
{
$this->echoError(sprintf("Failed downloading the Composer signature from %s", $signatureUrl));
return false;
}
else
{
$rc = Artisan::call('migrate');
$output = Artisan::output();
var_dump($rc);
var_dump($output);
$this->echoOK($this->composerSignature);
}
return true;
}
private function needLicense()
private function installComposer()
{
if ($_SERVER['REQUEST_METHOD'] != 'POST')
$rc = -1;
system('php -r "copy(\'https://getcomposer.org/installer\', \'composer-setup.php\');"', $rc);
if ($rc != 0)
{
return $this->render('license');
$this->echoError('Failed to fetch Composer');
return false;
}
else
ob_start();
system(sprintf('php -r "if (hash_file(\'SHA384\', \'composer-setup.php\') === \'%s\') { echo \'Installer verified\'; } else { echo \'Installer corrupt\'; unlink(\'composer-setup.php\'); } echo PHP_EOL;"', $this->composerSignature), $rc);
$result = ob_get_clean();
echo nl2br($result);
if ($rc != 0)
{
move_uploaded_file($_FILES['license-file']['tmp_name'], sprintf('%s/blue-twilight.lic', $this->baseDirectory));
header(sprintf('Location: %s', $_SERVER['REQUEST_URI']), true, 302);
die();
$this->echoError('Composer verification failed');
return false;
}
ob_start();
system('php composer-setup.php', $rc);
$result = ob_get_clean();
echo nl2br($result);
if ($rc != 0)
{
$this->echoError('Failed to install Composer');
return false;
}
ob_start();
system('php -r "unlink(\'composer-setup.php\');"', $rc);
$result = ob_get_clean();
echo nl2br($result);
if ($rc != 0)
{
$this->echoError('Failed to remove Composer setup file');
return false;
}
$this->echoOK();
return true;
}
private function render($viewName)
private function runComposer()
{
$viewName = pathinfo($viewName, PATHINFO_BASENAME);
$viewPath = sprintf('%s/resources/views/installer/%s.php', $this->baseDirectory, $viewName);
ob_start();
system('php composer.phar install', $rc);
$result = ob_get_clean();
echo nl2br($result);
if ($rc != 0)
{
$this->echoError('Installing Composer packages failed');
return false;
}
$translator = new Translator('en');
$translator->addLoader('file', new PhpFileLoader());
$translator->addResource('file', sprintf('%s/resources/lang/en/installer.php', $this->baseDirectory), 'en');
$licenseInfo = $this->licenseInfo;
require $viewPath;
}
private function verifyLicense()
{
return (require $this->baseDirectory . '/verify-license.php');
$this->echoOK();
return true;
}
}

View File

@ -16,7 +16,7 @@
@endif
<div class="row" style="margin-top: 30px;">
<div class="col-md-6 offset-md-3">
<div class="col-md-6 mr-md-auto ml-md-auto">
<form action="{{ route('install.administrator') }}" method="post">
{{ csrf_field() }}
<div class="form-group">

View File

@ -6,7 +6,7 @@
<p>@lang('installer.requirements_intro')</p>
<div class="row" style="margin-top: 30px;">
<div class="col-md-8 offset-md-2">
<div class="col-md-8 mr-md-auto ml-md-auto">
<table class="table table-striped">
<tbody>
<tr>

View File

@ -6,7 +6,7 @@
<p>@lang('installer.database_intro')</p>
<div class="row" style="margin-top: 30px;">
<div class="col-md-6 offset-md-3">
<div class="col-md-6 mr-md-auto ml-md-auto">
@if (!is_null($database_error))
<div class="alert alert-danger">
<p><strong>Database error:</strong> {{ $database_error }}</p>

View File

@ -1,9 +1,5 @@
<nav class="navbar navbar-toggleable-md navbar-inverse bg-primary">
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbar-content" aria-controls="navbar-content" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="{{ route('install.check') }}"><i class="fa fa-fw fa-photo"></i> @lang('installer.app_name')</a>
<nav class="navbar bg-primary navbar-dark">
<a class="navbar-brand" href="{{ route('install.check') }}" style="color: #fff;"><i class="fa fa-fw fa-photo"></i> @lang('installer.app_name')</a>
<div class="collapse navbar-collapse" id="navbar-content">
<ul class="navbar-nav mr-auto">
</ul>