Ejemplo n.º 1
0
OCP\JSON::callCheck();
session_write_close();
if (isset($_POST['progresskey']) && isset($_POST['getprogress'])) {
    echo OCP\JSON::success(array('percent' => OC_Cache::get($_POST['progresskey'])));
    exit;
}
$file = \OC\Files\Filesystem::file_get_contents($_POST['path'] . '/' . $_POST['file']);
if (!$file) {
    OCP\JSON::error(array('error' => '404'));
}
$file = Sabre\VObject\StringUtil::convertToUTF8($file);
$import = new OC_Calendar_Import($file);
$import->setUserID(OCP\User::getUser());
$import->setTimeZone(OC_Calendar_App::$tz);
$import->enableProgressCache();
$import->setProgresskey($_POST['progresskey']);
if (!$import->isValid()) {
    OCP\JSON::error(array('error' => 'notvalid'));
    exit;
}
$newcal = false;
if ($_POST['method'] == 'new') {
    $calendars = OC_Calendar_Calendar::allCalendars(OCP\User::getUser());
    foreach ($calendars as $calendar) {
        if ($calendar['displayname'] == $_POST['calname']) {
            $id = $calendar['id'];
            $newcal = false;
            break;
        }
        $newcal = true;
    }
    $path = (string) $argv[1];
    $userid = (string) $argv[2];
    $calendarid = (int) $argv[3];
    $tz = (string) $argv[4];
}
//it's not necessary to load all apps
$RUNTIME_NOAPPS = true;
require_once OCROOT . '/lib/base.php';
//set userid
OC_User::setUserId($userid);
//get content of calendar file
$ics = file_get_contents($path);
//check if calendar app is enabled and load calendar scripts
OC_Util::checkAppEnabled('calendar');
OC_App::loadApp('calendar');
//delete all old calendar entries
$stmt = OCP\DB::prepare('DELETE FROM `*PREFIX*clndr_objects` WHERE `calendarid` = ?');
$stmt->execute(array($calendarid));
//initialize a new import object
$import = new OC_Calendar_Import($ics);
$import->setCalendarID($calendarid);
$import->setProgresskey(false);
$import->setTimeZone($tz);
//import calendar
try {
    $import->import();
    $count = $import->getCount();
    echo "imported " . $count . " objects in calendar\n";
} catch (Exception $e) {
    echo "import failed: " . $e;
}