-
Notifications
You must be signed in to change notification settings - Fork 0
/
LibEvent.php
54 lines (45 loc) · 1.44 KB
/
LibEvent.php
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/*
* This file is part of the Lib
*
* Copyright (C) 2017 pineray
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Plugin\Lib;
use Eccube\Application;
use Eccube\Event\EventArgs;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
class LibEvent
{
/** @var \Eccube\Application $app */
private $app;
public function __construct(\Eccube\Application $app)
{
$this->app = $app;
}
public function onFrontResponse(FilterResponseEvent $event)
{
$cron_interval = $this->app['plugin.lib.service.state']->get('plugin.lib.cron_interval', 0);
if ($cron_interval > 0) {
$cron_last = $this->app['plugin.lib.service.state']->get('plugin.lib.cron_last', null);
if ($cron_last === null) {
$this->app['plugin.lib.service.cron']->run();
}
else {
$last_timestamp = $cron_last->getTimestamp();
$now = new \DateTime();
$now_timestamp = $now->getTimestamp();
if ($now_timestamp >= $last_timestamp + $cron_interval) {
$this->app['plugin.lib.service.cron']->run();
}
}
}
}
public function onCronRun()
{
// Clean up any garbage in the queue service.
$this->app['plugin.lib.repository.Queue']->garbageCollection();
}
}