-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Todo reminder notification #73
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a0208f7
Added a mechanism that sends reminder notifications to the todos assi…
rommsen 52b9179
Added a subscriber that listens to TodoAssigneeWasReminded events and…
rommsen d31b22b
Added distinct read model for TodoReminders.
rommsen 37523b5
Wrapped the events in an ArrayIterator to comply with type hints of c…
rommsen 7a86383
Added docblocks and final
rommsen d193a42
todo_id is not belonging to the payload because it is the aggregate_i…
rommsen a424296
Using Zend\Mail for sending actual mails
rommsen 728001b
Renamed smtp_connection.local.php.dist to mail_connection.local.php.dist
rommsen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,20 @@ | ||
<?php | ||
return [ | ||
'proophessor-do' => [ | ||
'mail' => [ | ||
'transport' => 'in_memory', // smtp or in_memory (default) | ||
// uncomment if you want to use smtp. Preset for gmail | ||
// 'smtp' => [ | ||
// 'name' => 'gmail.com', | ||
// 'host' => 'smtp.gmail.com', | ||
// 'port' => 587, | ||
// 'connection_class' => 'plain', | ||
// 'connection_config' => [ | ||
// 'username' => 'YOUR_USERNAME_HERE', | ||
// 'password' => 'YOUR_PASSWORD_HERE', | ||
// 'ssl' => 'tls', | ||
// ], | ||
// ], | ||
] | ||
] | ||
]; |
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
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,28 @@ | ||
<?php | ||
|
||
namespace Prooph\ProophessorDo\Migrations; | ||
|
||
use Doctrine\DBAL\Migrations\AbstractMigration; | ||
use Doctrine\DBAL\Schema\Schema; | ||
use Prooph\ProophessorDo\Projection\Table; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your needs! | ||
*/ | ||
class Version20160308110616 extends AbstractMigration | ||
{ | ||
public function up(Schema $schema) | ||
{ | ||
$user = $schema->createTable(Table::TODO_REMINDER); | ||
|
||
$user->addColumn('todo_id', 'string', ['length' => 36]); | ||
$user->addColumn('reminder', 'string', ['length' => 30]); | ||
$user->addColumn('status', 'string', ['length' => 10]); | ||
$user->setPrimaryKey(['todo_id']); | ||
} | ||
|
||
public function down(Schema $schema) | ||
{ | ||
$schema->dropTable(Table::TODO_REMINDER); | ||
} | ||
} |
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,39 @@ | ||
<?php | ||
/** | ||
* This script looks for todos with open reminders and reminds the assignees | ||
*/ | ||
namespace { | ||
|
||
use Prooph\ProophessorDo\Model\Todo\Command\RemindTodoAssignee; | ||
use Prooph\ProophessorDo\Model\Todo\TodoId; | ||
use Prooph\ProophessorDo\Model\Todo\TodoReminder; | ||
use Prooph\ProophessorDo\Projection\Todo\TodoReminderFinder; | ||
use Prooph\ServiceBus\CommandBus; | ||
|
||
chdir(dirname(__DIR__)); | ||
|
||
// Setup autoloading | ||
require 'vendor/autoload.php'; | ||
|
||
$container = require 'config/container.php'; | ||
|
||
$commandBus = $container->get(CommandBus::class); | ||
$todoReminderFinder = $container->get(TodoReminderFinder::class); | ||
|
||
$todoReminder = $todoReminderFinder->findOpen(); | ||
|
||
if (!$todoReminder) { | ||
echo "Nothing to do. Exiting.\n"; | ||
exit; | ||
} | ||
|
||
foreach ($todoReminder as $reminder) { | ||
echo "Send reminder for Todo with id {$reminder->todo_id}.\n"; | ||
$commandBus->dispatch( | ||
RemindTodoAssignee::forTodo( | ||
TodoId::fromString($reminder->todo_id), TodoReminder::fromString($reminder->reminder, $reminder->status) | ||
)); | ||
} | ||
|
||
echo "Done!\n"; | ||
} |
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,59 @@ | ||
<?php | ||
namespace Prooph\ProophessorDo\App\Mail; | ||
|
||
use Prooph\ProophessorDo\Model\Todo\Event\TodoAssigneeWasReminded; | ||
use Prooph\ProophessorDo\Projection\Todo\TodoFinder; | ||
use Prooph\ProophessorDo\Projection\User\UserFinder; | ||
use Zend\Mail\Transport\TransportInterface; | ||
use Zend\Mail; | ||
|
||
/** | ||
* Class SendTodoReminderMailSubscriber | ||
* | ||
* @package Prooph\ProophessorDo\App\Mail | ||
* @author Roman Sachse <[email protected]> | ||
*/ | ||
final class SendTodoReminderMailSubscriber | ||
{ | ||
/** | ||
* @var UserFinder | ||
*/ | ||
private $userFinder; | ||
/** | ||
* @var TodoFinder | ||
*/ | ||
private $todoFinder; | ||
/** | ||
* @var TransportInterface | ||
*/ | ||
private $mailer; | ||
|
||
/** | ||
* @param UserFinder $userFinder | ||
* @param TodoFinder $todoFinder | ||
* @param TransportInterface $mailer | ||
*/ | ||
public function __construct(UserFinder $userFinder, TodoFinder $todoFinder, TransportInterface $mailer) | ||
{ | ||
$this->userFinder = $userFinder; | ||
$this->todoFinder = $todoFinder; | ||
$this->mailer = $mailer; | ||
} | ||
|
||
/** | ||
* @param TodoAssigneeWasReminded $event | ||
*/ | ||
public function __invoke(TodoAssigneeWasReminded $event) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. phpdoc missing |
||
{ | ||
$user = $this->userFinder->findById($event->userId()->toString()); | ||
$todo = $this->todoFinder->findById($event->todoId()->toString()); | ||
|
||
$mail = new Mail\Message(); | ||
$mail->setBody("Hello {$user->name}. This a reminder for '{$todo->text}'. Don't be lazy!"); | ||
$mail->setFrom('[email protected]', 'Proophessor-do'); | ||
$mail->addTo($user->email, $user->name); | ||
$mail->setSubject('Proophessor-do Todo Reminder'); | ||
|
||
$this->mailer->send($mail); | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
src/Container/App/Mail/SendTodoReminderMailSubscriberFactory.php
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,95 @@ | ||
<?php | ||
|
||
namespace Prooph\ProophessorDo\Container\App\Mail; | ||
|
||
use Interop\Config\ConfigurationTrait; | ||
use Interop\Config\ProvidesDefaultOptions; | ||
use Interop\Config\RequiresConfig; | ||
use Interop\Config\RequiresMandatoryOptions; | ||
use Interop\Container\ContainerInterface; | ||
use Prooph\ProophessorDo\App\Mail\SendTodoReminderMailSubscriber; | ||
use Prooph\ProophessorDo\Projection\Todo\TodoFinder; | ||
use Prooph\ProophessorDo\Projection\User\UserFinder; | ||
use Zend\Mail\Transport\InMemory as InMemoryTransport; | ||
use Zend\Mail\Transport\Smtp as SmtpTransport; | ||
use Zend\Mail\Transport\SmtpOptions; | ||
|
||
|
||
/** | ||
* Class RemindTodoAssigneeHandlerFactory | ||
* | ||
* @package Prooph\ProophessorDo\Container\Model\Todo | ||
* @author Roman Sachse <[email protected]> | ||
*/ | ||
final class SendTodoReminderMailSubscriberFactory implements RequiresConfig, RequiresMandatoryOptions, ProvidesDefaultOptions | ||
{ | ||
use ConfigurationTrait; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function vendorName() | ||
{ | ||
return 'proophessor-do'; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function packageName() | ||
{ | ||
return 'mail'; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function mandatoryOptions() | ||
{ | ||
return ['transport']; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function defaultOptions() | ||
{ | ||
return ['transport' => 'in_memory']; | ||
} | ||
|
||
/** | ||
* @param ContainerInterface $container | ||
* @return SendTodoReminderMailSubscriber | ||
*/ | ||
public function __invoke(ContainerInterface $container) | ||
{ | ||
return new SendTodoReminderMailSubscriber( | ||
$container->get(UserFinder::class), | ||
$container->get(TodoFinder::class), | ||
$this->getTransport($container->get('config')) | ||
); | ||
} | ||
|
||
/** | ||
* @param $config | ||
* @return SmtpTransport | ||
*/ | ||
private function getTransport($config) | ||
{ | ||
$config = $this->optionsWithFallback($config); | ||
|
||
switch ($config['transport']) { | ||
case 'in_memory': | ||
return new InMemoryTransport(); | ||
|
||
case 'smtp': | ||
$transport = new SmtpTransport(); | ||
$transport->setOptions(new SmtpOptions($config['smtp'])); | ||
|
||
return $transport; | ||
} | ||
throw new \InvalidArgumentException( | ||
"Transport of type '{$config['transport']}' not known (use in_memory or smtp)" | ||
); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/Container/Model/Todo/RemindTodoAssigneeHandlerFactory.php
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,26 @@ | ||
<?php | ||
|
||
namespace Prooph\ProophessorDo\Container\Model\Todo; | ||
|
||
use Interop\Container\ContainerInterface; | ||
use Prooph\ProophessorDo\Model\Todo\Handler\RemindTodoAssigneeHandler; | ||
use Prooph\ProophessorDo\Model\Todo\TodoList; | ||
use Prooph\ProophessorDo\Projection\Todo\TodoFinder; | ||
|
||
/** | ||
* Class RemindTodoAssigneeHandlerFactory | ||
* | ||
* @package Prooph\ProophessorDo\Container\Model\Todo | ||
* @author Roman Sachse <[email protected]> | ||
*/ | ||
final class RemindTodoAssigneeHandlerFactory | ||
{ | ||
/** | ||
* @param ContainerInterface $container | ||
* @return RemindTodoAssigneeHandlerFactory | ||
*/ | ||
public function __invoke(ContainerInterface $container) | ||
{ | ||
return new RemindTodoAssigneeHandler($container->get(TodoList::class), $container->get(TodoFinder::class)); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/Container/Projection/Todo/TodoReminderFinderFactory.php
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,32 @@ | ||
<?php | ||
/* | ||
* This file is part of prooph/proophessor. | ||
* (c) 2014-2015 prooph software GmbH <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* Date: 5/4/15 - 8:53 PM | ||
*/ | ||
namespace Prooph\ProophessorDo\Container\Projection\Todo; | ||
|
||
use Interop\Container\ContainerInterface; | ||
use Prooph\ProophessorDo\Projection\Todo\TodoReminderFinder; | ||
|
||
/** | ||
* Class TodoFinderFactory | ||
* | ||
* @package Prooph\ProophessorDo\Projection\Todo | ||
* @author Roman Sachse <[email protected]> | ||
*/ | ||
final class TodoReminderFinderFactory | ||
{ | ||
/** | ||
* @param ContainerInterface $container | ||
* @return TodoReminderFinder | ||
*/ | ||
public function __invoke(ContainerInterface $container) | ||
{ | ||
return new TodoReminderFinder($container->get('doctrine.connection.default')); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should have proophessor-do namespace, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just tried to match the other scripts in the folder. Dont mind adding the namespace