Completed
Push — master ( 3b7290...73d268 )
by
unknown
11:56
created

addOrocrmSalesOpportunityForeignKeys()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 53
Code Lines 43

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 53
rs 9.5797
cc 1
eloc 43
nc 1
nop 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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_22\AddOpportunityStatus;
27
28
/**
29
 * @SuppressWarnings(PHPMD.TooManyMethods)
30
 * @SuppressWarnings(PHPMD.ExcessiveClassLength)
31
 */
32
class OroCRMSalesBundleInstaller implements
33
    Installation,
34
    ExtendExtensionAwareInterface,
35
    NoteExtensionAwareInterface,
36
    ActivityExtensionAwareInterface,
37
    AttachmentExtensionAwareInterface,
38
    ActivityListExtensionAwareInterface
39
{
40
    /**
41
     * @var ExtendExtension
42
     */
43
    protected $extendExtension;
44
45
    /**
46
     * @var NoteExtension
47
     */
48
    protected $noteExtension;
49
50
    /**
51
     * @var ActivityExtension
52
     */
53
    protected $activityExtension;
54
55
    /**
56
     * @var AttachmentExtension
57
     */
58
    protected $attachmentExtension;
59
60
    /** @var ActivityListExtension */
61
    protected $activityListExtension;
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    public function setActivityListExtension(ActivityListExtension $activityListExtension)
67
    {
68
        $this->activityListExtension = $activityListExtension;
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    public function setExtendExtension(ExtendExtension $extendExtension)
75
    {
76
        $this->extendExtension = $extendExtension;
77
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82
    public function setNoteExtension(NoteExtension $noteExtension)
83
    {
84
        $this->noteExtension = $noteExtension;
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     */
90
    public function setActivityExtension(ActivityExtension $activityExtension)
91
    {
92
        $this->activityExtension = $activityExtension;
93
    }
94
95
    /**
96
     * {@inheritdoc}
97
     */
98
    public function setAttachmentExtension(AttachmentExtension $attachmentExtension)
99
    {
100
        $this->attachmentExtension = $attachmentExtension;
101
    }
102
103
    /**
104
     * {@inheritdoc}
105
     */
106
    public function getMigrationVersion()
107
    {
108
        return 'v1_22';
109
    }
110
111
    /**
112
     * {@inheritdoc}
113
     */
114
    public function up(Schema $schema, QueryBag $queries)
115
    {
116
        /** Tables generation **/
117
        $this->createOrocrmSalesOpportunityTable($schema);
118
        $this->createOrocrmSalesLeadStatusTable($schema);
119
        $this->createOrocrmSalesFunnelTable($schema);
120
        $this->createOrocrmSalesOpportStatusTable($schema);
121
        $this->createOrocrmSalesOpportCloseRsnTable($schema);
122
        $this->createOrocrmSalesLeadTable($schema);
123
        $this->createOrocrmSalesB2bCustomerTable($schema);
124
125
        /** Tables update */
126
        $this->addOroEmailMailboxProcessorColumns($schema);
127
128
        /** Foreign keys generation **/
129
        $this->addOrocrmSalesOpportunityForeignKeys($schema);
130
        $this->addOrocrmSalesFunnelForeignKeys($schema);
131
        $this->addOrocrmSalesLeadForeignKeys($schema);
132
        $this->addOrocrmSalesB2bCustomerForeignKeys($schema);
133
        $this->addOroEmailMailboxProcessorForeignKeys($schema);
134
135
        /** Apply extensions */
136
        SalesNoteMigration::addNoteAssociations($schema, $this->noteExtension);
137
        $this->activityExtension->addActivityAssociation($schema, 'oro_email', 'orocrm_sales_lead');
138
        $this->activityExtension->addActivityAssociation($schema, 'oro_email', 'orocrm_sales_opportunity');
139
        $this->activityExtension->addActivityAssociation($schema, 'oro_email', 'orocrm_sales_b2bcustomer');
140
        $this->activityExtension->addActivityAssociation($schema, 'orocrm_call', 'orocrm_sales_lead');
141
        $this->activityExtension->addActivityAssociation($schema, 'orocrm_call', 'orocrm_sales_opportunity');
142
        $this->activityExtension->addActivityAssociation($schema, 'orocrm_call', 'orocrm_sales_b2bcustomer');
143
        $this->activityExtension->addActivityAssociation($schema, 'orocrm_task', 'orocrm_sales_lead');
144
        $this->activityExtension->addActivityAssociation($schema, 'orocrm_task', 'orocrm_sales_opportunity');
145
        $this->activityExtension->addActivityAssociation($schema, 'orocrm_task', 'orocrm_sales_b2bcustomer');
146
        $this->activityExtension->addActivityAssociation($schema, 'oro_calendar_event', 'orocrm_sales_lead');
147
        $this->activityExtension->addActivityAssociation($schema, 'oro_calendar_event', 'orocrm_sales_opportunity');
148
        $this->activityExtension->addActivityAssociation($schema, 'oro_calendar_event', 'orocrm_sales_b2bcustomer');
149
        OpportunityAttachment::addOpportunityAttachment($schema, $this->attachmentExtension);
150
        InheritanceActivityTargets::addInheritanceTargets($schema, $this->activityListExtension);
151
152
        SalesOrganizations::addOrganization($schema);
153
        AddOpportunityStatus::addStatusField($schema, $this->extendExtension, $queries);
154
    }
155
156
    /**
157
     * Create orocrm_sales_opportunity table
158
     *
159
     * @param Schema $schema
160
     */
161
    protected function createOrocrmSalesOpportunityTable(Schema $schema)
162
    {
163
        $table = $schema->createTable('orocrm_sales_opportunity');
164
        $table->addColumn('id', 'integer', ['autoincrement' => true]);
165
        $table->addColumn('contact_id', 'integer', ['notnull' => false]);
166
        $table->addColumn('close_reason_name', 'string', ['notnull' => false, 'length' => 32]);
167
        $table->addColumn('user_owner_id', 'integer', ['notnull' => false]);
168
        $table->addColumn('customer_id', 'integer', ['notnull' => false]);
169
        $table->addColumn('data_channel_id', 'integer', ['notnull' => false]);
170
        $table->addColumn('lead_id', 'integer', ['notnull' => false]);
171
        $table->addColumn('workflow_item_id', 'integer', ['notnull' => false]);
172
        $table->addColumn('workflow_step_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->addUniqueIndex(['workflow_item_id'], 'uniq_c0fe4aac1023c4ee');
198
        $table->addIndex(['user_owner_id'], 'idx_c0fe4aac9eb185f9', []);
199
        $table->addIndex(['lead_id'], 'idx_c0fe4aac55458d', []);
200
        $table->addIndex(['customer_id'], 'IDX_C0FE4AAC9395C3F3', []);
201
        $table->addIndex(['data_channel_id'], 'IDX_C0FE4AACBDC09B73', []);
202
        $table->addIndex(['close_reason_name'], 'idx_c0fe4aacd81b931c', []);
203
        $table->setPrimaryKey(['id']);
204
        $table->addIndex(['workflow_step_id'], 'idx_c0fe4aac71fe882c', []);
205
    }
206
207
    /**
208
     * Create orocrm_sales_lead_status table
209
     *
210
     * @param Schema $schema
211
     */
212 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...
213
    {
214
        $table = $schema->createTable('orocrm_sales_lead_status');
215
        $table->addColumn('name', 'string', ['length' => 32]);
216
        $table->addColumn('label', 'string', ['length' => 255]);
217
        $table->addUniqueIndex(['label'], 'uniq_4516951bea750e8');
218
        $table->setPrimaryKey(['name']);
219
    }
220
221
    /**
222
     * Create orocrm_sales_funnel table
223
     *
224
     * @param Schema $schema
225
     */
226
    protected function createOrocrmSalesFunnelTable(Schema $schema)
227
    {
228
        $table = $schema->createTable('orocrm_sales_funnel');
229
        $table->addColumn('id', 'integer', ['autoincrement' => true]);
230
        $table->addColumn('user_owner_id', 'integer', ['notnull' => false]);
231
        $table->addColumn('opportunity_id', 'integer', ['notnull' => false]);
232
        $table->addColumn('lead_id', 'integer', ['notnull' => false]);
233
        $table->addColumn('workflow_item_id', 'integer', ['notnull' => false]);
234
        $table->addColumn('workflow_step_id', 'integer', ['notnull' => false]);
235
        $table->addColumn('data_channel_id', 'integer', ['notnull' => false]);
236
        $table->addColumn('startdate', 'date', []);
237
        $table->addColumn('createdat', 'datetime', []);
238
        $table->addColumn('updatedat', 'datetime', ['notnull' => false]);
239
        $table->addIndex(['opportunity_id'], 'idx_e20c73449a34590f', []);
240
        $table->addIndex(['workflow_step_id'], 'idx_e20c734471fe882c', []);
241
        $table->addIndex(['lead_id'], 'idx_e20c734455458d', []);
242
        $table->addIndex(['startdate'], 'sales_start_idx', []);
243
        $table->setPrimaryKey(['id']);
244
        $table->addIndex(['user_owner_id'], 'idx_e20c73449eb185f9', []);
245
        $table->addIndex(['data_channel_id'], 'IDX_E20C7344BDC09B73', []);
246
        $table->addUniqueIndex(['workflow_item_id'], 'uniq_e20c73441023c4ee');
247
    }
248
249
    /**
250
     * Create orocrm_sales_opport_status table
251
     *
252
     * @param Schema $schema
253
     */
254 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...
255
    {
256
        $table = $schema->createTable('orocrm_sales_opport_status');
257
        $table->addColumn('name', 'string', ['length' => 32]);
258
        $table->addColumn('label', 'string', ['length' => 255]);
259
        $table->addUniqueIndex(['label'], 'uniq_2db212b5ea750e8');
260
        $table->setPrimaryKey(['name']);
261
    }
262
263
    /**
264
     * Create orocrm_sales_opport_close_rsn table
265
     *
266
     * @param Schema $schema
267
     */
268 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...
269
    {
270
        $table = $schema->createTable('orocrm_sales_opport_close_rsn');
271
        $table->addColumn('name', 'string', ['length' => 32]);
272
        $table->addColumn('label', 'string', ['length' => 255]);
273
        $table->addUniqueIndex(['label'], 'uniq_fa526a41ea750e8');
274
        $table->setPrimaryKey(['name']);
275
    }
276
277
    /**
278
     * Create orocrm_sales_lead table
279
     *
280
     * @param Schema $schema
281
     */
282
    protected function createOrocrmSalesLeadTable(Schema $schema)
283
    {
284
        $table = $schema->createTable('orocrm_sales_lead');
285
        $table->addColumn('id', 'integer', ['autoincrement' => true]);
286
        $table->addColumn('address_id', 'integer', ['notnull' => false]);
287
        $table->addColumn('contact_id', 'integer', ['notnull' => false]);
288
        $table->addColumn('user_owner_id', 'integer', ['notnull' => false]);
289
        $table->addColumn('customer_id', 'integer', ['notnull' => false]);
290
        $table->addColumn('data_channel_id', 'integer', ['notnull' => false]);
291
        $table->addColumn('status_name', 'string', ['notnull' => false, 'length' => 32]);
292
        $table->addColumn('workflow_item_id', 'integer', ['notnull' => false]);
293
        $table->addColumn('workflow_step_id', 'integer', ['notnull' => false]);
294
        $table->addColumn('name', 'string', ['length' => 255]);
295
        $table->addColumn('name_prefix', 'string', ['notnull' => false, 'length' => 255]);
296
        $table->addColumn('first_name', 'string', ['length' => 255]);
297
        $table->addColumn('middle_name', 'string', ['notnull' => false, 'length' => 255]);
298
        $table->addColumn('last_name', 'string', ['length' => 255]);
299
        $table->addColumn('name_suffix', 'string', ['notnull' => false, 'length' => 255]);
300
        $table->addColumn('job_title', 'string', ['notnull' => false, 'length' => 255]);
301
        $table->addColumn('phone_number', 'string', ['notnull' => false, 'length' => 255]);
302
        $table->addColumn('email', 'string', ['notnull' => false, 'length' => 255]);
303
        $table->addColumn('company_name', 'string', ['notnull' => false, 'length' => 255]);
304
        $table->addColumn('website', 'string', ['notnull' => false, 'length' => 255]);
305
        $table->addColumn('number_of_employees', 'integer', ['notnull' => false]);
306
        $table->addColumn('industry', 'string', ['notnull' => false, 'length' => 255]);
307
        $table->addColumn('createdat', 'datetime', []);
308
        $table->addColumn('updatedat', 'datetime', ['notnull' => false]);
309
        $table->addColumn('notes', 'text', ['notnull' => false]);
310
311
        $this->extendExtension->addEnumField(
312
            $schema,
313
            'orocrm_sales_lead',
314
            'source',
315
            'lead_source'
316
        );
317
318
        $this->extendExtension->addManyToOneRelation(
319
            $schema,
320
            $table,
321
            'campaign',
322
            'orocrm_campaign',
323
            'combined_name',
324
            ['extend' => ['owner' => ExtendScope::OWNER_CUSTOM]]
325
        );
326
327
        $table->addIndex(['status_name'], 'idx_73db46336625d392', []);
328
        $table->addIndex(['user_owner_id'], 'idx_73db46339eb185f9', []);
329
        $table->addIndex(['customer_id'], 'IDX_73DB46339395C3F3', []);
330
        $table->addIndex(['data_channel_id'], 'IDX_73DB4633BDC09B73', []);
331
        $table->addIndex(['createdat'], 'lead_created_idx', []);
332
        $table->addIndex(['contact_id'], 'idx_73db4633e7a1254a', []);
333
        $table->setPrimaryKey(['id']);
334
        $table->addIndex(['workflow_step_id'], 'idx_73db463371fe882c', []);
335
        $table->addIndex(['address_id'], 'idx_73db4633f5b7af75', []);
336
        $table->addUniqueIndex(['workflow_item_id'], 'uniq_73db46331023c4ee');
337
    }
338
339
    /**
340
     * Create orocrm_sales_b2bcustomer table
341
     *
342
     * @param Schema $schema
343
     */
344
    protected function createOrocrmSalesB2bCustomerTable(Schema $schema)
345
    {
346
        $table = $schema->createTable('orocrm_sales_b2bcustomer');
347
        $table->addColumn('id', 'integer', ['autoincrement' => true]);
348
        $table->addColumn('user_owner_id', 'integer', ['notnull' => false]);
349
        $table->addColumn('billing_address_id', 'integer', ['notnull' => false]);
350
        $table->addColumn('shipping_address_id', 'integer', ['notnull' => false]);
351
        $table->addColumn('data_channel_id', 'integer', ['notnull' => false]);
352
        $table->addColumn('account_id', 'integer', ['notnull' => false]);
353
        $table->addColumn('contact_id', 'integer', ['notnull' => false]);
354
        $table->addColumn('name', 'string', ['length' => 255]);
355
        $table->addColumn('lifetime', 'money', ['notnull' => false]);
356
        $table->addColumn('createdAt', 'datetime', []);
357
        $table->addColumn('updatedAt', 'datetime', []);
358
        $table->setPrimaryKey(['id']);
359
        $table->addIndex(['account_id'], 'IDX_94CC12929B6B5FBA', []);
360
        $table->addIndex(['shipping_address_id'], 'IDX_9C6CFD74D4CFF2B', []);
361
        $table->addIndex(['billing_address_id'], 'IDX_9C6CFD779D0C0E4', []);
362
        $table->addIndex(['contact_id'], 'IDX_9C6CFD7E7A1254A', []);
363
        $table->addIndex(['data_channel_id'], 'IDX_DAC0BD29BDC09B73', []);
364
        $table->addIndex(['user_owner_id'], 'IDX_9C6CFD79EB185F9', []);
365
366
        $table->addColumn(
367
            'website',
368
            'string',
369
            [
370
                'oro_options' => [
371
                    'extend'    => ['is_extend' => true, 'owner' => ExtendScope::OWNER_CUSTOM],
372
                    'datagrid'  => ['is_visible' => DatagridScope::IS_VISIBLE_HIDDEN],
373
                    'dataaudit' => ['auditable' => true]
374
                ]
375
            ]
376
        );
377
        $table->addColumn(
378
            'employees',
379
            'integer',
380
            [
381
                'oro_options' => [
382
                    'extend'    => ['is_extend' => true, 'owner' => ExtendScope::OWNER_CUSTOM],
383
                    'datagrid'  => ['is_visible' => DatagridScope::IS_VISIBLE_HIDDEN],
384
                    'dataaudit' => ['auditable' => true]
385
                ]
386
            ]
387
        );
388
        $table->addColumn(
389
            'ownership',
390
            'string',
391
            [
392
                'oro_options' => [
393
                    'extend'    => ['is_extend' => true, 'owner' => ExtendScope::OWNER_CUSTOM],
394
                    'datagrid'  => ['is_visible' => DatagridScope::IS_VISIBLE_HIDDEN],
395
                    'dataaudit' => ['auditable' => true]
396
                ]
397
            ]
398
        );
399
        $table->addColumn(
400
            'ticker_symbol',
401
            'string',
402
            [
403
                'oro_options' => [
404
                    'extend'    => ['is_extend' => true, 'owner' => ExtendScope::OWNER_CUSTOM],
405
                    'datagrid'  => ['is_visible' => DatagridScope::IS_VISIBLE_HIDDEN],
406
                    'dataaudit' => ['auditable' => true]
407
                ]
408
            ]
409
        );
410
        $table->addColumn(
411
            'rating',
412
            'string',
413
            [
414
                'oro_options' => [
415
                    'extend'    => ['is_extend' => true, 'owner' => ExtendScope::OWNER_CUSTOM],
416
                    'datagrid'  => ['is_visible' => DatagridScope::IS_VISIBLE_HIDDEN],
417
                    'dataaudit' => ['auditable' => true]
418
                ]
419
            ]
420
        );
421
    }
422
423
    /**
424
     * Add orocrm_sales_opportunity foreign keys.
425
     *
426
     * @param Schema $schema
427
     */
428
    protected function addOrocrmSalesOpportunityForeignKeys(Schema $schema)
429
    {
430
        $table = $schema->getTable('orocrm_sales_opportunity');
431
        $table->addForeignKeyConstraint(
432
            $schema->getTable('orocrm_contact'),
433
            ['contact_id'],
434
            ['id'],
435
            ['onUpdate' => null, 'onDelete' => 'SET NULL']
436
        );
437
        $table->addForeignKeyConstraint(
438
            $schema->getTable('orocrm_sales_opport_close_rsn'),
439
            ['close_reason_name'],
440
            ['name'],
441
            ['onUpdate' => null, 'onDelete' => null]
442
        );
443
        $table->addForeignKeyConstraint(
444
            $schema->getTable('oro_user'),
445
            ['user_owner_id'],
446
            ['id'],
447
            ['onUpdate' => null, 'onDelete' => 'SET NULL']
448
        );
449
        $table->addForeignKeyConstraint(
450
            $schema->getTable('orocrm_sales_b2bcustomer'),
451
            ['customer_id'],
452
            ['id'],
453
            ['onDelete' => 'SET NULL', 'onUpdate' => null]
454
        );
455
        $table->addForeignKeyConstraint(
456
            $schema->getTable('orocrm_channel'),
457
            ['data_channel_id'],
458
            ['id'],
459
            ['onDelete' => 'SET NULL', 'onUpdate' => null],
460
            'FK_C0FE4AACBDC09B73'
461
        );
462
        $table->addForeignKeyConstraint(
463
            $schema->getTable('orocrm_sales_lead'),
464
            ['lead_id'],
465
            ['id'],
466
            ['onUpdate' => null, 'onDelete' => 'SET NULL']
467
        );
468
        $table->addForeignKeyConstraint(
469
            $schema->getTable('oro_workflow_item'),
470
            ['workflow_item_id'],
471
            ['id'],
472
            ['onUpdate' => null, 'onDelete' => 'SET NULL']
473
        );
474
        $table->addForeignKeyConstraint(
475
            $schema->getTable('oro_workflow_step'),
476
            ['workflow_step_id'],
477
            ['id'],
478
            ['onUpdate' => null, 'onDelete' => 'SET NULL']
479
        );
480
    }
481
482
    /**
483
     * Add orocrm_sales_funnel foreign keys.
484
     *
485
     * @param Schema $schema
486
     */
487 View Code Duplication
    protected function addOrocrmSalesFunnelForeignKeys(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...
488
    {
489
        $table = $schema->getTable('orocrm_sales_funnel');
490
        $table->addForeignKeyConstraint(
491
            $schema->getTable('oro_user'),
492
            ['user_owner_id'],
493
            ['id'],
494
            ['onUpdate' => null, 'onDelete' => 'SET NULL']
495
        );
496
        $table->addForeignKeyConstraint(
497
            $schema->getTable('orocrm_sales_opportunity'),
498
            ['opportunity_id'],
499
            ['id'],
500
            ['onUpdate' => null, 'onDelete' => 'SET NULL']
501
        );
502
        $table->addForeignKeyConstraint(
503
            $schema->getTable('orocrm_sales_lead'),
504
            ['lead_id'],
505
            ['id'],
506
            ['onUpdate' => null, 'onDelete' => 'SET NULL']
507
        );
508
        $table->addForeignKeyConstraint(
509
            $schema->getTable('oro_workflow_item'),
510
            ['workflow_item_id'],
511
            ['id'],
512
            ['onUpdate' => null, 'onDelete' => 'SET NULL']
513
        );
514
        $table->addForeignKeyConstraint(
515
            $schema->getTable('oro_workflow_step'),
516
            ['workflow_step_id'],
517
            ['id'],
518
            ['onUpdate' => null, 'onDelete' => 'SET NULL']
519
        );
520
        $table->addForeignKeyConstraint(
521
            $schema->getTable('orocrm_channel'),
522
            ['data_channel_id'],
523
            ['id'],
524
            ['onDelete' => 'SET NULL', 'onUpdate' => null],
525
            'FK_E20C7344BDC09B73'
526
        );
527
    }
528
529
    /**
530
     * Add orocrm_sales_lead foreign keys.
531
     *
532
     * @param Schema $schema
533
     */
534 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...
535
    {
536
        $table = $schema->getTable('orocrm_sales_lead');
537
        $table->addForeignKeyConstraint(
538
            $schema->getTable('orocrm_campaign'),
539
            ['campaign_id'],
540
            ['id'],
541
            ['onUpdate' => null, 'onDelete' => 'SET NULL']
542
        );
543
        $table->addForeignKeyConstraint(
544
            $schema->getTable('oro_address'),
545
            ['address_id'],
546
            ['id'],
547
            ['onUpdate' => null, 'onDelete' => 'SET NULL']
548
        );
549
        $table->addForeignKeyConstraint(
550
            $schema->getTable('orocrm_contact'),
551
            ['contact_id'],
552
            ['id'],
553
            ['onUpdate' => null, 'onDelete' => 'SET NULL']
554
        );
555
        $table->addForeignKeyConstraint(
556
            $schema->getTable('oro_user'),
557
            ['user_owner_id'],
558
            ['id'],
559
            ['onUpdate' => null, 'onDelete' => 'SET NULL']
560
        );
561
        $table->addForeignKeyConstraint(
562
            $schema->getTable('orocrm_sales_b2bcustomer'),
563
            ['customer_id'],
564
            ['id'],
565
            ['onDelete' => 'SET NULL', 'onUpdate' => null]
566
        );
567
        $table->addForeignKeyConstraint(
568
            $schema->getTable('orocrm_channel'),
569
            ['data_channel_id'],
570
            ['id'],
571
            ['onDelete' => 'SET NULL', 'onUpdate' => null],
572
            'FK_73DB4633BDC09B73'
573
        );
574
        $table->addForeignKeyConstraint(
575
            $schema->getTable('orocrm_sales_lead_status'),
576
            ['status_name'],
577
            ['name'],
578
            ['onUpdate' => null, 'onDelete' => null]
579
        );
580
        $table->addForeignKeyConstraint(
581
            $schema->getTable('oro_workflow_item'),
582
            ['workflow_item_id'],
583
            ['id'],
584
            ['onUpdate' => null, 'onDelete' => 'SET NULL']
585
        );
586
        $table->addForeignKeyConstraint(
587
            $schema->getTable('oro_workflow_step'),
588
            ['workflow_step_id'],
589
            ['id'],
590
            ['onUpdate' => null, 'onDelete' => 'SET NULL']
591
        );
592
    }
593
594
    /**
595
     * Add orocrm_sales_b2bcustomer foreign keys.
596
     *
597
     * @param Schema $schema
598
     */
599 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...
600
    {
601
        $table = $schema->getTable('orocrm_sales_b2bcustomer');
602
        $table->addForeignKeyConstraint(
603
            $schema->getTable('oro_user'),
604
            ['user_owner_id'],
605
            ['id'],
606
            ['onDelete' => 'SET NULL', 'onUpdate' => null]
607
        );
608
        $table->addForeignKeyConstraint(
609
            $schema->getTable('oro_address'),
610
            ['shipping_address_id'],
611
            ['id'],
612
            ['onDelete' => 'SET NULL', 'onUpdate' => null]
613
        );
614
        $table->addForeignKeyConstraint(
615
            $schema->getTable('orocrm_channel'),
616
            ['data_channel_id'],
617
            ['id'],
618
            ['onDelete' => 'SET NULL', 'onUpdate' => null]
619
        );
620
        $table->addForeignKeyConstraint(
621
            $schema->getTable('oro_address'),
622
            ['billing_address_id'],
623
            ['id'],
624
            ['onDelete' => 'SET NULL', 'onUpdate' => null]
625
        );
626
        $table->addForeignKeyConstraint(
627
            $schema->getTable('orocrm_account'),
628
            ['account_id'],
629
            ['id'],
630
            ['onDelete' => 'SET NULL', 'onUpdate' => null]
631
        );
632
        $table->addForeignKeyConstraint(
633
            $schema->getTable('orocrm_contact'),
634
            ['contact_id'],
635
            ['id'],
636
            ['onDelete' => 'SET NULL', 'onUpdate' => null]
637
        );
638
    }
639
640
    /**
641
     * Create oro_email_mailbox_processor table
642
     *
643
     * @param Schema $schema
644
     */
645 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...
646
    {
647
        $table = $schema->getTable('oro_email_mailbox_process');
648
649
        $table->addColumn('lead_channel_id', 'integer', ['notnull' => false]);
650
        $table->addColumn('lead_owner_id', 'integer', ['notnull' => false]);
651
        $table->addColumn('lead_source_id', 'string', ['notnull' => false, 'length' => 32]);
652
        $table->addIndex(['lead_owner_id'], 'IDX_CE8602A3D46FE3FA', []);
653
        $table->addIndex(['lead_channel_id'], 'IDX_CE8602A35A6EBA36', []);
654
    }
655
656
    /**
657
     * Add oro_email_mailbox_processor foreign keys.
658
     *
659
     * @param Schema $schema
660
     */
661
    public static function addOroEmailMailboxProcessorForeignKeys(Schema $schema)
662
    {
663
        $table = $schema->getTable('oro_email_mailbox_process');
664
        $table->addForeignKeyConstraint(
665
            $schema->getTable('orocrm_channel'),
666
            ['lead_channel_id'],
667
            ['id'],
668
            ['onDelete' => 'SET NULL', 'onUpdate' => null]
669
        );
670
        $table->addForeignKeyConstraint(
671
            $schema->getTable('oro_user'),
672
            ['lead_owner_id'],
673
            ['id'],
674
            ['onDelete' => 'SET NULL', 'onUpdate' => null]
675
        );
676
    }
677
}
678