fusiongrokker

Entries Tagged as Mango

How to debug Mango plugin issues

Occasionally I get emailed or otherwise contacted for help with resolving Mango issues, and generally my initial advice is always the same; so I thought it might be worth posting it here to help people get started in diagnosing their own problems.

  1. Install my LogViewer plugin
  2. Make sure you enable verbose logging.
  3. Clear any logs that may be saved up. The best thing to do is isolate the issue and start with empty logs.
  4. After you do those things, re-do whatever is causing the issue; for example activating a problem plugin, or embedding its pod, etc. This should create a log entry with whatever the problem is, and since you cleared your logs in step 3, it will be easy to find.

Then, the error information that LogViewer provides should be able to get you started on debugging your issue.

Posted in ColdFusion | Mango | 1 Response September 24 2010

Broadcasting your own events (from plugins) in Mango

One of the great features of Mango Blog is the plugin architecture. Generally, this means that a skin author includes extensibility points via Mango's standard events at pre-determined spots, which allows plugins to add their own content to various places on the page -- like the post content footer, in the case of Related Entries.

The skin author does so by including code similar to this in the skin:

<mango:Event name="beforePostContentEnd" />

In addition, you can include additional information in a template event by including additional attributes, like this:

<mango:Event name="beforePostContentEnd" foo="bar" />

Plugins listen for these events and respond to them.

Wouldn't it be nice if one plugin could broadcast events for other plugins to respond to? Well, they can.

The init method signature in your average plugin is based on this:

<cffunction name="init" access="public" output="false">
    <cfargument name="mainManager" type="any" required="true" />
    <cfargument name="preferences" type="any" required="true" />

    <cfset setManager(arguments.mainManager) />
    <cfset setPreferencesManager(arguments.preferences) />
    <cfset setPackage("com/mypackage/myplugin") />

    <cfreturn this />
</cffunction>

The "manager" and "preferencesManager" values that are being saved here are for the plugin developer's access into Mango's component API. If you want to use some Mango functionality, you should find it in one of those somewhere (instead of digging around in the Application scope).

In order to broadcast our own event, we'll need to get the plugin queue, and call its createEvent method.

<cfset getManager().getPluginQueue().createEvent( ... ) />

CreateEvent takes 4 arguments:

  1. Name
  2. Data
  3. Type
  4. Message

Name is simply the name of the event. Something like "myCustomPluginEvent" would work. When defining events, try to make them descriptive but concise. There's no need to use the word "event" in your event name, for example.

Data is a structure that will be available to the plugin that responds to your event, and should contain everything that the plugin needs to process the event. I'll cover this in more detail in a moment.

Type is the event type. There are a few to choose from:

Each has their own usage and details, but for today I will only cover the last one: (Generic) where you pass an empty string to the third argument of the createEvent method, or do not include this argument at all (the default is an empty string).

And lastly, Message is another way to pass any necessary data in the event. This is typically used to display a message to the user, but it is not limited to a string type -- in fact, the default is an empty structure.

So, if we want to create a new generic message named "FooEvent", then we do so like this:

<cfset event = getManager().getPluginQueue().createEvent( "FooEvent", myData ) />

And then we can broadcast that event, like this:

<cfset event = getManager().getPluginQueue().broadcastEvent( event ) />

Notice that I'm re-using the event variable. The broadcastEvent method is passed the current value of the event object, and when all plugins respond that would like to, the event object is returned to the code that broadcast the event, in whatever state that the plugins left it in. In other words, plugins can modify the event object, and then it is available once again to the code that originated the event.

Above, I passed a variable called myData into the createEvent method. This can be of any type, as long as it includes everything that a plugin might need to respond to your event. It would be typical to use a structure.

When using certain event types, certain data is expected for the data argument of the createEvent method. For example, if you use the "Collection" type, the event has special handling that expects the data argument to be a structure containing keys named "query", "collection", and "arguments." You can find all of the event types and check out what they expect by looking at their event classes, located in {Mango-Install}/components/events.

And that's about it! When you broadcast the event, Mango will check for any plugins that listen for your event (by name), and let them respond to it. Afterwards, the object will be returned to your plugin, and you can continue as normal.

Posted in Mango | 3 Responses September 07 2010

The Faces Behind The Fruit

Ever wonder who these people are enriching your Mango experience? Wonder no more.

I took the opportunity to get a photo with Laura -- the creator of Mango -- at CFUnited this year. Thanks to Ben Nadel, who took the photo. We bribed him by also taking one for his blog header rotation. ;)

Adam and Laura at CFUnited 2010

Of course there are other people involved with Mango, but they weren't at CFUnited. Or if they were, they didn't say hi to me. Maybe next ti... oh wait.

Posted in Mango | 1 Response August 26 2010

Related Entries 1.1.4 - Works in Mango 1.5

As I mentioned Thursday, Mango's 1.5 release broke my Related Entries plugin. I found the time to fix it on my train ride home last night, so this morning I'm releasing the update.

While I was in there fixing the bug, I also found a way to improve the save/update process that the plugin is manipulating, so it should also be faster by a significant margin.

Plugin:
Related Entries
Version:
1.1.4
Requires:
Mango Blog 1.5+
Auto-install URL:
http://fusiongrokker.com/get/RelatedEntries

Posted in Mango | My projects | 2 Responses July 10 2010