Skip to content

Commit

Permalink
fixes #813 by adding a few more try-catch (#814)
Browse files Browse the repository at this point in the history
* fixes #813 by adding a few more try-catch
  • Loading branch information
ildyria authored Dec 12, 2020
1 parent c373443 commit 68ef354
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 30 deletions.
23 changes: 23 additions & 0 deletions app/ControllerFunctions/Install/DefaultConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,29 @@ class DefaultConfig
// ],
];

/**
* Set the result array permissions and errors.
*
* @return mixed
*/
public function __construct()
{
$db_possibilities = [
['mysql', 'mysqli'],
['mysql', 'pdo_mysql'],
['pgsql', 'pgsql'],
['pgsql', 'pdo_pgsql'],
['sqlite', 'sqlite3'],
];

// additional requirement depending of the .env/base config
foreach ($db_possibilities as $db_possibility) {
if (config('database.default') == $db_possibility[0]) {
$this->config['requirements']['php'][] = $db_possibility[1];
}
}
}

public function get_core()
{
return $this->config['core'];
Expand Down
17 changes: 9 additions & 8 deletions app/ControllerFunctions/Install/RequirementsChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public function check(array $requirements)
$results = [];
foreach ($requirements as $type => $requirement_) {
switch ($type) {
// check php requirements
// check php requirements
case 'php':
foreach ($requirements[$type] as $requirement) {
foreach ($requirement_ as $requirement) {
$results['requirements'][$type][$requirement] = true;
if (!extension_loaded($requirement)) {
// @codeCoverageIgnoreStart
Expand All @@ -45,9 +45,9 @@ public function check(array $requirements)
}

break;
// check apache requirements
// check apache requirements
case 'apache':
foreach ($requirements[$type] as $requirement) {
foreach ($requirement_ as $requirement) {
// if function doesn't exist we can't check apache modules
// @codeCoverageIgnoreStart
if (function_exists('apache_get_modules')) {
Expand All @@ -63,10 +63,10 @@ public function check(array $requirements)
}
break;

// @codeCoverageIgnoreStart
// @codeCoverageIgnoreStart
default:
break;
// @codeCoverageIgnoreEnd
// @codeCoverageIgnoreEnd
}
}

Expand All @@ -90,7 +90,8 @@ public function checkPHPversion(string $minPhpVersion = null)
$minVersionPhp = $this->getMinPhpVersion();
// @codeCoverageIgnoreEnd
}
if (version_compare($currentPhpVersion['version'], $minVersionPhp)
if (
version_compare($currentPhpVersion['version'], $minVersionPhp)
>= 0
) {
$supported = true;
Expand Down Expand Up @@ -145,4 +146,4 @@ protected function getMinPhpVersion()
}

// @codeCoverageIgnoreEnd
}
}
5 changes: 5 additions & 0 deletions app/Http/Middleware/AdminCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Http\Middleware;

use App\MiddlewareFunctions\IsInstalled;
use App\ModelFunctions\SessionFunctions;
use Closure;
use Illuminate\Http\Request;
Expand All @@ -30,6 +31,10 @@ public function __construct(SessionFunctions $sessionFunctions)
*/
public function handle($request, Closure $next)
{
if (!IsInstalled::assert()) {
return $next($request);
}

if (!$this->sessionFunctions->is_admin()) {
return response('false');
}
Expand Down
9 changes: 7 additions & 2 deletions app/Http/Middleware/DBExists.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use App\Redirections\ToInstall;
use Closure;
use Illuminate\Database\QueryException;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Schema;

Expand All @@ -21,10 +22,14 @@ class DBExists
*/
public function handle($request, Closure $next)
{
if (!Schema::hasTable('configs')) {
try {
if (!Schema::hasTable('configs')) {
return ToInstall::go();
}
} catch (QueryException $e) {
return ToInstall::go();
}

return $next($request);
}
}
}
23 changes: 3 additions & 20 deletions app/Http/Middleware/InstalledCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace App\Http\Middleware;

use App\MiddlewareFunctions\IsInstalled;
use App\Redirections\ToHome;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Schema;

class InstalledCheck
{
Expand All @@ -21,27 +21,10 @@ class InstalledCheck
*/
public function handle($request, Closure $next)
{
// this should not happen but you never know.
// if the key is not provided AND
// the database (config table exists) is set
// or installed.log exists
// this will generate an infinite loop. We do not want that.
if (file_exists(base_path('.NO_SECURE_KEY'))) {
return $next($request);
}

// base safety
if (file_exists(base_path('installed.log'))) {
return ToHome::go();
}

// This is the second safety:
// Assume you do a "git pull" but forget to do the migration,
// the installed.log will not be created!!!
if (Schema::hasTable('configs')) {
if (IsInstalled::assert()) {
return ToHome::go();
}

return $next($request);
}
}
}
39 changes: 39 additions & 0 deletions app/MiddlewareFunctions/IsInstalled.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace App\MiddlewareFunctions;

use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\Schema;

class IsInstalled
{
public static function assert(): bool
{
// this should not happen but you never know.
// if the key is not provided AND
// the database (config table exists) is set
// or installed.log exists
// this will generate an infinite loop. We do not want that.
if (file_exists(base_path('.NO_SECURE_KEY'))) {
return false;
}

// base safety
if (file_exists(base_path('installed.log'))) {
return true;
}

// This is the second safety:
// Assume you do a "git pull" but forget to do the migration,
// the installed.log will not be created!!!
try {
if (Schema::hasTable('configs')) {
return true;
}

return false;
} catch (QueryException $e) {
return false;
}
}
}

0 comments on commit 68ef354

Please sign in to comment.