Merge pull request #1761 from CachetHQ/cleanup-subscribers-component-deletions

When removing a component, clean up the subscriptions
This commit is contained in:
Graham Campbell
2016-05-06 14:12:39 +01:00
3 changed files with 42 additions and 2 deletions

View File

@@ -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();
}
}

View File

@@ -34,7 +34,7 @@ class EventServiceProvider extends ServiceProvider
//
],
'CachetHQ\Cachet\Bus\Events\Component\ComponentWasRemovedEvent' => [
//
'CachetHQ\Cachet\Bus\Handlers\Events\Component\CleanupComponentSubscriptionsHandler',
],
'CachetHQ\Cachet\Bus\Events\Component\ComponentWasUpdatedEvent' => [
'CachetHQ\Cachet\Bus\Handlers\Events\Component\SendComponentUpdateEmailNotificationHandler',

View File

@@ -18,7 +18,7 @@ class ComponentWasRemovedEventTest extends AbstractComponentEventTestCase
{
protected function objectHasHandlers()
{
return false;
return true;
}
protected function getObjectAndParams()