Skip to content

Commit

Permalink
refactor: remove unused code after merging of paths (#11029)
Browse files Browse the repository at this point in the history
This PR removes code does is not used anymore now that the products data
and images dirs have been merged for all flavors.
  • Loading branch information
stephanegigandet authored Nov 25, 2024
1 parent adbcc0b commit 046d898
Show file tree
Hide file tree
Showing 10 changed files with 1,239 additions and 214 deletions.
27 changes: 10 additions & 17 deletions lib/ProductOpener/Images.pm
Original file line number Diff line number Diff line change
Expand Up @@ -715,10 +715,6 @@ sub process_image_upload ($product_id, $imagefield, $user_id, $time, $comment, $

$log->debug("process_image_upload", {product_id => $product_id, imagefield => $imagefield}) if $log->is_debug();

# The product_id can be prefixed by a server (e.g. off:[code]) with a different $www_root
my $product_www_root = www_root_for_product_id($product_id);
my $product_data_root = data_root_for_product_id($product_id);

# debug message passed back to apps in case of an error

my $debug = "product_id: $product_id - user_id: $user_id - imagefield: $imagefield";
Expand Down Expand Up @@ -770,7 +766,7 @@ sub process_image_upload ($product_id, $imagefield, $user_id, $time, $comment, $
local $log->context->{time} = $time;

# Check if we have already received this image before
my $images_ref = retrieve("$product_data_root/products/$path/images.sto");
my $images_ref = retrieve("$BASE_DIRS{PRODUCTS}/$path/images.sto");
defined $images_ref or $images_ref = {};

my $file_size = -s $file;
Expand Down Expand Up @@ -806,7 +802,7 @@ sub process_image_upload ($product_id, $imagefield, $user_id, $time, $comment, $
# create them

# Create the directories for the product
my $target_image_dir = "$product_www_root/images/products/$path";
my $target_image_dir = "$BASE_DIRS{PRODUCTS_IMAGES}/$path";
ensure_dir_created_or_die($target_image_dir);

my $lock_path = "$target_image_dir/$imgid.lock";
Expand Down Expand Up @@ -1054,15 +1050,15 @@ sub process_image_upload ($product_id, $imagefield, $user_id, $time, $comment, $
# Create a link to the image in /new_images so that it can be batch processed by OCR
# and computer vision algorithms

(-e "$product_data_root/new_images") or mkdir("$product_data_root/new_images", 0755);
(-e "$BASE_DIRS{PRODUCTS}/new_images") or mkdir("$BASE_DIRS{PRODUCTS}/new_images", 0755);
my $code = $product_id;
$code =~ s/.*\///;
symlink("$target_image_dir/$imgid.jpg",
"$product_data_root/new_images/" . time() . "." . $code . "." . $imagefield . "." . $imgid . ".jpg");
"$BASE_DIRS{PRODUCTS}/new_images/" . time() . "." . $code . "." . $imagefield . "." . $imgid . ".jpg");

# Save the image file size so that we can skip the image before processing it if it is uploaded again
$images_ref->{$size_orig} = $imgid;
store("$product_data_root/products/$path/images.sto", $images_ref);
store("$BASE_DIRS{PRODUCTS}/$path/images.sto", $images_ref);
}
else {
# Could not read image
Expand Down Expand Up @@ -1289,10 +1285,7 @@ sub process_image_crop ($user_id, $product_id, $id, $imgid, $angle, $normalize,
my $new_product_ref = retrieve_product($product_id);
my $rev = $new_product_ref->{rev} + 1; # For naming images

# The product_id can be prefixed by a server (e.g. off:[code]) with a different $www_root
my $product_www_root = www_root_for_product_id($product_id);

my $source_path = "$product_www_root/images/products/$path/$imgid.jpg";
my $source_path = "$BASE_DIRS{PRODUCTS_IMAGES}/$path/$imgid.jpg";

local $log->context->{code} = $code;
local $log->context->{product_id} = $product_id;
Expand Down Expand Up @@ -1407,7 +1400,7 @@ sub process_image_crop ($user_id, $product_id, $id, $imgid, $angle, $normalize,

$background->Resize(geometry => "${w}x${h}!");

my $bg_path = "$product_www_root/images/products/$path/$imgid.${crop_size}.background.jpg";
my $bg_path = "$BASE_DIRS{PRODUCTS_IMAGES}/$path/$imgid.${crop_size}.background.jpg";
$log->debug("writing background image to file", {width => $background->Get('width'), path => $bg_path})
if $log->is_debug();
$imagemagick_error = $background->Write("jpeg:${bg_path}");
Expand Down Expand Up @@ -1582,7 +1575,7 @@ sub process_image_crop ($user_id, $product_id, $id, $imgid, $angle, $normalize,
$filename = $id . "." . $rev;

_set_magickal_options($source, undef);
my $full_path = "$product_www_root/images/products/$path/$filename.full.jpg";
my $full_path = "$BASE_DIRS{PRODUCTS_IMAGES}/$path/$filename.full.jpg";
local $log->context->{full_path} = $full_path;
$imagemagick_error = $source->Write("jpeg:${full_path}");
($imagemagick_error)
Expand All @@ -1603,7 +1596,7 @@ sub process_image_crop ($user_id, $product_id, $id, $imgid, $angle, $normalize,
$log->trace("performing adaptive threshold") if $log->is_trace();

$img2->AdaptiveThreshold(width => $window, height => $window);
$img2->Write("jpeg:$product_www_root/images/products/$path/$filename.full.lat.jpg");
$img2->Write("jpeg:$BASE_DIRS{PRODUCTS_IMAGES}/$path/$filename.full.lat.jpg");
}

$log->debug("generating resized versions") if $log->is_debug();
Expand Down Expand Up @@ -1634,7 +1627,7 @@ sub process_image_crop ($user_id, $product_id, $id, $imgid, $angle, $normalize,
);
_set_magickal_options($img, $w);

my $final_path = "$product_www_root/images/products/$path/$filename.$max.jpg";
my $final_path = "$BASE_DIRS{PRODUCTS_IMAGES}/$path/$filename.$max.jpg";
my $imagemagick_error = $img->Write("jpeg:${final_path}");
if (($imagemagick_error) and ($imagemagick_error =~ /(\d+)/) and ($1 >= 400))
{ # ImageMagick returns a string starting with a number greater than 400 for errors
Expand Down
Loading

0 comments on commit 046d898

Please sign in to comment.