Add in a backchannel for import results. No way to view these results

yet.
This commit is contained in:
Solomon Peachy 2009-01-14 20:34:23 -05:00
parent b142121746
commit bad68fb16d
7 changed files with 52 additions and 19 deletions

View File

@ -58,6 +58,8 @@ For further information about Photo Organizer, see its web site at:
[add] Add ability to generate ISO8601 dates.
[add] Add ability to insert RSS feeds into page headers.
[add] The first RSS feeds added, photo listings by user/folder/album
[db] Add indexes on the exposure date and version creation date columns.
[add] Background imports log their results for the user to examine later.
2.36.1 (September 27, 2008)
@ -78,7 +80,7 @@ For further information about Photo Organizer, see its web site at:
[fix] A miscalculation on the pretty-printing of lat/long values.
[misc] Be smarter in how we link to Google Maps.
[add] Where possible, automatically detect the flash type used.
2.36 (August 17, 2008)
[add] Allow the import 'master' prescedence to be configurable. [#368]

View File

@ -619,13 +619,19 @@ function emit_import_actions($database, $userid) {
$photos_in_import = pg_fetch_row(pg_query($database, "select count(identifier) from pending_imports where users = $userid"));
$num_photos = $photos_in_import[0];
if ($num_photos <= 0) return "";
$results_import = pg_fetch_row(pg_query($database, "select count(identifier) from import_results where users = $userid"));
$num_photos2 = $results_import[0];
$rval = "";
$rval .= "<br/>";
$rval .= "<table><tr>";
$rval .= "<td><b>".$strings['import_remaining'].": $num_photos&nbsp;</b></td>";
$rval .= "</td></tr></table>";
if ($num_photos > 0 || $num_photos2 > 0) {
$rval .= "<br/>";
$rval .= "<table><tr>";
$rval .= "<td><b>".$strings['import_results'].": $num_photos2&nbsp;</b></td>";
$rval .= "<td><b>".$strings['import_remaining'].": $num_photos&nbsp;</b></td>";
$rval .= "</td></tr></table>";
}
return $rval;
}

View File

@ -239,9 +239,11 @@ function photo_import_all($database, $image_data) {
$serialized = base64_encode(serialize($image_data));
/* This is implicitly ROW EXCLUSIVE locked */
pg_query($database, "insert into pending_imports(identifier, users, folder, photo_data) VALUES (nextval('pending_imports_sequence'), $po_user[id], $folder, '$serialized')");
return $image_data['num_of_files'];
}
function photo_import_worker($database, $userid = FALSE) {
function photo_import_worker($database, $userid = FALSE, $background = TRUE) {
while (TRUE) {
// printf("worker %d...\n", posix_getpid());
$add = '';
@ -305,7 +307,12 @@ function photo_import_worker($database, $userid = FALSE) {
photo_import_single($database, $index, $image_data, $output);
}
print $output; // XXX shove this somewhere!
if ($background) {
$output = pg_escape_string($output);
$foo = pg_query($database, "insert into import_results(users, log_data) values ($po_options[user_id], '$output')");
} else {
print $output;
}
}
}

View File

@ -438,6 +438,7 @@ $strings['import_transferring_metadata'] = 'Transferring metadata';
$strings['import_watermarking'] = 'Watermarking image';
$strings['import_complete'] = 'Image import complete.';
$strings['import_all_complete'] = 'All images imported.';
$strings['import_all_queued'] = 'images queued for import.';
$strings['import_moving_file_to_tmp'] = 'Moving uploaded file into temporary directory';
$strings['import_copying_into_repo'] = 'Copying original image <strong>%s</strong> into repository';
@ -456,7 +457,8 @@ $strings['import_replace_with'] = 'replace image with';
$strings['import_uncompress'] = 'Uncompressing';
$strings['import_validating_xml'] = 'Validating <b>data.xml</b>';
$strings['import_replace_in_album'] = 'replace old master in albums?';
$strings['import_remaining'] = 'Images remaining to be imported';
$strings['import_remaining'] = 'Images remaining';
$strings['import_results'] = 'Images imported';
/* Generic stuff */

View File

@ -48,6 +48,7 @@ if ($local_bulk_upload &&
$current_tag = "not_implemented";
$character_data = "";
$count = 0;
function load_default_image_data_values($default_folder) {
global $po_user;
@ -501,7 +502,8 @@ function XML_EndElement($parser, $name) {
switch ($name) {
case "PHOTO":
photo_import_all($database, $image_data);
$count += photo_import_all($database, $image_data);
$count++;
$image_data = load_default_image_data_values($default_folder_id);
break;
case "TITLE":
@ -647,7 +649,8 @@ function upload_directory($database, $upload_path, $user_id, $target_folder, $or
global $strings;
parse_XML($upload_path);
$num_imported = 0;
$files = array(); /* Sorted of files in directory */
$fileroots = array(); /* basename -> array(files) */
$dirs = array(); /* Directories */
@ -715,7 +718,7 @@ function upload_directory($database, $upload_path, $user_id, $target_folder, $or
} else {
$new_folder = $data[0];
}
upload_directory($database, $upload_path . "/" . $file_name, $user_id, $new_folder, $original_file_type);
$num_imported += upload_directory($database, $upload_path . "/" . $file_name, $user_id, $new_folder, $original_file_type);
}
/* Import the the individual files */
@ -743,7 +746,7 @@ function upload_directory($database, $upload_path, $user_id, $target_folder, $or
}
/* And finally kick off the import of the master + versions */
photo_import_all($database, $image_data);
$num_imported += photo_import_all($database, $image_data);
}
}
@ -757,6 +760,8 @@ function upload_directory($database, $upload_path, $user_id, $target_folder, $or
print $strings['generic_done'].".<br/>";
}
}
return $num_queued;
}
/* ================================== */
@ -874,19 +879,22 @@ switch ($original_file_type) {
$image_data['file'][$index]['type'] = $original_file_type;
$image_data['file'][$index]['remark'] = "";
$image_data['num_of_files']++;
photo_import_all($database, $image_data);
$count += $photo_import_all($database, $image_data);
}
if ($temporary_directory) {
$old_mask = umask(0077);
upload_directory($database, $temporary_directory, $po_user['id'], $default_folder_id, $original_file_type);
$count += upload_directory($database, $temporary_directory, $po_user['id'], $default_folder_id, $original_file_type);
umask($old_mask);
}
if (!$external_workers)
photo_import_worker($database, $po_user['id']);
print "<p>$count ".$strings['import_all_queued']."</p>";
if (!$external_workers) {
photo_import_worker($database, $po_user['id'], FALSE);
print "<p>".$strings['import_all_complete']."</p>";
}
print "<p>".$strings['import_all_complete']."</p>";
print "</div>\n";
site_footer($database);

View File

@ -103,7 +103,7 @@ if ($go) {
photo_import_all($database, $image_data);
if (!$external_workers)
photo_import_worker($database, $po_user['id']);
photo_import_worker($database, $po_user['id'], FALSE);
print "<br/>".$strings['import_complete']."<br/>";
site_footer($database);

View File

@ -65,6 +65,14 @@ CREATE TABLE pending_imports (
photo_data TEXT
);
CREATE SEQUENCE import_results_sequence START 1;
CREATE TABLE import_results (
identifier integer NOT NULL PRIMARY KEY DEFAULT nextval('import_results_sequence'),
users integer references users(identifier) NOT NULL,
log_data TEXT
);
---- Speed up some queries
create index photo_exposure_date_idx on photo(date_of_exposure);