Fix posts alerts

pull/379/head
Richard van den Berg 2015-01-28 12:45:16 +01:00
parent 506e1fcb0d
commit 11052d85ce
3 changed files with 13 additions and 9 deletions

View File

@ -5,7 +5,7 @@ App::uses('File', 'Utility');
require_once 'AppShell.php';
class EventShell extends AppShell
{
public $uses = array('Event', 'Attribute', 'Job', 'User', 'Task', 'Whitelist');
public $uses = array('Event', 'Post', 'Attribute', 'Job', 'User', 'Task', 'Whitelist');
public function doPublish() {
$id = $this->args[0];
@ -309,8 +309,9 @@ class EventShell extends AppShell
$user = $this->User->read(null, $user_id);
$eventId = $this->args[2];
$result = $this->Post->sendPostsEmail($user_id, $post_id, $event_id, $title, $message);
$this->Job->saveField('progress', '100');
if ($result != true) $this->Job->saveField('message', 'Job done.');
$job['Job']['progress'] = 100;
$job['Job']['message'] = 'Emails sent.';
$this->Job->save($job);
}
public function enqueueCaching() {

View File

@ -61,6 +61,7 @@ class PostsController extends AppController {
}
$distribution = $this->Event->data['Event']['distribution'];
$org = $this->Event->data['Event']['org'];
$event_id = $this->Event->data['Event']['id'];
break;
case 'thread' :
$target_thread_id = $target_id;
@ -75,6 +76,7 @@ class PostsController extends AppController {
}
}
$title = $this->Thread->data['Thread']['title'];
$event_id = $this->Thread->data['Thread']['event_id'];
}
break;
case 'post' :
@ -110,10 +112,9 @@ class PostsController extends AppController {
if ($target_thread_id == null) {
// We have a post that was posted in a new thread. This could also mean that someone created the first post related to an event!
$this->Thread->create();
// Take the title from above and the id of the event as event_id if we are adding a post to an event.
// Take the title from above if we are adding a post to an event.
if ($target_type === 'event') {
$title = $eventDiscussionTitle;
$event_id = $this->Event->data['Event']['id'];
}
$newThread = array(
'date_created' => date('Y/m/d H:i:s'),
@ -150,8 +151,8 @@ class PostsController extends AppController {
$this->Thread->read(null, $target_thread_id);
$this->Thread->updateAfterPostChange(true);
$this->Session->setFlash(__('Post added'));
$this->Post->sendPostsEmailRouter($this->Auth->user('id'), $this->Post->getId(), $event_id, $title, $this->request->data['Post']['message']);
$this->redirect(array('action' => 'view', $this->Post->getId()));
$this->Post->sendPostsEmailRouter($this->Auth->user('id'), $post_id, $event_id, $title, $this->request->data['Post']['message']);
} else {
$this->Session->setFlash('The post could not be added.');
}

View File

@ -26,7 +26,7 @@ class Post extends AppModel {
$data = array(
'worker' => 'default',
'job_type' => 'posts_alert',
'job_input' => 'Thread: ' . $thread_id,
'job_input' => 'Post: ' . $post_id,
'status' => 0,
'retries' => 0,
'org' => $user['User']['org'],
@ -54,7 +54,8 @@ class Post extends AppModel {
// If the post belongs to an event, E-mail all users in the org that have contactalert set
if ($event_id) {
$event = $this->Event->read(null, $event_id);
$Event = new Event();
$event = $Event->read(null, $event_id);
//Insert extra field here: alertOrg or something, then foreach all the org members
//limit this array to users with contactalerts turned on!
$orgMembers = array();
@ -76,7 +77,7 @@ class Post extends AppModel {
}
// Add all users who posted in this thread
$temp = $this->Post->findAllByThreadId($post['Post']['thread_id'],array('user_id'));
$temp = $this->findAllByThreadId($post['Post']['thread_id'],array('user_id'));
foreach ($temp as $tempElement) {
$user = $this->User->findById($tempElement['Post']['user_id'], array('email', 'gpgkey', 'contactalert', 'id'));
if(!empty($user) && $user['User']['id'] != $user_id && !in_array($user, $orgMembers)) {
@ -106,6 +107,7 @@ class Post extends AppModel {
$gpg = new Crypt_GPG(array('homedir' => Configure::read('GnuPG.homedir'))); // , 'debug' => true
$gpg->addSignKey(Configure::read('GnuPG.email'), Configure::read('GnuPG.password'));
$bodySigned = $gpg->sign($body,Crypt_GPG::SIGN_MODE_CLEAR);
$result = false;
foreach ($orgMembers as &$recipient) {
if (!empty($recipient['User']['gpgkey'])) {
// import the key of the user into the keyring