diff --git a/app/Console/Commands/Upgrade/RunCommand.php b/app/Console/Commands/Upgrade/RunCommand.php index a86dd40..6c79071 100644 --- a/app/Console/Commands/Upgrade/RunCommand.php +++ b/app/Console/Commands/Upgrade/RunCommand.php @@ -30,6 +30,7 @@ final class RunCommand extends Command { $this->init(); $this->processLinks(); + $this->syncDatabaseNotes(); } private function init(): void @@ -58,4 +59,20 @@ final class RunCommand extends Command 'executed' => 1, ]); } + + private function syncDatabaseNotes(): void + { + /** @var object{executed: int} $upgrades */ + $upgrades = DB::table('upgrades')->first(); + + if ($upgrades->executed !== 1) { + return; + } + + $this->call('upgrade:sync-database-notes'); + + DB::table('upgrades')->update([ + 'executed' => 2, + ]); + } } diff --git a/app/Console/Commands/Upgrade/SyncDatabaseNotesCommand.php b/app/Console/Commands/Upgrade/SyncDatabaseNotesCommand.php new file mode 100644 index 0000000..241263d --- /dev/null +++ b/app/Console/Commands/Upgrade/SyncDatabaseNotesCommand.php @@ -0,0 +1,58 @@ +nodes() + ->where('is_file', true) + ->where('extension', 'md') + ->get(); + + foreach ($nodes as $node) { + $path = $getPathFromVaultNode->handle($node); + Storage::disk('local')->put($path, $node->content ?? ''); + } + } + } catch (Throwable) { + $this->error('Something went wrong syncing database notes to disk'); + + return self::FAILURE; + } + + $this->info('All notes were successfully synced to disk'); + + return self::SUCCESS; + } +}