|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace TreeHouse\IoBundle\Import; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Bridge\Doctrine\RegistryInterface; |
|
6
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
7
|
|
|
use TreeHouse\IoBundle\Entity\Feed; |
|
8
|
|
|
use TreeHouse\IoBundle\Entity\ImportRepository; |
|
9
|
|
|
use TreeHouse\IoBundle\Import\Event\ImportEvent; |
|
10
|
|
|
|
|
11
|
|
|
class ImportRotator |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var RegistryInterface |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $doctrine; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var EventDispatcherInterface |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $eventDispatcher; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @param RegistryInterface $doctrine |
|
25
|
|
|
* @param EventDispatcherInterface $dispatcher |
|
26
|
|
|
*/ |
|
27
|
|
|
public function __construct(RegistryInterface $doctrine, EventDispatcherInterface $dispatcher) |
|
28
|
|
|
{ |
|
29
|
|
|
$this->doctrine = $doctrine; |
|
30
|
|
|
$this->eventDispatcher = $dispatcher; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @return EventDispatcherInterface |
|
35
|
|
|
*/ |
|
36
|
|
|
public function getEventDispatcher() |
|
37
|
|
|
{ |
|
38
|
|
|
return $this->eventDispatcher; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Rotates imported feeds. |
|
43
|
|
|
* |
|
44
|
|
|
* @param Feed $feed The feed to rotate imports for |
|
45
|
|
|
* @param int $max The number of imports to keep |
|
46
|
|
|
*/ |
|
47
|
|
|
public function rotate(Feed $feed, $max = 4) |
|
48
|
|
|
{ |
|
49
|
|
|
/** @var ImportRepository $repo */ |
|
50
|
|
|
$repo = $this->doctrine->getRepository('TreeHouseIoBundle:Import'); |
|
51
|
|
|
$imports = $repo->findCompletedByFeed($feed); |
|
52
|
|
|
|
|
53
|
|
|
if (sizeof($imports) <= $max) { |
|
54
|
|
|
return; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$manager = $this->doctrine->getManager(); |
|
58
|
|
|
foreach (array_slice($imports, $max) as $import) { |
|
59
|
|
|
$this->eventDispatcher->dispatch(ImportEvents::IMPORT_ROTATE, new ImportEvent($import)); |
|
|
|
|
|
|
60
|
|
|
$manager->remove($import); |
|
61
|
|
|
$manager->flush(); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: