Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Email submitters when a bug report is made or commented on #159

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion addons-menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@
$addons = Addon::getAll($type, $limit, $current_page, $sort, $order);
$template_addons = Addon::filterMenuTemplate($addons, $addon_name);

$pagination_addons = Addon::filterMenuTemplate(Addon::getAll($type));
$pagination = PaginationTemplate::get()
->setItemsPerPage($limit)
->setTotalItems(Addon::count($type))
->setTotalItems(count($pagination_addons))
->setCurrentPage($current_page);

$tpl = StkTemplate::get("addons/menu.tpl")
Expand Down
24 changes: 0 additions & 24 deletions include/Addon.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2001,30 +2001,6 @@ public static function exists($id)
return static::existsField("addons", "id", static::cleanId($id), DBConnection::PARAM_STR);
}

/**
* Get the total number of addons of a type
*
* @param int $type the addon type
*
* @return int
* @throws AddonException
*/
public static function count($type)
{
Assert::true(static::isAllowedType($type));

try
{
$count = DBConnection::get()->count("addons", "`type` = :type", [":type" => $type]);
}
catch (DBException $e)
{
throw new AddonException(exception_message_db(_("count the number of addons")));
}

return $count;
}

/**
* Checks if the current logged in user can modify the addon
*
Expand Down
88 changes: 86 additions & 2 deletions include/Bug.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,47 @@ public static function add($user_id, $addon_id, $bug_title, $bug_description)
throw new BugException(exception_message_db(_("create a bug")));
}

return DBConnection::get()->lastInsertId();
$ret = DBConnection::get()->lastInsertId();

// TODO maybe move refactor
// Get uploader email address
try
{
$uploader = DBConnection::get()->query(
'SELECT `uploader`
FROM `{DB_VERSION}_addons`
WHERE `id` = :addon_id
LIMIT 1',
DBConnection::FETCH_FIRST,
[':addon_id' => $addon_id],
[':addon_id' => DBConnection::PARAM_STR]
);
$user = DBConnection::get()->query(
'SELECT `username`, `email`
FROM `{DB_VERSION}_users`
WHERE `id` = :uploader_id
LIMIT 1',
DBConnection::FETCH_FIRST,
[':uploader_id' => $uploader['uploader']],
[':uploader_id' => DBConnection::PARAM_INT]
);
}
catch (DBException $e)
{
throw new AddonException(exception_message_db(_('find addon uploader email record')));
}

$content = $bug_title . "\n" . $bug_description;
try
{
StkMail::get()->addonBugNotification($user['email'], $user_id, $addon_id, $content, false);
}
catch (StkMailException $e)
{
throw new AddonException('Failed to send email to user. ' . $e->getMessage());
}

return $ret;
}

/**
Expand Down Expand Up @@ -569,8 +609,52 @@ public static function addComment($user_id, $bug_id, $comment_description)
{
throw new BugException(exception_message_db(_("create a bug comment")));
}

$ret = DBConnection::get()->lastInsertId();

// TODO maybe move refactor
// Get uploader email address
try
{
$addon = DBConnection::get()->query(
'SELECT `uploader`
FROM `{DB_VERSION}_addons`
WHERE `id` = :addon_id
LIMIT 1',
DBConnection::FETCH_FIRST,
[':addon_id' => $addon_id],
[':addon_id' => DBConnection::PARAM_STR]
);
$user = DBConnection::get()->query(
'SELECT `username`, `email`
FROM `{DB_VERSION}_users`
WHERE `id` = :uploader_id
LIMIT 1',
DBConnection::FETCH_FIRST,
[':uploader_id' => $addon['uploader']],
[':uploader_id' => DBConnection::PARAM_INT]
);
}
catch (DBException $e)
{
throw new AddonException(exception_message_db(_('find addon uploader email record')));
}

// Don't send email if commenting on own addon
if ($user_id != $addon['uploader']) {

$content = $bug_title . "\n" . $bug_description;
try
{
StkMail::get()->addonBugNotification($user['email'], $user_id, $addon_id, $content, true);
}
catch (StkMailException $e)
{
throw new AddonException('Failed to send email to user. ' . $e->getMessage());
}
}

return DBConnection::get()->lastInsertId();
return $ret;
}

/**
Expand Down
30 changes: 30 additions & 0 deletions include/StkMail.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,36 @@ public function addonNoteNotification($email, $addon_name, $notes)
$this->send();
}

/**
* Send email when a new addon bug report is created/updated
*
* @param string $email
* @param string $addon_name
* @param string $notes
*
* @throws StkMailException
*/
public function addonBugNotification($email, $user_id, $addon_name, $content, $comment)
{
if ($comment)
{
$subject = "New bug report for add-on '$addon_name'";
$message =
"$user_id has made a bug report concerning your add-on, '$addon_name.' The report is shown below.\n\n";
} else {
$subject = "New reply to bug report for add-on '$addon_name'";
$message =
"$user_id has commented on a bug report concerning your add-on, '$addon_name.' The reply is shown below.\n\n";
}
$message .= $content;

$this->addAddress($email);
$this->mail->Subject = $subject;
$this->mail->Body = $this->mail->AltBody = $message;

$this->send();
}

/**
* Send a new mail to the moderator list mail
*
Expand Down