Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions lib/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use OCP\IConfig;
use OCP\IDBConnection;
use Psr\Log\LoggerInterface;
use Throwable;

/**
* @brief Class for managing the data in the activities
Expand Down Expand Up @@ -108,8 +107,10 @@ public function bulkSend(IEvent $event, array $affectedUsers): array {

$activityIds = [];
try {
$qb = $this->connection->getQueryBuilder();
$qb->insert('activity')
if ($this->insertActivity === null) {
$this->insertActivity = $this->connection->getQueryBuilder();
}
$this->insertActivity->insert('activity')
->values([
'app' => $this->insertActivity->createParameter('app'),
'subject' => $this->insertActivity->createParameter('subject'),
Expand All @@ -127,7 +128,7 @@ public function bulkSend(IEvent $event, array $affectedUsers): array {
'object_id' => $this->insertActivity->createParameter('object_id'),
]);

$qb->setParameters([
$this->insertActivity->setParameters([
'app' => $event->getApp(),
'type' => $event->getType(),
'user' => $event->getAuthor(),
Expand All @@ -144,14 +145,15 @@ public function bulkSend(IEvent $event, array $affectedUsers): array {
]);

foreach ($affectedUsers as $affectedUser) {
$qb->setParameter('affecteduser', $affectedUser);
$qb->executeStatement();
$activityIds[$qb->getLastInsertId()] = (string)$affectedUser;
$this->insertActivity->setParameter('affecteduser', $affectedUser);
$this->insertActivity->executeStatement();
$activityIds[$this->insertActivity->getLastInsertId()] = (string)$affectedUser;
}

$this->connection->commit();
} catch (Throwable) {
} catch (Exception $e) {
// Make sure to always roll back, otherwise the outer code runs in a failed transaction
$this->logger->error('Could not create bulk activities', ['exception' => $e]);
$this->connection->rollBack();
return [];
}
Expand Down
Loading