When removing a component, clean up the subscriptions. Closes #1739
This commit is contained in:
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Cachet.
|
||||||
|
*
|
||||||
|
* (c) Alt Three Services Limited
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace CachetHQ\Cachet\Bus\Handlers\Events\Component;
|
||||||
|
|
||||||
|
use CachetHQ\Cachet\Bus\Events\Component\ComponentWasRemovedEvent;
|
||||||
|
use CachetHQ\Cachet\Models\Component;
|
||||||
|
use CachetHQ\Cachet\Models\Subscription;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the cleanup component subscriptions handler.
|
||||||
|
*
|
||||||
|
* @author James Brooks <james@alt-three.com>
|
||||||
|
*/
|
||||||
|
class CleanupComponentSubscriptionsHandler
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle the event.
|
||||||
|
*
|
||||||
|
* @param \CachetHQ\Cachet\Bus\Events\Component\ComponentWasRemovedEvent $event
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle(ComponentWasRemovedEvent $event)
|
||||||
|
{
|
||||||
|
$component = $event->component;
|
||||||
|
$subscription = Subscription::forComponent($component->id);
|
||||||
|
|
||||||
|
// Cleanup the subscriptions.
|
||||||
|
$subscription->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -34,7 +34,7 @@ class EventServiceProvider extends ServiceProvider
|
|||||||
//
|
//
|
||||||
],
|
],
|
||||||
'CachetHQ\Cachet\Bus\Events\Component\ComponentWasRemovedEvent' => [
|
'CachetHQ\Cachet\Bus\Events\Component\ComponentWasRemovedEvent' => [
|
||||||
//
|
'CachetHQ\Cachet\Bus\Handlers\Events\Component\CleanupComponentSubscriptionsHandler',
|
||||||
],
|
],
|
||||||
'CachetHQ\Cachet\Bus\Events\Component\ComponentWasUpdatedEvent' => [
|
'CachetHQ\Cachet\Bus\Events\Component\ComponentWasUpdatedEvent' => [
|
||||||
'CachetHQ\Cachet\Bus\Handlers\Events\Component\SendComponentUpdateEmailNotificationHandler',
|
'CachetHQ\Cachet\Bus\Handlers\Events\Component\SendComponentUpdateEmailNotificationHandler',
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ class ComponentWasRemovedEventTest extends AbstractComponentEventTestCase
|
|||||||
{
|
{
|
||||||
protected function objectHasHandlers()
|
protected function objectHasHandlers()
|
||||||
{
|
{
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getObjectAndParams()
|
protected function getObjectAndParams()
|
||||||
|
|||||||
Reference in New Issue
Block a user