OCP\JSON::checkLoggedIn();
OCP\App::checkAppEnabled('calendar');
+session_write_close();
$nl="\r\n";
$comps = array('VEVENT'=>true, 'VTODO'=>true, 'VJOURNAL'=>true);
-$progressfile = 'import_tmp/' . md5(session_id()) . '.txt';
+global $progresskey;
+$progresskey = 'calendar.import-' . $_GET['progresskey'];
+
+if (isset($_GET['progress']) && $_GET['progress']) {
+ echo OC_Cache::get($progresskey);
+ die;
+}
function writeProgress($pct) {
- if(is_writable('import_tmp/')){
- $progressfopen = fopen($progressfile, 'w');
- fwrite($progressfopen, $pct);
- fclose($progressfopen);
- }
+ global $progresskey;
+ OC_Cache::set($progresskey, $pct, 300);
}
writeProgress('10');
$file = OC_Filesystem::file_get_contents($_POST['path'] . '/' . $_POST['file']);
// finished import
writeProgress('100');
sleep(3);
-if(is_writable('import_tmp/')){
- unlink($progressfile);
-}
+OC_Cache::remove($progresskey);
OCP\JSON::success();
+++ /dev/null
-This folder contains static files with the percentage of the import.
-Requires write permission
}
$('#newcalendar').attr('readonly', 'readonly');
$('#calendar').attr('disabled', 'disabled');
- var progressfile = $('#progressfile').val();
- $.post(OC.filePath('calendar', 'ajax/import', 'import.php'), {method: String (method), calname: String (calname), path: String (path), file: String (filename), id: String (calid)}, function(data){
+ var progresskey = $('#progresskey').val();
+ $.post(OC.filePath('calendar', 'ajax/import', 'import.php') + '?progresskey='+progresskey, {method: String (method), calname: String (calname), path: String (path), file: String (filename), id: String (calid)}, function(data){
if(data.status == 'success'){
$('#progressbar').progressbar('option', 'value', 100);
$('#import_done').css('display', 'block');
});
$('#form_container').css('display', 'none');
$('#progressbar_container').css('display', 'block');
- window.setTimeout('Calendar_Import.getimportstatus(\'' + progressfile + '\')', 500);
+ window.setTimeout('Calendar_Import.getimportstatus(\'' + progresskey + '\')', 500);
});
$('#calendar').change(function(){
if($('#calendar option:selected').val() == 'newcal'){
}
});
},
- getimportstatus: function(progressfile){
- $.get(OC.filePath('calendar', 'import_tmp', progressfile), function(percent){
+ getimportstatus: function(progresskey){
+ $.get(OC.filePath('calendar', 'ajax/import', 'import.php') + '?progress=1&progresskey=' + progresskey, function(percent){
$('#progressbar').progressbar('option', 'value', parseInt(percent));
if(percent < 100){
- window.setTimeout('Calendar_Import.getimportstatus(\'' + progressfile + '\')', 500);
+ window.setTimeout('Calendar_Import.getimportstatus(\'' + progresskey + '\')', 500);
}else{
$('#import_done').css('display', 'block');
}
<div id="form_container">
<input type="hidden" id="filename" value="<?php echo $_['filename'];?>">
<input type="hidden" id="path" value="<?php echo $_['path'];?>">
-<input type="hidden" id="progressfile" value="<?php echo md5(session_id()) . '.txt';?>">
+<input type="hidden" id="progresskey" value="<?php echo rand() ?>">
<p style="text-align:center;"><b><?php echo $l->t('Please choose the calendar'); ?></b></p>
<select style="width:100%;" id="calendar" name="calendar">
<?php
OCP\JSON::checkLoggedIn();
OCP\App::checkAppEnabled('contacts');
+session_write_close();
+
$nl = "\n";
-$progressfile = 'import_tmp/' . md5(session_id()) . '.txt';
+global $progresskey;
+$progresskey = 'contacts.import-' . $_GET['progresskey'];
+
+if (isset($_GET['progress']) && $_GET['progress']) {
+ echo OC_Cache::get($progresskey);
+ die;
+}
function writeProgress($pct) {
- if(is_writable('import_tmp/')){
- $progressfopen = fopen($progressfile, 'w');
- fwrite($progressfopen, $pct);
- fclose($progressfopen);
- }
+ global $progresskey;
+ OC_Cache::set($progresskey, $pct, 300);
}
writeProgress('10');
$view = $file = null;
//done the import
writeProgress('100');
sleep(3);
-if(is_writable('import_tmp/')){
- unlink($progressfile);
-}
+OC_Cache::remove($progresskey);
if(isset($_POST['fstype']) && $_POST['fstype'] == 'OC_FilesystemView') {
if(!$view->unlink('/' . $_POST['file'])) {
OCP\Util::writeLog('contacts','Import: Error unlinking OC_FilesystemView ' . '/' . $_POST['file'], OCP\Util::ERROR);
+++ /dev/null
-This folder contains static files with the percentage of the import.
-Requires write permission
}\r
$('#newaddressbook').attr('readonly', 'readonly');\r
$('#contacts').attr('disabled', 'disabled');\r
- var progressfile = $('#progressfile').val();\r
- $.post(OC.filePath('contacts', '', 'import.php'), {method: String (method), addressbookname: String (addressbookname), path: String (path), file: String (filename), id: String (addressbookid)}, function(jsondata){\r
+ var progresskey = $('#progresskey').val();
+ $.post(OC.filePath('contacts', '', 'import.php') + '?progresskey='+progresskey, {method: String (method), addressbookname: String (addressbookname), path: String (path), file: String (filename), id: String (addressbookid)}, function(jsondata){
if(jsondata.status == 'success'){\r
$('#progressbar').progressbar('option', 'value', 100);\r
$('#import_done').find('p').html(t('contacts', 'Result: ') + jsondata.data.imported + t('contacts', ' imported, ') + jsondata.data.failed + t('contacts', ' failed.'));\r
});\r
$('#form_container').css('display', 'none');\r
$('#progressbar_container').css('display', 'block');\r
- window.setTimeout('Contacts_Import.getimportstatus(\'' + progressfile + '\')', 500);\r
+ window.setTimeout('Contacts_Import.getimportstatus(\'' + progresskey + '\')', 500);
});\r
$('#contacts').change(function(){\r
if($('#contacts option:selected').val() == 'newaddressbook'){\r
}\r
});\r
},\r
- getimportstatus: function(progressfile){\r
- $.get(OC.filePath('contacts', 'import_tmp', progressfile), function(percent){\r
+ getimportstatus: function(progresskey){
+ $.get(OC.filePath('contacts', '', 'import.php') + '?progress=1&progresskey=' + progresskey, function(percent){
$('#progressbar').progressbar('option', 'value', parseInt(percent));\r
if(percent < 100){\r
- window.setTimeout('Contacts_Import.getimportstatus(\'' + progressfile + '\')', 500);\r
+ window.setTimeout('Contacts_Import.getimportstatus(\'' + progresskey + '\')', 500);
}else{\r
$('#import_done').css('display', 'block');\r
}\r
<div id="form_container">
<input type="hidden" id="filename" value="<?php echo $_['filename'];?>">
<input type="hidden" id="path" value="<?php echo $_['path'];?>">
- <input type="hidden" id="progressfile" value="<?php echo md5(session_id()) . '.txt';?>">
+ <input type="hidden" id="progresskey" value="<?php echo rand() ?>">
<p class="bold" style="text-align:center;"><?php echo $l->t('Please choose the addressbook'); ?></p>
<select style="width:100%;" id="contacts" name="contacts">
<?php
--- /dev/null
+<?php
+/**
+ * Copyright (c) 2012 Bart Visscher <bartv@thisnet.nl>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+class OC_Cache {
+ static protected $cache;
+
+ static protected function init() {
+ self::$cache = new OC_Cache_File();
+ }
+
+ static public function get($key) {
+ if (!self::$cache) {
+ self::init();
+ }
+ return self::$cache->get($key);
+ }
+
+ static public function set($key, $value, $ttl=0) {
+ if (empty($key)) {
+ return false;
+ }
+ if (!self::$cache) {
+ self::init();
+ }
+ return self::$cache->set($key, $value, $ttl);
+ }
+
+ static public function remove($key) {
+ if (!self::$cache) {
+ self::init();
+ }
+ return self::$cache->remove($key);
+ }
+
+}
--- /dev/null
+<?php
+/**
+ * Copyright (c) 2012 Bart Visscher <bartv@thisnet.nl>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+
+class OC_Cache_File {
+ protected function getStorage() {
+ if(OC_User::isLoggedIn()){
+ $subdir = 'cache';
+ $view = new OC_FilesystemView('/'.OC_User::getUser());
+ if(!$view->file_exists($subdir)) {
+ $view->mkdir($subdir);
+ }
+ return new OC_FilesystemView('/'.OC_User::getUser().'/'.$subdir);
+ }else{
+ OC_Log::write('core','Can\'t get cache storage, user not logged in', OC_Log::ERROR);
+ return false;
+ }
+ }
+
+ public function get($key) {
+ $storage = $this->getStorage();
+ if ($storage->is_file($key)) {
+ $mtime = $storage->filemtime($key);
+ if ($mtime < time()) {
+ $storage->unlink($key);
+ return false;
+ }
+ return $storage->file_get_contents($key);
+ }
+ return false;
+ }
+
+ public function set($key, $value, $ttl) {
+ $storage = $this->getStorage();
+ if ($storage->file_put_contents($key, $value)) {
+ return $storage->touch($key, time() + $ttl);
+ }
+ return false;
+ }
+
+ public function remove($key) {
+ $storage = $this->getStorage();
+ return $storage->unlink($key);
+ }
+}