Improved checks when adding contacts

This commit is contained in:
Michael 2021-03-25 05:45:16 +00:00
parent 86e5fdece6
commit 8424c78a59
2 changed files with 9 additions and 4 deletions

View File

@ -229,7 +229,7 @@ function settings_post(App $a)
notice(DI::l10n()->t('Contact CSV file upload error'));
} else {
$csvArray = array_map('str_getcsv', file($_FILES['importcontact-filename']['tmp_name']));
Logger::info('Import started', ['lines' => count($csvArray)]);
Logger::notice('Import started', ['lines' => count($csvArray)]);
// import contacts
foreach ($csvArray as $csvRow) {
// The 1st row may, or may not contain the headers of the table
@ -237,18 +237,20 @@ function settings_post(App $a)
// or the handle of the account, therefore we check for either
// "http" or "@" to be present in the string.
// All other fields from the row will be ignored
if ((strpos($csvRow[0],'@') !== false) || (strpos($csvRow[0],'http') !== false)) {
if ((strpos($csvRow[0],'@') !== false) || in_array(parse_url($csvRow[0], PHP_URL_SCHEME), ['http', 'https'])) {
Worker::add(PRIORITY_LOW, 'AddContact', $_SESSION['uid'], $csvRow[0]);
} else {
Logger::notice('Invalid account', ['url' => $csvRow[0]]);
}
}
Logger::info('Import done');
Logger::notice('Import done');
info(DI::l10n()->t('Importing Contacts done'));
// delete temp file
unlink($_FILES['importcontact-filename']['tmp_name']);
}
} else {
Logger::info('Import triggered, but no import file was found.');
Logger::notice('Import triggered, but no import file was found.');
}
return;

View File

@ -2821,6 +2821,9 @@ class Contact
$count = 0;
foreach ($urls as $url) {
if (empty($url) || !is_string($url)) {
continue;
}
$contact = self::getByURL($url, false, ['id', 'updated']);
if (empty($contact['id'])) {
Worker::add(PRIORITY_LOW, 'AddContact', 0, $url);