From 124c72ada384e524bc583fcc2296324fee159ce6 Mon Sep 17 00:00:00 2001 From: Anders Jurisoo Date: Sun, 15 Dec 2019 16:31:32 +0100 Subject: [PATCH] Simplification of the file state system --- src/Controllers/PipeDreamAPIController.php | 26 +++++----------------- src/ProjectFileManager.php | 23 +++++++++++++++++-- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/Controllers/PipeDreamAPIController.php b/src/Controllers/PipeDreamAPIController.php index 2293e67..5a0021f 100644 --- a/src/Controllers/PipeDreamAPIController.php +++ b/src/Controllers/PipeDreamAPIController.php @@ -26,16 +26,16 @@ public function build() // Optionally reverse the previous design iteration // This is useful to remove previous mistakes and timestamp conflicts - $this->args->reverseHistory ? $this->project->reverseHistory() : null; + // $this->args->reverseHistory ? $this->project->reverseHistory() : null; // Write the files generated $this->project->write($this->args->reviewFiles); - // We wont need them - $this->deleteDefaultMigrations(); + // If there are user/password_reset tables already present + $this->project->deleteDuplicateDefaultMigrations($this->args->reviewFiles); // Save the changes we made - $this->project->persistHistory(); + // $this->project->persistHistory(); // Ensure migrations are autoloaded exec('cd .. && composer dumpautoload'); @@ -50,26 +50,12 @@ public function build() private function setupProjectEnvironment() { $this->project = ProjectFileManager::make( - $this->args->isSandboxed + env('PIPEDREAM_IS_SANDBOXED') ); } - private function deleteDefaultMigrations() - { - $this->project->delete(json_decode(' - [ - { - "path": "database/migrations/2014_10_12_000000_create_users_table.php" - }, - { - "path": "database/migrations/2014_10_12_100000_create_password_resets_table.php" - } - ] - ')); - } - private function pathToFileName($path) { return substr($path, strrpos($path, '/') + 1); } -} +} \ No newline at end of file diff --git a/src/ProjectFileManager.php b/src/ProjectFileManager.php index b0773cb..1390342 100644 --- a/src/ProjectFileManager.php +++ b/src/ProjectFileManager.php @@ -23,7 +23,7 @@ public static function make($isSandboxed) public function write($files) { - $this->recordCurrentStateFor($files); + // $this->recordCurrentStateFor($files); collect($files)->each(function ($file) { $this->storage()->put($file->path, $file->content); @@ -32,7 +32,7 @@ public function write($files) public function delete($files) { - $this->recordCurrentStateFor($files); + // $this->recordCurrentStateFor($files); collect($files)->each(function ($file) { $this->storage()->delete($file->path); @@ -58,6 +58,25 @@ public function persistHistory() ); } + public function deleteDuplicateDefaultMigrations($files) + { + if(collect($files)->pluck('path')->filter(function($path) { + return preg_match('/create_users_table/', $path); + })->isNotEmpty()) { + $this->delete([ + json_decode('{"path": "database/migrations/2014_10_12_000000_create_users_table.php"}') + ]); + } + + if(collect($files)->pluck('path')->filter(function($path) { + return preg_match('/create_password_resets_table/', $path); + })->isNotEmpty()) { + $this->delete([ + json_decode('{"path": "database/migrations/2014_10_12_100000_create_password_resets_table.php"}') + ]); + } + } + /*********** PRIVATE ************************************************** */ private function setupSandboxProject() {