@ -39,16 +39,28 @@ if(!$file) {
exit();
}
if(isset($_POST['method']) & & $_POST['method'] == 'new') {
$id = OC_Contacts_Addressbook::add(OCP\USER::getUser(), $_POST['addressbookname']);
$id = OC_Contacts_Addressbook::add(OCP\USER::getUser(),
$_POST['addressbookname']);
if(!$id) {
OCP\JSON::error(array('data' => array('message' => 'Error creating address book.')));
OCP\JSON::error(
array(
'data' => array('message' => 'Error creating address book.')
)
);
exit();
}
OC_Contacts_Addressbook::setActive($id, 1);
}else{
$id = $_POST['id'];
if(!$id) {
OCP\JSON::error(array('data' => array('message' => 'Error getting the ID of the address book.', 'file'=>$_POST['file'])));
OCP\JSON::error(
array(
'data' => array(
'message' => 'Error getting the ID of the address book.',
'file'=>$_POST['file']
)
)
);
exit();
}
OC_Contacts_App::getAddressbook($id); // is owner access check
@ -79,10 +91,20 @@ writeProgress('70');
$imported = 0;
$failed = 0;
if(!count($parts) > 0) {
OCP\JSON::error(array('data' => array('message' => 'No contacts to import in '.$_POST['file'].'. Please check if the file is corrupted.', 'file'=>$_POST['file'])));
OCP\JSON::error(
array(
'data' => array(
'message' => 'No contacts to import in '
. $_POST['file'].'. Please check if the file is corrupted.',
'file'=>$_POST['file']
)
)
);
if(isset($_POST['fstype']) & & $_POST['fstype'] == 'OC_FilesystemView') {
if(!$view->unlink('/imports/' . $_POST['file'])) {
OCP\Util::writeLog('contacts','Import: Error unlinking OC_FilesystemView ' . '/' . $_POST['file'], OCP\Util::ERROR);
OCP\Util::writeLog('contacts',
'Import: Error unlinking OC_FilesystemView ' . '/' . $_POST['file'],
OCP\Util::ERROR);
}
}
exit();
@ -91,14 +113,18 @@ foreach($parts as $part){
$card = OC_VObject::parse($part);
if (!$card) {
$failed += 1;
OCP\Util::writeLog('contacts','Import: skipping card. Error parsing VCard: '.$part, OCP\Util::ERROR);
OCP\Util::writeLog('contacts',
'Import: skipping card. Error parsing VCard: ' . $part,
OCP\Util::ERROR);
continue; // Ditch cards that can't be parsed by Sabre.
}
try {
OC_Contacts_VCard::add($id, $card);
$imported += 1;
} catch (Exception $e) {
OCP\Util::writeLog('contacts', 'Error importing vcard: '.$e->getMessage().$nl.$card, OCP\Util::ERROR);
OCP\Util::writeLog('contacts',
'Error importing vcard: ' . $e->getMessage() . $nl . $card,
OCP\Util::ERROR);
$failed += 1;
}
}
@ -108,7 +134,17 @@ sleep(3);
OC_Cache::remove($progresskey);
if(isset($_POST['fstype']) & & $_POST['fstype'] == 'OC_FilesystemView') {
if(!$view->unlink('/imports/' . $_POST['file'])) {
OCP\Util::writeLog('contacts','Import: Error unlinking OC_FilesystemView ' . '/' . $_POST['file'], OCP\Util::ERROR);
}
}
OCP\JSON::success(array('data' => array('imported'=>$imported, 'failed'=>$failed, 'file'=>$_POST['file'])));
OCP\Util::writeLog('contacts',
'Import: Error unlinking OC_FilesystemView ' . '/' . $_POST['file'],
OCP\Util::ERROR);
}
}
OCP\JSON::success(
array(
'data' => array(
'imported'=>$imported,
'failed'=>$failed,
'file'=>$_POST['file'],
)
)
);