From: Bart Visscher Date: Mon, 4 Jun 2012 15:42:59 +0000 (+0200) Subject: Calendar & Contacts: Store import progress in OC_Cache X-Git-Tag: v4.5.0beta1~74^2~424^2~30^2~6 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=091b343d5cc2766eb84d49b5f2c3c691b5d41a18;p=nextcloud-server.git Calendar & Contacts: Store import progress in OC_Cache Convert calendar and contacts import to use a caching system for storing the import progress percentage. OC_Cache can later be made smarter about storing values. --- diff --git a/apps/calendar/ajax/import/import.php b/apps/calendar/ajax/import/import.php index 904c07c52e7..a3eaed844a1 100644 --- a/apps/calendar/ajax/import/import.php +++ b/apps/calendar/ajax/import/import.php @@ -10,18 +10,22 @@ ob_start(); 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']); @@ -114,7 +118,5 @@ foreach($uids as $uid) { // finished import writeProgress('100'); sleep(3); -if(is_writable('import_tmp/')){ - unlink($progressfile); -} +OC_Cache::remove($progresskey); OCP\JSON::success(); diff --git a/apps/calendar/import_tmp/Info b/apps/calendar/import_tmp/Info deleted file mode 100644 index abafbce435c..00000000000 --- a/apps/calendar/import_tmp/Info +++ /dev/null @@ -1,2 +0,0 @@ -This folder contains static files with the percentage of the import. -Requires write permission diff --git a/apps/calendar/js/loader.js b/apps/calendar/js/loader.js index 60d92f448ee..838521ec7f5 100644 --- a/apps/calendar/js/loader.js +++ b/apps/calendar/js/loader.js @@ -43,8 +43,8 @@ Calendar_Import={ } $('#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'); @@ -52,7 +52,7 @@ Calendar_Import={ }); $('#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'){ @@ -62,11 +62,11 @@ Calendar_Import={ } }); }, - 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'); } diff --git a/apps/calendar/templates/part.import.php b/apps/calendar/templates/part.import.php index e93ea1af4c9..39cda29c20d 100644 --- a/apps/calendar/templates/part.import.php +++ b/apps/calendar/templates/part.import.php @@ -2,7 +2,7 @@
- +

t('Please choose the calendar'); ?>

- +

t('Please choose the addressbook'); ?>