Issues (3627)

IntegrationsBundle/Entity/ObjectMapping.php (1 issue)

1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * @copyright   2018 Mautic Inc. All rights reserved
7
 * @author      Mautic, Inc.
8
 *
9
 * @link        https://www.mautic.com
10
 *
11
 * @license     GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
12
 */
13
14
namespace Mautic\IntegrationsBundle\Entity;
15
16
use Doctrine\DBAL\Types\Type;
17
use Doctrine\ORM\Mapping as ORM;
18
use Mautic\CoreBundle\Doctrine\Mapping\ClassMetadataBuilder;
19
20
class ObjectMapping
21
{
22
    /**
23
     * @var int
24
     */
25
    private $id;
26
27
    /**
28
     * @var \DateTime|null
29
     */
30
    private $dateCreated;
31
32
    /**
33
     * @var string
34
     */
35
    private $integration;
36
37
    /**
38
     * @var string
39
     */
40
    private $internalObjectName;
41
42
    /**
43
     * @var int
44
     */
45
    private $internalObjectId;
46
47
    /**
48
     * @var string
49
     */
50
    private $integrationObjectName;
51
52
    /**
53
     * @var string
54
     */
55
    private $integrationObjectId;
56
57
    /**
58
     * @var \DateTimeInterface
59
     */
60
    private $lastSyncDate;
61
62
    /**
63
     * @var array
64
     */
65
    private $internalStorage = [];
66
67
    /**
68
     * @var bool
69
     */
70
    private $isDeleted = false;
71
72
    /**
73
     * @var string|null
74
     */
75
    private $integrationReferenceId;
76
77
    public static function loadMetadata(ORM\ClassMetadata $metadata): void
78
    {
79
        $builder = new ClassMetadataBuilder($metadata);
80
81
        $builder
82
            ->setTable('sync_object_mapping')
83
            ->setCustomRepositoryClass(ObjectMappingRepository::class)
84
            ->addIndex(['integration', 'integration_object_name', 'integration_object_id', 'integration_reference_id'], 'integration_object')
85
            ->addIndex(['integration', 'integration_object_name', 'integration_reference_id', 'integration_object_id'], 'integration_reference')
86
            ->addIndex(['integration', 'last_sync_date'], 'integration_last_sync_date');
87
88
        $builder->addId();
89
90
        $builder
91
            ->createField('dateCreated', Type::DATETIME)
92
            ->columnName('date_created')
93
            ->build();
94
95
        $builder
96
            ->createField('integration', Type::STRING)
97
            ->build();
98
99
        $builder
100
            ->createField('internalObjectName', Type::STRING)
101
            ->columnName('internal_object_name')
102
            ->build();
103
104
        $builder->addBigIntIdField('internalObjectId', 'internal_object_id', false);
105
106
        $builder
107
            ->createField('integrationObjectName', Type::STRING)
108
            ->columnName('integration_object_name')
109
            ->build();
110
111
        // Must be a string as not all IDs are integer based
112
        $builder
113
            ->createField('integrationObjectId', Type::STRING)
114
            ->columnName('integration_object_id')
115
            ->build();
116
117
        $builder
118
            ->createField('lastSyncDate', Type::DATETIME)
119
            ->columnName('last_sync_date')
120
            ->build();
121
122
        $builder
123
            ->createField('internalStorage', Type::JSON_ARRAY)
124
            ->columnName('internal_storage')
125
            ->build();
126
127
        $builder
128
            ->createField('isDeleted', Type::BOOLEAN)
129
            ->columnName('is_deleted')
130
            ->build();
131
132
        $builder
133
            ->createField('integrationReferenceId', Type::STRING)
0 ignored issues
show
Deprecated Code introduced by
The constant Doctrine\DBAL\Types\Type::STRING has been deprecated: Use {@see Types::STRING} instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

133
            ->createField('integrationReferenceId', /** @scrutinizer ignore-deprecated */ Type::STRING)

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
134
            ->columnName('integration_reference_id')
135
            ->nullable()
136
            ->build();
137
    }
138
139
    /**
140
     * ObjectMapping constructor.
141
     *
142
     * @throws \Exception
143
     */
144
    public function __construct(?\DateTime $dateCreated = null)
145
    {
146
        if (null === $dateCreated) {
147
            $dateCreated = new \DateTime();
148
        }
149
150
        $this->dateCreated  = $dateCreated;
151
        $this->lastSyncDate = $dateCreated;
152
    }
153
154
    /**
155
     * @return int|null ?int
156
     */
157
    public function getId()
158
    {
159
        return $this->id;
160
    }
161
162
    /**
163
     * @param int $id
164
     *
165
     * @return ObjectMapping
166
     */
167
    public function setId($id)
168
    {
169
        $this->id = $id;
170
171
        return $this;
172
    }
173
174
    /**
175
     * @return \DateTime|null
176
     */
177
    public function getDateCreated()
178
    {
179
        return $this->dateCreated;
180
    }
181
182
    /**
183
     * @return string
184
     */
185
    public function getIntegration()
186
    {
187
        return $this->integration;
188
    }
189
190
    /**
191
     * @param string $integration
192
     *
193
     * @return ObjectMapping
194
     */
195
    public function setIntegration($integration)
196
    {
197
        $this->integration = $integration;
198
199
        return $this;
200
    }
201
202
    /**
203
     * @return string
204
     */
205
    public function getInternalObjectName()
206
    {
207
        return $this->internalObjectName;
208
    }
209
210
    /**
211
     * @param string $internalObjectName
212
     *
213
     * @return ObjectMapping
214
     */
215
    public function setInternalObjectName($internalObjectName)
216
    {
217
        $this->internalObjectName = $internalObjectName;
218
219
        return $this;
220
    }
221
222
    /**
223
     * @return int
224
     */
225
    public function getInternalObjectId()
226
    {
227
        return $this->internalObjectId;
228
    }
229
230
    /**
231
     * @param int $internalObjectId
232
     *
233
     * @return ObjectMapping
234
     */
235
    public function setInternalObjectId($internalObjectId)
236
    {
237
        $this->internalObjectId = $internalObjectId;
238
239
        return $this;
240
    }
241
242
    /**
243
     * @return string
244
     */
245
    public function getIntegrationObjectName()
246
    {
247
        return $this->integrationObjectName;
248
    }
249
250
    /**
251
     * @param string $integrationObjectName
252
     *
253
     * @return ObjectMapping
254
     */
255
    public function setIntegrationObjectName($integrationObjectName)
256
    {
257
        $this->integrationObjectName = $integrationObjectName;
258
259
        return $this;
260
    }
261
262
    /**
263
     * @return string
264
     */
265
    public function getIntegrationObjectId()
266
    {
267
        return $this->integrationObjectId;
268
    }
269
270
    /**
271
     * @param string $integrationObjectId
272
     *
273
     * @return ObjectMapping
274
     */
275
    public function setIntegrationObjectId($integrationObjectId)
276
    {
277
        $this->integrationObjectId = $integrationObjectId;
278
279
        return $this;
280
    }
281
282
    /**
283
     * @return \DateTimeInterface
284
     */
285
    public function getLastSyncDate()
286
    {
287
        return $this->lastSyncDate;
288
    }
289
290
    /**
291
     * @param \DateTimeInterface|null $lastSyncDate
292
     *
293
     * @return ObjectMapping
294
     *
295
     * @throws \Exception
296
     */
297
    public function setLastSyncDate($lastSyncDate)
298
    {
299
        if (null === $lastSyncDate) {
300
            $lastSyncDate = new \DateTime();
301
        }
302
303
        $this->lastSyncDate = $lastSyncDate;
304
305
        return $this;
306
    }
307
308
    /**
309
     * @return array
310
     */
311
    public function getInternalStorage()
312
    {
313
        return $this->internalStorage;
314
    }
315
316
    /**
317
     * @param array $internalStorage
318
     *
319
     * @return ObjectMapping
320
     */
321
    public function setInternalStorage($internalStorage)
322
    {
323
        $this->internalStorage = $internalStorage;
324
325
        return $this;
326
    }
327
328
    /**
329
     * @param $key
330
     * @param $value
331
     *
332
     * @return $this
333
     */
334
    public function appendToInternalStorage($key, $value)
335
    {
336
        $this->internalStorage[$key] = $value;
337
338
        return $this;
339
    }
340
341
    /**
342
     * @return bool
343
     */
344
    public function isDeleted()
345
    {
346
        return $this->isDeleted;
347
    }
348
349
    /**
350
     * @param bool $isDeleted
351
     *
352
     * @return ObjectMapping
353
     */
354
    public function setIsDeleted($isDeleted)
355
    {
356
        $this->isDeleted = $isDeleted;
357
358
        return $this;
359
    }
360
361
    /**
362
     * @return string|null
363
     */
364
    public function getIntegrationReferenceId()
365
    {
366
        return $this->integrationReferenceId;
367
    }
368
369
    /**
370
     * @param string|null $integrationReferenceId
371
     *
372
     * @return ObjectMapping
373
     */
374
    public function setIntegrationReferenceId($integrationReferenceId)
375
    {
376
        $this->integrationReferenceId = $integrationReferenceId;
377
378
        return $this;
379
    }
380
}
381