Calendar: small cleanup of import progress writing

This commit is contained in:
Bart Visscher 2012-05-30 18:23:23 +02:00
parent 0934a975b2
commit 2ae58ee6c0
1 changed files with 15 additions and 24 deletions

View File

@ -7,16 +7,23 @@
*/ */
//check for calendar rights or create new one //check for calendar rights or create new one
ob_start(); ob_start();
OCP\JSON::checkLoggedIn(); OCP\JSON::checkLoggedIn();
OCP\App::checkAppEnabled('calendar'); OCP\App::checkAppEnabled('calendar');
$nl="\r\n"; $nl="\r\n";
$comps = array('VEVENT'=>true, 'VTODO'=>true, 'VJOURNAL'=>true); $comps = array('VEVENT'=>true, 'VTODO'=>true, 'VJOURNAL'=>true);
$progressfile = 'import_tmp/' . md5(session_id()) . '.txt'; $progressfile = 'import_tmp/' . md5(session_id()) . '.txt';
if(is_writable('import_tmp/')){
function writeProgress($pct) {
if(is_writable('import_tmp/')){
$progressfopen = fopen($progressfile, 'w'); $progressfopen = fopen($progressfile, 'w');
fwrite($progressfopen, '10'); fwrite($progressfopen, $pct);
fclose($progressfopen); fclose($progressfopen);
}
} }
writeProgress('10');
$file = OC_Filesystem::file_get_contents($_POST['path'] . '/' . $_POST['file']); $file = OC_Filesystem::file_get_contents($_POST['path'] . '/' . $_POST['file']);
if($_POST['method'] == 'new'){ if($_POST['method'] == 'new'){
$id = OC_Calendar_Calendar::addCalendar(OCP\USER::getUser(), $_POST['calname']); $id = OC_Calendar_Calendar::addCalendar(OCP\USER::getUser(), $_POST['calname']);
@ -29,20 +36,12 @@ if($_POST['method'] == 'new'){
} }
$id = $_POST['id']; $id = $_POST['id'];
} }
if(is_writable('import_tmp/')){ writeProgress('20');
$progressfopen = fopen($progressfile, 'w');
fwrite($progressfopen, '20');
fclose($progressfopen);
}
// normalize the newlines // normalize the newlines
$file = str_replace(array("\r","\n\n"), array("\n","\n"), $file); $file = str_replace(array("\r","\n\n"), array("\n","\n"), $file);
$lines = explode("\n", $file); $lines = explode("\n", $file);
unset($file); unset($file);
if(is_writable('import_tmp/')){ writeProgress('30');
$progressfopen = fopen($progressfile, 'w');
fwrite($progressfopen, '30');
fclose($progressfopen);
}
// analyze the file, group components by uid, and keep refs to originating calendar object // analyze the file, group components by uid, and keep refs to originating calendar object
// $cals is array calendar objects, keys are 1st line# $cal, ie array( $cal => $caldata ) // $cals is array calendar objects, keys are 1st line# $cal, ie array( $cal => $caldata )
// $caldata is array( 'first' => 1st component line#, 'last' => last comp line#, 'end' => end line# ) // $caldata is array( 'first' => 1st component line#, 'last' => last comp line#, 'end' => end line# )
@ -86,11 +85,7 @@ foreach($lines as $line) {
$i++; $i++;
} }
// import the calendar // import the calendar
if(is_writable('import_tmp/')){ writeProgress('60');
$progressfopen = fopen($progressfile, 'w');
fwrite($progressfopen, '60');
fclose($progressfopen);
}
foreach($uids as $uid) { foreach($uids as $uid) {
$prefix=$suffix=$content=array(); $prefix=$suffix=$content=array();
@ -117,11 +112,7 @@ foreach($uids as $uid) {
} }
} }
// finished import // finished import
if(is_writable('import_tmp/')){ writeProgress('100');
$progressfopen = fopen($progressfile, 'w');
fwrite($progressfopen, '100');
fclose($progressfopen);
}
sleep(3); sleep(3);
if(is_writable('import_tmp/')){ if(is_writable('import_tmp/')){
unlink($progressfile); unlink($progressfile);