Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add invalid and error details to vcard import report #9605

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion program/actions/contacts/import.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ public function run($args = [])
self::$stats = new stdClass();
self::$stats->names = [];
self::$stats->skipped_names = [];
self::$stats->invalid_names = [];
self::$stats->error_names = [];
self::$stats->count = count($vcards);
self::$stats->inserted = 0;
self::$stats->skipped = 0;
Expand Down Expand Up @@ -187,6 +189,7 @@ public function run($args = [])
// skip invalid (incomplete) entries
if (!$CONTACTS->validate($a_record, true)) {
self::$stats->invalid++;
self::$stats->invalid_names[] = rcube_addressbook::compose_display_name($a_record, true);
continue;
}

Expand Down Expand Up @@ -251,6 +254,7 @@ public function run($args = [])
self::$stats->names[] = $a_record['name'] ?: $email;
} else {
self::$stats->errors++;
self::$stats->error_names[] = $a_record['name'] ?: $email;
}
}

Expand Down Expand Up @@ -431,7 +435,7 @@ public static function import_confirm($attrib)
{
$rcmail = rcmail::get_instance();
$vars = get_object_vars(self::$stats);
$vars['names'] = $vars['skipped_names'] = '';
$vars['names'] = $vars['skipped_names'] = $vars['invalid_names'] = $vars['error_names'] = '';
johndoh marked this conversation as resolved.
Show resolved Hide resolved

$content = html::p(null, $rcmail->gettext([
'name' => 'importconfirm',
Expand All @@ -453,6 +457,24 @@ public static function import_confirm($attrib)
. html::p('em', implode(', ', array_map(['rcube', 'Q'], self::$stats->skipped_names)));
}

if (self::$stats->invalid) {
$content .= html::p(null, $rcmail->gettext([
'name' => 'importconfirminvalid',
'nr' => self::$stats->invalid,
'vars' => $vars,
]) . ':')
. html::p('em', implode(', ', array_map(['rcube', 'Q'], self::$stats->invalid_names)));
}

if (self::$stats->errors) {
$content .= html::p(null, $rcmail->gettext([
'name' => 'importconfirmerrors',
'nr' => self::$stats->errors,
'vars' => $vars,
]) . ':')
. html::p('em', implode(', ', array_map(['rcube', 'Q'], self::$stats->error_names)));
}

return html::div($attrib, $content);
}

Expand Down
2 changes: 2 additions & 0 deletions program/localization/en_US/messages.inc
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ $messages['importwait'] = 'Importing, please wait...';
$messages['importformaterror'] = 'Import failed! The uploaded file is not a valid import data file.';
$messages['importconfirm'] = '<b>Successfully imported $inserted contacts</b>';
$messages['importconfirmskipped'] = '<b>Skipped $skipped existing entries</b>';
$messages['importconfirminvalid'] = '<b>Skipped $invalid invalid entries</b>';
$messages['importconfirmerrors'] = '<b>Failed to import $errors valid contacts</b>';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably get rid of HTML tags from all these three messages.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think removing the <b> tags would be a breaking change because the formatting should be moved to the skin to do this properly. I can work on this in a separate PR.

$messages['importmessagesuccess'] = 'Successfully imported $nr messages';
$messages['importmessageerror'] = 'Import failed! The uploaded file is not a valid message or mailbox file';
$messages['opnotpermitted'] = 'Operation not permitted!';
Expand Down