Skip to content

Commit b8088be

Browse files
Merge branch 'main' into simpler-template
2 parents 7ce8ad7 + b9ab217 commit b8088be

457 files changed

Lines changed: 67010 additions & 9078 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/labeler.yml

Lines changed: 216 additions & 28 deletions
Large diffs are not rendered by default.

.github/workflows/crowdin-per-language.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- name: Checkout
2323
uses: actions/checkout@v4
2424
- name: Matrix
25-
uses: crowdin/github-action@v1.20.0
25+
uses: crowdin/github-action@v1.20.1
2626
with:
2727
upload_translations: false # default is false
2828
download_translations: true

.github/workflows/crowdin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- name: Checkout
1414
uses: actions/checkout@v4
1515
- name: crowdin action
16-
uses: crowdin/github-action@v1.20.0
16+
uses: crowdin/github-action@v1.20.1
1717
with:
1818
upload_translations: false # default is false
1919
# Use this option to upload translations for a single specified language

Makefile

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ DOCKER_COMPOSE=docker compose --env-file=${ENV_FILE} ${LOAD_EXTRA_ENV_FILE}
5555
DOCKER_COMPOSE_TEST=WEB_RESOURCES_PATH=./web-default ROBOTOFF_URL="http://backend:8881/" GOOGLE_CLOUD_VISION_API_URL="http://backend:8881/" COMPOSE_PROJECT_NAME=${COMPOSE_PROJECT_NAME}_test PO_COMMON_PREFIX=test_ MONGO_EXPOSE_PORT=27027 docker compose --env-file=${ENV_FILE}
5656
# Enable Redis only for integration tests
5757
DOCKER_COMPOSE_INT_TEST=REDIS_URL="redis:6379" ${DOCKER_COMPOSE_TEST}
58+
TEST_CMD ?= yath test -PProductOpener::LoadData
5859

5960
.DEFAULT_GOAL := usage
6061

@@ -262,7 +263,7 @@ tests: build_taxonomies_test build_lang_test unit_test integration_test
262263
unit_test: create_folders
263264
@echo "🥫 Running unit tests …"
264265
${DOCKER_COMPOSE_TEST} up -d memcached postgres mongodb
265-
${DOCKER_COMPOSE_TEST} run ${COVER_OPTS} -T --rm backend prove -l --jobs ${CPU_COUNT} -r tests/unit
266+
${DOCKER_COMPOSE_TEST} run ${COVER_OPTS} -e PO_EAGER_LOAD_DATA=1 -T --rm backend yath test --job-count=${CPU_COUNT} -PProductOpener::LoadData tests/unit
266267
${DOCKER_COMPOSE_TEST} stop
267268
@echo "🥫 unit tests success"
268269

@@ -273,7 +274,7 @@ integration_test: create_folders
273274
# this is the place where variables are important
274275
${DOCKER_COMPOSE_INT_TEST} up -d memcached postgres mongodb backend dynamicfront incron minion redis
275276
# note: we need the -T option for ci (non tty environment)
276-
${DOCKER_COMPOSE_INT_TEST} exec ${COVER_OPTS} -T backend prove -l -r tests/integration
277+
${DOCKER_COMPOSE_INT_TEST} exec ${COVER_OPTS} -e PO_EAGER_LOAD_DATA=1 -T backend yath -PProductOpener::LoadData tests/integration
277278
${DOCKER_COMPOSE_INT_TEST} stop
278279
@echo "🥫 integration tests success"
279280

@@ -283,19 +284,21 @@ test-stop:
283284
${DOCKER_COMPOSE_TEST} stop
284285

285286
# usage: make test-unit test=test-name.t
286-
# you can add args= to pass options, like args="-d" to debug
287+
# you can use TEST_CMD to change test command, like TEST_CMD="perl -d" to debug a test
288+
# you can also add args= to pass more options to your test command
287289
test-unit: guard-test create_folders
288290
@echo "🥫 Running test: 'tests/unit/${test}' …"
289291
${DOCKER_COMPOSE_TEST} up -d memcached postgres mongodb
290-
${DOCKER_COMPOSE_TEST} run --rm backend perl ${args} tests/unit/${test}
292+
${DOCKER_COMPOSE_TEST} run --rm -e PO_EAGER_LOAD_DATA=1 backend ${TEST_CMD} ${args} tests/unit/${test}
291293

292294
# usage: make test-int test=test-name.t
293-
# to update expected results: make test-int test="test-name.t --update-expected-results"
294-
# you can add args= to pass options, like args="-d" to debug
295+
# to update expected results: make test-int test="test-name.t :: --update-expected-results"
296+
# you can use TEST_CMD to change test command, like TEST_CMD="perl -d" to debug a test
297+
# you can also add args= to pass more options to your test command
295298
test-int: guard-test create_folders
296299
@echo "🥫 Running test: 'tests/integration/${test}' …"
297300
${DOCKER_COMPOSE_INT_TEST} up -d memcached postgres mongodb backend dynamicfront incron minion redis
298-
${DOCKER_COMPOSE_INT_TEST} exec backend perl ${args} tests/integration/${test}
301+
${DOCKER_COMPOSE_INT_TEST} exec -e PO_EAGER_LOAD_DATA=1 backend ${TEST_CMD} ${args} tests/integration/${test}
299302
# better shutdown, for if we do a modification of the code, we need a restart
300303
${DOCKER_COMPOSE_INT_TEST} stop backend
301304

@@ -378,17 +381,19 @@ check_critic:
378381
@echo "🥫 Checking with perlcritic"
379382
test -z "${TO_CHECK}" || ${DOCKER_COMPOSE} run --rm --no-deps backend perlcritic ${TO_CHECK}
380383

381-
TAXONOMIES_TO_CHECK := $(shell [ -x "`which git 2>/dev/null`" ] && git diff origin/main --name-only | grep 'taxonomies*/*\.txt$$' | grep -v '\.result.txt' | xargs ls -d 2>/dev/null | grep -v "^.$$")
384+
TAXONOMIES_TO_CHECK := $(shell [ -x "`which git 2>/dev/null`" ] && git diff origin/main --name-only | grep 'taxonomies.*/.*\.txt$$' | grep -v '\.result.txt' | xargs ls -d 2>/dev/null | grep -v "^.$$")
382385

386+
# TODO remove --no-sort as soon as we have sorted taxonomies
383387
check_taxonomies:
384388
@echo "🥫 Checking taxonomies"
385389
test -z "${TAXONOMIES_TO_CHECK}" || \
386-
${DOCKER_COMPOSE} run --rm --no-deps backend scripts/taxonomies/sort_each_taxonomy_entry.sh --check ${TAXONOMIES_TO_CHECK}
390+
${DOCKER_COMPOSE} run --rm --no-deps backend scripts/taxonomies/lint_taxonomy.pl --verbose --check --no-sort ${TAXONOMIES_TO_CHECK}
387391

392+
# TODO remove --no-sort as soon as we have sorted taxonomies
388393
lint_taxonomies:
389394
@echo "🥫 Linting taxonomies"
390395
test -z "${TAXONOMIES_TO_CHECK}" || \
391-
${DOCKER_COMPOSE} run --rm --no-deps backend scripts/taxonomies/sort_each_taxonomy_entry.sh ${TAXONOMIES_TO_CHECK}
396+
${DOCKER_COMPOSE} run --rm --no-deps backend scripts/taxonomies/lint_taxonomy.pl --verbose --no-sort ${TAXONOMIES_TO_CHECK}
392397

393398

394399
check_openapi_v2:
@@ -412,7 +417,11 @@ build_taxonomies: create_folders
412417
# GITHUB_TOKEN might be empty, but if it's a valid token it enables pushing taxonomies to build cache repository
413418
${DOCKER_COMPOSE} run --no-deps --rm -e GITHUB_TOKEN=${GITHUB_TOKEN} backend /opt/product-opener/scripts/taxonomies/build_tags_taxonomy.pl ${name}
414419

415-
rebuild_taxonomies: build_taxonomies
420+
# a version where we force building without using cache
421+
# use it when you are developing in Tags.pm and want to iterate
422+
# at the end, change the $BUILD_TAGS_VERSION in Tags.pm
423+
rebuild_taxonomies:
424+
${DOCKER_COMPOSE} run --no-deps --rm -e TAXONOMY_NO_GET_FROM_CACHE=1 backend /opt/product-opener/scripts/taxonomies/build_tags_taxonomy.pl ${name}
416425

417426
build_taxonomies_test: create_folders
418427
@echo "🥫 build taxonomies"

cgi/display.pl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105

106106
if (defined $request_ref->{error_message}) {
107107
$log->debug("analyze_request error", {request_ref => $request_ref});
108-
display_error($request_ref->{error_message}, $request_ref->{status_code});
108+
display_error($request_ref, $request_ref->{error_message}, $request_ref->{status_code});
109109
$log->debug("analyze_request error - return Apache2::Const::OK");
110110
return Apache2::Const::OK;
111111
}
@@ -139,7 +139,7 @@
139139
)
140140
{
141141

142-
display_error_and_exit(lang("no_owner_defined"), 200);
142+
display_error_and_exit($request_ref, lang("no_owner_defined"), 200);
143143
}
144144

145145
if ((defined $request_ref->{api}) and (defined $request_ref->{api_action})) {

cgi/export_products.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
my $html = '';
5959

6060
if (not defined $Owner_id) {
61-
display_error_and_exit(lang("no_owner_defined"), 200);
61+
display_error_and_exit($request_ref, lang("no_owner_defined"), 200);
6262
}
6363

6464
# Require moderator status to launch the export / import process,

cgi/generate_sample_import_file.pl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
use ProductOpener::Producers qw/generate_import_export_columns_groups_for_select2/;
3636
use ProductOpener::Tags qw/%language_fields %tags_fields/;
3737
use ProductOpener::Food qw/default_unit_for_nid/;
38+
use ProductOpener::TaxonomySuggestions qw/:all/;
3839

3940
use Apache2::RequestRec ();
4041
use Apache2::Const ();
@@ -54,6 +55,8 @@
5455

5556
my $workbook = Excel::Writer::XLSX->new(\*STDOUT);
5657
my $worksheet = $workbook->add_worksheet();
58+
my $worksheet_categories = $workbook->add_worksheet(lang("categories"));
59+
5760
my %formats = (
5861
normal => $workbook->add_format(border => 1, bold => 1),
5962
mandatory => $workbook->add_format(
@@ -249,4 +252,11 @@
249252
}
250253
}
251254

255+
my $tagtype = "categories";
256+
my @category_entries = ProductOpener::TaxonomySuggestions::generate_sorted_list_of_taxonomy_entries($tagtype, $lc, {});
257+
foreach my $i (0 .. $#category_entries) {
258+
my $category_entry = display_taxonomy_tag($lc, $tagtype, $category_entries[$i]);
259+
$worksheet_categories->write($i, 0, $category_entry);
260+
}
261+
252262
exit(0);

cgi/import_file_process.pl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
my $template_data_ref;
5858

5959
if (not defined $Owner_id) {
60-
display_error_and_exit(lang("no_owner_defined"), 200);
60+
display_error_and_exit($request_ref, lang("no_owner_defined"), 200);
6161
}
6262

6363
my $import_files_ref = retrieve("$BASE_DIRS{IMPORT_FILES}/${Owner_id}/import_files.sto");
@@ -78,7 +78,7 @@
7878
}
7979
else {
8080
$log->debug("File not found in import_files.sto", {file_id => $file_id}) if $log->is_debug();
81-
display_error_and_exit("File not found.", 404);
81+
display_error_and_exit($request_ref, "File not found.", 404);
8282
}
8383

8484
$log->debug("File found in import_files.sto",
@@ -95,7 +95,7 @@
9595
my $results_ref = load_csv_or_excel_file($file);
9696

9797
if ($results_ref->{error}) {
98-
display_error_and_exit($results_ref->{error}, 200);
98+
display_error_and_exit($request_ref, $results_ref->{error}, 200);
9999
}
100100

101101
my $headers_ref = $results_ref->{headers};
@@ -152,7 +152,7 @@
152152
if ($results_ref->{error}) {
153153
$import_files_ref->{$file_id}{imports}{$import_id}{convert_error} = $results_ref->{error};
154154
store("$BASE_DIRS{IMPORT_FILES}/${Owner_id}/import_files.sto", $import_files_ref);
155-
display_error_and_exit($results_ref->{error}, 200);
155+
display_error_and_exit($request_ref, $results_ref->{error}, 200);
156156
}
157157

158158
my $args_ref = {

cgi/import_file_select_format.pl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
my $template_data_ref = {};
6363

6464
if (not defined $Owner_id) {
65-
display_error_and_exit(lang("no_owner_defined"), 200);
65+
display_error_and_exit($request_ref, lang("no_owner_defined"), 200);
6666
}
6767

6868
my $import_files_ref = retrieve("$BASE_DIRS{IMPORT_FILES}/${Owner_id}/import_files.sto");
@@ -84,7 +84,7 @@
8484
}
8585
else {
8686
$log->debug("File not found in import_files.sto", {file_id => $file_id}) if $log->is_debug();
87-
display_error_and_exit("File not found.", 404);
87+
display_error_and_exit($request_ref, "File not found.", 404);
8888
}
8989

9090
$log->debug("File found in import_files.sto",
@@ -96,7 +96,7 @@
9696
my $results_ref = load_csv_or_excel_file($file);
9797

9898
if ($results_ref->{error}) {
99-
display_error_and_exit($results_ref->{error}, 200);
99+
display_error_and_exit($request_ref, $results_ref->{error}, 200);
100100
}
101101

102102
my $headers_ref = $results_ref->{headers};

cgi/import_file_upload.pl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
local $log->context->{action} = $action;
6060

6161
if (not defined $Owner_id) {
62-
display_error_and_exit(lang("no_owner_defined"), 200);
62+
display_error_and_exit($request_ref, lang("no_owner_defined"), 200);
6363
}
6464

6565
if ($action eq "process") {
@@ -81,7 +81,8 @@
8181
$log->debug("processing upload form", {filename => $filename, file_id => $file_id, extension => $extension})
8282
if $log->is_debug();
8383

84-
ensure_dir_created("$BASE_DIRS{IMPORT_FILES}/${Owner_id}") or display_error_and_exit("Missing path", 503);
84+
ensure_dir_created("$BASE_DIRS{IMPORT_FILES}/${Owner_id}")
85+
or display_error_and_exit($request_ref, "Missing path", 503);
8586

8687
open(my $out, ">", "$BASE_DIRS{IMPORT_FILES}/${Owner_id}/$file_id.$extension");
8788
while (my $chunk = <$file>) {

0 commit comments

Comments
 (0)