Completed
Push — master ( cd8605...3b7290 )
by
unknown
09:46
created

LoadOpportunityStateData::getData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
namespace OroCRM\Bundle\SalesBundle\Migrations\Data\ORM;
4
5
use Doctrine\Common\Persistence\ObjectManager;
6
7
use Oro\Bundle\EntityExtendBundle\Migration\Fixture\AbstractEnumFixture;
8
9
use OroCRM\Bundle\SalesBundle\Entity\Opportunity;
10
11
class LoadOpportunityStateData extends AbstractEnumFixture
12
{
13
    /**
14
     * @var ObjectManager
15
     */
16
    protected $manager;
17
18
    /**
19
     * @var array
20
     */
21
    protected $statusMapping = [
22
        'won' => 'won',
23
        'lost' => 'lost',
24
        'in_progress' => 'solution_development'
25
    ];
26
27
    /**
28
     * @return array
29
     */
30
    protected function getData()
31
    {
32
        return [
33
            'identification_alignment' => 'Identification & Alignment',
34
            'needs_analysis' => 'Needs Analysis',
35
            'solution_development' => 'Solution Development',
36
            'negotiation' => 'Negotiation',
37
            'won' => 'Closed Won',
38
            'lost' => 'Closed Lost'
39
        ];
40
    }
41
42
    /**
43
     * @return string
44
     */
45
    protected function getEnumCode()
46
    {
47
        return Opportunity::INTERNAL_STATE_CODE;
48
    }
49
50
    /**
51
     * @param ObjectManager $manager
52
     */
53
    public function load(ObjectManager $manager)
54
    {
55
        $this->manager = $manager;
56
        $repository = $manager->getRepository('OroCRMSalesBundle:Opportunity');
57
        $connection = $repository->createQueryBuilder('o')->getEntityManager()->getConnection();
58
        $query = 'UPDATE orocrm_sales_opportunity SET state_id = ? WHERE status_name = ?';
59
        parent::load($manager);
60
61
        foreach ($this->statusMapping as $status => $state) {
62
            $connection->executeQuery($query, [$state, $status]);
63
        }
64
    }
65
}
66