Skip to content
Snippets Groups Projects
Commit 8a25c3f1 authored by David Siegfried's avatar David Siegfried Committed by Jan-Hendrik Willms
Browse files

prevent warning in forum, fixes #4611

Closes #4611

Merge request studip/studip!3424
parent b9753c6a
No related branches found
No related tags found
No related merge requests found
...@@ -77,7 +77,7 @@ class ForumAbo ...@@ -77,7 +77,7 @@ class ForumAbo
{ {
// send message to all abo-users // send message to all abo-users
$db = DBManager::get(); $db = DBManager::get();
$messaging = new ForumBulkMail(); $messaging = new messaging();
// get all parent topic-ids, to find out which users to notify // get all parent topic-ids, to find out which users to notify
$path = ForumEntry::getPathToPosting($topic_id); $path = ForumEntry::getPathToPosting($topic_id);
...@@ -95,9 +95,11 @@ class ForumAbo ...@@ -95,9 +95,11 @@ class ForumAbo
// get details for topic // get details for topic
$topic = ForumEntry::getConstraints($topic_id); $topic = ForumEntry::getConstraints($topic_id);
$template = $GLOBALS['template_factory']->open('mail/forum_notification'); if (!$topic) {
return;
}
// notify users $template = $GLOBALS['template_factory']->open('mail/forum_notification');// notify users
while ($data = $stmt->fetch(PDO::FETCH_ASSOC)) { while ($data = $stmt->fetch(PDO::FETCH_ASSOC)) {
$user_id = $data['user_id']; $user_id = $data['user_id'];
...@@ -149,8 +151,6 @@ class ForumAbo ...@@ -149,8 +151,6 @@ class ForumAbo
); );
} }
} }
$messaging->bulkSend();
} }
/** /**
......
...@@ -129,7 +129,7 @@ class ForumActivity ...@@ -129,7 +129,7 @@ class ForumActivity
$data['actor_id'] = ''; $data['actor_id'] = '';
} }
$activity = Studip\Activity\Activity::create($data); Studip\Activity\Activity::create($data);
} }
/** /**
...@@ -140,7 +140,7 @@ class ForumActivity ...@@ -140,7 +140,7 @@ class ForumActivity
*/ */
private static function getPostUsername($post) private static function getPostUsername($post)
{ {
if ($post['anonymous']) { if (!empty($post['anonymous'])) {
return _('Anonym'); return _('Anonym');
} }
......
<?php
/**
* ForumBulkMail.php - Experimental mailer to handle large amounts of mails at high speed
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* @author Till Glöggler <tgloeggl@uos.de>
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL version 3
* @category Stud.IP
*/
class ForumBulkMail extends messaging
{
var $bulk_mail;
/**
* Overwrites the parent method. This method combines messages with the same
* content and prepares them for sending them as a mail with multiple
* recepients instead of one mail for each recipient.
* The actual sending task is done bulkSend().
*
* @global object $user
*
* @param string $rec_user_id user_id of recipient
* @param string $snd_user_id user_id of sender
* @param string $message the message
* @param string $subject subject for the message
* @param string $message_id the message_id in the database
*/
public function sendingEmail($rec_user_id, $snd_user_id, $message, $subject, $message_id)
{
$receiver = User::find($rec_user_id);
if ($receiver && $receiver->email) {
setTempLanguage($receiver->id);
if (empty($this->bulk_mail[md5($message)][getenv('LANG')])) {
$title = "[Stud.IP - " . Config::get()->UNI_NAME_CLEAN . "] ".stripslashes(kill_format(str_replace(["\r","\n"], '', $subject)));
if ($snd_user_id != "____%system%____") {
$sender = User::find($snd_user_id);
$reply_to = $sender->email;
}
$template = $GLOBALS['template_factory']->open('mail/text');
$template->message = kill_format(stripslashes($message));
$template->rec_fullname = $receiver->getFullName();
$mailmessage = $template->render();
$template = $GLOBALS['template_factory']->open('mail/html');
$template->lang = getUserLanguagePath($rec_user_id);
$template->message = stripslashes($message);
$template->rec_fullname = $receiver->getFullName();
$mailhtml = $template->render();
$this->bulk_mail[md5($message)][getenv('LANG')] = [
'text' => $mailmessage,
'html' => $mailhtml,
'title' => $title,
'reply_to' => $reply_to,
'message_id' => $message_id,
'users' => []
];
}
$this->bulk_mail[md5($message)][getenv('LANG')]['users'][$receiver->id] = $receiver->email;
restoreLanguage();
}
}
/**
* Sends the collected messages from sendingMail as e-mail.
*/
public function bulkSend()
{
// if nothing to do, return
if (empty($this->bulk_mail)) {
return;
}
// send a mail, for each language one
foreach ($this->bulk_mail as $lang_data) {
foreach ($lang_data as $data) {
$mail = new StudipMail();
$mail->setSubject($data['title']);
foreach ($data['users'] as $user_id => $to) {
$mail->addRecipient($to, get_fullname($user_id), 'Bcc');
}
$mail->setBodyText($data['text']);
if (mb_strlen($data['reply_to'])) {
$mail->setSenderEmail($data['reply_to']);
}
$user_cfg = UserConfig::get($user_id);
if ($user_cfg->MAIL_AS_HTML) {
$mail->setBodyHtml($data['html']);
}
if ($GLOBALS["ENABLE_EMAIL_ATTACHMENTS"]){
$message = Message::find($data['message_id']);
$current_user = User::findCurrent();
$message_folder = MessageFolder::findTopFolder($message->id);
$attachments = FileManager::getFolderFilesRecursive(
$message_folder,
$current_user->id
);
foreach ($attachments as $attachment) {
$mail->addStudipAttachment($attachment);
}
}
$mail->send();
}
}
}
}
This diff is collapsed.
...@@ -20,7 +20,8 @@ class ForumLike { ...@@ -20,7 +20,8 @@ class ForumLike {
* *
* @param string $topic_id * @param string $topic_id
*/ */
static function like($topic_id) { public static function like($topic_id)
{
$stmt = DBManager::get()->prepare("REPLACE INTO $stmt = DBManager::get()->prepare("REPLACE INTO
forum_likes (topic_id, user_id) forum_likes (topic_id, user_id)
VALUES (?, ?)"); VALUES (?, ?)");
...@@ -28,10 +29,13 @@ class ForumLike { ...@@ -28,10 +29,13 @@ class ForumLike {
// get posting owner // get posting owner
$data = ForumEntry::getConstraints($topic_id); $data = ForumEntry::getConstraints($topic_id);
if (!$data) {
return;
}
// notify owner of posting about the like // notify owner of posting about the like
setTempLanguage($data['user_id']); setTempLanguage($data['user_id']);
$notification = get_fullname($GLOBALS['user']->id) . _(' gefällt einer deiner Forenbeiträge!'); $notification = $GLOBALS['user']->getFullName() . _(' gefällt einer deiner Forenbeiträge!');
restoreLanguage(); restoreLanguage();
PersonalNotifications::add( PersonalNotifications::add(
...@@ -39,7 +43,7 @@ class ForumLike { ...@@ -39,7 +43,7 @@ class ForumLike {
URLHelper::getURL('dispatch.php/course/forum/index/index/' . $topic_id .'?highlight_topic='. $topic_id .'#'. $topic_id), URLHelper::getURL('dispatch.php/course/forum/index/index/' . $topic_id .'?highlight_topic='. $topic_id .'#'. $topic_id),
$notification, $notification,
$topic_id, $topic_id,
Icon::create('forum', 'clickable') Icon::create('forum')
); );
} }
......
...@@ -158,7 +158,9 @@ class ForumPerm { ...@@ -158,7 +158,9 @@ class ForumPerm {
if (empty($perms[$topic_id])) { if (empty($perms[$topic_id])) {
// find out if the posting is the last in the thread // find out if the posting is the last in the thread
$constraints = ForumEntry::getConstraints($topic_id); $constraints = ForumEntry::getConstraints($topic_id);
if (!$constraints) {
return false;
}
$stmt = DBManager::get()->prepare("SELECT user_id, seminar_id $stmt = DBManager::get()->prepare("SELECT user_id, seminar_id
FROM forum_entries WHERE topic_id = ?"); FROM forum_entries WHERE topic_id = ?");
$stmt->execute([$topic_id]); $stmt->execute([$topic_id]);
...@@ -205,7 +207,7 @@ class ForumPerm { ...@@ -205,7 +207,7 @@ class ForumPerm {
{ {
$data = ForumEntry::getConstraints($topic_id); $data = ForumEntry::getConstraints($topic_id);
if ($data['seminar_id'] != $seminar_id) { if (!$data || $data['seminar_id'] !== $seminar_id) {
throw new AccessDeniedException(sprintf( throw new AccessDeniedException(sprintf(
_('Forum: Sie haben keine Berechtigung auf den Eintrag mit der ID %s zuzugreifen!'), _('Forum: Sie haben keine Berechtigung auf den Eintrag mit der ID %s zuzugreifen!'),
$topic_id $topic_id
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment