I needed a quick 'n dirty way to import an existing spreadsheet of events data into a Mura calendar. After a little trial and error, and much cobbling together of snippets from the Mura forums, here's my result.

Events from XLS data are imported into a table "temp_data" then gathered using the query below. This could be the base for a mura plugin, with an upload option and cfspreadsheet.

Before I ran the import, I created a custom extended attribute set and a page subtype of 'event listing', so we could import this client's custom data attributes.

I also made a parent page called 'events' and got the ID from the mura admin, which is used as the parent ID for all the new entries.

The page subtype is also hard coded below, you'll want to change that to match your own subtype (if not called 'event listing'), and remove the custom attributes stuff, or change those to match your own extended attributes for your events.

This is a crude-but-working example of adding custom attributes, categories, and the main content data all in a single pass, along with the 'start and stop' dates for each event, which I'll use on the front end to group and display the coming events (rather than using those dates to actually show or hide the content directly).

Ideally, the parent ID, site ID and other things would be set by the plugin or site you were working on. But for a one-time import this worked great.

view plain print about
1<!--- IMPORT FROM TEMP TABLE --->
2<cfquery name="dataQ" datasource="#application.configBean.getDatasource()#">
3SELECT *
4FROM temp_data
5</cfquery>    
6
7<!--- loop data, save content for each --->
8<cfoutput>
9    <cfloop query="dataQ">
10        <cfset contentBean = application.contentManager.getBean() />
11        <cfset contentBean.setSiteID('calendarsite')>
12        <cfset contentBean.setType('Page')>
13        <cfset contentBean.setSubtype('Event Listing')>
14        <!--- data --->
15        <cfset contentBean.setBody('#dataQ.eventName#') />
16        <cfset contentBean.setTitle('#dataQ.eventName#') />
17        <!--- to use display per start/stop dates, set to type '2' --->
18        <cfset contentBean.setDisplay(2)>
19        <cfset contentBean.setDisplayStart('#dateFormat(dataQ.datestart,'yyyy-mm-dd')#') />
20        <cfset contentBean.setDisplayStop('#dateFormat(dataQ.dateend,'yyyy-mm-dd')#') />
21        <!--- import categories from our data 'type' (this data only uses one category or 'type' per entry)--->
22        <cfset c = trim(dataQ.type)>
23        <cfset category = application.categorymanager.getBean("category").loadBy(name="#c#",siteid='calendarsite')>
24        <!--- save category if not already available for this site --->
25        <cfif category.getIsNew() eq 1>
26            <cfset category.setName(c)>
27            <cfset category.setSiteID('calendarsite')>
28            <cfset category.save()>    
29        </cfif>
30        <!--- add category ID --->
31        <cfset contentBean.setCategories(category.getCategoryID())>
32        <!--- events custom attributes --->
33        <cfset contentBean.setLocation('#dataQ.location#') />
34        <cfset contentBean.setChannel('#dataQ.channel#') />
35        <cfset contentBean.setLevel('#dataQ.level#') />
36        <!--- events calendar parent id --->
37        <cfset contentBean.setParentID('A48EAF6D-1EC9-549D-5210B43882960200')>
38        <cfset contentBean.save() />
39    </cfloop>
40
41// #dataQ.recordCount# events imported //
42</cfoutput>

I put that into a blank page called 'import.cfm' right in the root of this site, and pointed my browser at it... done!