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

LoadOpportunityStateData   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 6
Bugs 0 Features 0
Metric Value
wmc 4
c 6
b 0
f 0
lcom 1
cbo 2
dl 0
loc 55
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getData() 0 11 1
A getEnumCode() 0 4 1
A load() 0 12 2
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