├── License ├── README.md └── automatedimport.php /License: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Georg Ehrke 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | cl-calendarimport 2 | ================= 3 | 4 | ### __NOT COMPATIBLE WITH OWNCLOUD 9 - WON'T FIX__ 5 | 6 | 7 | PHP command line script for importing calendar files into your ownCloud calendar 8 | 9 | ### License 10 | This project is licensed under the terms of the MIT License. 11 | 12 | ### How to setup: 13 | - set the correct path for OCROOT on line 25 14 | 15 | ### Attention 16 | - all existing events in the calendar will be deleted before importing the file 17 | 18 | ### Parameters 19 | - user of webserver - checkout your distros doc 20 | - name of this script - should be automatedimport.php if you didn't rename it 21 | - userid of calendar owner - userid of the calendars owner, probably your userid 22 | - id of calendar - to get this id, take a look at the table %prefix%calendar_calendars in your database 23 | - valid PHP timezone - checkout [http://www.php.net/manual/en/timezones.php](http://www.php.net/manual/en/timezones.php) 24 | 25 | ### How to run this script from command line: 26 | ```bash 27 | $ sudo -u php 28 | ```` 29 | #### Example on debian: 30 | ```bash 31 | $ sudo -u www-data php automatedimport.php /home/georg/somerandomicsfile.ics georg 7 Europe/Berlin 32 | ``` 33 | -------------------------------------------------------------------------------- /automatedimport.php: -------------------------------------------------------------------------------- 1 | georgehrke <.> com> 4 | * This file is licensed under the MIT License 5 | * See the LICENSE file. 6 | * 7 | * @repo: https://github.com/georgehrke/cl-calendarimport 8 | * 9 | * Parameters: 10 | * - checkout your distros doc 11 | * - should be automatedimport.php if you didn't rename it 12 | * - userid of the calendars owner, probably your userid 13 | * - to get this id, take a look at the table %prefix%clndr_calendars in your database 14 | * - checkout http://www.php.net/manual/en/timezones.php 15 | * 16 | * what todo before first run: 17 | * - set the correct path for OCROOT on line 25 18 | * 19 | * How to run this script from command line: 20 | * $ sudo -u php 21 | * Example on debian: 22 | * $ sudo -u www-data php automatedimport.php /home/georg/somerandomicsfile.ics georg 7 Europe/Berlin 23 | */ 24 | //define the root path of ownCloud 25 | define('OCROOT', ''); 26 | $nl = "\n"; 27 | 28 | //disable all error reporting. 29 | //elsewise there will be a lot of PHP Notices because this script is running on command line 30 | error_reporting(0); 31 | 32 | if(OCROOT === ''){ 33 | echo 'please set ownCloud\'s root path in ' . $argv[0] . $nl; 34 | exit; 35 | } 36 | 37 | //check if all necessary parameters are given 38 | if($argc < 5){ 39 | echo 'Parameters:' . $nl; 40 | echo $argv[0] . ' ' . $nl; 41 | exit; 42 | } 43 | 44 | //define vars 45 | $path = (string) $argv[1]; 46 | $userid = (string) $argv[2]; 47 | $calendarid = (int) $argv[3]; 48 | $tz = (string) $argv[4]; 49 | 50 | //it's not necessary to load all apps 51 | $RUNTIME_NOAPPS = true; 52 | require_once(OCROOT . '/lib/base.php'); 53 | 54 | //set userid 55 | OC_User::setUserId($userid); 56 | 57 | //get content of calendar file 58 | $ics = file_get_contents($path); 59 | 60 | //check if calendar app is enabled and load calendar scripts 61 | OC_Util::checkAppEnabled('calendar'); 62 | OC_App::loadApp('calendar'); 63 | 64 | //delete all old calendar entries 65 | $stmt = OCP\DB::prepare( 'DELETE FROM `*PREFIX*clndr_objects` WHERE `calendarid` = ?' ); 66 | $stmt->execute(array($calendarid)); 67 | 68 | //initialize a new import object 69 | $import = new OC_Calendar_Import($ics); 70 | $import->setCalendarID($calendarid); 71 | $import->setProgresskey(false); 72 | $import->setTimeZone($tz); 73 | 74 | //import calendar 75 | $import->import(); 76 | --------------------------------------------------------------------------------