Skip to content

Commit fa0653e

Browse files
authored
Merge pull request mautic#15199 from patrykgruszka/fix-execute-query-usage
Replace improper executeQuery usage with executeStatement for data modification queries
2 parents 28985fb + cfc19e0 commit fa0653e

File tree

16 files changed

+22
-22
lines changed

16 files changed

+22
-22
lines changed

app/bundles/CampaignBundle/Entity/LeadEventLogRepository.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ public function removeEventLogsByCampaignId(int $campaignId): void
625625
$conn = $this->getEntityManager()->getConnection();
626626
$deleteEntries = true;
627627
while ($deleteEntries) {
628-
$deleteEntries = $conn->executeQuery($sql, [$campaignId], [Types::INTEGER])->rowCount();
628+
$deleteEntries = $conn->executeStatement($sql, [$campaignId], [Types::INTEGER]);
629629
}
630630
}
631631

@@ -639,7 +639,7 @@ public function removeEventLogs(array $eventIds): void
639639
$conn = $this->getEntityManager()->getConnection();
640640
$deleteEntries = true;
641641
while ($deleteEntries) {
642-
$deleteEntries = $conn->executeQuery($sql, [$eventIds], [ArrayParameterType::INTEGER])->rowCount();
642+
$deleteEntries = $conn->executeStatement($sql, [$eventIds], [ArrayParameterType::INTEGER]);
643643
}
644644
}
645645

app/bundles/CampaignBundle/Entity/SummaryRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function summarize(
138138
' triggered_count = s.triggered_count_i, '.
139139
' log_counts_processed = s.log_counts_processed_i;';
140140

141-
$this->getEntityManager()->getConnection()->executeQuery($sql);
141+
$this->getEntityManager()->getConnection()->executeStatement($sql);
142142
}
143143
}
144144
}

app/bundles/CampaignBundle/Tests/Functional/Entity/LeadEventLogRepositoryTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ public function testThatRemoveEventLogsMethodRemovesLogs(): void
2121

2222
$insertStatement = $connection->prepare('INSERT INTO `'.MAUTIC_TABLE_PREFIX.'campaign_lead_event_log` (`event_id`, `lead_id`, `rotation`, `is_scheduled`, `system_triggered`) VALUES (?, ?, ?, ?, ?);');
2323

24-
$connection->executeQuery('SET FOREIGN_KEY_CHECKS=0;');
24+
$connection->executeStatement('SET FOREIGN_KEY_CHECKS=0;');
2525
foreach ($this->getLeadCampaignEventData($eventId) as $row) {
26-
$insertStatement->executeQuery($row);
26+
$insertStatement->executeStatement($row);
2727
}
28-
$connection->executeQuery('SET FOREIGN_KEY_CHECKS=1;');
28+
$connection->executeStatement('SET FOREIGN_KEY_CHECKS=1;');
2929

3030
Assert::assertCount(3, $leadEventLogRepository->findAll());
3131

app/bundles/CoreBundle/Entity/AuditLogRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,6 @@ public function anonymizeAllIpAddress(): int
261261
$sql = "UPDATE {$table_name} SET ip_address = '*.*.*.*' WHERE ip_address != '*.*.*.*'";
262262
$conn = $this->getEntityManager()->getConnection();
263263

264-
return $conn->executeQuery($sql)->rowCount();
264+
return $conn->executeStatement($sql);
265265
}
266266
}

app/bundles/CoreBundle/Entity/IpAddressRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,6 @@ public function anonymizeAllIpAddress(): int
114114
$sql = "UPDATE {$table_name} SET ip_address = '*.*.*.*', ip_details = 'N;' WHERE ip_address != '*.*.*.*'";
115115
$conn = $this->getEntityManager()->getConnection();
116116

117-
return $conn->executeQuery($sql)->rowCount();
117+
return $conn->executeStatement($sql);
118118
}
119119
}

app/bundles/CoreBundle/EventListener/MigrationCommandSubscriber.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function addGeneratedColumns(ConsoleTerminateEvent $event): void
6060
$output->writeln("<info>++</info> adding generated column <comment>{$generatedColumn->getColumnName()}</comment>");
6161
$output->writeln("<comment>-></comment> {$generatedColumn->getAlterTableSql()}");
6262

63-
$this->connection->executeQuery($generatedColumn->getAlterTableSql());
63+
$this->connection->executeStatement($generatedColumn->getAlterTableSql());
6464

6565
$duration = (string) $stopwatch->stop($generatedColumn->getColumnName());
6666
$output->writeln("<info>++</info> generated column added ({$duration})");

app/bundles/CoreBundle/EventListener/OptimisticLockSubscriber.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function postUpdate(LifecycleEventArgs $args): void
5454
return "{$name} = :{$name}";
5555
}, $metadata->getIdentifierFieldNames())))
5656
->setParameters($entityManager->getUnitOfWork()->getEntityIdentifier($object))
57-
->executeQuery();
57+
->executeStatement();
5858

5959
$newVersion = (int) $connection->executeQuery('SELECT @newVersion')->fetchOne();
6060
$object->setVersion($newVersion);

app/bundles/CoreBundle/Test/MauticMysqlTestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ protected function resetAutoincrement(array $tables): void
145145
$connection = $this->connection;
146146

147147
foreach ($tables as $table) {
148-
$connection->executeQuery(sprintf('ALTER TABLE `%s%s` AUTO_INCREMENT=1', $prefix, $table));
148+
$connection->executeStatement(sprintf('ALTER TABLE `%s%s` AUTO_INCREMENT=1', $prefix, $table));
149149
}
150150
}
151151

@@ -160,7 +160,7 @@ protected function truncateTables(string ...$tables): void
160160
$prefix = MAUTIC_TABLE_PREFIX;
161161

162162
foreach ($tables as $table) {
163-
$this->connection->executeQuery("SET FOREIGN_KEY_CHECKS = 0; TRUNCATE TABLE `{$prefix}{$table}`; SET FOREIGN_KEY_CHECKS = 1;");
163+
$this->connection->executeStatement("SET FOREIGN_KEY_CHECKS = 0; TRUNCATE TABLE `{$prefix}{$table}`; SET FOREIGN_KEY_CHECKS = 1;");
164164
}
165165
}
166166

app/bundles/CoreBundle/Tests/Unit/EventListener/MigrationCommandSubscriberTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public function testAddGeneratedColumnsWhenDoesNotExist(): void
154154
->willReturn(['id' => new \stdClass()]);
155155

156156
$this->connection->expects($this->once())
157-
->method('executeQuery');
157+
->method('executeStatement');
158158

159159
$this->subscriber->addGeneratedColumns($this->event);
160160
}

app/bundles/FormBundle/Tests/Controller/SubmissionFunctionalTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ protected function beforeTearDown(): void
507507
$tablePrefix = static::getContainer()->getParameter('mautic.db_table_prefix');
508508

509509
if ($this->connection->createSchemaManager()->tablesExist("{$tablePrefix}form_results_1_submission")) {
510-
$this->connection->executeQuery("DROP TABLE {$tablePrefix}form_results_1_submission");
510+
$this->connection->executeStatement("DROP TABLE {$tablePrefix}form_results_1_submission");
511511
}
512512
}
513513

0 commit comments

Comments
 (0)