From a58bca390b937e57d586f6d52227edc8233f52f8 Mon Sep 17 00:00:00 2001 From: Nabeel S Date: Wed, 11 Dec 2019 15:12:31 -0500 Subject: [PATCH] Fix BindingResolutionError when debug toolbar isn't present (#465) * Fix BindingResolutionError when debug toolbar isn't present * Formatting --- .travis/deploy_script.sh | 11 +++++---- app/Console/Commands/Version.php | 1 + app/Providers/AppServiceProvider.php | 12 ++++++---- app/Services/VersionService.php | 2 ++ app/helpers.php | 12 ++++++++++ .../Http/Controllers/ImporterController.php | 21 +++++++++++++---- .../Http/Controllers/InstallerController.php | 6 ++++- tests/VersionTest.php | 23 ++++++++++++------- 8 files changed, 67 insertions(+), 21 deletions(-) diff --git a/.travis/deploy_script.sh b/.travis/deploy_script.sh index 6a578c7a..1b4570ba 100755 --- a/.travis/deploy_script.sh +++ b/.travis/deploy_script.sh @@ -18,15 +18,20 @@ if [ "$TRAVIS" = "true" ]; then exit 0 fi + # Write the version out but place the branch ID in there + # This is only for the dev branch BASE_VERSION=$(php artisan phpvms:version --base-only) - PKG_NAME=${BASE_VERSION}-${TRAVIS_BRANCH} + + # This now includes the pre-release version, so "-dev" by default + PKG_NAME=${BASE_VERSION} # Don't pass in a version here, just write out the latest hash - php artisan phpvms:version --write > VERSION + php artisan phpvms:version --write >VERSION VERSION=$(cat VERSION) fi echo "Version: $VERSION" + echo "Package name: $TAR_NAME" FILE_NAME="phpvms-$PKG_NAME" TAR_NAME="$FILE_NAME.tar.gz" @@ -99,8 +104,6 @@ if [ "$TRAVIS" = "true" ]; then composer dump-autoload make clean - echo "Writing $TAR_NAME" - cd /tmp tar -czf $TAR_NAME -C $TRAVIS_BUILD_DIR/../ phpvms sha256sum $TAR_NAME >"$TAR_NAME.sha256" diff --git a/app/Console/Commands/Version.php b/app/Console/Commands/Version.php index e8bda4a7..e4b4a3b6 100644 --- a/app/Console/Commands/Version.php +++ b/app/Console/Commands/Version.php @@ -50,6 +50,7 @@ class Version extends Command } } + // Always write out the build ID/build number which is the commit hash $build_number = $this->versionSvc->getBuildId($cfg); $cfg['current']['commit'] = $build_number; $cfg['build']['number'] = $build_number; diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 6ab3cb33..4c35ccca 100755 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -25,6 +25,7 @@ use App\Models\Subfleet; use App\Models\User; use App\Repositories\SettingRepository; use App\Services\ModuleService; +use Illuminate\Contracts\Container\BindingResolutionException; use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\View; use Illuminate\Support\ServiceProvider; @@ -75,10 +76,13 @@ class AppServiceProvider extends ServiceProvider $this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class); } - if (config('app.debug_toolbar') === true) { - app('debugbar')->enable(); - } else { - app('debugbar')->disable(); + try { + if (config('app.debug_toolbar') === true) { + app('debugbar')->enable(); + } else { + app('debugbar')->disable(); + } + } catch (BindingResolutionException $e) { } } } diff --git a/app/Services/VersionService.php b/app/Services/VersionService.php index 50e74730..26b39721 100644 --- a/app/Services/VersionService.php +++ b/app/Services/VersionService.php @@ -185,6 +185,8 @@ class VersionService extends Service $current_version = $this->cleanVersionString($current_version); } + // Replace "dev" with "alpha", since + $latest_version = $this->getLatestVersion(); // Convert to semver diff --git a/app/helpers.php b/app/helpers.php index 39e03138..e7b83ccd 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -4,6 +4,18 @@ use App\Exceptions\SettingNotFound; use Carbon\Carbon; use Illuminate\Contracts\View\Factory; +/* + * array_key_first only exists in PHP 7.3+ + */ +if (!function_exists('array_key_first')) { + function array_key_first(array $arr) + { + foreach ($arr as $key => $unused) { + return $key; + } + } +} + if (!function_exists('in_mask')) { /** * Return true/false if a value exists in a mask diff --git a/modules/Installer/Http/Controllers/ImporterController.php b/modules/Installer/Http/Controllers/ImporterController.php index 16aab197..d0ad704f 100644 --- a/modules/Installer/Http/Controllers/ImporterController.php +++ b/modules/Installer/Http/Controllers/ImporterController.php @@ -3,6 +3,7 @@ namespace Modules\Installer\Http\Controllers; use App\Contracts\Controller; +use Illuminate\Contracts\Container\BindingResolutionException; use Illuminate\Http\Request; use Illuminate\Support\Facades\Log; use Modules\Installer\Services\Importer\ImporterService; @@ -15,7 +16,10 @@ class ImporterController extends Controller { $this->importerSvc = $importerSvc; - app('debugbar')->disable(); + try { + app('debugbar')->disable(); + } catch (BindingResolutionException $e) { + } } /** @@ -28,7 +32,10 @@ class ImporterController extends Controller */ public function index(Request $request) { - app('debugbar')->disable(); // saves the query logging + try { + app('debugbar')->disable(); + } catch (BindingResolutionException $e) { + } return view('installer::importer/step1-configure'); } @@ -42,7 +49,10 @@ class ImporterController extends Controller */ public function config(Request $request) { - app('debugbar')->disable(); // saves the query logging + try { + app('debugbar')->disable(); + } catch (BindingResolutionException $e) { + } try { // Save the credentials to use later @@ -78,7 +88,10 @@ class ImporterController extends Controller */ public function run(Request $request) { - app('debugbar')->disable(); // saves the query logging + try { + app('debugbar')->disable(); + } catch (BindingResolutionException $e) { + } $importer = $request->input('importer'); $start = $request->input('start'); diff --git a/modules/Installer/Http/Controllers/InstallerController.php b/modules/Installer/Http/Controllers/InstallerController.php index 4b7fada1..9d49cfe4 100644 --- a/modules/Installer/Http/Controllers/InstallerController.php +++ b/modules/Installer/Http/Controllers/InstallerController.php @@ -11,6 +11,7 @@ use App\Services\Installer\MigrationService; use App\Services\Installer\SeederService; use App\Services\UserService; use App\Support\Countries; +use Illuminate\Contracts\Container\BindingResolutionException; use Illuminate\Database\QueryException; use Illuminate\Http\Request; use Illuminate\Support\Facades\Hash; @@ -63,7 +64,10 @@ class InstallerController extends Controller $this->seederSvc = $seederSvc; $this->userService = $userService; - app('debugbar')->disable(); + try { + app('debugbar')->disable(); + } catch (BindingResolutionException $e) { + } } /** diff --git a/tests/VersionTest.php b/tests/VersionTest.php index fb76bf17..4b14d970 100644 --- a/tests/VersionTest.php +++ b/tests/VersionTest.php @@ -20,17 +20,24 @@ class VersionTest extends TestCase public function testGreaterThanVersionStrings(): void { $test = [ - '7.0.0' => '6.0.0', - '7.0.0+1231s' => '6.0.0', - '7.0.0-beta' => '7.0.0-alpha', - '7.0.0-beta.1' => '7.0.0-beta', - '7.0.0-beta.2' => '7.0.0-beta.1', - '7.0.0-beta.2+a34sdf' => '7.0.0-beta.1', + ['7.0.0' => '6.0.0'], + ['7.0.0+1231s' => '6.0.0'], + // ['7.0.0-beta' => '7.0.0-dev'], + ['7.0.0-beta' => '7.0.0-alpha'], + ['7.0.0-beta.1' => '7.0.0-beta'], + ['7.0.0-beta.2' => '7.0.0-beta.1'], + ['7.0.0-beta.2+a34sdf' => '7.0.0-beta.1'], ]; $versionSvc = app(VersionService::class); - foreach ($test as $newVersion => $currentVersion) { - $this->assertTrue($versionSvc->isGreaterThan($newVersion, $currentVersion)); + foreach ($test as $set) { + $newVersion = array_key_first($set); + $currentVersion = $set[$newVersion]; + + $this->assertTrue( + $versionSvc->isGreaterThan($newVersion, $currentVersion), + "{$newVersion} not greater than ${currentVersion}" + ); } }