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

Sort output in export script. #3323

Merged
merged 1 commit into from
Feb 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- Improve layout of some admin pages.
- Development improvements:
- Include failure count in send report error output, #3316
- Sort output in export script. #3323
- Security:
- Increase minimum password length to eight.

Expand Down
14 changes: 8 additions & 6 deletions bin/export-import-data
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ sub export {
if (@categories) {
my @contacts = $body->contacts->search({
category => { -in => \@categories },
}, {
order_by => 'category',
})->all;
die "Categories mismatch" unless scalar @categories == scalar @contacts;
for (@contacts) {
Expand All @@ -56,7 +58,7 @@ sub export {
}
}

my $templates = $body->response_templates;
my $templates = $body->response_templates->search(undef, { order_by => 'title' });
if (@categories) {
$templates = $templates->search({
'contact.category' => { -in => \@categories }
Expand All @@ -69,27 +71,27 @@ sub export {
title => $_->title,
text => $_->text,
state => $_->state,
categories => [ map { $_->category } $_->contacts->all ],
categories => [ sort map { $_->category } $_->contacts->all ],
auto_response => $_->auto_response,
external_status_code => $_->external_status_code,
};
}

for ($body->roles->all) {
for ($body->roles->search(undef, { order_by => 'name' })->all) {
push @{$out{roles}}, {
permissions => $_->permissions,
name => $_->name,
};
}

for ($body->users->all) {
for ($body->users->search(undef, { order_by => 'name' })->all) {
my $cats = $_->get_extra_metadata('categories');
my @cat_names = map { $body->contacts->find({id => $_})->category } @$cats;
my @cat_names = sort map { $body->contacts->find({id => $_})->category } @$cats;
push @{$out{users}}, {
email => $_->email,
name => $_->name,
password => $_->password,
roles => [ map { $_->name } $_->roles->all ],
roles => [ sort map { $_->name } $_->roles->all ],
categories => \@cat_names,
areas => $_->area_ids || [],
};
Expand Down