CSVImport and "import as HTML"

To anyone who knows, but specifically to John F. and Daniel B.:

Unless I am missing something, one option that doesn’t appear to have been ported from Omeka Classic is importing text as HTML. I have used both the RRCHNM CSVImport as well as Daniel’s (https://github.com/Daniel-KM/Omeka-S-module-CSVImport).

With Daniel’s module, which basically implements CSVImportPlus from Omeka Classic, the wrench icon gives me option to “Import as URL reference”. So I am able to paste a hyperlink into a CSV import file, and have it appear in the UI as a hyperlink - but not title it. I tried importing an title as the column, and the entire code appears, not the intended HTML.

Is this missing on purpose? Is there something I am missing? Or is it just not implemented yet?

This is deliberate, and necessary. Omeka S does not allow metadata values to include HTML, so that option is no longer present. To use HTML, Omeka S has a couple different options: HTML Media and HTML Blocks for sites.

About this point, I’m creating a new data type for html/xml content, but the issue https://github.com/omeka/omeka-s/issues/1241 should be clarified first.

Patrick, I see. And what about importing URI values? This appears to be stored as two fields in the “values” table (sorry, can’t remember the name off the top of my head). I think that would be a useful addition in the short-term, even if pure HTML in a field/column is not supported (until Daniel does html/xml anyway).

If you add a media “url” to an item, it saves the url in the media table, and the title is a standard property (dcterms:title) (value table), that is importable by csv import, on another row.
If you add a media “html” to an item, it saves the content and the title in the column “data” of the media table. The title is currently not importable via csv import.

I’m looking into a similar feature for the project I’m working on; If you edit an item that’s already present, you can add a field with URI and Label. These are then rendered as hyperlinks in the UI.

Though, with the CSV-import module I’m stuck at trying to implement this where the URI from a CSV from column 11 gets used in combination with a label from column 12 (or a string provided during import)

1 Like

@benbakelaar; If I understand you correctly, you want to import a URI and have a Label over it? e.g.: your CSVfile would be:
ID, label, URI
1, Omeka support forum, CSVImport and "import as HTML"
2, blabla, http://www.example.com
etc…

I need(ed) a similar solution where researchers have put URI’s in a CSV-file and wee need them to show on the page. Since it’s a ton of URI’s we won’t add them manually, so importing is the only way for us.

I’m nowhere near an Omeka S specialiast so I do not know the implications of my proposal, yet for us it worked without an issue on a small sample of the data.

To ‘fix’ this issue, I decided to mess in the backend of Omeka, so some SQL-knowledge would help you. I rely on a few hackish solutions, so they are specific for the project I’m assigned to; yet I hope I can explain it broad enough for you to be of use.

  1. determine two properties you don’t need for the import - the property comes from the vocabularies of OMEKA S. By default you have Dublin Core, but you can easily add more.
  2. Assign the URI to one property and the Label to the second property during the mapping phase of the import process.
  3. Go to your PHPMyAdmin control panel > open the Omeka SQL Backend > go to the value table.
  4. Sort the Media table based on ‘resource_id’ (or ID’s) and go to the very last page. On that last page you’ll see your last imported item from the CSV file.; Write down the ‘resource_id’.
  5. Look for the first item you imported in that batch… It can be tricky to find, yet you can use an SQL-query where you look for the ‘label’ you’ve provided in the column ‘value’. Write the ‘resource_id’ down of this resource. You now have two resources, indicating a range that represents the batch you’ve imported. Let’s call it id_min and id_max for the sake of this post.
  6. Now look for the property ID that ‘holds’ the uri and for the property ID that ‘holds’ the Label.
  7. Write a query (I don’t know exactly how it’d look for you, cause my labels were static so I needed a different approach) where you update every record where resource_id <= min_id and resrouce_id >= min_id and property_id = property_id_of_where_your_LABEL_is_stored. This selects those properties, now update this selection based on the same property_id and insert the VALUE of the same resource_id where your URI is stored and put that in the URI-field. (Again I don’t know how this query would look, but in a worst case scenario you can use Python to connect to your SQL and do that calculations for you)
  8. After this process you’re stuck with redundant data i.e. there will be rows in your database that have the URI stored as a value (from step 2) Write a query to delete all records where resource_id <= min_id and resrouce_id >= min_id and and uri = “” and property_id = The_dummy_property_id_you_set_in_step_2

One issue remains though and that’s the fact that it won’t open in target="_blank". I’m guessing I can force it to do so by modifying Omeka’s core PHP code, or try to figure a way out to include a JS-file that modifies the target of the URL after a pageload. At this stage I think it’s technically possible, but I do not know where to look for in Omeka’s files.

2 Likes

Thanks @fre!

I have direct access to the SQL database and have become familiar with the schema, so yes there are a few ways I could go about it.

I would actually suggest doing a direct SQL import rather than loading the data in via CSVImport. Since CSVImport requires the primary identifier, we can presume you already have this in some spreadsheet or file. So you can simply take 3 fields, primary identifier + URL text + URL address and construct a formula to compose a SQL INSERT for each row. If it requires 2 SQL inserts rather than one, just add semi-colon between.

This is how I would tackle it absent a solution in the module itself.

1 Like

Hi @benbakelaar;

I’m curious; when you do a direct import in the SQL, can you then also create a job to undo it if it turns out that the data is buggy? I imagine you can do it also via SQL-directly. The thing is I need to do as much as possible via existing GUI’s or write scripts to do it so that it can be reproduced by others. Then again, doing a direct import isn’t that hard as well.

I don’t know if it applies to your project or not, but I more or less managed to find a hack to make the URI’s open in new tabs and make them appear visually different from plain text. My solution is far from ideal, though it’s written out here: Include Custom Javascript

1 Like