Only send component change email when the status changes. Fixes #1989
This commit is contained in:
@@ -0,0 +1,59 @@
|
|||||||
|
<?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\Events\Component;
|
||||||
|
|
||||||
|
use CachetHQ\Cachet\Models\Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the component status was updated event.
|
||||||
|
*
|
||||||
|
* @author James Brooks <james@alt-three.com>
|
||||||
|
*/
|
||||||
|
final class ComponentStatusWasUpdatedEvent implements ComponentEventInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The component that was updated.
|
||||||
|
*
|
||||||
|
* @var \CachetHQ\Cachet\Models\Component
|
||||||
|
*/
|
||||||
|
public $component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The original status of the component.
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
public $original_status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The new status of the component.
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
public $new_status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new component was updated event instance.
|
||||||
|
*
|
||||||
|
* @param \CachetHQ\Cachet\Models\Component $component
|
||||||
|
* @param int $original_status
|
||||||
|
* @param int $new_status
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(Component $component, $original_status, $new_status)
|
||||||
|
{
|
||||||
|
$this->component = $component;
|
||||||
|
$this->original_status = $original_status;
|
||||||
|
$this->new_status = $new_status;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,6 +12,7 @@
|
|||||||
namespace CachetHQ\Cachet\Bus\Handlers\Commands\Component;
|
namespace CachetHQ\Cachet\Bus\Handlers\Commands\Component;
|
||||||
|
|
||||||
use CachetHQ\Cachet\Bus\Commands\Component\UpdateComponentCommand;
|
use CachetHQ\Cachet\Bus\Commands\Component\UpdateComponentCommand;
|
||||||
|
use CachetHQ\Cachet\Bus\Events\Component\ComponentStatusWasUpdatedEvent;
|
||||||
use CachetHQ\Cachet\Bus\Events\Component\ComponentWasUpdatedEvent;
|
use CachetHQ\Cachet\Bus\Events\Component\ComponentWasUpdatedEvent;
|
||||||
use CachetHQ\Cachet\Models\Component;
|
use CachetHQ\Cachet\Models\Component;
|
||||||
|
|
||||||
@@ -28,6 +29,10 @@ class UpdateComponentCommandHandler
|
|||||||
{
|
{
|
||||||
$component = $command->component;
|
$component = $command->component;
|
||||||
|
|
||||||
|
if ($command->status && $component->status !== $command->status) {
|
||||||
|
event(new ComponentStatusWasUpdatedEvent($component, $component->status, $command->status));
|
||||||
|
}
|
||||||
|
|
||||||
$component->update($this->filter($command));
|
$component->update($this->filter($command));
|
||||||
|
|
||||||
event(new ComponentWasUpdatedEvent($component));
|
event(new ComponentWasUpdatedEvent($component));
|
||||||
|
|||||||
@@ -36,6 +36,9 @@ class EventServiceProvider extends ServiceProvider
|
|||||||
'CachetHQ\Cachet\Bus\Events\ComponentGroup\ComponentGroupWasUpdatedEvent' => [
|
'CachetHQ\Cachet\Bus\Events\ComponentGroup\ComponentGroupWasUpdatedEvent' => [
|
||||||
//
|
//
|
||||||
],
|
],
|
||||||
|
'CachetHQ\Cachet\Bus\Events\Component\ComponentStatusWasUpdatedEvent' => [
|
||||||
|
'CachetHQ\Cachet\Bus\Handlers\Events\Component\SendComponentUpdateEmailNotificationHandler',
|
||||||
|
],
|
||||||
'CachetHQ\Cachet\Bus\Events\Component\ComponentWasAddedEvent' => [
|
'CachetHQ\Cachet\Bus\Events\Component\ComponentWasAddedEvent' => [
|
||||||
//
|
//
|
||||||
],
|
],
|
||||||
@@ -43,7 +46,7 @@ class EventServiceProvider extends ServiceProvider
|
|||||||
'CachetHQ\Cachet\Bus\Handlers\Events\Component\CleanupComponentSubscriptionsHandler',
|
'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\Events\Incident\IncidentWasRemovedEvent' => [
|
'CachetHQ\Cachet\Bus\Events\Incident\IncidentWasRemovedEvent' => [
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<?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\Tests\Cachet\Bus\Events\Component;
|
||||||
|
|
||||||
|
use CachetHQ\Cachet\Bus\Events\Component\ComponentStatusWasUpdatedEvent;
|
||||||
|
use CachetHQ\Cachet\Models\Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the component status was updated event test.
|
||||||
|
*
|
||||||
|
* @author James Brooks <james@alt-three.com>
|
||||||
|
*/
|
||||||
|
class ComponentStatusWasUpdatedEventTest extends AbstractComponentEventTestCase
|
||||||
|
{
|
||||||
|
protected function objectHasHandlers()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getObjectAndParams()
|
||||||
|
{
|
||||||
|
$params = ['component' => new Component(), 'original_status' => 1, 'new_status' => 1];
|
||||||
|
$object = new ComponentStatusWasUpdatedEvent($params['component'], $params['original_status'], $params['new_status']);
|
||||||
|
|
||||||
|
return compact('params', 'object');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,7 +18,7 @@ class ComponentWasUpdatedEventTest extends AbstractComponentEventTestCase
|
|||||||
{
|
{
|
||||||
protected function objectHasHandlers()
|
protected function objectHasHandlers()
|
||||||
{
|
{
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getObjectAndParams()
|
protected function getObjectAndParams()
|
||||||
|
|||||||
Reference in New Issue
Block a user