DataFixtureRepository::isDataFixtureExists()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 11
rs 9.4285
cc 2
eloc 8
nc 2
nop 2
1
<?php
2
3
namespace RDV\Bundle\MigrationBundle\Entity\Repository;
4
5
use Doctrine\ORM\EntityRepository;
6
7
class DataFixtureRepository extends EntityRepository
8
{
9
    /**
10
     * @param string $where
11
     * @param array  $parameters
12
     *
13
     * @return bool
14
     */
15
    public function isDataFixtureExists($where, array $parameters = [])
16
    {
17
        $entityId = $this->createQueryBuilder('m')
18
            ->select('m.id')
19
            ->where($where)
20
            ->setMaxResults(1)
21
            ->getQuery()
22
            ->execute($parameters);
23
24
        return $entityId ? true : false;
25
    }
26
27
    /**
28
     * Update data fixture history
29
     *
30
     * @param array  $updateFields assoc array with field names and values that should be updated
31
     * @param string $where        condition
32
     * @param array  $parameters   optional parameters for where condition
33
     */
34
    public function updateDataFixtureHistory(array $updateFields, $where, array $parameters = [])
35
    {
36
        $qb = $this->_em
37
            ->createQueryBuilder()
38
            ->update('RdvMigrationBundle:DataFixture', 'm')
39
            ->where($where);
40
41
        foreach ($updateFields as $fieldName => $fieldValue) {
42
            $qb->set($fieldName, $fieldValue);
43
        }
44
        $qb->getQuery()->execute($parameters);
45
    }
46
}
47