Skip to content

Commit

Permalink
Some fixes for handling tasks now that there may be multiple tasks with
Browse files Browse the repository at this point in the history
the same UID.
  • Loading branch information
mrubinsk committed Mar 1, 2015
1 parent e79a875 commit b60f9fa
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 10 deletions.
9 changes: 7 additions & 2 deletions nag/lib/Api.php
Expand Up @@ -974,11 +974,16 @@ public function import($content, $contentType, $tasklist = null)
$task->fromiCalendar($content);
if (isset($task->uid)) {
try {
$existing = $storage->getByUID($task->uid);
$existing = $storage->getByUID($task->uid, null, false);
$task->owner = $existing->owner;
$storage->modify($existing->id, $task->toHash());
} catch ( Horde_Exception_NotFound $e ) {
$storage->add($task->toHash());
$hash = $task->toHash();
unset($hash['tasklist_id']);
unset($hash['task_id']);
unset($hash['parent']);
$storage->open($tasklist);
$storage->add($hash);
}
$ids[] = $task->uid;
} else {
Expand Down
10 changes: 10 additions & 0 deletions nag/lib/Driver.php
Expand Up @@ -83,6 +83,16 @@ public function listAlarms($date)
return $alarms;
}

/**
* Sets the currently open tasklist.
*
* @param string $tasklist The tasklist.
*/
public function open($tasklist)
{
$this->_tasklist = $tasklist;
}

/**
* Adds a task and handles notification.
*
Expand Down
36 changes: 33 additions & 3 deletions nag/lib/Driver/Sql.php
Expand Up @@ -55,9 +55,35 @@ public function get($taskIds)
* @throws Horde_Exception_NotFound
* @throws Nag_Exception
*/
public function getByUID($uids)
public function getByUID($uids, $tasklists = null, $getall = true)

This comment has been minimized.

Copy link
@yunosh

yunosh Mar 5, 2015

Member

Changing this API requires to change it in Driver.php and the the other driver implementations too.

{
return $this->_getBy($uids, 'task_uid');
$results = $this->_getBy($uids, 'task_uid', $tasklists);
if ($getall) {
return $results;
}

$owner_lists = Nag::listTasklists(true);
$task = null;
foreach ($results as $row) {
if (isset($owner_lists[$row->tasklist])) {
$task = $row;
break;
}
}
if (empty($task)) {
$readable_lists = Nag::listTasklists();
foreach ($results as $row) {
if (isset($readable_lists[$row->tasklist])) {
$task = $row;
break;
}
}
}

if (empty($task)) {
throw new Horde_Exception_NotFound();
}
return $task;
}

/**
Expand All @@ -70,7 +96,7 @@ public function getByUID($uids)
* @throws Horde_Exception_NotFound
* @throws Nag_Exception
*/
protected function _getBy($taskIds, $column)
protected function _getBy($taskIds, $column, array $tasklists = null)
{
if (!is_array($taskIds)) {
$query = 'SELECT * FROM nag_tasks WHERE ' . $column . ' = ?';
Expand All @@ -84,6 +110,10 @@ protected function _getBy($taskIds, $column)
$values = $taskIds;
}

if (!empty($tasklists)) {
$query .= ' AND task_owner IN (' . implode(',', array_fill(0, count($tasklists), '?')) . ')';
}

This comment has been minimized.

Copy link
@yunosh

yunosh Mar 5, 2015

Member

You set the placeholders, but not the values.

This comment has been minimized.

Copy link
@mrubinsk

mrubinsk Mar 5, 2015

Author Member

Fixed in 056723a

try {
$rows = $this->_db->selectAll($query, $values);
} catch (Horde_Db_Exception $e) {
Expand Down
15 changes: 11 additions & 4 deletions nag/lib/Nag.php
Expand Up @@ -1829,6 +1829,7 @@ public static function sendITipNotifications(
}

/* Determine all notification-specific strings. */
$method = 'REQUEST';
switch ($action) {
case self::ITIP_CANCEL:
/* Cancellation. */
Expand All @@ -1841,17 +1842,21 @@ public static function sendITipNotifications(
$view->header = sprintf(_("%s has cancelled an instance of the recurring \"%s\"."), $ident->getName(), $task->name);
}
break;
case self::ITIP_REQUEST:
case self::ITIP_UPDATE:
if (!empty($task->organizer) && $task->organizer != Nag::getUserEmail($task->creator)) {
// Sending a progress update.
$method = 'REPLY';
} else {
$method = 'UPDATE';
}
case self::ITIP_REQUEST:
default:
$method = 'REQUEST';
if (empty($task->status) || $task->status == self::RESPONSE_NONE) {
/* Invitation. */
$filename = 'task-invitation.ics';
$view->subject = $task->name;
$view->header = sprintf(_("%s wishes to make you aware of \"%s\"."), $ident->getName(), $task->name);
} else {
$method = 'UPDATE';
$filename = 'task-update.ics';
$view->subject = sprintf(_("Updated: %s."), $task->name);
$view->header = sprintf(_("%s wants to notify you about changes of \"%s\"."), $ident->getName(), $task->name);
Expand Down Expand Up @@ -1891,7 +1896,9 @@ public static function sendITipNotifications(
$multipart->addPart($inner);
$multipart->addPart($ics2);

$recipient = new Horde_Mail_Rfc822_Address($email);
$recipient = $method != 'REPLY'
? new Horde_Mail_Rfc822_Address($email)
: new Horde_Mail_Rfc822_Address($task->organizer);

$mail = new Horde_Mime_Mail(
array('Subject' => $view->subject,
Expand Down
2 changes: 1 addition & 1 deletion nag/lib/Task.php
Expand Up @@ -1526,7 +1526,7 @@ public function fromiCalendar(Horde_Icalendar_Vtodo $vTodo)
if (empty($params[$id]['RELTYPE']) ||
Horde_String::upper($params[$id]['RELTYPE']) == 'PARENT') {

$parent = $this->_storage->getByUID($relation);
$parent = $this->_storage->getByUID($relation, $this->tasklist);
$this->parent_id = $parent->id;
break;
}
Expand Down

0 comments on commit b60f9fa

Please sign in to comment.