From 15cf3fefaf540fc772339d9c9f8040fa902e9ae8 Mon Sep 17 00:00:00 2001 From: Matt Stauffer Date: Tue, 7 Feb 2023 21:59:58 -0500 Subject: [PATCH] Handle old, customized sample valet drivers more gracefully --- cli/Valet/Upgrader.php | 18 +++++++++- cli/stubs/Valet3SampleValetDriver.php | 51 +++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 cli/stubs/Valet3SampleValetDriver.php diff --git a/cli/Valet/Upgrader.php b/cli/Valet/Upgrader.php index 389ccd1..b9a7f6a 100644 --- a/cli/Valet/Upgrader.php +++ b/cli/Valet/Upgrader.php @@ -52,7 +52,19 @@ public function fixOldSampleValetDriver(): void $samplePath = VALET_HOME_PATH.'/Drivers/SampleValetDriver.php'; if ($this->files->exists($samplePath)) { - if (! str_contains($this->files->get($samplePath), 'namespace')) { + $contents = $this->files->get($samplePath); + + if (! str_contains($contents, 'namespace')) { + if ($contents !== $this->files->get(__DIR__.'/../stubs/Valet3SampleValetDriver.php')) { + warning('Existing SampleValetDriver.php has been customized.'); + warning('Backing up at '.$samplePath.'.bak'); + + $this->files->putAsUser( + VALET_HOME_PATH . '/Drivers/SampleValetDriver.php.bak', + $contents + ); + } + $this->files->putAsUser( VALET_HOME_PATH.'/Drivers/SampleValetDriver.php', $this->files->getStub('SampleValetDriver.php') @@ -73,6 +85,10 @@ public function errorIfOldCustomDrivers(): void } foreach ($this->files->scanDir($driversPath) as $driver) { + if (! ends_with($driver, 'ValetDriver.php')) { + continue; + } + if (! str_contains($this->files->get($driversPath.'/'.$driver), 'namespace')) { warning('Please make sure all custom drivers have been upgraded for Valet 4.'); exit; diff --git a/cli/stubs/Valet3SampleValetDriver.php b/cli/stubs/Valet3SampleValetDriver.php new file mode 100644 index 0000000..d0abd2a --- /dev/null +++ b/cli/stubs/Valet3SampleValetDriver.php @@ -0,0 +1,51 @@ +