1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Application\Migrations; |
4
|
|
|
|
5
|
|
|
use Azine\MailgunWebhooksBundle\Entity\MailgunEvent; |
6
|
|
|
use Azine\MailgunWebhooksBundle\Entity\MailgunMessageSummary; |
7
|
|
|
use Doctrine\DBAL\Migrations\AbortMigrationException; |
|
|
|
|
8
|
|
|
use Doctrine\DBAL\Migrations\AbstractMigration; |
|
|
|
|
9
|
|
|
use Doctrine\DBAL\Schema\Schema; |
10
|
|
|
use Doctrine\ORM\EntityManager; |
11
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
12
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Update your db-table structure before applying this migration (doctrine:migration:diff && doctrine:migration:migrate). |
16
|
|
|
* |
17
|
|
|
* Important Note: doctrine:migration: diff will suggest to add a foreign key constraint like this: |
18
|
|
|
* "ALTER TABLE mailgun_event ADD CONSTRAINT FK_1271933F537A1329 FOREIGN KEY (message_id) REFERENCES mailgun_message_summary (id) ON DELETE CASCADE". |
19
|
|
|
* !!! BUT this constraint can only be added after the migration below ran successfully. !!! |
20
|
|
|
* |
21
|
|
|
* Add MessageSummary Entity to keep track and summarize what happened with a sent email. |
22
|
|
|
* Rename table email_traffic_statistics to mailgun_email_traffic_statistics |
23
|
|
|
*/ |
24
|
|
|
class Version20201228090100 extends AbstractMigration implements ContainerAwareInterface |
25
|
|
|
{ |
26
|
|
|
/** @var EntityManager */ |
27
|
|
|
private $manager; |
28
|
|
|
|
29
|
|
|
public function setContainer(ContainerInterface $container = null) |
30
|
|
|
{ |
31
|
|
|
$this->manager = $container->get('doctrine.orm.entity_manager'); |
|
|
|
|
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param Schema $schema |
36
|
|
|
* @throws AbortMigrationException |
37
|
|
|
*/ |
38
|
|
|
public function up(Schema $schema) |
39
|
|
|
{ |
40
|
|
|
$this->abortIf('mysql' != $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param Schema $schema |
45
|
|
|
* @throws \Doctrine\ORM\OptimisticLockException |
46
|
|
|
*/ |
47
|
|
|
public function postUp(Schema $schema) |
48
|
|
|
{ |
49
|
|
|
$repository = $this->manager->getRepository(MailgunMessageSummary::class); |
50
|
|
|
$processing = true; |
51
|
|
|
$page=0; |
52
|
|
|
$pageSize=100; |
53
|
|
|
while($processing) { |
54
|
|
|
$query = $this->manager->createQuery("select e from " . MailgunEvent::class . " e"); |
55
|
|
|
$query->setFirstResult($page*$pageSize); |
56
|
|
|
$query->setMaxResults($pageSize); |
57
|
|
|
$iterableResult = $query->iterate(); |
58
|
|
|
$counter = 0; |
59
|
|
|
foreach ($iterableResult as $row) { |
60
|
|
|
$repository->createOrUpdateMessageSummary($row[0]); |
61
|
|
|
$this->manager->flush(); |
62
|
|
|
$counter++; |
63
|
|
|
} |
64
|
|
|
$this->manager->commit(); |
65
|
|
|
$this->manager->clear(); |
66
|
|
|
$processing = $counter == $pageSize; |
67
|
|
|
$this->manager->beginTransaction(); |
68
|
|
|
$page++; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param Schema $schema |
74
|
|
|
* @throws AbortMigrationException |
75
|
|
|
*/ |
76
|
|
|
public function down(Schema $schema) |
77
|
|
|
{ |
78
|
|
|
$this->abortIf('mysql' != $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.'); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths