Skip to content

Commit

Permalink
Added an event that reports files being deleted when calling the `sch…
Browse files Browse the repository at this point in the history
…ema:dump --prune` command
  • Loading branch information
andrey-helldar committed Dec 12, 2024
1 parent 32b95e9 commit 2472b49
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Illuminate/Database/Console/DumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Database\Connection;
use Illuminate\Database\ConnectionResolverInterface;
use Illuminate\Database\Events\SchemaDumped;
use Illuminate\Database\Events\SchemaPruned;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Facades\Config;
use Symfony\Component\Console\Attribute\AsCommand;
Expand Down Expand Up @@ -52,10 +53,12 @@ public function handle(ConnectionResolverInterface $connections, Dispatcher $dis

if ($this->option('prune')) {
(new Filesystem)->deleteDirectory(
database_path('migrations'), $preserve = false
$path = database_path('migrations'), $preserve = false
);

$info .= ' and pruned';

$dispatcher->dispatch(new SchemaPruned($connection, $path));
}

$this->components->info($info.' successfully.');
Expand Down
45 changes: 45 additions & 0 deletions src/Illuminate/Database/Events/SchemaPruned.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace Illuminate\Database\Events;

use Illuminate\Database\Connection;

class SchemaPruned
{
/**
* The database connection instance.
*
* @var \Illuminate\Database\Connection
*/
public Connection $connection;

/**
* The database connection name.
*
* @var string
*/
public ?string $connectionName;

/**
* Path to the deleted directory.
*
* @var string
*/
public string $path;

/**
* Create a new event instance.
*
* @param \Illuminate\Database\Connection $connection
* @param string $path
* @return void
*/
public function __construct(Connection $connection, string $path)
{
$this->connection = $connection;
$this->connectionName = $connection->getName();
$this->path = $path;
}
}

0 comments on commit 2472b49

Please sign in to comment.