/** * Search by organizer filter */ public function testSearchByUserFilter() { $backend = new Tasks_Backend_Sql(); $filter = new Tasks_Model_TaskFilter(array(array('field' => 'organizer', 'operator' => 'equals', 'value' => Tinebase_Model_User::CURRENTACCOUNT))); $tasks = $backend->search($filter); $this->assertTrue(count($tasks) > 0); }
/** * this function creates a Tasks_Model_Task and stores it in the database * * @param Tinebase_Model_Container $container * @param stream|string $vobjectData */ public static function create(Tinebase_Model_Container $container, $name, $vobjectData, $onlyCurrentUserOrganizer = 'unused') { if (is_resource($vobjectData)) { $vobjectData = stream_get_contents($vobjectData); } // Converting to UTF-8, if needed $vobjectData = Sabre\DAV\StringUtil::ensureUTF8($vobjectData); #Sabre_CalDAV_ICalendarUtil::validateICalendarObject($vobjectData, array('VTODO', 'VFREEBUSY')); list($backend, $version) = Tasks_Convert_Task_VCalendar_Factory::parseUserAgent($_SERVER['HTTP_USER_AGENT']); try { $task = Tasks_Convert_Task_VCalendar_Factory::factory($backend, $version)->toTine20Model($vobjectData); } catch (Exception $e) { Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . ' ' . $e); Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . " " . $vobjectData); throw new Sabre\DAV\Exception\PreconditionFailed($e->getMessage()); } $task->container_id = $container->getId(); $id = ($pos = strpos($name, '.')) === false ? $name : substr($name, 0, $pos); $task->setId($id); self::enforceEventParameters($task); // check if there is already an existing task with this ID // this can happen when the invitation email is faster then the caldav update or // or when an task gets moved to another container $filter = new Tasks_Model_TaskFilter(array(array('field' => 'is_deleted', 'operator' => 'equals', 'value' => Tinebase_Model_Filter_Bool::VALUE_NOTSET), array('condition' => 'OR', 'filters' => array(array('field' => 'id', 'operator' => 'equals', 'value' => $id), array('field' => 'uid', 'operator' => 'equals', 'value' => $id))))); $existingEvent = Tasks_Controller_Task::getInstance()->search($filter, null, false, false, 'sync')->getFirstRecord(); if ($existingEvent === null) { try { $task = Tasks_Controller_Task::getInstance()->create($task); } catch (Exception $e) { Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . ' ' . $e); Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . " " . $vobjectData); Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . " " . print_r($task->toArray(), true)); throw new Sabre\DAV\Exception\PreconditionFailed($e->getMessage()); } $vevent = new self($container, $task); } else { if ($existingEvent->is_deleted) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' recovering already deleted task'); } // @TODO have a undelete/recover workflow beginning in controller $existingEvent->is_deleted = 0; $existingEvent->deleted_by = NULL; $existingEvent->deleted_time = NULL; $be = new Tasks_Backend_Sql(); $be->updateMultiple($existingEvent->getId(), array('is_deleted' => 0, 'deleted_by' => NULL, 'deleted_time' => NULL)); } if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' update existing task with id: ' . $existingEvent->getId()); } $vevent = new self($container, $existingEvent); $vevent->put($vobjectData); } return $vevent; }