|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace OroCRM\Bundle\SalesBundle\Migrations\Schema\v1_22; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Schema\Schema; |
|
6
|
|
|
use Doctrine\DBAL\Types\Type; |
|
7
|
|
|
|
|
8
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
|
9
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
10
|
|
|
|
|
11
|
|
|
use Oro\Bundle\MigrationBundle\Migration\OrderedMigrationInterface; |
|
12
|
|
|
use Oro\Bundle\EntityExtendBundle\Migration\Extension\ExtendExtension; |
|
13
|
|
|
use Oro\Bundle\EntityExtendBundle\Migration\Extension\ExtendExtensionAwareInterface; |
|
14
|
|
|
use Oro\Bundle\EntityExtendBundle\EntityConfig\ExtendScope; |
|
15
|
|
|
use Oro\Bundle\MigrationBundle\Migration\Migration; |
|
16
|
|
|
use Oro\Bundle\MigrationBundle\Migration\ParametrizedSqlMigrationQuery; |
|
17
|
|
|
use Oro\Bundle\MigrationBundle\Migration\QueryBag; |
|
18
|
|
|
use Oro\Bundle\EntityBundle\EntityConfig\DatagridScope; |
|
19
|
|
|
use Oro\Bundle\EntityExtendBundle\Migration\OroOptions; |
|
20
|
|
|
use Oro\Bundle\EntityExtendBundle\Migration\ExtendOptionsManager; |
|
21
|
|
|
|
|
22
|
|
|
use OroCRM\Bundle\SalesBundle\Entity\Opportunity; |
|
23
|
|
|
|
|
24
|
|
|
class AddOpportunityStatus implements |
|
25
|
|
|
Migration, |
|
26
|
|
|
ExtendExtensionAwareInterface, |
|
27
|
|
|
ContainerAwareInterface, |
|
28
|
|
|
OrderedMigrationInterface |
|
29
|
|
|
{ |
|
30
|
|
|
/** @var ContainerInterface */ |
|
31
|
|
|
protected $container; |
|
32
|
|
|
|
|
33
|
|
|
/** @var ExtendExtension */ |
|
34
|
|
|
protected $extendExtension; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* {@inheritdoc} |
|
38
|
|
|
*/ |
|
39
|
|
|
public function getOrder() |
|
40
|
|
|
{ |
|
41
|
|
|
return 1; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param ExtendExtension $extendExtension |
|
46
|
|
|
*/ |
|
47
|
|
|
public function setExtendExtension(ExtendExtension $extendExtension) |
|
48
|
|
|
{ |
|
49
|
|
|
$this->extendExtension = $extendExtension; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* {@inheritdoc} |
|
54
|
|
|
*/ |
|
55
|
|
|
public function setContainer(ContainerInterface $container = null) |
|
56
|
|
|
{ |
|
57
|
|
|
$this->container = $container; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* {@inheritdoc} |
|
62
|
|
|
*/ |
|
63
|
|
|
public function up(Schema $schema, QueryBag $queries) |
|
64
|
|
|
{ |
|
65
|
|
|
/** @var ExtendOptionsManager $extendOptionsManager */ |
|
66
|
|
|
$extendOptionsManager = $this->container->get('oro_entity_extend.migration.options_manager'); |
|
67
|
|
|
$extendOptionsManager->removeColumnOptions('orocrm_sales_opportunity', 'status'); |
|
68
|
|
|
self::addStatusField($schema, $this->extendExtension, $queries); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param Schema $schema |
|
73
|
|
|
* @param ExtendExtension $extendExtension |
|
74
|
|
|
* @param QueryBag $queries |
|
75
|
|
|
*/ |
|
76
|
|
|
public static function addStatusField(Schema $schema, ExtendExtension $extendExtension, QueryBag $queries) |
|
77
|
|
|
{ |
|
78
|
|
|
$enumTable = $extendExtension->addEnumField( |
|
79
|
|
|
$schema, |
|
80
|
|
|
'orocrm_sales_opportunity', |
|
81
|
|
|
'status', |
|
82
|
|
|
Opportunity::INTERNAL_STATUS_CODE, |
|
83
|
|
|
false, |
|
84
|
|
|
false, |
|
85
|
|
|
[ |
|
86
|
|
|
'extend' => ['owner' => ExtendScope::OWNER_SYSTEM], |
|
87
|
|
|
'datagrid' => ['is_visible' => DatagridScope::IS_VISIBLE_TRUE], |
|
88
|
|
|
'dataaudit' => ['auditable' => true], |
|
89
|
|
|
'importexport' => ["order" => 90, "short" => true] |
|
90
|
|
|
] |
|
91
|
|
|
); |
|
92
|
|
|
|
|
93
|
|
|
$options = new OroOptions(); |
|
94
|
|
|
$options->set( |
|
95
|
|
|
'enum', |
|
96
|
|
|
'immutable_codes', |
|
97
|
|
|
[ |
|
98
|
|
|
'in_progress', |
|
99
|
|
|
'won', |
|
100
|
|
|
'lost' |
|
101
|
|
|
] |
|
102
|
|
|
); |
|
103
|
|
|
|
|
104
|
|
|
$enumTable->addOption(OroOptions::KEY, $options); |
|
|
|
|
|
|
105
|
|
|
$statuses = [ |
|
106
|
|
|
'identification_alignment' => 'Identification & Alignment', |
|
107
|
|
|
'needs_analysis' => 'Needs Analysis', |
|
108
|
|
|
'solution_development' => 'Solution Development', |
|
109
|
|
|
'negotiation' => 'Negotiation', |
|
110
|
|
|
'in_progress' => 'In Progress', |
|
111
|
|
|
'won' => 'Closed Won', |
|
112
|
|
|
'lost' => 'Closed Lost' |
|
113
|
|
|
]; |
|
114
|
|
|
$defaultValue = 'in_progress'; |
|
115
|
|
|
$query = 'INSERT INTO oro_enum_opportunity_status (id, name, priority, is_default) |
|
116
|
|
|
VALUES (:id, :name, :priority, :is_default)'; |
|
117
|
|
|
$i = 1; |
|
118
|
|
|
foreach ($statuses as $key => $value) { |
|
119
|
|
|
$dropFieldsQuery = new ParametrizedSqlMigrationQuery(); |
|
120
|
|
|
$dropFieldsQuery->addSql( |
|
121
|
|
|
$query, |
|
122
|
|
|
['id' => $key, 'name' => $value, 'priority' => $i, 'is_default' => $defaultValue === $key], |
|
123
|
|
|
[ |
|
124
|
|
|
'id' => Type::STRING, |
|
125
|
|
|
'name' => Type::STRING, |
|
126
|
|
|
'priority' => Type::INTEGER, |
|
127
|
|
|
'is_default' => Type::BOOLEAN |
|
128
|
|
|
] |
|
129
|
|
|
); |
|
130
|
|
|
$queries->addQuery($dropFieldsQuery); |
|
131
|
|
|
$i++; |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: