[Solved]: Merging description data from an existing xml file into the description field [Solved]: Merging description data from an existing xml file into the description field
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

[Solved]: Merging description data from an existing xml file into the description field

Started by chrisv, April 21, 2009, 05:35:14 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

chrisv

I'm running Coppermine version 1.4.21 with Apache 2 on a Ubuntu 8.04 OS.  I have a collection of about 5000 images that I've successfully imported into Coppermine.  Each of these photos has a unique filename such as 001.jpg, 002.jpg, etc.  I'd like to add descriptive information about each of these photos within coppermine. From a previous image program, I have a single XML file that has a description for each of the 5000 images.  Is there a way to take the description from the XML file and somehow merge it into the Coppermine description field so that I don't have to manually cut and paste this information for each image?  Here is a sample of the xml file:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE GreenstoneDirectoryMetadata SYSTEM "http://greenstone.org/dtd/GreenstoneDirectoryMetadata/1.0/GreenstoneDirectoryMetadata.dtd">
<DirectoryMetadata>
   <FileSet>
      <FileName>001.jpg</FileName>
      <Description>
         <Metadata name="Title">Northington and Bordeaux Cash Grocery</Metadata>
         <Metadata name="Filename">1</Metadata>
         <Metadata name="Publisher">Huntsville Arts Commission</Metadata>
         <Metadata name="Creator">n/a</Metadata>
         <Metadata name="Date">1950</Metadata>
         <Metadata name="Place">Sam Houston Avenue</Metadata>
         <Metadata name="Type">Image</Metadata>
         <Metadata name="Description">Northington and  Boudreaux Cash Grocery, west side of Sam Houston Avenue, ca. 1950, present day (2003) location of Sam Houston Antique Mall.</Metadata>
      </Description>
   </FileSet>
   <FileSet>
      <FileName>002.jpg</FileName>
      <Description>
         <Metadata name="Title">President's residence, Sam Houston State Teachers College</Metadata>
         <Metadata name="Filename">2</Metadata>
         <Metadata name="Publisher">Huntsville Arts Commission</Metadata>
         <Metadata name="Creator">n/a</Metadata>
         <Metadata name="Date">1940</Metadata>
         <Metadata name="Place">Sam Houston State Teachers College
         </Metadata>
         <Metadata name="Type">Image</Metadata>
         <Metadata name="Description">President's residence, Sam Houston State Teachers College</Metadata>
      </Description>
   </FileSet>

Nibbler

Should be able to do this with the script below. Set the path to the xml file where indicated, upload it into your Coppermine directory and run from your browser.


<?php

define
('IN_COPPERMINE'true);
require 
'include/init.inc.php';

// Set path to source xml file here
$source 'data.xml';

$xml simplexml_load_file($source);

foreach (
$xml as $file) {
    
    
$filename addslashes($file->FileName);
    
    
$result $file->xpath('Description/Metadata[@name="Title"]');
    
$title addslashes($result[0]);
    
    
$result $file->xpath('Description/Metadata[@name="Description"]');
    
$caption addslashes($result[0]);
    
    
$sql "UPDATE {$CONFIG['TABLE_PICTURES']} SET title = '$title', caption = '$caption' WHERE filename = '$filename'";
    
cpg_db_query($sql);
    
    echo 
"<p>Set '$filename' to title '$title' and caption '$caption'</p>";
}

chrisv

Nibbler,

The script worked great.  You just saved me at least 2 days worth of work.  Thank you,