Skip to content

Commit d94a2ab

Browse files
author
Heath Dutton ☕
authored
Merge pull request #157 from TheDMSGroup/ENG-1030-bigint-ids
[ENG-1030] Upgrade IDs to Bigint where appropriate.
2 parents 1102d15 + 2bbb883 commit d94a2ab

5 files changed

Lines changed: 63 additions & 4 deletions

File tree

Entity/BigIntUnsignedTrait.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
/*
4+
* @copyright 2018 Mautic Contributors. All rights reserved
5+
* @author Digital Media Solutions, LLC
6+
*
7+
* @link http://mautic.org
8+
*
9+
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
10+
*/
11+
12+
namespace MauticPlugin\MauticContactSourceBundle\Entity;
13+
14+
use Doctrine\DBAL\Types\Type;
15+
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
16+
use Doctrine\ORM\Mapping\ClassMetadata;
17+
18+
trait BigIntUnsignedTrait
19+
{
20+
/**
21+
* Adds autogenerated ID field type of BIGINT UNSIGNED.
22+
*
23+
* @param ClassMetadataBuilder $builder
24+
* @param string $fieldName
25+
* @param string $columnName
26+
* @param bool $isPrimary
27+
* @param bool $isNullable
28+
*/
29+
public static function addBigIntUnsignedIdField(
30+
ClassMetadataBuilder $builder,
31+
$fieldName = 'id',
32+
$columnName = 'id',
33+
$isPrimary = true,
34+
$isNullable = false
35+
) {
36+
$cm = $builder->getClassMetadata();
37+
$cm->mapField(
38+
[
39+
'fieldName' => $fieldName,
40+
'columnName' => $columnName,
41+
'id' => $isPrimary,
42+
'nullable' => $isNullable,
43+
'type' => Type::BIGINT,
44+
'options' => [
45+
'unsigned' => true,
46+
],
47+
]
48+
);
49+
if ($isPrimary) {
50+
$cm->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_AUTO);
51+
}
52+
}
53+
}

Entity/Cache.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
*/
2626
class Cache
2727
{
28+
use BigIntUnsignedTrait;
29+
2830
/** @var int $id */
2931
private $id;
3032

@@ -88,7 +90,7 @@ public static function loadMetadata(ORM\ClassMetadata $metadata)
8890
{
8991
$builder = new ClassMetadataBuilder($metadata);
9092

91-
$builder->addId();
93+
self::addBigIntUnsignedIdField($builder);
9294

9395
$builder->setTable('contactsource_cache');
9496

Entity/Event.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
*/
2121
class Event
2222
{
23+
use BigIntUnsignedTrait;
24+
2325
/**
2426
* @ORM\Column(name="id", type="integer")
2527
* @ORM\Id
@@ -83,7 +85,7 @@ public static function loadMetadata(ORM\ClassMetadata $metadata)
8385
->addIndex(['contactsource_id', 'date_added'], 'contactsource_id_date_added')
8486
->addIndex(['contact_id'], 'contact_id');
8587

86-
$builder->addId();
88+
self::addBigIntUnsignedIdField($builder);
8789

8890
$builder->createManyToOne('contactSource', 'ContactSource')
8991
->addJoinColumn('contactsource_id', 'id', true, false, null)

Entity/Stat.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
*/
2323
class Stat
2424
{
25+
use BigIntUnsignedTrait;
26+
2527
/**
2628
* Real-time: Indicates that the contact was accepted by one or more clients.
2729
* Not real-time: Indicates we accepted the contact outright.
@@ -132,7 +134,7 @@ public static function loadMetadata(ORM\ClassMetadata $metadata)
132134
$builder->setTable('contactsource_stats')
133135
->setCustomRepositoryClass('MauticPlugin\MauticContactSourceBundle\Entity\StatRepository');
134136

135-
$builder->addId();
137+
self::addBigIntUnsignedIdField($builder);
136138

137139
$builder->createManyToOne('contactSource', 'ContactSource')
138140
->addJoinColumn('contactsource_id', 'id', true, false, null)

Model/Api.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ private function createContact()
931931

932932
// Apply to the contact for save later.
933933
$this->getUtmTag()->setLead($contact);
934-
/** @var UtmTagRepository $utmRepo */
934+
/* @var UtmTagRepository $utmRepo */
935935
// Randomly causes Doctrine\ORM\ORMInvalidArgumentException in production.
936936
// $utmRepo = $this->em->getRepository('MauticLeadBundle:UtmTag');
937937
// $utmRepo->saveEntity($this->getUtmTag(), false);

0 commit comments

Comments
 (0)