1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2025-01-18 07:52:21 +01:00

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.
This commit is contained in:
Bart Visscher 2012-06-04 17:42:59 +02:00
parent 7784120db4
commit 28a12ee6ff
4 changed files with 19 additions and 18 deletions

View File

@ -10,16 +10,21 @@ ob_start();
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;
@ -93,9 +98,7 @@ foreach($parts as $part){
//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);

View File

@ -1,2 +0,0 @@
This folder contains static files with the percentage of the import.
Requires write permission

View File

@ -42,8 +42,8 @@ Contacts_Import={
}
$('#newaddressbook').attr('readonly', 'readonly');
$('#contacts').attr('disabled', 'disabled');
var progressfile = $('#progressfile').val();
$.post(OC.filePath('contacts', '', 'import.php'), {method: String (method), addressbookname: String (addressbookname), path: String (path), file: String (filename), id: String (addressbookid)}, function(jsondata){
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'){
$('#progressbar').progressbar('option', 'value', 100);
$('#import_done').find('p').html(t('contacts', 'Result: ') + jsondata.data.imported + t('contacts', ' imported, ') + jsondata.data.failed + t('contacts', ' failed.'));
@ -55,7 +55,7 @@ Contacts_Import={
});
$('#form_container').css('display', 'none');
$('#progressbar_container').css('display', 'block');
window.setTimeout('Contacts_Import.getimportstatus(\'' + progressfile + '\')', 500);
window.setTimeout('Contacts_Import.getimportstatus(\'' + progresskey + '\')', 500);
});
$('#contacts').change(function(){
if($('#contacts option:selected').val() == 'newaddressbook'){
@ -65,11 +65,11 @@ Contacts_Import={
}
});
},
getimportstatus: function(progressfile){
$.get(OC.filePath('contacts', 'import_tmp', progressfile), function(percent){
getimportstatus: function(progresskey){
$.get(OC.filePath('contacts', '', 'import.php') + '?progress=1&progresskey=' + progresskey, function(percent){
$('#progressbar').progressbar('option', 'value', parseInt(percent));
if(percent < 100){
window.setTimeout('Contacts_Import.getimportstatus(\'' + progressfile + '\')', 500);
window.setTimeout('Contacts_Import.getimportstatus(\'' + progresskey + '\')', 500);
}else{
$('#import_done').css('display', 'block');
}

View File

@ -2,7 +2,7 @@
<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