mirror of
https://github.com/brufdev/many-notes.git
synced 2026-01-23 11:29:45 -06:00
Add command to sync the database notes to the disk
This commit is contained in:
@@ -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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
58
app/Console/Commands/Upgrade/SyncDatabaseNotesCommand.php
Normal file
58
app/Console/Commands/Upgrade/SyncDatabaseNotesCommand.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Console\Commands\Upgrade;
|
||||
|
||||
use App\Actions\GetPathFromVaultNode;
|
||||
use App\Models\Vault;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Throwable;
|
||||
|
||||
final class SyncDatabaseNotesCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'upgrade:sync-database-notes';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Sync database notes to disk';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(GetPathFromVaultNode $getPathFromVaultNode): int
|
||||
{
|
||||
try {
|
||||
$vaults = Vault::all();
|
||||
|
||||
foreach ($vaults as $vault) {
|
||||
$nodes = $vault->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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user