2015-02-01 16:42:27 +00:00
< ? php
$installedVersionTasks = OCP\Config :: getAppValue ( 'tasks' , 'installed_version' );
$installedVersionTasksEnhanced = OCP\Config :: getAppValue ( 'tasks_enhanced' , 'installed_version' );
\OC :: $CLASSPATH [ 'OC_Calendar_Calendar' ] = 'calendar/lib/calendar.php' ;
\OC :: $CLASSPATH [ 'OC_Calendar_Object' ] = 'calendar/lib/object.php' ;
if ( version_compare ( $installedVersionTasksEnhanced , '0.4.1' , '<=' ) && version_compare ( $installedVersionTasks , '0.5.0' , '<=' ) ) {
try {
$stmt = \OCP\DB :: prepare ( 'SELECT * FROM `*PREFIX*clndr_calendars`' );
$result = $stmt -> execute ();
$calendars = array ();
while ( $row = $result -> fetchRow ()) {
$calendars [] = $row ;
}
foreach ( $calendars as $calendar ) {
$calendar_entries = \OC_Calendar_Object :: all ( $calendar [ 'id' ]);
foreach ( $calendar_entries as $task ) {
if ( $task [ 'objecttype' ] != 'VTODO' ) {
continue ;
}
2015-04-17 10:52:09 +00:00
$vcalendar = \Sabre\VObject\Reader :: read ( $task [ 'calendardata' ]);
2015-02-01 16:42:27 +00:00
$vtodo = $vcalendar -> VTODO ;
$children = $vtodo -> children ;
$taskId = $task [ 'id' ];
$comments = $vtodo -> COMMENT ;
if ( $comments ){
foreach ( $comments as $com ) {
$idx = 0 ;
foreach ( $children as $i => & $property ) {
2015-07-09 21:57:51 +00:00
if ( $property [ 'ID' ] && $com [ 'ID' ]) {
if ( $property -> name == 'COMMENT' && $property [ 'ID' ] -> getValue () == ( int ) $com [ 'ID' ] -> getValue () ) {
unset ( $vtodo -> children [ $idx ]);
}
2015-02-01 16:42:27 +00:00
}
$idx += 1 ;
}
2015-07-09 21:57:51 +00:00
if ( $com [ 'ID' ] && $com [ 'USERID' ] && $com [ 'DATE-TIME' ] ) {
$vtodo -> add ( 'COMMENT' , $com -> getValue (),
array (
'X-OC-ID' => ( int ) $com [ 'ID' ] -> getValue (),
'X-OC-USERID' => $com [ 'USERID' ] -> getValue (),
'X-OC-DATE-TIME' => $com [ 'DATE-TIME' ] -> getValue ()
)
);
}
2015-02-01 16:42:27 +00:00
OCP\Util :: emitHook ( 'OC_Calendar' , 'editEvent' , $taskId );
}
$data = $vcalendar -> serialize ();
$oldobject = \OC_Calendar_Object :: find ( $taskId );
2015-04-17 10:52:09 +00:00
$object = \Sabre\VObject\Reader :: read ( $data );
2015-02-01 16:42:27 +00:00
$type = 'VTODO' ;
$startdate = null ;
$enddate = null ;
$summary = '' ;
$repeating = 0 ;
$uid = null ;
foreach ( $object -> children as $property ) {
if ( $property -> name == 'VTODO' ) {
foreach ( $property -> children as & $element ) {
if ( $element -> name == 'SUMMARY' ) {
2015-07-09 21:57:51 +00:00
$summary = $element -> getValue ();
2015-02-01 16:42:27 +00:00
}
elseif ( $element -> name == 'UID' ) {
2015-07-09 21:57:51 +00:00
$uid = $element -> getValue ();
2015-02-01 16:42:27 +00:00
}
};
break ;
}
}
$stmt = OCP\DB :: prepare ( 'UPDATE `*PREFIX*clndr_objects` SET `objecttype`=?,`startdate`=?,`enddate`=?,`repeating`=?,`summary`=?,`calendardata`=?,`lastmodified`= ? WHERE `id` = ?' );
$stmt -> execute ( array ( $type , $startdate , $enddate , $repeating , $summary , $data , time (), $taskId ));
\OC_Calendar_Calendar :: touchCalendar ( $oldobject [ 'calendarid' ]);
}
}
}
} catch ( \Exception $e ){
}
2015-04-17 10:52:09 +00:00
}