-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from digitalrisks/reset
Add command to reset
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace DigitalRisks\LaravelEventStore\Console\Commands; | ||
|
||
use DigitalRisks\LaravelEventStore\Client; | ||
use Illuminate\Console\Command; | ||
use GuzzleHttp\Exception\ClientException; | ||
|
||
class EventStoreReset extends Command | ||
{ | ||
protected $signature = 'eventstore:reset'; | ||
|
||
protected $description = 'Wipe the database and recreate the persistent subscriptions.'; | ||
protected $client; | ||
|
||
public function __construct(Client $client) | ||
{ | ||
$this->client = $client; | ||
|
||
parent::__construct(); | ||
} | ||
|
||
public function handle() | ||
{ | ||
if (! $this->confirm('Please stop all workers first. Continue?')) return; | ||
|
||
$this->call('migrate:fresh'); | ||
|
||
$streams = collect(config('eventstore.subscription_streams')); | ||
|
||
$streams->map([$this, 'deleteSubscription']); | ||
$streams->map([$this, 'createSubscription']); | ||
} | ||
|
||
public function deleteSubscription($stream) | ||
{ | ||
$name = config('eventstore.group'); | ||
|
||
try { | ||
$this->client->delete("/subscriptions/{$stream}/{$name}"); | ||
} | ||
catch (ClientException $e) { | ||
throw_if($e->getCode() !== 404, $e); | ||
} | ||
} | ||
|
||
public function createSubscription($stream) | ||
{ | ||
$name = config('eventstore.group'); | ||
|
||
$this->client->put("/subscriptions/{$stream}/{$name}"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters