$orphans[] = $pdf_id; } else { if ($path != $cpath) { // the path is not a cannonical path... fix it echo "path not canoncial: {$path} -> {$cpath}\n"; $other_pdf_id = get_pdf_id($cpath); if ($other_pdf_id) { // another record is using this file with an alternative path name... merge the records only // TODO: merge metadata only -- they're using the same file echo "redundant path with {$other_pdf_id}: merge with {$pdf_id} \n"; merge_pdf_metadata(array($pdf_id, $other_pdf_id), $cpath); } else { echo "update path to be canonical...\n"; $pdf['path'] = $cpath; unset($pdf['id']); update_pdf_info($pdf_id, $pdf); } } } // check for duplicates of this file and merge if necessary $dupes = get_pdf_ids_with_hash($pdf['md5']); if (count($dupes) > 1) { // merge with duplicates $path = null; $dupe_paths = array(); foreach ($dupes as $dupe_id) { $dupe_info = get_pdf_info($dupe_id); if ($path == null) { $path = $dupe_info['path']; } else { $dupe_paths[] = $dupe_info['path'];
function service_update_pdf($args, $fields) { if (count($args) == 0) { err_bad_input_format("expected at least one argument in URL"); } if (!get_pdf_info($args[0])) { err_bad_input_data('file_id', $args[0], 'not a valid pdf id'); } foreach ($args as $pdf_id) { update_pdf_info($pdf_id, $fields); } }