From 85924de63cfbd47fd9cf569e64d0f4118fc08b48 Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Tue, 21 Feb 2012 20:54:53 +1300 Subject: [PATCH] A command-line script to load a calendar from an iCalendar file. Currently only tested for calendars, but I suspect it will also work just fine for an addressbook also. --- scripts/load_calendar.php | 123 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100755 scripts/load_calendar.php diff --git a/scripts/load_calendar.php b/scripts/load_calendar.php new file mode 100755 index 00000000..6b3596eb --- /dev/null +++ b/scripts/load_calendar.php @@ -0,0 +1,123 @@ +#!/usr/bin/env php +user_no = -1; + $this->principal_id = -1; + $this->logged_in = false; + return; + } + + $this->user_no = $user_no; + $principal = new Principal('user_no',$user_no); + // Assign each field in the selected record to the object + foreach( $principal AS $k => $v ) { + $this->{$k} = $v; + } + $this->username = $principal->username(); + $this->principal_id = $principal->principal_id(); + $this->email = $principal->email(); + $this->dav_name = $principal->dav_name(); + $this->principal = $principal; + + $this->logged_in = true; + + } + + function AllowedTo($do_something) { + return $this->logged_in; + } +} +$session = new FakeSession(); + +$dest = new DAVResource($target); +$session = new FakeSession($dest->user_no()); +if ( $mode == 'append' && ! $dest->Exists() ) { + printf( "The target '%s' does not exist.\n", $target ); + exit(1); +} + +if ( ! $dest->IsCollection() ) { + printf( "The target '%s' is not a collection.\n", $target ); + exit(1); +} + +$user_no = $dest->user_no(); +$username = $session->username; +param_to_global('mode'); +include_once('caldav-PUT-functions.php'); +controlRequestContainer( $session->username, $dest->user_no(), $target, false, ($dest->IsPublic() ? true : false)); +import_collection( $ics, $dest->user_no(), $target, $session->user_no, ($mode == 'append') ); +printf(translate("Calendar '%s' was loaded from file.\n"), $target); +