Пример #1
0
function merge_pdf_metadata($pdf_ids, $path)
{
    if (count($pdf_ids) < 2) {
        err_bad_input_format("expected at least 2 pdf ids");
    }
    // validate pdf arguments and gather merged pdf attributes
    $attributes = array();
    $tags = array();
    $total_pages = 0;
    foreach ($pdf_ids as $pdf_id) {
        $pdf = get_pdf_info($pdf_id);
        if (!$pdf) {
            err_bad_input_data('pdfid', $pdf_id, 'not a valid pdf id');
        }
        if (!isset($attributes['title']) && $pdf['title']) {
            $attributes['title'] = $pdf['title'];
        }
        if (!isset($attributes['date']) && $pdf['date']) {
            $attributes['date'] = $pdf['date'];
        }
        if (!isset($attributes['origin']) && $pdf['origin']) {
            $attributes['origin'] = $pdf['origin'];
        }
        if (!isset($attributes['recipient']) && $pdf['recipient']) {
            $attributes['recipient'] = $pdf['recipient'];
        }
        $tags = array_unique(array_merge($tags, find_tags_for_pdf($pdf_id)));
    }
    foreach ($pdf_ids as $pdf_id) {
        delete_pdf_metadata($pdf_id);
    }
    $new_id = add_pdf_to_db($path, $attributes);
    foreach ($tags as $tag) {
        tag_pdf($new_id, $tag);
    }
    if (!$new_id) {
        err_internal("could not insert merged file to db");
    }
    return $new_id;
}
Пример #2
0
            // it already has a db record
            $attributes = get_pdf_info($id);
            if ($attributes['md5'] != $md5) {
                // ...with an incorrect md5 value, correct it.
                unset($attributes['id']);
                echo "fixing md5 info: {$id}: {$path} \n";
                $attributes['md5'] = $md5;
                print_r($attributes);
                update_pdf_info($id, $attributes);
            }
        } else {
            // it has no db record... insert it
            echo "inserting: {$path} \n";
            $attributes = array('md5' => $md5);
            print_r($attributes);
            add_pdf_to_db($path, $attributes);
        }
    }
}
$orphans = array();
// check every existing db record
foreach (find_pdfs_all() as $pdf_id) {
    $pdf = get_pdf_info($pdf_id);
    if ($pdf) {
        $path = $pdf['path'];
        $cpath = canonicalize_path($path);
        if (!file_exists(get_full_path($path))) {
            // the file was deleted. keep the data, but make it an orphan (no path)
            echo "*** file {$cpath} doesn't exist! adding to orphans list\n";
            $orphans[] = $pdf_id;
        } else {