Skip to content

Commit

Permalink
pkp#8826 Add missing FK and index on email_log.sender_id
Browse files Browse the repository at this point in the history
  • Loading branch information
asmecher committed May 8, 2024
1 parent 363a145 commit c7a07bb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion classes/log/EmailLogDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function insertObject($entry)
$this->datetimeToDB($entry->getDateSent())
),
[
$entry->getSenderId(),
$entry->getSenderId() ?: null,
$entry->getEventType(),
$entry->getAssocType(),
$entry->getAssocId(),
Expand Down
7 changes: 4 additions & 3 deletions classes/log/SubmissionEmailLogDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public function getBySubmissionId($submissionId)
*
* @return DAOResultFactory<SubmissionEmailLogEntry>
*/
function getBySenderId($submissionId, $eventType, $senderId) {
public function getBySenderId($submissionId, $eventType, $senderId)
{
$result = $this->retrieveRange(
'SELECT e.*
FROM email_log e
Expand All @@ -88,7 +89,7 @@ function getBySenderId($submissionId, $eventType, $senderId) {
Application::ASSOC_TYPE_SUBMISSION,
(int) $submissionId,
(int) $eventType,
(int) $senderId
$senderId ?: null
]
);

Expand All @@ -110,7 +111,7 @@ public function logMailable(int $eventType, Mailable $mailable, Submission $subm
$entry->setEventType($eventType);
$entry->setAssocId($submission->getId());
$entry->setDateSent(Core::getCurrentDate());
$entry->setSenderId($sender ? $sender->getId() : 0);
$entry->setSenderId($sender ? $sender->getId() : null);
$entry->setSubject(Mail::compileParams(
$clonedMailable->subject,
$clonedMailable->getData(Locale::getLocale())
Expand Down
6 changes: 5 additions & 1 deletion classes/migration/install/LogMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ public function up(): void
$table->bigInteger('log_id')->autoIncrement();
$table->bigInteger('assoc_type');
$table->bigInteger('assoc_id');
$table->bigInteger('sender_id');

$table->bigInteger('sender_id')->nullable();
$table->foreign('sender_id')->references('user_id')->on('users')->onDelete('cascade');
$table->index(['sender_id'], 'email_log_sender_id');

$table->datetime('date_sent');
$table->bigInteger('event_type')->nullable();
$table->string('from_address', 255)->nullable();
Expand Down

0 comments on commit c7a07bb

Please sign in to comment.