1 | <?php |
||
21 | class MessageManager extends BaseEntityManager implements MessageManagerInterface |
||
22 | { |
||
23 | /** |
||
24 | * {@inheritdoc} |
||
25 | */ |
||
26 | public function save($message, $andFlush = true) |
||
27 | { |
||
28 | //Hack for ConsumerHandlerCommand->optimize() |
||
29 | if ($message->getId() && !$this->em->getUnitOfWork()->isInIdentityMap($message)) { |
||
|
|||
30 | $message = $this->getEntityManager()->getUnitOfWork()->merge($message); |
||
31 | } |
||
32 | |||
33 | parent::save($message, $andFlush); |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * {@inheritdoc} |
||
38 | */ |
||
39 | public function findByTypes(array $types, $state, $batchSize) |
||
40 | { |
||
41 | $params = array(); |
||
42 | $query = $this->prepareStateQuery($state, $types, $batchSize, $params); |
||
43 | |||
44 | $query->setParameters($params); |
||
45 | |||
46 | return $query->getQuery()->execute(); |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * {@inheritdoc} |
||
51 | */ |
||
52 | public function findByAttempts(array $types, $state, $batchSize, $maxAttempts = null, $attemptDelay = 10) |
||
53 | { |
||
54 | $params = array(); |
||
55 | $query = $this->prepareStateQuery($state, $types, $batchSize, $params); |
||
56 | |||
57 | if ($maxAttempts) { |
||
58 | $query |
||
59 | ->andWhere('m.restartCount < :maxAttempts') |
||
60 | ->andWhere('m.updatedAt < :delayDate'); |
||
61 | |||
62 | $params['maxAttempts'] = $maxAttempts; |
||
63 | $now = new \DateTime(); |
||
64 | $params['delayDate'] = $now->add(\DateInterval::createFromDateString(($attemptDelay * -1).' second')); |
||
65 | } |
||
66 | |||
67 | $query->setParameters($params); |
||
68 | |||
69 | return $query->getQuery()->execute(); |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * {@inheritdoc} |
||
74 | */ |
||
75 | public function countStates() |
||
76 | { |
||
77 | $tableName = $this->getEntityManager()->getClassMetadata($this->class)->table['name']; |
||
78 | |||
79 | $stm = $this->getConnection()->query(sprintf('SELECT state, count(state) as cnt FROM %s GROUP BY state', $tableName)); |
||
80 | |||
81 | $states = array( |
||
82 | MessageInterface::STATE_DONE => 0, |
||
83 | MessageInterface::STATE_ERROR => 0, |
||
84 | MessageInterface::STATE_IN_PROGRESS => 0, |
||
85 | MessageInterface::STATE_OPEN => 0, |
||
86 | ); |
||
87 | |||
88 | foreach ($stm->fetch() as $data) { |
||
89 | $states[$data['state']] = $data['cnt']; |
||
90 | } |
||
91 | |||
92 | return $states; |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * {@inheritdoc} |
||
97 | */ |
||
98 | public function cleanup($maxAge) |
||
99 | { |
||
100 | $tableName = $this->getEntityManager()->getClassMetadata($this->class)->table['name']; |
||
101 | |||
102 | $date = new \DateTime('now'); |
||
103 | $date->sub(new \DateInterval(sprintf('PT%sS', $maxAge))); |
||
104 | |||
105 | $qb = $this->getRepository()->createQueryBuilder('message') |
||
106 | ->delete() |
||
107 | ->where('message.state = :state') |
||
108 | ->andWhere('message.completedAt < :date') |
||
109 | ->setParameter('state', MessageInterface::STATE_DONE) |
||
110 | ->setParameter('date', $date); |
||
111 | |||
112 | $qb->getQuery()->execute(); |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * {@inheritdoc} |
||
117 | */ |
||
118 | public function cancel(MessageInterface $message, $force = false) |
||
128 | |||
129 | /** |
||
130 | * {@inheritdoc} |
||
131 | */ |
||
132 | public function restart(MessageInterface $message) |
||
146 | |||
147 | /** |
||
148 | * @param int $state |
||
149 | * @param array $types |
||
150 | * @param int $batchSize |
||
151 | * @param array $parameters |
||
152 | * |
||
153 | * @return QueryBuilder |
||
154 | */ |
||
155 | protected function prepareStateQuery($state, $types, $batchSize, &$parameters) |
||
185 | |||
186 | /** |
||
187 | * {@inheritdoc} |
||
188 | */ |
||
189 | public function getPager(array $criteria, $page, $limit = 10, array $sort = array()) |
||
230 | } |
||
231 |
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.