Completed
Push — master ( a18731...e2e070 )
by
unknown
99:54 queued 47:45
created

OroCRMSalesBundleInstaller::up()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 48
Code Lines 36

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 48
rs 9.125
c 0
b 0
f 0
cc 1
eloc 36
nc 1
nop 2
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\NoteBundle\Migration\Extension\NoteExtension;
20
use Oro\Bundle\NoteBundle\Migration\Extension\NoteExtensionAwareInterface;
21
22
use OroCRM\Bundle\SalesBundle\Migrations\Schema\v1_5\OroCRMSalesBundle as SalesNoteMigration;
23
use OroCRM\Bundle\SalesBundle\Migrations\Schema\v1_7\OpportunityAttachment;
24
use OroCRM\Bundle\SalesBundle\Migrations\Schema\v1_11\OroCRMSalesBundle as SalesOrganizations;
25
use OroCRM\Bundle\SalesBundle\Migrations\Schema\v1_21\InheritanceActivityTargets;
26
use OroCRM\Bundle\SalesBundle\Migrations\Schema\v1_24\InheritanceActivityTargets as OpportunityLeadInheritance;
27
use OroCRM\Bundle\SalesBundle\Migrations\Schema\v1_22\AddOpportunityStatus;
28
use OroCRM\Bundle\SalesBundle\Migrations\Schema\v1_24\AddLeadStatus;
29
use OroCRM\Bundle\SalesBundle\Migrations\Schema\v1_25\AddLeadAddressTable;
30
31
/**
32
 * @SuppressWarnings(PHPMD.TooManyMethods)
33
 * @SuppressWarnings(PHPMD.ExcessiveClassLength)
34
 */
35
class OroCRMSalesBundleInstaller implements
36
    Installation,
37
    ExtendExtensionAwareInterface,
38
    NoteExtensionAwareInterface,
39
    ActivityExtensionAwareInterface,
40
    AttachmentExtensionAwareInterface,
41
    ActivityListExtensionAwareInterface
42
{
43
    /** @var ExtendExtension */
44
    protected $extendExtension;
45
46
    /** @var NoteExtension */
47
    protected $noteExtension;
48
49
    /** @var ActivityExtension */
50
    protected $activityExtension;
51
52
    /** @var AttachmentExtension */
53
    protected $attachmentExtension;
54
55
    /** @var ActivityListExtension */
56
    protected $activityListExtension;
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function setActivityListExtension(ActivityListExtension $activityListExtension)
62
    {
63
        $this->activityListExtension = $activityListExtension;
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function setExtendExtension(ExtendExtension $extendExtension)
70
    {
71
        $this->extendExtension = $extendExtension;
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77
    public function setNoteExtension(NoteExtension $noteExtension)
78
    {
79
        $this->noteExtension = $noteExtension;
80
    }
81
82
    /**
83
     * {@inheritdoc}
84
     */
85
    public function setActivityExtension(ActivityExtension $activityExtension)
86
    {
87
        $this->activityExtension = $activityExtension;
88
    }
89
90
    /**
91
     * {@inheritdoc}
92
     */
93
    public function setAttachmentExtension(AttachmentExtension $attachmentExtension)
94
    {
95
        $this->attachmentExtension = $attachmentExtension;
96
    }
97
98
    /**
99
     * {@inheritdoc}
100
     */
101
    public function getMigrationVersion()
102
    {
103
        return 'v1_27';
104
    }
105
106
    /**
107
     * {@inheritdoc}
108
     */
109
    public function up(Schema $schema, QueryBag $queries)
110
    {
111
        /** Tables generation **/
112
        $this->createOrocrmSalesOpportunityTable($schema);
113
        $this->createOrocrmSalesLeadStatusTable($schema);
114
        $this->createOrocrmSalesFunnelTable($schema);
115
        $this->createOrocrmSalesOpportStatusTable($schema);
116
        $this->createOrocrmSalesOpportCloseRsnTable($schema);
117
        $this->createOrocrmSalesLeadTable($schema);
118
        $this->createOrocrmSalesB2bCustomerTable($schema);
119
        $this->createOrocrmLeadPhoneTable($schema);
120
        $this->createOrocrmSalesLeadEmailTable($schema);
121
        $this->createOrocrmB2bCustomerPhoneTable($schema);
122
        $this->createOrocrmB2bCustomerEmailTable($schema);
123
124
        /** Tables update */
125
        $this->addOroEmailMailboxProcessorColumns($schema);
126
127
        /** Foreign keys generation **/
128
        $this->addOrocrmSalesOpportunityForeignKeys($schema);
129
        $this->addOrocrmSalesFunnelForeignKeys($schema);
130
        $this->addOrocrmSalesLeadForeignKeys($schema);
131
        $this->addOrocrmSalesB2bCustomerForeignKeys($schema);
132
        $this->addOroEmailMailboxProcessorForeignKeys($schema);
133
        $this->addOrocrmB2bCustomerPhoneForeignKeys($schema);
134
        $this->addOrocrmB2bCustomerEmailForeignKeys($schema);
135
        $this->addOrocrmLeadPhoneForeignKeys($schema);
136
        $this->addOrocrmSalesLeadEmailForeignKeys($schema);
137
138
139
        /** Apply extensions */
140
        SalesNoteMigration::addNoteAssociations($schema, $this->noteExtension);
141
        $this->activityExtension->addActivityAssociation($schema, 'oro_email', 'orocrm_sales_lead');
142
        $this->activityExtension->addActivityAssociation($schema, 'oro_email', 'orocrm_sales_opportunity');
143
        $this->activityExtension->addActivityAssociation($schema, 'oro_email', 'orocrm_sales_b2bcustomer');
144
        $this->activityExtension->addActivityAssociation($schema, 'oro_calendar_event', 'orocrm_sales_lead');
145
        $this->activityExtension->addActivityAssociation($schema, 'oro_calendar_event', 'orocrm_sales_opportunity');
146
        $this->activityExtension->addActivityAssociation($schema, 'oro_calendar_event', 'orocrm_sales_b2bcustomer');
147
        OpportunityAttachment::addOpportunityAttachment($schema, $this->attachmentExtension);
148
        InheritanceActivityTargets::addInheritanceTargets($schema, $this->activityListExtension);
149
        OpportunityLeadInheritance::addInheritanceTargets($schema, $this->activityListExtension);
150
151
        SalesOrganizations::addOrganization($schema);
152
153
        $this->addOpportunityStatusField($schema, $queries);
154
        AddLeadStatus::addStatusField($schema, $this->extendExtension, $queries);
155
        AddLeadAddressTable::createLeadAddressTable($schema);
156
    }
157
158
    /**
159
     * Create orocrm_sales_opportunity table
160
     *
161
     * @param Schema $schema
162
     */
163
    protected function createOrocrmSalesOpportunityTable(Schema $schema)
164
    {
165
        $table = $schema->createTable('orocrm_sales_opportunity');
166
        $table->addColumn('id', 'integer', ['autoincrement' => true]);
167
        $table->addColumn('contact_id', 'integer', ['notnull' => false]);
168
        $table->addColumn('close_reason_name', 'string', ['notnull' => false, 'length' => 32]);
169
        $table->addColumn('user_owner_id', 'integer', ['notnull' => false]);
170
        $table->addColumn('customer_id', 'integer', ['notnull' => false]);
171
        $table->addColumn('data_channel_id', 'integer', ['notnull' => false]);
172
        $table->addColumn('lead_id', 'integer', ['notnull' => false]);
173
        $table->addColumn('name', 'string', ['length' => 255]);
174
        $table->addColumn('close_date', 'date', ['notnull' => false]);
175
        $table->addColumn(
176
            'probability',
177
            'percent',
178
            ['notnull' => false, 'precision' => 0, 'comment' => '(DC2Type:percent)']
179
        );
180
        $table->addColumn(
181
            'budget_amount',
182
            'money',
183
            ['notnull' => false, 'precision' => 0, 'comment' => '(DC2Type:money)']
184
        );
185
        $table->addColumn(
186
            'close_revenue',
187
            'money',
188
            ['notnull' => false, 'precision' => 0, 'comment' => '(DC2Type:money)']
189
        );
190
        $table->addColumn('customer_need', 'text', ['notnull' => false]);
191
        $table->addColumn('proposed_solution', 'text', ['notnull' => false]);
192
        $table->addColumn('created_at', 'datetime', []);
193
        $table->addColumn('updated_at', 'datetime', []);
194
        $table->addColumn('notes', 'text', ['notnull' => false]);
195
        $table->addIndex(['contact_id'], 'idx_c0fe4aace7a1254a', []);
196
        $table->addIndex(['created_at'], 'opportunity_created_idx', []);
197
        $table->addIndex(['user_owner_id'], 'idx_c0fe4aac9eb185f9', []);
198
        $table->addIndex(['lead_id'], 'idx_c0fe4aac55458d', []);
199
        $table->addIndex(['customer_id'], 'IDX_C0FE4AAC9395C3F3', []);
200
        $table->addIndex(['data_channel_id'], 'IDX_C0FE4AACBDC09B73', []);
201
        $table->addIndex(['close_reason_name'], 'idx_c0fe4aacd81b931c', []);
202
        $table->setPrimaryKey(['id']);
203
    }
204
205
    /**
206
     * Create orocrm_sales_lead_status table
207
     *
208
     * @param Schema $schema
209
     */
210 View Code Duplication
    protected function createOrocrmSalesLeadStatusTable(Schema $schema)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
211
    {
212
        $table = $schema->createTable('orocrm_sales_lead_status');
213
        $table->addColumn('name', 'string', ['length' => 32]);
214
        $table->addColumn('label', 'string', ['length' => 255]);
215
        $table->addUniqueIndex(['label'], 'uniq_4516951bea750e8');
216
        $table->setPrimaryKey(['name']);
217
    }
218
219
    /**
220
     * Create orocrm_sales_funnel table
221
     *
222
     * @param Schema $schema
223
     */
224 View Code Duplication
    protected function createOrocrmSalesFunnelTable(Schema $schema)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
225
    {
226
        $table = $schema->createTable('orocrm_sales_funnel');
227
        $table->addColumn('id', 'integer', ['autoincrement' => true]);
228
        $table->addColumn('user_owner_id', 'integer', ['notnull' => false]);
229
        $table->addColumn('opportunity_id', 'integer', ['notnull' => false]);
230
        $table->addColumn('lead_id', 'integer', ['notnull' => false]);
231
        $table->addColumn('data_channel_id', 'integer', ['notnull' => false]);
232
        $table->addColumn('startdate', 'date', []);
233
        $table->addColumn('createdat', 'datetime', []);
234
        $table->addColumn('updatedat', 'datetime', ['notnull' => false]);
235
        $table->addIndex(['opportunity_id'], 'idx_e20c73449a34590f', []);
236
        $table->addIndex(['lead_id'], 'idx_e20c734455458d', []);
237
        $table->addIndex(['startdate'], 'sales_start_idx', []);
238
        $table->setPrimaryKey(['id']);
239
        $table->addIndex(['user_owner_id'], 'idx_e20c73449eb185f9', []);
240
        $table->addIndex(['data_channel_id'], 'IDX_E20C7344BDC09B73', []);
241
    }
242
243
    /**
244
     * Create orocrm_sales_opport_status table
245
     *
246
     * @param Schema $schema
247
     */
248 View Code Duplication
    protected function createOrocrmSalesOpportStatusTable(Schema $schema)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
249
    {
250
        $table = $schema->createTable('orocrm_sales_opport_status');
251
        $table->addColumn('name', 'string', ['length' => 32]);
252
        $table->addColumn('label', 'string', ['length' => 255]);
253
        $table->addUniqueIndex(['label'], 'uniq_2db212b5ea750e8');
254
        $table->setPrimaryKey(['name']);
255
    }
256
257
    /**
258
     * Create orocrm_sales_opport_close_rsn table
259
     *
260
     * @param Schema $schema
261
     */
262 View Code Duplication
    protected function createOrocrmSalesOpportCloseRsnTable(Schema $schema)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
263
    {
264
        $table = $schema->createTable('orocrm_sales_opport_close_rsn');
265
        $table->addColumn('name', 'string', ['length' => 32]);
266
        $table->addColumn('label', 'string', ['length' => 255]);
267
        $table->addUniqueIndex(['label'], 'uniq_fa526a41ea750e8');
268
        $table->setPrimaryKey(['name']);
269
    }
270
271
    /**
272
     * Create orocrm_sales_lead table
273
     *
274
     * @param Schema $schema
275
     */
276
    protected function createOrocrmSalesLeadTable(Schema $schema)
277
    {
278
        $table = $schema->createTable('orocrm_sales_lead');
279
        $table->addColumn('id', 'integer', ['autoincrement' => true]);
280
        $table->addColumn('address_id', 'integer', ['notnull' => false]);
281
        $table->addColumn('contact_id', 'integer', ['notnull' => false]);
282
        $table->addColumn('user_owner_id', 'integer', ['notnull' => false]);
283
        $table->addColumn('customer_id', 'integer', ['notnull' => false]);
284
        $table->addColumn('data_channel_id', 'integer', ['notnull' => false]);
285
        $table->addColumn('name', 'string', ['length' => 255]);
286
        $table->addColumn('name_prefix', 'string', ['notnull' => false, 'length' => 255]);
287
        $table->addColumn('first_name', 'string', ['notnull' => false, 'length' => 255]);
288
        $table->addColumn('middle_name', 'string', ['notnull' => false, 'length' => 255]);
289
        $table->addColumn('last_name', 'string', ['notnull' => false, 'length' => 255]);
290
        $table->addColumn('name_suffix', 'string', ['notnull' => false, 'length' => 255]);
291
        $table->addColumn('job_title', 'string', ['notnull' => false, 'length' => 255]);
292
        $table->addColumn('company_name', 'string', ['notnull' => false, 'length' => 255]);
293
        $table->addColumn('website', 'string', ['notnull' => false, 'length' => 255]);
294
        $table->addColumn('number_of_employees', 'integer', ['notnull' => false]);
295
        $table->addColumn('industry', 'string', ['notnull' => false, 'length' => 255]);
296
        $table->addColumn('createdat', 'datetime', []);
297
        $table->addColumn('updatedat', 'datetime', ['notnull' => false]);
298
        $table->addColumn('notes', 'text', ['notnull' => false]);
299
        $table->addColumn('twitter', 'string', ['length' => 255, 'notnull' => false]);
300
        $table->addColumn('linkedin', 'string', ['length' => 255, 'notnull' => false]);
301
302
        $this->extendExtension->addEnumField(
303
            $schema,
304
            'orocrm_sales_lead',
305
            'source',
306
            'lead_source'
307
        );
308
309
        $this->extendExtension->addManyToOneRelation(
310
            $schema,
311
            $table,
312
            'campaign',
313
            'orocrm_campaign',
314
            'combined_name',
315
            ['extend' => ['owner' => ExtendScope::OWNER_CUSTOM]]
316
        );
317
318
        $table->addIndex(['user_owner_id'], 'idx_73db46339eb185f9', []);
319
        $table->addIndex(['customer_id'], 'IDX_73DB46339395C3F3', []);
320
        $table->addIndex(['data_channel_id'], 'IDX_73DB4633BDC09B73', []);
321
        $table->addIndex(['createdat'], 'lead_created_idx', []);
322
        $table->addIndex(['contact_id'], 'idx_73db4633e7a1254a', []);
323
        $table->setPrimaryKey(['id']);
324
        $table->addIndex(['address_id'], 'idx_73db4633f5b7af75', []);
325
    }
326
327
    /**
328
     * Create orocrm_sales_b2bcustomer table
329
     *
330
     * @param Schema $schema
331
     */
332
    protected function createOrocrmSalesB2bCustomerTable(Schema $schema)
333
    {
334
        $table = $schema->createTable('orocrm_sales_b2bcustomer');
335
        $table->addColumn('id', 'integer', ['autoincrement' => true]);
336
        $table->addColumn('user_owner_id', 'integer', ['notnull' => false]);
337
        $table->addColumn('billing_address_id', 'integer', ['notnull' => false]);
338
        $table->addColumn('shipping_address_id', 'integer', ['notnull' => false]);
339
        $table->addColumn('data_channel_id', 'integer', ['notnull' => false]);
340
        $table->addColumn('account_id', 'integer', ['notnull' => false]);
341
        $table->addColumn('contact_id', 'integer', ['notnull' => false]);
342
        $table->addColumn('name', 'string', ['length' => 255]);
343
        $table->addColumn('lifetime', 'money', ['notnull' => false]);
344
        $table->addColumn('createdAt', 'datetime', []);
345
        $table->addColumn('updatedAt', 'datetime', []);
346
        $table->setPrimaryKey(['id']);
347
        $table->addIndex(['account_id'], 'IDX_94CC12929B6B5FBA', []);
348
        $table->addIndex(['shipping_address_id'], 'IDX_9C6CFD74D4CFF2B', []);
349
        $table->addIndex(['billing_address_id'], 'IDX_9C6CFD779D0C0E4', []);
350
        $table->addIndex(['contact_id'], 'IDX_9C6CFD7E7A1254A', []);
351
        $table->addIndex(['data_channel_id'], 'IDX_DAC0BD29BDC09B73', []);
352
        $table->addIndex(['user_owner_id'], 'IDX_9C6CFD79EB185F9', []);
353
354
        $table->addColumn(
355
            'website',
356
            'string',
357
            [
358
                'oro_options' => [
359
                    'extend'    => ['is_extend' => true, 'owner' => ExtendScope::OWNER_CUSTOM],
360
                    'datagrid'  => ['is_visible' => DatagridScope::IS_VISIBLE_HIDDEN],
361
                    'dataaudit' => ['auditable' => true]
362
                ]
363
            ]
364
        );
365
        $table->addColumn(
366
            'employees',
367
            'integer',
368
            [
369
                'oro_options' => [
370
                    'extend'    => ['is_extend' => true, 'owner' => ExtendScope::OWNER_CUSTOM],
371
                    'datagrid'  => ['is_visible' => DatagridScope::IS_VISIBLE_HIDDEN],
372
                    'dataaudit' => ['auditable' => true]
373
                ]
374
            ]
375
        );
376
        $table->addColumn(
377
            'ownership',
378
            'string',
379
            [
380
                'oro_options' => [
381
                    'extend'    => ['is_extend' => true, 'owner' => ExtendScope::OWNER_CUSTOM],
382
                    'datagrid'  => ['is_visible' => DatagridScope::IS_VISIBLE_HIDDEN],
383
                    'dataaudit' => ['auditable' => true]
384
                ]
385
            ]
386
        );
387
        $table->addColumn(
388
            'ticker_symbol',
389
            'string',
390
            [
391
                'oro_options' => [
392
                    'extend'    => ['is_extend' => true, 'owner' => ExtendScope::OWNER_CUSTOM],
393
                    'datagrid'  => ['is_visible' => DatagridScope::IS_VISIBLE_HIDDEN],
394
                    'dataaudit' => ['auditable' => true]
395
                ]
396
            ]
397
        );
398
        $table->addColumn(
399
            'rating',
400
            'string',
401
            [
402
                'oro_options' => [
403
                    'extend'    => ['is_extend' => true, 'owner' => ExtendScope::OWNER_CUSTOM],
404
                    'datagrid'  => ['is_visible' => DatagridScope::IS_VISIBLE_HIDDEN],
405
                    'dataaudit' => ['auditable' => true]
406
                ]
407
            ]
408
        );
409
    }
410
411
    /**
412
     * Create orocrm_lead_phone table
413
     *
414
     * @param Schema $schema
415
     */
416
    protected function createOrocrmLeadPhoneTable(Schema $schema)
417
    {
418
        $table = $schema->createTable('orocrm_sales_lead_phone');
419
        $table->addColumn('id', 'integer', ['autoincrement' => true]);
420
        $table->addColumn('owner_id', 'integer', ['notnull' => false]);
421
        $table->addColumn('phone', 'string', ['length' => 255]);
422
        $table->addColumn('is_primary', 'boolean', ['notnull' => false]);
423
        $table->setPrimaryKey(['id']);
424
        $table->addIndex(['owner_id'], 'IDX_8475907F7E3C61F9', []);
425
        $table->addIndex(['phone', 'is_primary'], 'lead_primary_phone_idx', []);
426
        $table->addIndex(['phone'], 'lead_phone_idx');
427
    }
428
429
    /**
430
     * Create orocrm_sales_lead_email table
431
     *
432
     * @param Schema $schema
433
     */
434
    protected function createOrocrmSalesLeadEmailTable(Schema $schema)
435
    {
436
        $table = $schema->createTable('orocrm_sales_lead_email');
437
        $table->addColumn('id', 'integer', ['autoincrement' => true]);
438
        $table->addColumn('owner_id', 'integer', ['notnull' => false]);
439
        $table->addColumn('email', 'string', ['length' => 255]);
440
        $table->addColumn('is_primary', 'boolean', ['notnull' => false]);
441
        $table->setPrimaryKey(['id']);
442
        $table->addIndex(['owner_id'], 'IDX_9F15A0937E3C61F9', []);
443
        $table->addIndex(['email', 'is_primary'], 'lead_primary_email_idx', []);
444
    }
445
446
    /**
447
     * Create orocrm_b2bcustomer_phone table
448
     *
449
     * @param Schema $schema
450
     */
451
    protected function createOrocrmB2bCustomerPhoneTable(Schema $schema)
452
    {
453
        $table = $schema->createTable('orocrm_sales_b2bcustomer_phone');
454
        $table->addColumn('id', 'integer', ['autoincrement' => true]);
455
        $table->addColumn('owner_id', 'integer', ['notnull' => false]);
456
        $table->addColumn('phone', 'string', ['length' => 255]);
457
        $table->addColumn('is_primary', 'boolean', ['notnull' => false]);
458
        $table->setPrimaryKey(['id']);
459
        $table->addIndex(['owner_id'], 'IDX_F0D0BDFA7E3C61F9', []);
460
        $table->addIndex(['phone', 'is_primary'], 'primary_b2bcustomer_phone_idx', []);
461
        $table->addIndex(['phone'], 'b2bcustomer_phone_idx');
462
    }
463
464
    /**
465
     * Create orocrm_b2bcustomer_email table
466
     *
467
     * @param Schema $schema
468
     */
469
    protected function createOrocrmB2bCustomerEmailTable(Schema $schema)
470
    {
471
        $table = $schema->createTable('orocrm_sales_b2bcustomer_email');
472
        $table->addColumn('id', 'integer', ['autoincrement' => true]);
473
        $table->addColumn('owner_id', 'integer', ['notnull' => false]);
474
        $table->addColumn('email', 'string', ['length' => 255]);
475
        $table->addColumn('is_primary', 'boolean', ['notnull' => false]);
476
        $table->setPrimaryKey(['id']);
477
        $table->addIndex(['owner_id'], 'IDX_D564AB17E3C61F9', []);
478
        $table->addIndex(['email', 'is_primary'], 'primary_b2bcustomer_email_idx', []);
479
    }
480
481
    /**
482
     * Add orocrm_sales_opportunity foreign keys.
483
     *
484
     * @param Schema $schema
485
     */
486 View Code Duplication
    protected function addOrocrmSalesOpportunityForeignKeys(Schema $schema)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
487
    {
488
        $table = $schema->getTable('orocrm_sales_opportunity');
489
        $table->addForeignKeyConstraint(
490
            $schema->getTable('orocrm_contact'),
491
            ['contact_id'],
492
            ['id'],
493
            ['onUpdate' => null, 'onDelete' => 'SET NULL']
494
        );
495
        $table->addForeignKeyConstraint(
496
            $schema->getTable('orocrm_sales_opport_close_rsn'),
497
            ['close_reason_name'],
498
            ['name'],
499
            ['onUpdate' => null, 'onDelete' => null]
500
        );
501
        $table->addForeignKeyConstraint(
502
            $schema->getTable('oro_user'),
503
            ['user_owner_id'],
504
            ['id'],
505
            ['onUpdate' => null, 'onDelete' => 'SET NULL']
506
        );
507
        $table->addForeignKeyConstraint(
508
            $schema->getTable('orocrm_sales_b2bcustomer'),
509
            ['customer_id'],
510
            ['id'],
511
            ['onDelete' => 'SET NULL', 'onUpdate' => null]
512
        );
513
        $table->addForeignKeyConstraint(
514
            $schema->getTable('orocrm_channel'),
515
            ['data_channel_id'],
516
            ['id'],
517
            ['onDelete' => 'SET NULL', 'onUpdate' => null],
518
            'FK_C0FE4AACBDC09B73'
519
        );
520
        $table->addForeignKeyConstraint(
521
            $schema->getTable('orocrm_sales_lead'),
522
            ['lead_id'],
523
            ['id'],
524
            ['onUpdate' => null, 'onDelete' => 'SET NULL']
525
        );
526
    }
527
528
    /**
529
     * Add orocrm_sales_funnel foreign keys.
530
     *
531
     * @param Schema $schema
532
     */
533
    protected function addOrocrmSalesFunnelForeignKeys(Schema $schema)
534
    {
535
        $table = $schema->getTable('orocrm_sales_funnel');
536
        $table->addForeignKeyConstraint(
537
            $schema->getTable('oro_user'),
538
            ['user_owner_id'],
539
            ['id'],
540
            ['onUpdate' => null, 'onDelete' => 'SET NULL']
541
        );
542
        $table->addForeignKeyConstraint(
543
            $schema->getTable('orocrm_sales_opportunity'),
544
            ['opportunity_id'],
545
            ['id'],
546
            ['onUpdate' => null, 'onDelete' => 'SET NULL']
547
        );
548
        $table->addForeignKeyConstraint(
549
            $schema->getTable('orocrm_sales_lead'),
550
            ['lead_id'],
551
            ['id'],
552
            ['onUpdate' => null, 'onDelete' => 'SET NULL']
553
        );
554
        $table->addForeignKeyConstraint(
555
            $schema->getTable('orocrm_channel'),
556
            ['data_channel_id'],
557
            ['id'],
558
            ['onDelete' => 'SET NULL', 'onUpdate' => null],
559
            'FK_E20C7344BDC09B73'
560
        );
561
    }
562
563
    /**
564
     * Add orocrm_sales_lead foreign keys.
565
     *
566
     * @param Schema $schema
567
     */
568 View Code Duplication
    protected function addOrocrmSalesLeadForeignKeys(Schema $schema)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
569
    {
570
        $table = $schema->getTable('orocrm_sales_lead');
571
        $table->addForeignKeyConstraint(
572
            $schema->getTable('orocrm_campaign'),
573
            ['campaign_id'],
574
            ['id'],
575
            ['onUpdate' => null, 'onDelete' => 'SET NULL']
576
        );
577
        $table->addForeignKeyConstraint(
578
            $schema->getTable('oro_address'),
579
            ['address_id'],
580
            ['id'],
581
            ['onUpdate' => null, 'onDelete' => 'SET NULL']
582
        );
583
        $table->addForeignKeyConstraint(
584
            $schema->getTable('orocrm_contact'),
585
            ['contact_id'],
586
            ['id'],
587
            ['onUpdate' => null, 'onDelete' => 'SET NULL']
588
        );
589
        $table->addForeignKeyConstraint(
590
            $schema->getTable('oro_user'),
591
            ['user_owner_id'],
592
            ['id'],
593
            ['onUpdate' => null, 'onDelete' => 'SET NULL']
594
        );
595
        $table->addForeignKeyConstraint(
596
            $schema->getTable('orocrm_sales_b2bcustomer'),
597
            ['customer_id'],
598
            ['id'],
599
            ['onDelete' => 'SET NULL', 'onUpdate' => null]
600
        );
601
        $table->addForeignKeyConstraint(
602
            $schema->getTable('orocrm_channel'),
603
            ['data_channel_id'],
604
            ['id'],
605
            ['onDelete' => 'SET NULL', 'onUpdate' => null],
606
            'FK_73DB4633BDC09B73'
607
        );
608
    }
609
610
    /**
611
     * Add orocrm_sales_b2bcustomer foreign keys.
612
     *
613
     * @param Schema $schema
614
     */
615 View Code Duplication
    protected function addOrocrmSalesB2bCustomerForeignKeys(Schema $schema)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
616
    {
617
        $table = $schema->getTable('orocrm_sales_b2bcustomer');
618
        $table->addForeignKeyConstraint(
619
            $schema->getTable('oro_user'),
620
            ['user_owner_id'],
621
            ['id'],
622
            ['onDelete' => 'SET NULL', 'onUpdate' => null]
623
        );
624
        $table->addForeignKeyConstraint(
625
            $schema->getTable('oro_address'),
626
            ['shipping_address_id'],
627
            ['id'],
628
            ['onDelete' => 'SET NULL', 'onUpdate' => null]
629
        );
630
        $table->addForeignKeyConstraint(
631
            $schema->getTable('orocrm_channel'),
632
            ['data_channel_id'],
633
            ['id'],
634
            ['onDelete' => 'SET NULL', 'onUpdate' => null]
635
        );
636
        $table->addForeignKeyConstraint(
637
            $schema->getTable('oro_address'),
638
            ['billing_address_id'],
639
            ['id'],
640
            ['onDelete' => 'SET NULL', 'onUpdate' => null]
641
        );
642
        $table->addForeignKeyConstraint(
643
            $schema->getTable('orocrm_account'),
644
            ['account_id'],
645
            ['id'],
646
            ['onDelete' => 'SET NULL', 'onUpdate' => null]
647
        );
648
        $table->addForeignKeyConstraint(
649
            $schema->getTable('orocrm_contact'),
650
            ['contact_id'],
651
            ['id'],
652
            ['onDelete' => 'SET NULL', 'onUpdate' => null]
653
        );
654
    }
655
656
    /**
657
     * Add opportunity status Enum field and initialize default enum values
658
     *
659
     * @param Schema $schema
660
     * @param QueryBag $queries
661
     */
662
    protected function addOpportunityStatusField(Schema $schema, QueryBag $queries)
663
    {
664
        $immutableCodes = ['in_progress', 'won', 'lost'];
665
666
        AddOpportunityStatus::addStatusField($schema, $this->extendExtension, $immutableCodes);
667
668
        $statuses = [
669
            'in_progress' => 'Open',
670
            'identification_alignment' => 'Identification & Alignment',
671
            'needs_analysis' => 'Needs Analysis',
672
            'solution_development' => 'Solution Development',
673
            'negotiation' => 'Negotiation',
674
            'won' => 'Closed Won',
675
            'lost' => 'Closed Lost',
676
        ];
677
678
        AddOpportunityStatus::addEnumValues($queries, $statuses);
679
    }
680
681
    /**
682
     * Create oro_email_mailbox_processor table
683
     *
684
     * @param Schema $schema
685
     */
686 View Code Duplication
    public static function addOroEmailMailboxProcessorColumns(Schema $schema)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
687
    {
688
        $table = $schema->getTable('oro_email_mailbox_process');
689
690
        $table->addColumn('lead_channel_id', 'integer', ['notnull' => false]);
691
        $table->addColumn('lead_owner_id', 'integer', ['notnull' => false]);
692
        $table->addColumn('lead_source_id', 'string', ['notnull' => false, 'length' => 32]);
693
        $table->addIndex(['lead_owner_id'], 'IDX_CE8602A3D46FE3FA', []);
694
        $table->addIndex(['lead_channel_id'], 'IDX_CE8602A35A6EBA36', []);
695
    }
696
697
    /**
698
     * Add oro_email_mailbox_processor foreign keys.
699
     *
700
     * @param Schema $schema
701
     */
702
    public static function addOroEmailMailboxProcessorForeignKeys(Schema $schema)
703
    {
704
        $table = $schema->getTable('oro_email_mailbox_process');
705
        $table->addForeignKeyConstraint(
706
            $schema->getTable('orocrm_channel'),
707
            ['lead_channel_id'],
708
            ['id'],
709
            ['onDelete' => 'SET NULL', 'onUpdate' => null]
710
        );
711
        $table->addForeignKeyConstraint(
712
            $schema->getTable('oro_user'),
713
            ['lead_owner_id'],
714
            ['id'],
715
            ['onDelete' => 'SET NULL', 'onUpdate' => null]
716
        );
717
    }
718
719
    /**
720
     * Add orocrm_b2bcustomer_phone foreign keys.
721
     *
722
     * @param Schema $schema
723
     */
724
    protected function addOrocrmB2bCustomerPhoneForeignKeys(Schema $schema)
725
    {
726
        $table = $schema->getTable('orocrm_sales_b2bcustomer_phone');
727
        $table->addForeignKeyConstraint(
728
            $schema->getTable('orocrm_sales_b2bcustomer'),
729
            ['owner_id'],
730
            ['id'],
731
            ['onDelete' => 'CASCADE', 'onUpdate' => null]
732
        );
733
    }
734
735
    /**
736
     * Add orocrm_b2bcustomer_email foreign keys.
737
     *
738
     * @param Schema $schema
739
     */
740
    protected function addOrocrmB2bCustomerEmailForeignKeys(Schema $schema)
741
    {
742
        $table = $schema->getTable('orocrm_sales_b2bcustomer_email');
743
        $table->addForeignKeyConstraint(
744
            $schema->getTable('orocrm_sales_b2bcustomer'),
745
            ['owner_id'],
746
            ['id'],
747
            ['onDelete' => 'CASCADE', 'onUpdate' => null]
748
        );
749
    }
750
751
    /**
752
     * Add orocrm_lead_phone foreign keys.
753
     *
754
     * @param Schema $schema
755
     */
756
    protected function addOrocrmLeadPhoneForeignKeys(Schema $schema)
757
    {
758
        $table = $schema->getTable('orocrm_sales_lead_phone');
759
        $table->addForeignKeyConstraint(
760
            $schema->getTable('orocrm_sales_lead'),
761
            ['owner_id'],
762
            ['id'],
763
            ['onDelete' => 'CASCADE', 'onUpdate' => null]
764
        );
765
    }
766
767
    /**
768
     * Add orocrm_sales_lead_email foreign keys.
769
     *
770
     * @param Schema $schema
771
     */
772
    protected function addOrocrmSalesLeadEmailForeignKeys(Schema $schema)
773
    {
774
        $table = $schema->getTable('orocrm_sales_lead_email');
775
        $table->addForeignKeyConstraint(
776
            $schema->getTable('orocrm_sales_lead'),
777
            ['owner_id'],
778
            ['id'],
779
            ['onDelete' => 'CASCADE', 'onUpdate' => null]
780
        );
781
    }
782
}
783