Roxen.git / server / modules / tags / xml-db-mirror.pike

version» Context lines:

Roxen.git/server/modules/tags/xml-db-mirror.pike:4:         #include <module.h>      inherit "module";   inherit "roxenlib";      import Parser.XML.Tree;      constant thread_safe = 1; - constant module_type = MODULE_TAG; + constant module_type = MODULE_TAG | MODULE_PROVIDER;   string module_name = "Tags: XML-DB Mirror";   string module_doc = #"   <p>Mirrors records from an XML file to a MySQL database. The module expects    the source file to have this structure:</p>      <pre> &lt;?xml version=\"1.0\" encoding=\"...\"?>    &lt;database name=\"...\"&gt;    &lt;dbrecord&gt;    &lt;some_field&gt;...&lt;/some_field&gt;    &lt;another_field&gt;...&lt;/another_field&gt;
Roxen.git/server/modules/tags/xml-db-mirror.pike:41:   // <pre> id field value   // -- ------------- -------------   // 1 some_field ...   // 1 another_field ...   // 2 some_field ...   // 2 another_field ...</pre>      #"   <p>No whitespace stripping takes place, and data will be decoded into Unicode    based on the <tt>encoding</tt> declaration in the XML header and stored in -  native widestring format.</p>"; +  native widestring format.</p>" + #" + <p>This module also acts as a backend for the feed import system.</p>" +  ;      // <p>An extra <tt>tbl_</tt><i>name</i><tt>_hash</tt> table keeps MD5 hashes of   // each record in order to identify unchanged records across imports.</p>               // FIXME:   //   // This module doesn't employ a strict locking method. There is just a
Roxen.git/server/modules/tags/xml-db-mirror.pike:457:    if (sizeof(set_fields))    set_fields += ",";    set_fields +=    "(" + next_id + ", '" + tag + "', '" + db->quote(val) + "')";    }    hashstr += tag + "|" + val + "|";    }       // Hash the new record and see if already a duplicate    string md5 = -  lower_case(String.string2hex(Crypto.MD5()-> -  hash(string_to_utf8(hashstr)))); +  lower_case(String.string2hex(Crypto.MD5.hash(string_to_utf8(hashstr))));    if (int existing_id = md5hashes[md5]) {    // Don't change this record but flag it as valid    valid_ids[existing_id] = 1;    info->count_unchanged++;    continue;    }       // Write new or updated record    if (sizeof(set_fields)) {    db->query("INSERT INTO " + tbl_name + " (id, field, value) "
Roxen.git/server/modules/tags/xml-db-mirror.pike:601:    if (string restr = args["search-fields"])    in_fields = map(restr / ",", String.trim_all_whites);    int use_wildcards = lower_case(args["wildcards"] || "no") != "no";    return search_recs(db, tbl_name, query, use_wildcards, in_fields);    }       RXML.parse_error("Must provide \"id\" or \"search\" attribute.\n");    }   }    + /* +  * Provider interface. +  */    -  + multiset(string) query_provides() + { +  return (< "feed_import_backend" >); + } +  + array(mapping(string:mixed)|string) read_article(string path, +  int|void edit, +  int|void discard_changes) + { +  return 0; + } +  + int(0..2) update_article(string path, string data, mapping md, +  mapping|void extra_md, int|void no_conflicts, +  void|function(string, mixed...:mixed) notify_cb) + { +  import_xml(path, data); +  return 1; + } +  + int prepare_article(string path) + { +  return 1; + } +  + int(0..1) check_imported(string source_path, int mtime, RoxenModule importer) + { +  return 0; + } +  + void delete_file(string source_path, RoxenModule loader, RoxenModule importer) + { +  return; + } +  + void reset_state(int|void force) + { +  return; + } +  +    TAGDOCUMENTATION;   #ifdef manual   constant tagdoc = ([    "emit#xml-db": ({ #"      <desc type='plugin'>   <p><short>Get or search for records in the mirrored database.</short></p>      <p>The returned records will contain all known fields as well as a special    <tt>_id</tt> field with the record ID.</p>   Newline at end of file added.