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 all 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
28 changes: 22 additions & 6 deletions 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 @@ -430,13 +434,10 @@ public static function import_map($attrib)
public static function import_confirm($attrib)
{
$rcmail = rcmail::get_instance();
$vars = get_object_vars(self::$stats);
$vars['names'] = $vars['skipped_names'] = '';

$content = html::p(null, $rcmail->gettext([
'name' => 'importconfirm',
'nr' => self::$stats->inserted,
'vars' => $vars,
'vars' => ['inserted' => self::$stats->inserted],
]) . (self::$stats->names ? ':' : '.')
);

Expand All @@ -447,12 +448,27 @@ public static function import_confirm($attrib)
if (self::$stats->skipped) {
$content .= html::p(null, $rcmail->gettext([
'name' => 'importconfirmskipped',
'nr' => self::$stats->skipped,
'vars' => $vars,
'vars' => ['skipped' => self::$stats->skipped],
]) . ':')
. html::p('em', implode(', ', array_map(['rcube', 'Q'], self::$stats->skipped_names)));
}

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

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

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

Expand Down
4 changes: 3 additions & 1 deletion program/localization/en_US/messages.inc
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ $messages['nogroupassignmentschanged'] = 'No group assignments changed.';
$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['importconfirmskipped'] = '<b>Skipped $skipped existing contacts</b>';
$messages['importconfirminvalid'] = '<b>Skipped $invalid invalid contacts</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