Skip to content

Commit

Permalink
[11.x] Added an event that reports files being deleted when calling t…
Browse files Browse the repository at this point in the history
…he `schema:dump --prune` command (#53870)

* Added an event that reports files being deleted when calling the `schema:dump --prune` command

* Rename event classes to better reflect functionality and update usage accordingly

* formatting

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
andrey-helldar and taylorotwell authored Dec 14, 2024
1 parent 1671bdd commit 83c3855
Show file tree
Hide file tree
Showing 2 changed files with 47 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 @@ -6,6 +6,7 @@
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Database\Connection;
use Illuminate\Database\ConnectionResolverInterface;
use Illuminate\Database\Events\MigrationsPruned;
use Illuminate\Database\Events\SchemaDumped;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Facades\Config;
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 MigrationsPruned($connection, $path));
}

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

namespace Illuminate\Database\Events;

use Illuminate\Database\Connection;

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

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

/**
* The path to the directory where migrations were pruned.
*
* @var string
*/
public $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 83c3855

Please sign in to comment.