1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OroCRM\Bundle\SalesBundle\Migrations\Schema; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Schema\Schema; |
6
|
|
|
|
7
|
|
|
use Oro\Bundle\ActivityBundle\Migration\Extension\ActivityExtension; |
8
|
|
|
use Oro\Bundle\ActivityBundle\Migration\Extension\ActivityExtensionAwareInterface; |
9
|
|
|
use Oro\Bundle\ActivityListBundle\Migration\Extension\ActivityListExtension; |
10
|
|
|
use Oro\Bundle\ActivityListBundle\Migration\Extension\ActivityListExtensionAwareInterface; |
11
|
|
|
use Oro\Bundle\AttachmentBundle\Migration\Extension\AttachmentExtension; |
12
|
|
|
use Oro\Bundle\AttachmentBundle\Migration\Extension\AttachmentExtensionAwareInterface; |
13
|
|
|
use Oro\Bundle\EntityBundle\EntityConfig\DatagridScope; |
14
|
|
|
use Oro\Bundle\EntityExtendBundle\EntityConfig\ExtendScope; |
15
|
|
|
use Oro\Bundle\EntityExtendBundle\Migration\Extension\ExtendExtension; |
16
|
|
|
use Oro\Bundle\EntityExtendBundle\Migration\Extension\ExtendExtensionAwareInterface; |
17
|
|
|
use Oro\Bundle\MigrationBundle\Migration\Installation; |
18
|
|
|
use Oro\Bundle\MigrationBundle\Migration\QueryBag; |
19
|
|
|
use Oro\Bundle\MigrationBundle\Migration\Extension\RenameExtension; |
20
|
|
|
use Oro\Bundle\MigrationBundle\Migration\Extension\RenameExtensionAwareInterface; |
21
|
|
|
use Oro\Bundle\NoteBundle\Migration\Extension\NoteExtension; |
22
|
|
|
use Oro\Bundle\NoteBundle\Migration\Extension\NoteExtensionAwareInterface; |
23
|
|
|
|
24
|
|
|
use OroCRM\Bundle\SalesBundle\Migrations\Schema\v1_5\OroCRMSalesBundle as SalesNoteMigration; |
25
|
|
|
use OroCRM\Bundle\SalesBundle\Migrations\Schema\v1_7\OpportunityAttachment; |
26
|
|
|
use OroCRM\Bundle\SalesBundle\Migrations\Schema\v1_11\OroCRMSalesBundle as SalesOrganizations; |
27
|
|
|
use OroCRM\Bundle\SalesBundle\Migrations\Schema\v1_21\InheritanceActivityTargets; |
28
|
|
|
use OroCRM\Bundle\SalesBundle\Migrations\Schema\v1_24\InheritanceActivityTargets as OpportunityLeadInheritance; |
29
|
|
|
use OroCRM\Bundle\SalesBundle\Migrations\Schema\v1_22\AddOpportunityStatus; |
30
|
|
|
use OroCRM\Bundle\SalesBundle\Migrations\Schema\v1_24\AddLeadStatus; |
31
|
|
|
use OroCRM\Bundle\SalesBundle\Migrations\Schema\v1_25\AddLeadAddressTable; |
32
|
|
|
use OroCRM\Bundle\SalesBundle\Migrations\Schema\v1_27\AddMultiCurrencyFields; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @SuppressWarnings(PHPMD.TooManyMethods) |
36
|
|
|
* @SuppressWarnings(PHPMD.ExcessiveClassLength) |
37
|
|
|
*/ |
38
|
|
|
class OroCRMSalesBundleInstaller implements |
39
|
|
|
Installation, |
40
|
|
|
ExtendExtensionAwareInterface, |
41
|
|
|
NoteExtensionAwareInterface, |
42
|
|
|
ActivityExtensionAwareInterface, |
43
|
|
|
AttachmentExtensionAwareInterface, |
44
|
|
|
ActivityListExtensionAwareInterface, |
45
|
|
|
RenameExtensionAwareInterface |
46
|
|
|
{ |
47
|
|
|
/** @var ExtendExtension */ |
48
|
|
|
protected $extendExtension; |
49
|
|
|
|
50
|
|
|
/** @var NoteExtension */ |
51
|
|
|
protected $noteExtension; |
52
|
|
|
|
53
|
|
|
/** @var ActivityExtension */ |
54
|
|
|
protected $activityExtension; |
55
|
|
|
|
56
|
|
|
/** @var AttachmentExtension */ |
57
|
|
|
protected $attachmentExtension; |
58
|
|
|
|
59
|
|
|
/** @var ActivityListExtension */ |
60
|
|
|
protected $activityListExtension; |
61
|
|
|
|
62
|
|
|
/** @var RenameExtension */ |
63
|
|
|
protected $renameExtension; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* {@inheritdoc} |
67
|
|
|
*/ |
68
|
|
|
public function setActivityListExtension(ActivityListExtension $activityListExtension) |
69
|
|
|
{ |
70
|
|
|
$this->activityListExtension = $activityListExtension; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* {@inheritdoc} |
75
|
|
|
*/ |
76
|
|
|
public function setExtendExtension(ExtendExtension $extendExtension) |
77
|
|
|
{ |
78
|
|
|
$this->extendExtension = $extendExtension; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* {@inheritdoc} |
83
|
|
|
*/ |
84
|
|
|
public function setNoteExtension(NoteExtension $noteExtension) |
85
|
|
|
{ |
86
|
|
|
$this->noteExtension = $noteExtension; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* {@inheritdoc} |
91
|
|
|
*/ |
92
|
|
|
public function setActivityExtension(ActivityExtension $activityExtension) |
93
|
|
|
{ |
94
|
|
|
$this->activityExtension = $activityExtension; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* {@inheritdoc} |
99
|
|
|
*/ |
100
|
|
|
public function setAttachmentExtension(AttachmentExtension $attachmentExtension) |
101
|
|
|
{ |
102
|
|
|
$this->attachmentExtension = $attachmentExtension; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* {@inheritdoc} |
107
|
|
|
*/ |
108
|
|
|
public function setRenameExtension(RenameExtension $renameExtension) |
109
|
|
|
{ |
110
|
|
|
$this->renameExtension = $renameExtension; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* {@inheritdoc} |
115
|
|
|
*/ |
116
|
|
|
public function getMigrationVersion() |
117
|
|
|
{ |
118
|
|
|
return 'v1_27'; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* {@inheritdoc} |
123
|
|
|
*/ |
124
|
|
|
public function up(Schema $schema, QueryBag $queries) |
125
|
|
|
{ |
126
|
|
|
/** Tables generation **/ |
127
|
|
|
$this->createOrocrmSalesOpportunityTable($schema); |
128
|
|
|
$this->createOrocrmSalesLeadStatusTable($schema); |
129
|
|
|
$this->createOrocrmSalesFunnelTable($schema); |
130
|
|
|
$this->createOrocrmSalesOpportStatusTable($schema); |
131
|
|
|
$this->createOrocrmSalesOpportCloseRsnTable($schema); |
132
|
|
|
$this->createOrocrmSalesLeadTable($schema); |
133
|
|
|
$this->createOrocrmSalesB2bCustomerTable($schema); |
134
|
|
|
$this->createOrocrmLeadPhoneTable($schema); |
135
|
|
|
$this->createOrocrmSalesLeadEmailTable($schema); |
136
|
|
|
$this->createOrocrmB2bCustomerPhoneTable($schema); |
137
|
|
|
$this->createOrocrmB2bCustomerEmailTable($schema); |
138
|
|
|
|
139
|
|
|
/** Tables update */ |
140
|
|
|
$this->addOroEmailMailboxProcessorColumns($schema); |
141
|
|
|
|
142
|
|
|
/** Foreign keys generation **/ |
143
|
|
|
$this->addOrocrmSalesOpportunityForeignKeys($schema); |
144
|
|
|
$this->addOrocrmSalesFunnelForeignKeys($schema); |
145
|
|
|
$this->addOrocrmSalesLeadForeignKeys($schema); |
146
|
|
|
$this->addOrocrmSalesB2bCustomerForeignKeys($schema); |
147
|
|
|
$this->addOroEmailMailboxProcessorForeignKeys($schema); |
148
|
|
|
$this->addOrocrmB2bCustomerPhoneForeignKeys($schema); |
149
|
|
|
$this->addOrocrmB2bCustomerEmailForeignKeys($schema); |
150
|
|
|
$this->addOrocrmLeadPhoneForeignKeys($schema); |
151
|
|
|
$this->addOrocrmSalesLeadEmailForeignKeys($schema); |
152
|
|
|
|
153
|
|
|
|
154
|
|
|
/** Apply extensions */ |
155
|
|
|
SalesNoteMigration::addNoteAssociations($schema, $this->noteExtension); |
156
|
|
|
$this->activityExtension->addActivityAssociation($schema, 'oro_email', 'orocrm_sales_lead'); |
157
|
|
|
$this->activityExtension->addActivityAssociation($schema, 'oro_email', 'orocrm_sales_opportunity'); |
158
|
|
|
$this->activityExtension->addActivityAssociation($schema, 'oro_email', 'orocrm_sales_b2bcustomer'); |
159
|
|
|
$this->activityExtension->addActivityAssociation($schema, 'oro_calendar_event', 'orocrm_sales_lead'); |
160
|
|
|
$this->activityExtension->addActivityAssociation($schema, 'oro_calendar_event', 'orocrm_sales_opportunity'); |
161
|
|
|
$this->activityExtension->addActivityAssociation($schema, 'oro_calendar_event', 'orocrm_sales_b2bcustomer'); |
162
|
|
|
OpportunityAttachment::addOpportunityAttachment($schema, $this->attachmentExtension); |
163
|
|
|
InheritanceActivityTargets::addInheritanceTargets($schema, $this->activityListExtension); |
164
|
|
|
OpportunityLeadInheritance::addInheritanceTargets($schema, $this->activityListExtension); |
165
|
|
|
|
166
|
|
|
SalesOrganizations::addOrganization($schema); |
167
|
|
|
|
168
|
|
|
$this->addOpportunityStatusField($schema, $queries); |
169
|
|
|
AddLeadStatus::addStatusField($schema, $this->extendExtension, $queries); |
170
|
|
|
AddLeadAddressTable::createLeadAddressTable($schema); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* Create orocrm_sales_opportunity table |
175
|
|
|
* |
176
|
|
|
* @param Schema $schema |
177
|
|
|
*/ |
178
|
|
|
protected function createOrocrmSalesOpportunityTable(Schema $schema) |
179
|
|
|
{ |
180
|
|
|
$table = $schema->createTable('orocrm_sales_opportunity'); |
181
|
|
|
$table->addColumn('id', 'integer', ['autoincrement' => true]); |
182
|
|
|
$table->addColumn('contact_id', 'integer', ['notnull' => false]); |
183
|
|
|
$table->addColumn('close_reason_name', 'string', ['notnull' => false, 'length' => 32]); |
184
|
|
|
$table->addColumn('user_owner_id', 'integer', ['notnull' => false]); |
185
|
|
|
$table->addColumn('customer_id', 'integer', ['notnull' => false]); |
186
|
|
|
$table->addColumn('data_channel_id', 'integer', ['notnull' => false]); |
187
|
|
|
$table->addColumn('lead_id', 'integer', ['notnull' => false]); |
188
|
|
|
$table->addColumn('name', 'string', ['length' => 255]); |
189
|
|
|
$table->addColumn('close_date', 'date', ['notnull' => false]); |
190
|
|
|
$table->addColumn( |
191
|
|
|
'probability', |
192
|
|
|
'percent', |
193
|
|
|
['notnull' => false, 'precision' => 0, 'comment' => '(DC2Type:percent)'] |
194
|
|
|
); |
195
|
|
|
$table->addColumn( |
196
|
|
|
'budget_amount_value', |
197
|
|
|
'money', |
198
|
|
|
['notnull' => false, 'precision' => 0, 'comment' => '(DC2Type:money)'] |
199
|
|
|
); |
200
|
|
|
$table->addColumn( |
201
|
|
|
'budget_amount_currency', |
202
|
|
|
'currency', |
203
|
|
|
['length' => 3, 'notnull' => false, 'comment' => '(DC2Type:currency)'] |
204
|
|
|
); |
205
|
|
|
$table->addColumn( |
206
|
|
|
'close_revenue_value', |
207
|
|
|
'money', |
208
|
|
|
['notnull' => false, 'precision' => 0, 'comment' => '(DC2Type:money)'] |
209
|
|
|
); |
210
|
|
|
$table->addColumn( |
211
|
|
|
'close_revenue_currency', |
212
|
|
|
'currency', |
213
|
|
|
['length' => 3, 'notnull' => false, 'comment' => '(DC2Type:currency)'] |
214
|
|
|
); |
215
|
|
|
$table->addColumn('customer_need', 'text', ['notnull' => false]); |
216
|
|
|
$table->addColumn('proposed_solution', 'text', ['notnull' => false]); |
217
|
|
|
$table->addColumn('created_at', 'datetime', []); |
218
|
|
|
$table->addColumn('updated_at', 'datetime', []); |
219
|
|
|
$table->addColumn('notes', 'text', ['notnull' => false]); |
220
|
|
|
$table->addColumn('closed_at', 'datetime', ['notnull' => false]); |
221
|
|
|
$table->addIndex(['contact_id'], 'idx_c0fe4aace7a1254a', []); |
222
|
|
|
$table->addIndex(['created_at'], 'opportunity_created_idx', []); |
223
|
|
|
$table->addIndex(['user_owner_id'], 'idx_c0fe4aac9eb185f9', []); |
224
|
|
|
$table->addIndex(['lead_id'], 'idx_c0fe4aac55458d', []); |
225
|
|
|
$table->addIndex(['customer_id'], 'IDX_C0FE4AAC9395C3F3', []); |
226
|
|
|
$table->addIndex(['data_channel_id'], 'IDX_C0FE4AACBDC09B73', []); |
227
|
|
|
$table->addIndex(['close_reason_name'], 'idx_c0fe4aacd81b931c', []); |
228
|
|
|
$table->setPrimaryKey(['id']); |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* Create orocrm_sales_lead_status table |
233
|
|
|
* |
234
|
|
|
* @param Schema $schema |
235
|
|
|
*/ |
236
|
|
View Code Duplication |
protected function createOrocrmSalesLeadStatusTable(Schema $schema) |
|
|
|
|
237
|
|
|
{ |
238
|
|
|
$table = $schema->createTable('orocrm_sales_lead_status'); |
239
|
|
|
$table->addColumn('name', 'string', ['length' => 32]); |
240
|
|
|
$table->addColumn('label', 'string', ['length' => 255]); |
241
|
|
|
$table->addUniqueIndex(['label'], 'uniq_4516951bea750e8'); |
242
|
|
|
$table->setPrimaryKey(['name']); |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* Create orocrm_sales_funnel table |
247
|
|
|
* |
248
|
|
|
* @param Schema $schema |
249
|
|
|
*/ |
250
|
|
View Code Duplication |
protected function createOrocrmSalesFunnelTable(Schema $schema) |
|
|
|
|
251
|
|
|
{ |
252
|
|
|
$table = $schema->createTable('orocrm_sales_funnel'); |
253
|
|
|
$table->addColumn('id', 'integer', ['autoincrement' => true]); |
254
|
|
|
$table->addColumn('user_owner_id', 'integer', ['notnull' => false]); |
255
|
|
|
$table->addColumn('opportunity_id', 'integer', ['notnull' => false]); |
256
|
|
|
$table->addColumn('lead_id', 'integer', ['notnull' => false]); |
257
|
|
|
$table->addColumn('data_channel_id', 'integer', ['notnull' => false]); |
258
|
|
|
$table->addColumn('startdate', 'date', []); |
259
|
|
|
$table->addColumn('createdat', 'datetime', []); |
260
|
|
|
$table->addColumn('updatedat', 'datetime', ['notnull' => false]); |
261
|
|
|
$table->addIndex(['opportunity_id'], 'idx_e20c73449a34590f', []); |
262
|
|
|
$table->addIndex(['lead_id'], 'idx_e20c734455458d', []); |
263
|
|
|
$table->addIndex(['startdate'], 'sales_start_idx', []); |
264
|
|
|
$table->setPrimaryKey(['id']); |
265
|
|
|
$table->addIndex(['user_owner_id'], 'idx_e20c73449eb185f9', []); |
266
|
|
|
$table->addIndex(['data_channel_id'], 'IDX_E20C7344BDC09B73', []); |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
/** |
270
|
|
|
* Create orocrm_sales_opport_status table |
271
|
|
|
* |
272
|
|
|
* @param Schema $schema |
273
|
|
|
*/ |
274
|
|
View Code Duplication |
protected function createOrocrmSalesOpportStatusTable(Schema $schema) |
|
|
|
|
275
|
|
|
{ |
276
|
|
|
$table = $schema->createTable('orocrm_sales_opport_status'); |
277
|
|
|
$table->addColumn('name', 'string', ['length' => 32]); |
278
|
|
|
$table->addColumn('label', 'string', ['length' => 255]); |
279
|
|
|
$table->addUniqueIndex(['label'], 'uniq_2db212b5ea750e8'); |
280
|
|
|
$table->setPrimaryKey(['name']); |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* Create orocrm_sales_opport_close_rsn table |
285
|
|
|
* |
286
|
|
|
* @param Schema $schema |
287
|
|
|
*/ |
288
|
|
View Code Duplication |
protected function createOrocrmSalesOpportCloseRsnTable(Schema $schema) |
|
|
|
|
289
|
|
|
{ |
290
|
|
|
$table = $schema->createTable('orocrm_sales_opport_close_rsn'); |
291
|
|
|
$table->addColumn('name', 'string', ['length' => 32]); |
292
|
|
|
$table->addColumn('label', 'string', ['length' => 255]); |
293
|
|
|
$table->addUniqueIndex(['label'], 'uniq_fa526a41ea750e8'); |
294
|
|
|
$table->setPrimaryKey(['name']); |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
/** |
298
|
|
|
* Create orocrm_sales_lead table |
299
|
|
|
* |
300
|
|
|
* @param Schema $schema |
301
|
|
|
*/ |
302
|
|
|
protected function createOrocrmSalesLeadTable(Schema $schema) |
303
|
|
|
{ |
304
|
|
|
$table = $schema->createTable('orocrm_sales_lead'); |
305
|
|
|
$table->addColumn('id', 'integer', ['autoincrement' => true]); |
306
|
|
|
$table->addColumn('address_id', 'integer', ['notnull' => false]); |
307
|
|
|
$table->addColumn('contact_id', 'integer', ['notnull' => false]); |
308
|
|
|
$table->addColumn('user_owner_id', 'integer', ['notnull' => false]); |
309
|
|
|
$table->addColumn('customer_id', 'integer', ['notnull' => false]); |
310
|
|
|
$table->addColumn('data_channel_id', 'integer', ['notnull' => false]); |
311
|
|
|
$table->addColumn('name', 'string', ['length' => 255]); |
312
|
|
|
$table->addColumn('name_prefix', 'string', ['notnull' => false, 'length' => 255]); |
313
|
|
|
$table->addColumn('first_name', 'string', ['notnull' => false, 'length' => 255]); |
314
|
|
|
$table->addColumn('middle_name', 'string', ['notnull' => false, 'length' => 255]); |
315
|
|
|
$table->addColumn('last_name', 'string', ['notnull' => false, 'length' => 255]); |
316
|
|
|
$table->addColumn('name_suffix', 'string', ['notnull' => false, 'length' => 255]); |
317
|
|
|
$table->addColumn('job_title', 'string', ['notnull' => false, 'length' => 255]); |
318
|
|
|
$table->addColumn('company_name', 'string', ['notnull' => false, 'length' => 255]); |
319
|
|
|
$table->addColumn('website', 'string', ['notnull' => false, 'length' => 255]); |
320
|
|
|
$table->addColumn('number_of_employees', 'integer', ['notnull' => false]); |
321
|
|
|
$table->addColumn('industry', 'string', ['notnull' => false, 'length' => 255]); |
322
|
|
|
$table->addColumn('createdat', 'datetime', []); |
323
|
|
|
$table->addColumn('updatedat', 'datetime', ['notnull' => false]); |
324
|
|
|
$table->addColumn('notes', 'text', ['notnull' => false]); |
325
|
|
|
$table->addColumn('twitter', 'string', ['length' => 255, 'notnull' => false]); |
326
|
|
|
$table->addColumn('linkedin', 'string', ['length' => 255, 'notnull' => false]); |
327
|
|
|
|
328
|
|
|
$this->extendExtension->addEnumField( |
329
|
|
|
$schema, |
330
|
|
|
'orocrm_sales_lead', |
331
|
|
|
'source', |
332
|
|
|
'lead_source' |
333
|
|
|
); |
334
|
|
|
|
335
|
|
|
$this->extendExtension->addManyToOneRelation( |
336
|
|
|
$schema, |
337
|
|
|
$table, |
338
|
|
|
'campaign', |
339
|
|
|
'orocrm_campaign', |
340
|
|
|
'combined_name', |
341
|
|
|
['extend' => ['owner' => ExtendScope::OWNER_CUSTOM]] |
342
|
|
|
); |
343
|
|
|
|
344
|
|
|
$table->addIndex(['user_owner_id'], 'idx_73db46339eb185f9', []); |
345
|
|
|
$table->addIndex(['customer_id'], 'IDX_73DB46339395C3F3', []); |
346
|
|
|
$table->addIndex(['data_channel_id'], 'IDX_73DB4633BDC09B73', []); |
347
|
|
|
$table->addIndex(['createdat'], 'lead_created_idx', []); |
348
|
|
|
$table->addIndex(['contact_id'], 'idx_73db4633e7a1254a', []); |
349
|
|
|
$table->setPrimaryKey(['id']); |
350
|
|
|
$table->addIndex(['address_id'], 'idx_73db4633f5b7af75', []); |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
/** |
354
|
|
|
* Create orocrm_sales_b2bcustomer table |
355
|
|
|
* |
356
|
|
|
* @param Schema $schema |
357
|
|
|
*/ |
358
|
|
|
protected function createOrocrmSalesB2bCustomerTable(Schema $schema) |
359
|
|
|
{ |
360
|
|
|
$table = $schema->createTable('orocrm_sales_b2bcustomer'); |
361
|
|
|
$table->addColumn('id', 'integer', ['autoincrement' => true]); |
362
|
|
|
$table->addColumn('user_owner_id', 'integer', ['notnull' => false]); |
363
|
|
|
$table->addColumn('billing_address_id', 'integer', ['notnull' => false]); |
364
|
|
|
$table->addColumn('shipping_address_id', 'integer', ['notnull' => false]); |
365
|
|
|
$table->addColumn('data_channel_id', 'integer', ['notnull' => false]); |
366
|
|
|
$table->addColumn('account_id', 'integer', ['notnull' => false]); |
367
|
|
|
$table->addColumn('contact_id', 'integer', ['notnull' => false]); |
368
|
|
|
$table->addColumn('name', 'string', ['length' => 255]); |
369
|
|
|
$table->addColumn('lifetime', 'money', ['notnull' => false]); |
370
|
|
|
$table->addColumn('createdAt', 'datetime', []); |
371
|
|
|
$table->addColumn('updatedAt', 'datetime', []); |
372
|
|
|
$table->setPrimaryKey(['id']); |
373
|
|
|
$table->addIndex(['account_id'], 'IDX_94CC12929B6B5FBA', []); |
374
|
|
|
$table->addIndex(['shipping_address_id'], 'IDX_9C6CFD74D4CFF2B', []); |
375
|
|
|
$table->addIndex(['billing_address_id'], 'IDX_9C6CFD779D0C0E4', []); |
376
|
|
|
$table->addIndex(['contact_id'], 'IDX_9C6CFD7E7A1254A', []); |
377
|
|
|
$table->addIndex(['data_channel_id'], 'IDX_DAC0BD29BDC09B73', []); |
378
|
|
|
$table->addIndex(['user_owner_id'], 'IDX_9C6CFD79EB185F9', []); |
379
|
|
|
|
380
|
|
|
$table->addColumn( |
381
|
|
|
'website', |
382
|
|
|
'string', |
383
|
|
|
[ |
384
|
|
|
'oro_options' => [ |
385
|
|
|
'extend' => ['is_extend' => true, 'owner' => ExtendScope::OWNER_CUSTOM], |
386
|
|
|
'datagrid' => ['is_visible' => DatagridScope::IS_VISIBLE_HIDDEN], |
387
|
|
|
'dataaudit' => ['auditable' => true] |
388
|
|
|
] |
389
|
|
|
] |
390
|
|
|
); |
391
|
|
|
$table->addColumn( |
392
|
|
|
'employees', |
393
|
|
|
'integer', |
394
|
|
|
[ |
395
|
|
|
'oro_options' => [ |
396
|
|
|
'extend' => ['is_extend' => true, 'owner' => ExtendScope::OWNER_CUSTOM], |
397
|
|
|
'datagrid' => ['is_visible' => DatagridScope::IS_VISIBLE_HIDDEN], |
398
|
|
|
'dataaudit' => ['auditable' => true] |
399
|
|
|
] |
400
|
|
|
] |
401
|
|
|
); |
402
|
|
|
$table->addColumn( |
403
|
|
|
'ownership', |
404
|
|
|
'string', |
405
|
|
|
[ |
406
|
|
|
'oro_options' => [ |
407
|
|
|
'extend' => ['is_extend' => true, 'owner' => ExtendScope::OWNER_CUSTOM], |
408
|
|
|
'datagrid' => ['is_visible' => DatagridScope::IS_VISIBLE_HIDDEN], |
409
|
|
|
'dataaudit' => ['auditable' => true] |
410
|
|
|
] |
411
|
|
|
] |
412
|
|
|
); |
413
|
|
|
$table->addColumn( |
414
|
|
|
'ticker_symbol', |
415
|
|
|
'string', |
416
|
|
|
[ |
417
|
|
|
'oro_options' => [ |
418
|
|
|
'extend' => ['is_extend' => true, 'owner' => ExtendScope::OWNER_CUSTOM], |
419
|
|
|
'datagrid' => ['is_visible' => DatagridScope::IS_VISIBLE_HIDDEN], |
420
|
|
|
'dataaudit' => ['auditable' => true] |
421
|
|
|
] |
422
|
|
|
] |
423
|
|
|
); |
424
|
|
|
$table->addColumn( |
425
|
|
|
'rating', |
426
|
|
|
'string', |
427
|
|
|
[ |
428
|
|
|
'oro_options' => [ |
429
|
|
|
'extend' => ['is_extend' => true, 'owner' => ExtendScope::OWNER_CUSTOM], |
430
|
|
|
'datagrid' => ['is_visible' => DatagridScope::IS_VISIBLE_HIDDEN], |
431
|
|
|
'dataaudit' => ['auditable' => true] |
432
|
|
|
] |
433
|
|
|
] |
434
|
|
|
); |
435
|
|
|
} |
436
|
|
|
|
437
|
|
|
/** |
438
|
|
|
* Create orocrm_lead_phone table |
439
|
|
|
* |
440
|
|
|
* @param Schema $schema |
441
|
|
|
*/ |
442
|
|
|
protected function createOrocrmLeadPhoneTable(Schema $schema) |
443
|
|
|
{ |
444
|
|
|
$table = $schema->createTable('orocrm_sales_lead_phone'); |
445
|
|
|
$table->addColumn('id', 'integer', ['autoincrement' => true]); |
446
|
|
|
$table->addColumn('owner_id', 'integer', ['notnull' => false]); |
447
|
|
|
$table->addColumn('phone', 'string', ['length' => 255]); |
448
|
|
|
$table->addColumn('is_primary', 'boolean', ['notnull' => false]); |
449
|
|
|
$table->setPrimaryKey(['id']); |
450
|
|
|
$table->addIndex(['owner_id'], 'IDX_8475907F7E3C61F9', []); |
451
|
|
|
$table->addIndex(['phone', 'is_primary'], 'lead_primary_phone_idx', []); |
452
|
|
|
$table->addIndex(['phone'], 'lead_phone_idx'); |
453
|
|
|
} |
454
|
|
|
|
455
|
|
|
/** |
456
|
|
|
* Create orocrm_sales_lead_email table |
457
|
|
|
* |
458
|
|
|
* @param Schema $schema |
459
|
|
|
*/ |
460
|
|
|
protected function createOrocrmSalesLeadEmailTable(Schema $schema) |
461
|
|
|
{ |
462
|
|
|
$table = $schema->createTable('orocrm_sales_lead_email'); |
463
|
|
|
$table->addColumn('id', 'integer', ['autoincrement' => true]); |
464
|
|
|
$table->addColumn('owner_id', 'integer', ['notnull' => false]); |
465
|
|
|
$table->addColumn('email', 'string', ['length' => 255]); |
466
|
|
|
$table->addColumn('is_primary', 'boolean', ['notnull' => false]); |
467
|
|
|
$table->setPrimaryKey(['id']); |
468
|
|
|
$table->addIndex(['owner_id'], 'IDX_9F15A0937E3C61F9', []); |
469
|
|
|
$table->addIndex(['email', 'is_primary'], 'lead_primary_email_idx', []); |
470
|
|
|
} |
471
|
|
|
|
472
|
|
|
/** |
473
|
|
|
* Create orocrm_b2bcustomer_phone table |
474
|
|
|
* |
475
|
|
|
* @param Schema $schema |
476
|
|
|
*/ |
477
|
|
|
protected function createOrocrmB2bCustomerPhoneTable(Schema $schema) |
478
|
|
|
{ |
479
|
|
|
$table = $schema->createTable('orocrm_sales_b2bcustomer_phone'); |
480
|
|
|
$table->addColumn('id', 'integer', ['autoincrement' => true]); |
481
|
|
|
$table->addColumn('owner_id', 'integer', ['notnull' => false]); |
482
|
|
|
$table->addColumn('phone', 'string', ['length' => 255]); |
483
|
|
|
$table->addColumn('is_primary', 'boolean', ['notnull' => false]); |
484
|
|
|
$table->setPrimaryKey(['id']); |
485
|
|
|
$table->addIndex(['owner_id'], 'IDX_F0D0BDFA7E3C61F9', []); |
486
|
|
|
$table->addIndex(['phone', 'is_primary'], 'primary_b2bcustomer_phone_idx', []); |
487
|
|
|
$table->addIndex(['phone'], 'b2bcustomer_phone_idx'); |
488
|
|
|
} |
489
|
|
|
|
490
|
|
|
/** |
491
|
|
|
* Create orocrm_b2bcustomer_email table |
492
|
|
|
* |
493
|
|
|
* @param Schema $schema |
494
|
|
|
*/ |
495
|
|
|
protected function createOrocrmB2bCustomerEmailTable(Schema $schema) |
496
|
|
|
{ |
497
|
|
|
$table = $schema->createTable('orocrm_sales_b2bcustomer_email'); |
498
|
|
|
$table->addColumn('id', 'integer', ['autoincrement' => true]); |
499
|
|
|
$table->addColumn('owner_id', 'integer', ['notnull' => false]); |
500
|
|
|
$table->addColumn('email', 'string', ['length' => 255]); |
501
|
|
|
$table->addColumn('is_primary', 'boolean', ['notnull' => false]); |
502
|
|
|
$table->setPrimaryKey(['id']); |
503
|
|
|
$table->addIndex(['owner_id'], 'IDX_D564AB17E3C61F9', []); |
504
|
|
|
$table->addIndex(['email', 'is_primary'], 'primary_b2bcustomer_email_idx', []); |
505
|
|
|
} |
506
|
|
|
|
507
|
|
|
/** |
508
|
|
|
* Add orocrm_sales_opportunity foreign keys. |
509
|
|
|
* |
510
|
|
|
* @param Schema $schema |
511
|
|
|
*/ |
512
|
|
View Code Duplication |
protected function addOrocrmSalesOpportunityForeignKeys(Schema $schema) |
|
|
|
|
513
|
|
|
{ |
514
|
|
|
$table = $schema->getTable('orocrm_sales_opportunity'); |
515
|
|
|
$table->addForeignKeyConstraint( |
516
|
|
|
$schema->getTable('orocrm_contact'), |
517
|
|
|
['contact_id'], |
518
|
|
|
['id'], |
519
|
|
|
['onUpdate' => null, 'onDelete' => 'SET NULL'] |
520
|
|
|
); |
521
|
|
|
$table->addForeignKeyConstraint( |
522
|
|
|
$schema->getTable('orocrm_sales_opport_close_rsn'), |
523
|
|
|
['close_reason_name'], |
524
|
|
|
['name'], |
525
|
|
|
['onUpdate' => null, 'onDelete' => null] |
526
|
|
|
); |
527
|
|
|
$table->addForeignKeyConstraint( |
528
|
|
|
$schema->getTable('oro_user'), |
529
|
|
|
['user_owner_id'], |
530
|
|
|
['id'], |
531
|
|
|
['onUpdate' => null, 'onDelete' => 'SET NULL'] |
532
|
|
|
); |
533
|
|
|
$table->addForeignKeyConstraint( |
534
|
|
|
$schema->getTable('orocrm_sales_b2bcustomer'), |
535
|
|
|
['customer_id'], |
536
|
|
|
['id'], |
537
|
|
|
['onDelete' => 'SET NULL', 'onUpdate' => null] |
538
|
|
|
); |
539
|
|
|
$table->addForeignKeyConstraint( |
540
|
|
|
$schema->getTable('orocrm_channel'), |
541
|
|
|
['data_channel_id'], |
542
|
|
|
['id'], |
543
|
|
|
['onDelete' => 'SET NULL', 'onUpdate' => null], |
544
|
|
|
'FK_C0FE4AACBDC09B73' |
545
|
|
|
); |
546
|
|
|
$table->addForeignKeyConstraint( |
547
|
|
|
$schema->getTable('orocrm_sales_lead'), |
548
|
|
|
['lead_id'], |
549
|
|
|
['id'], |
550
|
|
|
['onUpdate' => null, 'onDelete' => 'SET NULL'] |
551
|
|
|
); |
552
|
|
|
} |
553
|
|
|
|
554
|
|
|
/** |
555
|
|
|
* Add orocrm_sales_funnel foreign keys. |
556
|
|
|
* |
557
|
|
|
* @param Schema $schema |
558
|
|
|
*/ |
559
|
|
|
protected function addOrocrmSalesFunnelForeignKeys(Schema $schema) |
560
|
|
|
{ |
561
|
|
|
$table = $schema->getTable('orocrm_sales_funnel'); |
562
|
|
|
$table->addForeignKeyConstraint( |
563
|
|
|
$schema->getTable('oro_user'), |
564
|
|
|
['user_owner_id'], |
565
|
|
|
['id'], |
566
|
|
|
['onUpdate' => null, 'onDelete' => 'SET NULL'] |
567
|
|
|
); |
568
|
|
|
$table->addForeignKeyConstraint( |
569
|
|
|
$schema->getTable('orocrm_sales_opportunity'), |
570
|
|
|
['opportunity_id'], |
571
|
|
|
['id'], |
572
|
|
|
['onUpdate' => null, 'onDelete' => 'SET NULL'] |
573
|
|
|
); |
574
|
|
|
$table->addForeignKeyConstraint( |
575
|
|
|
$schema->getTable('orocrm_sales_lead'), |
576
|
|
|
['lead_id'], |
577
|
|
|
['id'], |
578
|
|
|
['onUpdate' => null, 'onDelete' => 'SET NULL'] |
579
|
|
|
); |
580
|
|
|
$table->addForeignKeyConstraint( |
581
|
|
|
$schema->getTable('orocrm_channel'), |
582
|
|
|
['data_channel_id'], |
583
|
|
|
['id'], |
584
|
|
|
['onDelete' => 'SET NULL', 'onUpdate' => null], |
585
|
|
|
'FK_E20C7344BDC09B73' |
586
|
|
|
); |
587
|
|
|
} |
588
|
|
|
|
589
|
|
|
/** |
590
|
|
|
* Add orocrm_sales_lead foreign keys. |
591
|
|
|
* |
592
|
|
|
* @param Schema $schema |
593
|
|
|
*/ |
594
|
|
View Code Duplication |
protected function addOrocrmSalesLeadForeignKeys(Schema $schema) |
|
|
|
|
595
|
|
|
{ |
596
|
|
|
$table = $schema->getTable('orocrm_sales_lead'); |
597
|
|
|
$table->addForeignKeyConstraint( |
598
|
|
|
$schema->getTable('orocrm_campaign'), |
599
|
|
|
['campaign_id'], |
600
|
|
|
['id'], |
601
|
|
|
['onUpdate' => null, 'onDelete' => 'SET NULL'] |
602
|
|
|
); |
603
|
|
|
$table->addForeignKeyConstraint( |
604
|
|
|
$schema->getTable('oro_address'), |
605
|
|
|
['address_id'], |
606
|
|
|
['id'], |
607
|
|
|
['onUpdate' => null, 'onDelete' => 'SET NULL'] |
608
|
|
|
); |
609
|
|
|
$table->addForeignKeyConstraint( |
610
|
|
|
$schema->getTable('orocrm_contact'), |
611
|
|
|
['contact_id'], |
612
|
|
|
['id'], |
613
|
|
|
['onUpdate' => null, 'onDelete' => 'SET NULL'] |
614
|
|
|
); |
615
|
|
|
$table->addForeignKeyConstraint( |
616
|
|
|
$schema->getTable('oro_user'), |
617
|
|
|
['user_owner_id'], |
618
|
|
|
['id'], |
619
|
|
|
['onUpdate' => null, 'onDelete' => 'SET NULL'] |
620
|
|
|
); |
621
|
|
|
$table->addForeignKeyConstraint( |
622
|
|
|
$schema->getTable('orocrm_sales_b2bcustomer'), |
623
|
|
|
['customer_id'], |
624
|
|
|
['id'], |
625
|
|
|
['onDelete' => 'SET NULL', 'onUpdate' => null] |
626
|
|
|
); |
627
|
|
|
$table->addForeignKeyConstraint( |
628
|
|
|
$schema->getTable('orocrm_channel'), |
629
|
|
|
['data_channel_id'], |
630
|
|
|
['id'], |
631
|
|
|
['onDelete' => 'SET NULL', 'onUpdate' => null], |
632
|
|
|
'FK_73DB4633BDC09B73' |
633
|
|
|
); |
634
|
|
|
} |
635
|
|
|
|
636
|
|
|
/** |
637
|
|
|
* Add orocrm_sales_b2bcustomer foreign keys. |
638
|
|
|
* |
639
|
|
|
* @param Schema $schema |
640
|
|
|
*/ |
641
|
|
View Code Duplication |
protected function addOrocrmSalesB2bCustomerForeignKeys(Schema $schema) |
|
|
|
|
642
|
|
|
{ |
643
|
|
|
$table = $schema->getTable('orocrm_sales_b2bcustomer'); |
644
|
|
|
$table->addForeignKeyConstraint( |
645
|
|
|
$schema->getTable('oro_user'), |
646
|
|
|
['user_owner_id'], |
647
|
|
|
['id'], |
648
|
|
|
['onDelete' => 'SET NULL', 'onUpdate' => null] |
649
|
|
|
); |
650
|
|
|
$table->addForeignKeyConstraint( |
651
|
|
|
$schema->getTable('oro_address'), |
652
|
|
|
['shipping_address_id'], |
653
|
|
|
['id'], |
654
|
|
|
['onDelete' => 'SET NULL', 'onUpdate' => null] |
655
|
|
|
); |
656
|
|
|
$table->addForeignKeyConstraint( |
657
|
|
|
$schema->getTable('orocrm_channel'), |
658
|
|
|
['data_channel_id'], |
659
|
|
|
['id'], |
660
|
|
|
['onDelete' => 'SET NULL', 'onUpdate' => null] |
661
|
|
|
); |
662
|
|
|
$table->addForeignKeyConstraint( |
663
|
|
|
$schema->getTable('oro_address'), |
664
|
|
|
['billing_address_id'], |
665
|
|
|
['id'], |
666
|
|
|
['onDelete' => 'SET NULL', 'onUpdate' => null] |
667
|
|
|
); |
668
|
|
|
$table->addForeignKeyConstraint( |
669
|
|
|
$schema->getTable('orocrm_account'), |
670
|
|
|
['account_id'], |
671
|
|
|
['id'], |
672
|
|
|
['onDelete' => 'SET NULL', 'onUpdate' => null] |
673
|
|
|
); |
674
|
|
|
$table->addForeignKeyConstraint( |
675
|
|
|
$schema->getTable('orocrm_contact'), |
676
|
|
|
['contact_id'], |
677
|
|
|
['id'], |
678
|
|
|
['onDelete' => 'SET NULL', 'onUpdate' => null] |
679
|
|
|
); |
680
|
|
|
} |
681
|
|
|
|
682
|
|
|
/** |
683
|
|
|
* Add opportunity status Enum field and initialize default enum values |
684
|
|
|
* |
685
|
|
|
* @param Schema $schema |
686
|
|
|
* @param QueryBag $queries |
687
|
|
|
*/ |
688
|
|
|
protected function addOpportunityStatusField(Schema $schema, QueryBag $queries) |
689
|
|
|
{ |
690
|
|
|
$immutableCodes = ['in_progress', 'won', 'lost']; |
691
|
|
|
|
692
|
|
|
AddOpportunityStatus::addStatusField($schema, $this->extendExtension, $immutableCodes); |
693
|
|
|
|
694
|
|
|
$statuses = [ |
695
|
|
|
'in_progress' => 'Open', |
696
|
|
|
'identification_alignment' => 'Identification & Alignment', |
697
|
|
|
'needs_analysis' => 'Needs Analysis', |
698
|
|
|
'solution_development' => 'Solution Development', |
699
|
|
|
'negotiation' => 'Negotiation', |
700
|
|
|
'won' => 'Closed Won', |
701
|
|
|
'lost' => 'Closed Lost', |
702
|
|
|
]; |
703
|
|
|
|
704
|
|
|
AddOpportunityStatus::addEnumValues($queries, $statuses); |
705
|
|
|
} |
706
|
|
|
|
707
|
|
|
/** |
708
|
|
|
* Create oro_email_mailbox_processor table |
709
|
|
|
* |
710
|
|
|
* @param Schema $schema |
711
|
|
|
*/ |
712
|
|
View Code Duplication |
public static function addOroEmailMailboxProcessorColumns(Schema $schema) |
|
|
|
|
713
|
|
|
{ |
714
|
|
|
$table = $schema->getTable('oro_email_mailbox_process'); |
715
|
|
|
|
716
|
|
|
$table->addColumn('lead_channel_id', 'integer', ['notnull' => false]); |
717
|
|
|
$table->addColumn('lead_owner_id', 'integer', ['notnull' => false]); |
718
|
|
|
$table->addColumn('lead_source_id', 'string', ['notnull' => false, 'length' => 32]); |
719
|
|
|
$table->addIndex(['lead_owner_id'], 'IDX_CE8602A3D46FE3FA', []); |
720
|
|
|
$table->addIndex(['lead_channel_id'], 'IDX_CE8602A35A6EBA36', []); |
721
|
|
|
} |
722
|
|
|
|
723
|
|
|
/** |
724
|
|
|
* Add oro_email_mailbox_processor foreign keys. |
725
|
|
|
* |
726
|
|
|
* @param Schema $schema |
727
|
|
|
*/ |
728
|
|
|
public static function addOroEmailMailboxProcessorForeignKeys(Schema $schema) |
729
|
|
|
{ |
730
|
|
|
$table = $schema->getTable('oro_email_mailbox_process'); |
731
|
|
|
$table->addForeignKeyConstraint( |
732
|
|
|
$schema->getTable('orocrm_channel'), |
733
|
|
|
['lead_channel_id'], |
734
|
|
|
['id'], |
735
|
|
|
['onDelete' => 'SET NULL', 'onUpdate' => null] |
736
|
|
|
); |
737
|
|
|
$table->addForeignKeyConstraint( |
738
|
|
|
$schema->getTable('oro_user'), |
739
|
|
|
['lead_owner_id'], |
740
|
|
|
['id'], |
741
|
|
|
['onDelete' => 'SET NULL', 'onUpdate' => null] |
742
|
|
|
); |
743
|
|
|
} |
744
|
|
|
|
745
|
|
|
/** |
746
|
|
|
* Add orocrm_b2bcustomer_phone foreign keys. |
747
|
|
|
* |
748
|
|
|
* @param Schema $schema |
749
|
|
|
*/ |
750
|
|
|
protected function addOrocrmB2bCustomerPhoneForeignKeys(Schema $schema) |
751
|
|
|
{ |
752
|
|
|
$table = $schema->getTable('orocrm_sales_b2bcustomer_phone'); |
753
|
|
|
$table->addForeignKeyConstraint( |
754
|
|
|
$schema->getTable('orocrm_sales_b2bcustomer'), |
755
|
|
|
['owner_id'], |
756
|
|
|
['id'], |
757
|
|
|
['onDelete' => 'CASCADE', 'onUpdate' => null] |
758
|
|
|
); |
759
|
|
|
} |
760
|
|
|
|
761
|
|
|
/** |
762
|
|
|
* Add orocrm_b2bcustomer_email foreign keys. |
763
|
|
|
* |
764
|
|
|
* @param Schema $schema |
765
|
|
|
*/ |
766
|
|
|
protected function addOrocrmB2bCustomerEmailForeignKeys(Schema $schema) |
767
|
|
|
{ |
768
|
|
|
$table = $schema->getTable('orocrm_sales_b2bcustomer_email'); |
769
|
|
|
$table->addForeignKeyConstraint( |
770
|
|
|
$schema->getTable('orocrm_sales_b2bcustomer'), |
771
|
|
|
['owner_id'], |
772
|
|
|
['id'], |
773
|
|
|
['onDelete' => 'CASCADE', 'onUpdate' => null] |
774
|
|
|
); |
775
|
|
|
} |
776
|
|
|
|
777
|
|
|
/** |
778
|
|
|
* Add orocrm_lead_phone foreign keys. |
779
|
|
|
* |
780
|
|
|
* @param Schema $schema |
781
|
|
|
*/ |
782
|
|
|
protected function addOrocrmLeadPhoneForeignKeys(Schema $schema) |
783
|
|
|
{ |
784
|
|
|
$table = $schema->getTable('orocrm_sales_lead_phone'); |
785
|
|
|
$table->addForeignKeyConstraint( |
786
|
|
|
$schema->getTable('orocrm_sales_lead'), |
787
|
|
|
['owner_id'], |
788
|
|
|
['id'], |
789
|
|
|
['onDelete' => 'CASCADE', 'onUpdate' => null] |
790
|
|
|
); |
791
|
|
|
} |
792
|
|
|
|
793
|
|
|
/** |
794
|
|
|
* Add orocrm_sales_lead_email foreign keys. |
795
|
|
|
* |
796
|
|
|
* @param Schema $schema |
797
|
|
|
*/ |
798
|
|
|
protected function addOrocrmSalesLeadEmailForeignKeys(Schema $schema) |
799
|
|
|
{ |
800
|
|
|
$table = $schema->getTable('orocrm_sales_lead_email'); |
801
|
|
|
$table->addForeignKeyConstraint( |
802
|
|
|
$schema->getTable('orocrm_sales_lead'), |
803
|
|
|
['owner_id'], |
804
|
|
|
['id'], |
805
|
|
|
['onDelete' => 'CASCADE', 'onUpdate' => null] |
806
|
|
|
); |
807
|
|
|
} |
808
|
|
|
} |
809
|
|
|
|
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.