/**
  * Migrates Infologs from egw 1.4 to Tasks.
  * 
  * @return void
  */
 public static function MigrateInfolog2Tasks()
 {
     $tasksBackend = Tasks_Backend_Factory::factory(Tasks_Backend_Factory::SQL);
     $db = Tinebase_Core::getDb();
     $stmt = $db->query($db->select()->from('egw_infolog'));
     while ($infolog = $stmt->fetchObject()) {
         $Task = self::$_mapping;
         foreach (array('info_datemodified', 'info_datecompleted', 'info_enddate', 'info_startdate') as $datefield) {
             if ((int) $infolog->{$datefield} == 0) {
                 continue;
             }
             $infolog->{$datefield} = new Tinebase_DateTime($infolog->{$datefield});
         }
         foreach (self::$_mapping as $TaskKey => $InfoKey) {
             if (!$InfoKey) {
                 continue;
             }
             // Map fields
             if (isset($infolog->{$InfoKey})) {
                 $Task[$TaskKey] = $infolog->{$InfoKey};
             }
         }
         //$Task['identifier'] = self::id2uid($Task['identifier']);      // uid
         unset($Task['identifier']);
         $Task['class'] = self::getClass($Task['class']);
         $Task['status'] = self::getStatus($Task['status']);
         $Task['container'] = self::getOwnersContainer($infolog->info_owner);
         $Task['organizer'] = $Task['organizer'] ? $Task['organizer'] : $Task['created_by'];
         error_log(print_r($Task, true));
         try {
             $Task20 = new Tasks_Model_Task(NULL, true, true);
             $Task20->setFromArray($Task);
         } catch (Tinebase_Exception_Record_Validation $e) {
             $validation_errors = $Task20->getValidationErrors();
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug('Could not migrate Infolog with info_id ' . $infolog->info_id . "\n" . 'Tasks_Setup_MigrateFromTine14::infolog2Task: ' . $e->getMessage() . "\n" . "Tasks_Model_Task::validation_errors: \n" . print_r($validation_errors, true));
             }
             continue;
         }
         $tasksBackend->create($Task20);
     }
 }
 /**
  * Seperates tasks data into the different tables
  *
  * @param Tasks_Model_Task $_task
  * @return array array of arrays
  */
 protected function _seperateTaskData($_task)
 {
     $_task->convertDates = true;
     $taskArray = $_task->toArray();
     $TableDescr = $this->_getTableInstance('tasks')->info();
     $taskparts['tasks'] = array_intersect_key($taskArray, array_flip($TableDescr['cols']));
     foreach (array('contact') as $table) {
         if (!empty($taskArray[$table])) {
             $taksparts[$table] = $taskArray[$table];
         }
     }
     return $taskparts;
 }
 /**
  * (non-PHPdoc)
  * @see ActiveSync_Frontend_Abstract::toTineModel()
  */
 public function toTineModel(Syncroton_Model_IEntry $data, $entry = null)
 {
     if ($entry instanceof Tasks_Model_Task) {
         $task = $entry;
     } else {
         $task = new Tasks_Model_Task(array('organizer' => Tinebase_Core::getUser()->getId()), TRUE);
     }
     foreach ($this->_mapping as $syncrotonProperty => $tine20Property) {
         if (!isset($data->{$syncrotonProperty})) {
             $task->{$tine20Property} = null;
             continue;
         }
         switch ($tine20Property) {
             case 'completed':
                 if ($data->{$syncrotonProperty} === 1) {
                     $task->status = 'COMPLETED';
                     $task->{$tine20Property} = $data->dateCompleted;
                 } else {
                     $task->status = 'IN-PROCESS';
                     $task->{$tine20Property} = NULL;
                 }
                 break;
             case 'description':
                 // @todo check $data->$fieldName->Type and convert to/from HTML if needed
                 if ($data->{$syncrotonProperty} instanceof Syncroton_Model_EmailBody) {
                     $task->{$tine20Property} = preg_replace("/(\r\n?|\n)/", "\r\n", $data->{$syncrotonProperty}->data);
                 } else {
                     $task->{$tine20Property} = null;
                 }
                 break;
             case 'priority':
                 $prioMapping = Tasks_Model_Priority::getMapping();
                 $task->{$tine20Property} = isset($data->{$syncrotonProperty}) && isset($prioMapping[$data->{$syncrotonProperty}]) ? $prioMapping[$data->{$syncrotonProperty}] : Tasks_Model_Priority::NORMAL;
                 break;
             default:
                 if ($data->{$syncrotonProperty} instanceof DateTime) {
                     $task->{$tine20Property} = new Tinebase_DateTime($data->{$syncrotonProperty});
                 } else {
                     $task->{$tine20Property} = $data->{$syncrotonProperty};
                 }
                 break;
         }
     }
     // task should be valid now
     $task->isValid();
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " taskData " . print_r($task->toArray(), TRUE));
     }
     return $task;
 }
Example #4
0
 /**
  * convert contact from xml to Addressbook_Model_Contact
  *
  * @todo handle images
  * @param SimpleXMLElement $_data
  * @return Addressbook_Model_Contact
  */
 public function toTineModel(SimpleXMLElement $_data, $_entry = null)
 {
     if ($_entry instanceof Tasks_Model_Task) {
         $task = $_entry;
     } else {
         $task = new Tasks_Model_Task(null, true);
     }
     $xmlData = $_data->children('uri:Tasks');
     foreach ($this->_mapping as $fieldName => $value) {
         switch ($value) {
             case 'completed':
                 if ((int) $xmlData->{$fieldName} === 1) {
                     $task->status = 'COMPLETED';
                     $task->completed = (string) $xmlData->DateCompleted;
                 } else {
                     $task->status = 'IN-PROCESS';
                     $task->completed = NULL;
                 }
                 break;
             case 'due':
                 if (isset($xmlData->{$fieldName})) {
                     $task->{$value} = new Tinebase_DateTime((string) $xmlData->{$fieldName});
                 } else {
                     $task->{$value} = null;
                 }
                 break;
             default:
                 if (isset($xmlData->{$fieldName})) {
                     $task->{$value} = (string) $xmlData->{$fieldName};
                 } else {
                     $task->{$value} = null;
                 }
                 break;
         }
     }
     if (version_compare($this->_device->acsversion, '12.0', '>=')) {
         $airSyncBase = $_data->children('uri:AirSyncBase');
         if (isset($airSyncBase->Body) && isset($airSyncBase->Body->Data)) {
             $task->description = preg_replace("/(\r\n?|\n)/", "\r\n", (string) $airSyncBase->Body->Data);
         }
     }
     // task should be valid now
     $task->isValid();
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " taskData " . print_r($task->toArray(), true));
     }
     return $task;
 }