-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathPackage.php
More file actions
33 lines (28 loc) · 1.08 KB
/
Package.php
File metadata and controls
33 lines (28 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
namespace Flowpack\JobQueue\Common;
use Flowpack\JobQueue\Common\Job\JobManager;
use Flowpack\JobQueue\Common\Queue\Message;
use Flowpack\JobQueue\Common\Queue\QueueInterface;
use Neos\Flow\Core\Bootstrap;
use Neos\Flow\Package\Package as BasePackage;
use Neos\Flow\Persistence\PersistenceManagerInterface;
class Package extends BasePackage
{
/**
* @param Bootstrap $bootstrap The current bootstrap
* @return void
*/
public function boot(Bootstrap $bootstrap)
{
if (PHP_SAPI === 'cli') {
$dispatcher = $bootstrap->getSignalSlotDispatcher();
$dispatcher->connect(JobManager::class, 'messageFinished', function (QueueInterface $queue, Message $message) use ($bootstrap) {
/** @var PersistenceManagerInterface $persistenceManager */
$persistenceManager = $bootstrap->getObjectManager()->get(PersistenceManagerInterface::class);
if ($persistenceManager->hasUnpersistedChanges()) {
$persistenceManager->persistAll();
}
});
}
}
}