1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Oro\Bundle\ActivityBundle\Migration\Extension; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Schema\Schema; |
6
|
|
|
|
7
|
|
|
use Oro\Bundle\ActivityBundle\EntityConfig\ActivityScope; |
8
|
|
|
use Oro\Bundle\EntityExtendBundle\Migration\Extension\ExtendExtension; |
9
|
|
|
use Oro\Bundle\EntityExtendBundle\Migration\Extension\ExtendExtensionAwareInterface; |
10
|
|
|
use Oro\Bundle\EntityExtendBundle\Migration\OroOptions; |
11
|
|
|
use Oro\Bundle\EntityExtendBundle\Tools\ExtendHelper; |
12
|
|
|
use Oro\Bundle\EntityExtendBundle\Tools\ExtendDbIdentifierNameGenerator; |
13
|
|
|
use Oro\Bundle\MigrationBundle\Migration\Extension\NameGeneratorAwareInterface; |
14
|
|
|
use Oro\Bundle\MigrationBundle\Tools\DbIdentifierNameGenerator; |
15
|
|
|
|
16
|
|
|
class ActivityExtension implements ExtendExtensionAwareInterface, NameGeneratorAwareInterface |
17
|
|
|
{ |
18
|
|
|
/** @var ExtendExtension */ |
19
|
|
|
protected $extendExtension; |
20
|
|
|
|
21
|
|
|
/** @var ExtendDbIdentifierNameGenerator */ |
22
|
|
|
protected $nameGenerator; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* {@inheritdoc} |
26
|
|
|
*/ |
27
|
|
|
public function setExtendExtension(ExtendExtension $extendExtension) |
28
|
|
|
{ |
29
|
|
|
$this->extendExtension = $extendExtension; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* {@inheritdoc} |
34
|
|
|
*/ |
35
|
|
|
public function setNameGenerator(DbIdentifierNameGenerator $nameGenerator) |
36
|
|
|
{ |
37
|
|
|
$this->nameGenerator = $nameGenerator; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Adds the association between the given table and the table contains activity records |
42
|
|
|
* |
43
|
|
|
* The activity entity must be included in 'activity' group ('groups' attribute of 'grouping' scope) |
44
|
|
|
* |
45
|
|
|
* @param Schema $schema |
46
|
|
|
* @param string $activityTableName Activity entity table name. It is owning side of the association |
47
|
|
|
* @param string $targetTableName Target entity table name |
48
|
|
|
* @param bool $immutable Set TRUE to prohibit disabling the activity association from UI |
49
|
|
|
*/ |
50
|
|
|
public function addActivityAssociation( |
51
|
|
|
Schema $schema, |
52
|
|
|
$activityTableName, |
53
|
|
|
$targetTableName, |
54
|
|
|
$immutable = false |
55
|
|
|
) { |
56
|
|
|
$targetTable = $schema->getTable($targetTableName); |
57
|
|
|
|
58
|
|
|
// Column names are used to show a title of target entity |
59
|
|
|
$targetTitleColumnNames = $targetTable->getPrimaryKeyColumns(); |
60
|
|
|
// Column names are used to show detailed info about target entity |
61
|
|
|
$targetDetailedColumnNames = $targetTable->getPrimaryKeyColumns(); |
62
|
|
|
// Column names are used to show target entity in a grid |
63
|
|
|
$targetGridColumnNames = $targetTable->getPrimaryKeyColumns(); |
64
|
|
|
|
65
|
|
|
$activityClassName = $this->extendExtension->getEntityClassByTableName($activityTableName); |
66
|
|
|
|
67
|
|
|
$options = new OroOptions(); |
68
|
|
|
$options->append( |
69
|
|
|
'activity', |
70
|
|
|
'activities', |
71
|
|
|
$activityClassName |
72
|
|
|
); |
73
|
|
|
if ($immutable) { |
74
|
|
|
$options->append( |
75
|
|
|
'activity', |
76
|
|
|
'immutable', |
77
|
|
|
$activityClassName |
78
|
|
|
); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
$targetTable->addOption(OroOptions::KEY, $options); |
|
|
|
|
82
|
|
|
|
83
|
|
|
$associationName = ExtendHelper::buildAssociationName( |
84
|
|
|
$this->extendExtension->getEntityClassByTableName($targetTableName), |
85
|
|
|
ActivityScope::ASSOCIATION_KIND |
86
|
|
|
); |
87
|
|
|
|
88
|
|
|
$this->extendExtension->addManyToManyRelation( |
89
|
|
|
$schema, |
90
|
|
|
$activityTableName, |
91
|
|
|
$associationName, |
92
|
|
|
$targetTable, |
93
|
|
|
$targetTitleColumnNames, |
94
|
|
|
$targetDetailedColumnNames, |
95
|
|
|
$targetGridColumnNames, |
96
|
|
|
[ |
97
|
|
|
'extend' => [ |
98
|
|
|
'without_default' => true |
99
|
|
|
] |
100
|
|
|
] |
101
|
|
|
); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Gets a table name for many-to-many relation |
106
|
|
|
* |
107
|
|
|
* @param string $activityTableName Activity entity table name. It is owning side of the association. |
108
|
|
|
* @param string $targetTableName Target entity table name. |
109
|
|
|
* |
110
|
|
|
* @return string |
111
|
|
|
*/ |
112
|
|
|
public function getAssociationTableName($activityTableName, $targetTableName) |
113
|
|
|
{ |
114
|
|
|
$sourceClassName = $this->extendExtension->getEntityClassByTableName($activityTableName); |
115
|
|
|
$targetClassName = $this->extendExtension->getEntityClassByTableName($targetTableName); |
116
|
|
|
|
117
|
|
|
$associationName = ExtendHelper::buildAssociationName( |
118
|
|
|
$targetClassName, |
119
|
|
|
ActivityScope::ASSOCIATION_KIND |
120
|
|
|
); |
121
|
|
|
|
122
|
|
|
return $this->nameGenerator->generateManyToManyJoinTableName( |
123
|
|
|
$sourceClassName, |
124
|
|
|
$associationName, |
125
|
|
|
$targetClassName |
126
|
|
|
); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: