1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kunstmaan\NodeBundle\Repository; |
4
|
|
|
|
5
|
|
|
use Kunstmaan\AdminBundle\Entity\BaseUser; |
6
|
|
|
use Kunstmaan\NodeBundle\Entity\NodeTranslation; |
7
|
|
|
use Kunstmaan\NodeBundle\Entity\NodeVersionLock; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* NodeVersionLockRepository |
11
|
|
|
* |
12
|
|
|
* This class was generated by the Doctrine ORM. Add your own custom |
13
|
|
|
* repository methods below. |
14
|
|
|
*/ |
15
|
|
View Code Duplication |
class NodeVersionLockRepository extends \Doctrine\ORM\EntityRepository |
|
|
|
|
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Check if there is a nodetranslation lock that's not passed the 30 minute threshold. |
19
|
|
|
* |
20
|
|
|
* @param NodeTranslation $nodeTranslation |
21
|
|
|
* @param bool $isPublicVersion |
22
|
|
|
* @param int $threshold |
23
|
|
|
* @param BaseUser $userToExclude |
|
|
|
|
24
|
|
|
* |
25
|
|
|
* @return NodeVersionLock[] |
26
|
|
|
*/ |
27
|
|
|
public function getLocksForNodeTranslation(NodeTranslation $nodeTranslation, $isPublicVersion, $threshold, BaseUser $userToExclude = null) |
28
|
|
|
{ |
29
|
|
|
$qb = $this->createQueryBuilder('nvl') |
30
|
|
|
->select('nvl') |
31
|
|
|
->where('nvl.nodeTranslation = :nt') |
32
|
|
|
->andWhere('nvl.publicVersion = :pub') |
33
|
|
|
->andWhere('nvl.createdAt > :date') |
34
|
|
|
->setParameter('nt', $nodeTranslation) |
35
|
|
|
->setParameter('pub', $isPublicVersion) |
36
|
|
|
->setParameter('date', new \DateTime(sprintf('-%s seconds', $threshold))) |
37
|
|
|
; |
38
|
|
|
|
39
|
|
|
if (!\is_null($userToExclude)) { |
40
|
|
|
$qb->andWhere('nvl.owner <> :owner') |
41
|
|
|
->setParameter('owner', $userToExclude->getUsername()) |
42
|
|
|
; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
return $qb->getQuery()->getResult(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Get locks that are passed the threshold. |
50
|
|
|
* |
51
|
|
|
* @param NodeTranslation $nodeTranslation |
52
|
|
|
* @param int $threshold |
53
|
|
|
* |
54
|
|
|
* @return mixed |
55
|
|
|
*/ |
56
|
|
|
public function getExpiredLocks(NodeTranslation $nodeTranslation, $threshold) |
57
|
|
|
{ |
58
|
|
|
$qb = $this->createQueryBuilder('nvl') |
59
|
|
|
->select('nvl') |
60
|
|
|
->where('nvl.nodeTranslation = :nt') |
61
|
|
|
->andWhere('nvl.createdAt < :date') |
62
|
|
|
->setParameter('nt', $nodeTranslation) |
63
|
|
|
->setParameter('date', new \DateTime(sprintf('-%s seconds', $threshold))); |
64
|
|
|
|
65
|
|
|
return $qb->getQuery()->getResult(); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.