-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalgolia.cfc
More file actions
71 lines (58 loc) · 3.88 KB
/
algolia.cfc
File metadata and controls
71 lines (58 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<cfcomponent displayname="Archive" hint="Content archive functionality" output="false" component="fcTypes">
<!--- The basic rule is: if publicly visible content is changed, archive first --->
<cffunction name="saved" access="public" output="false" hint="Invoked immediately before DB is updated">
<cfargument name="typename" type="string" required="true" hint="The type of the object" />
<cfargument name="oType" type="any" required="true" hint="A CFC instance of the object type" />
<cfargument name="stProperties" type="struct" required="true" hint="The object" />
<cfargument name="user" type="string" required="true" />
<cfargument name="auditNote" type="string" required="true" />
<cfargument name="bSessionOnly" type="boolean" required="true" />
<cfset var stProps = duplicate(arguments.stProperties) />
<cfset var lastupdatedby = "">
<cfset var st = {} />
<!--- do nothing while update app is happening --->
<cfif NOT isDefined("application.bInit") OR application.bInit eq false>
<cfreturn />
</cfif>
<!--- do nothing if it's a session-only update --->
<cfif arguments.bSessionOnly>
<cfreturn />
</cfif>
<!--- update index --->
<cfif application.fc.lib.algolia.isIndexable(stProps)>
<cfset structappend(stProps, application.fapi.getContentObject(typename=stProps.typename, objectid=stProps.objectid), false) />
<cfif StructKeyExists(stProps, 'status') AND stProps['status'] == 'approved'>
<cfif request.mode.debug><cflog file="algolia-event" text="saved(#arguments.typename#): update index stProperties=#serializeJSON(arguments.stProperties)#"></cfif>
<cfset application.fc.lib.algolia.importIntoIndex(stObject=stProps, operation="updated") />
<cfelse>
<cfif request.mode.debug><cflog file="algolia-event-draft" text="saved(#arguments.typename#): stProperties=#serializeJSON(arguments.stProperties)#"></cfif>
</cfif>
</cfif>
</cffunction>
<cffunction name="deleted" access="public" hint="I am invoked when a content object has been deleted">
<cfargument name="typename" type="string" required="true" hint="The type of the object" />
<cfargument name="oType" type="any" required="true" hint="A CFC instance of the object type" />
<cfargument name="stObject" type="struct" required="true" hint="The object" />
<cfargument name="user" type="string" required="true" />
<cfargument name="auditNote" type="string" required="true" />
<cfif application.fc.lib.algolia.isIndexable(arguments.stObject)>
<cfif request.mode.debug><cflog file="algolia-event" text="deleted(#arguments.typename#): stObject=#serializeJSON(arguments.stObject)#"></cfif>
<cfset application.fc.lib.algolia.importIntoIndex(stObject=arguments.stObject, operation="deleted") />
</cfif>
</cffunction>
<cffunction name="statusChanged" access="public" hint="I am invoked when a content object has been deleted">
<cfargument name="typename" type="string" required="true" hint="The type of the object" />
<cfargument name="oType" type="any" required="true" hint="A CFC instance of the object type" />
<cfargument name="stObject" type="struct" required="true" hint="The object" />
<cfargument name="newStatus" type="string" required="true" />
<cfargument name="previousStatus" type="string" required="true" />
<cfargument name="auditNote" type="string" required="true" />
<cfif application.fc.lib.algolia.isIndexable(arguments.stObject)>
<!--- if was approved, remove from index --->
<cfif arguments.previousStatus == 'approved' AND arguments.newStatus != 'approved'>
<cfif request.mode.debug><cflog file="algolia-event" text="statusChanged(#arguments.typename#) Removing from index [newStatus=#arguments.newStatus#|previousStatus=#arguments.previousStatus#]: stObject=#serializeJSON(arguments.stObject)#"></cfif>
<cfset application.fc.lib.algolia.importIntoIndex(stObject=arguments.stObject, operation="deleted") />
</cfif>
</cfif>
</cffunction>
</cfcomponent>