Skip to content

Commit 727abdc

Browse files
author
nbraddy
committed
Added preview_attempts column to resource table to prevent the same resources being targeted by create_previews script
git-svn-id: http://svn.resourcespace.org/svn/resourcespace@3633 c08608d7-6e46-0410-86ca-f2a6f1370df5
1 parent 537b89d commit 727abdc

File tree

4 files changed

+33
-10
lines changed

4 files changed

+33
-10
lines changed

batch/create_previews.php

+12-4
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function sigint_handler()
9797

9898

9999
// We fetch the list of resources to process.
100-
$resources=sql_query("SELECT resource.ref, resource.file_extension FROM resource WHERE resource.has_image = 0");
100+
$resources=sql_query("SELECT resource.ref, resource.file_extension, resource.preview_attempts FROM resource WHERE resource.has_image = 0 and resource.archive = 0 and resource.ref>0");
101101

102102
foreach($resources as $resource) // For each resources
103103
{
@@ -137,12 +137,12 @@ function sigint_handler()
137137
}
138138

139139
// Processing resource.
140-
echo sprintf("Processing resource n°%d.\n", $resource['ref']);
140+
echo sprintf("Processing resource id " . $resource['ref'] . " - preview attempt #" . $resource['preview_attempts'] . "\n");
141141

142142
$start_time = microtime(true);
143143

144144
// For each fork, we need a new connection to database.
145-
if ($use_mysqli){
145+
if ($use_mysqli){
146146
$db=mysqli_connect($mysql_server,$mysql_username,$mysql_password,$mysql_db);
147147
} else {
148148
mysql_connect($mysql_server,$mysql_username,$mysql_password);
@@ -164,7 +164,15 @@ function sigint_handler()
164164
}
165165
}
166166
}
167-
create_previews($resource['ref'], false, $resource['file_extension']);
167+
if ($resource['preview_attempts']<5 and $resource['file_extension']!="")
168+
{
169+
create_previews($resource['ref'], false, $resource['file_extension']);
170+
echo sprintf("Processed resource %d in %01.2f seconds.\n", $resource['ref'], microtime(true) - $start_time);
171+
}
172+
else
173+
{
174+
echo sprintf("Skipped resource " . $resource['ref'] . " - maximum attempts reached or nonexistent file extension. \n");
175+
}
168176

169177
echo sprintf("Processed resource %d in %01.2f seconds.\n", $resource['ref'], microtime(true) - $start_time);
170178

dbstruct/table_resource.txt

+1
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ mapzoom,int(11),YES,,,
3434
disk_usage,int(11),YES,,,
3535
disk_usage_last_updated,datetime,YES,,,
3636
file_size,int(11),YES,,,
37+
preview_attempts,int(11),YES,,,

include/image_processing.php

+11-4
Original file line numberDiff line numberDiff line change
@@ -553,9 +553,9 @@ function create_previews($ref,$thumbonly=false,$extension="jpg",$previewonly=fal
553553

554554
# File checksum (experimental) - disabled for now
555555
if (!$previewonly) {generate_file_checksum($ref,$extension);}
556-
557556
# first reset preview tweaks to 0
558557
sql_query("update resource set preview_tweaks = '0|1' where ref = '$ref'");
558+
559559

560560
# pages/tools/update_previews.php?previewbased=true
561561
# use previewbased to avoid touching original files (to preserve manually-uploaded preview images
@@ -722,7 +722,7 @@ function create_previews($ref,$thumbonly=false,$extension="jpg",$previewonly=fal
722722
# flag database so a thumbnail appears on the site
723723
if ($alternative==-1) # not for alternatives
724724
{
725-
sql_query("update resource set has_image=1,preview_extension='jpg',file_modified=now() where ref='$ref'");
725+
sql_query("update resource set has_image=1,preview_extension='jpg',preview_attempts=0,file_modified=now() where ref='$ref'");
726726
}
727727
}
728728
}
@@ -912,9 +912,16 @@ function create_previews_using_im($ref,$thumbonly=false,$extension="jpg",$previe
912912
{
913913
extract_mean_colour($target,$ref);
914914
# flag database so a thumbnail appears on the site
915-
sql_query("update resource set has_image=1,preview_extension='jpg',file_modified=now() where ref='$ref'");
915+
sql_query("update resource set has_image=1,preview_extension='jpg',preview_attempts=0,file_modified=now() where ref='$ref'");
916+
}
917+
else
918+
{
919+
if(!$target)
920+
{
921+
$preview_attempts=sql_value("select preview_attempts as value from resource where ref=" . $ref, 0);
922+
sql_query("update resource set preview_attempts=" . ($preview_attempts+1) . " where ref='$ref'");
923+
}
916924
}
917-
918925
return true;
919926
}
920927
else

pages/edit.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,15 @@
212212
tweak_preview_images($ref,0,0.7,$resource["preview_extension"]);
213213
break;
214214
case "restore":
215-
create_previews($ref,false,$resource["file_extension"]);
216-
refresh_collection_frame();
215+
if ($enable_thumbnail_creation_on_upload)
216+
{
217+
create_previews($ref,false,$resource["file_extension"]);
218+
refresh_collection_frame();
219+
}
220+
else
221+
{
222+
sql_query("update resource set preview_attempts=0, has_image=0 where ref='$ref'");
223+
}
217224
break;
218225
}
219226

0 commit comments

Comments
 (0)