1

Currently, in the application.cfc, I extend the Fusebox 5.5 Framework. Then in the OnRequestStart method below, I set the fusebox mode depending on a certain condition.

The problem is that sometimes, the fusebox xml files do not reparse no matter what changes I make. If I force a reparse using the url variables fusebox.parse=true&fusebox.loadclean=true&fusebox.password=xxx then the files parse again.

It is almost like Fusebox remains in production mode even though when I dump the FUSEBOX_PARAMETERS.mode it says "development-full-load"

What could be causing this? Is the way that the fusebox mode is being manipulated correct in the code below or should that kind of setting be done somewhere else (besides the fusebox.xml obviously)??

Any help would be great. Thanks

 <cffunction name="onRequestStart">
    <cfset variables.server_type = "Development" />

    <cfswitch expression="#variables.server_type#">
        <cfcase value="development">
            <cfset FUSEBOX_PARAMETERS.mode = "development-circuit-load" />
            <cfset FUSEBOX_PARAMETERS.debug = true />
            <cfset request.component_reload = true />
        </cfcase>
        <cfdefaultcase>
            <cfset FUSEBOX_PARAMETERS.mode = "production" />
            <cfset FUSEBOX_PARAMETERS.debug = false />
            <cfset request.component_reload = false />
        </cfdefaultcase>
    </cfswitch>
    <cfif (StructKeyExists(attributes, "fusebox.loadapp") AND attributes.fusebox.password EQ application.fusebox.password) OR FUSEBOX_PARAMETERS.mode NEQ application.fusebox.mode>
        <cfset this.onApplicationStart() />
    </cfif> 

    <cfset superReturn = super.onRequestStart(arguments.1) />
</cffunction>
James A Mohler
  • 11,060
  • 15
  • 46
  • 72
Paolo Broccardo
  • 1,942
  • 6
  • 34
  • 51

1 Answers1

3

See, FUSEBOX_PARAMETERS are stored in application scope, by default they are included in huge container application.fusebox. Fusebox settings are populated when super.onApplicationStart() invoked, so modifying them in onRequestStart does not make sense.

I would recommend to move your cfswitch code into the component body where you define application settings.

In onRequestStart you can force the application restart to reread the settings, possibly something like this:

<cfif StructKeyExists(attributes, "fusebox.loadapp") AND attributes["fusebox.password"] EQ application.fusebox.password>
    <cfset this.onApplicationStart() /
</cfif>

Please note that fusebox.loadapp is not built-in Fusebox attribute, it will work only for your app, simply prefixed like others for convenience. This way you can reread the singletones of your application.

Sergey Galashyn
  • 6,946
  • 2
  • 19
  • 39
  • Thanks for the reply - I suspected it had something to do with the application scope. So would putting the code in the onApplicationStart method work if I put it before the call to ? – Paolo Broccardo May 08 '11 at 13:26
  • @Cheeky, You mean putting your code, right? I think this `may` work in `onApplicationStart` too, but you'll need to do at least two things: (1) execute `super.onApplicationStart()` after that; (2) force application restart in request somehow, unless it wont be fired before timeout. Plus, I'm don't think `FUSEBOX_PARAMETERS` will work inside `onApplicationStart`, possibly you should try `application.fusebox` format instead. But simplest solution would be to do as I proposed in the answer. – Sergey Galashyn May 08 '11 at 14:26
  • @Sergii: Would you mind elaborating on "I would recommend to move your cfswitch code into the component body where you define application settings." In this application, all settings are defined in fusebox.init or appliction.cfc. There is no separate CFC for app settings. Thanks@Sergii: Would you mind elaborating on "I would recommend to move your cfswitch code into the component body where you define application settings." In this application, all settings are defined in fusebox.init or appliction.cfc. There is no separate CFC for app settings. So maybe in the fusebox.init place the switch, t – Paolo Broccardo May 12 '11 at 05:58
  • @Sergii: Ok, it works simply by running ` ` after the switch. So the code will have no effect in OnRequestStart unless those fusebox parameters are passed in. By default, fusebox is set to 'production' mode, so the only time I have to pass those parameters is when I'm on a development server. Or perhaps I can even check if the application.fusebox.mode is different from the request and call OnApplicationStart as well? – Paolo Broccardo May 12 '11 at 06:31
  • @Sergii: Ok, I've edited the original post to reflect the route i've taken. You see any issues? Thanks! – Paolo Broccardo May 12 '11 at 06:39
  • @Cheeky, I still think that you should move your cfswitch out from onRequestStart to have `FUSEBOX_PARAMETERS` properly parsed by Fusebox. I don't think it will be available on that phase. – Sergey Galashyn May 12 '11 at 07:41
  • @Sergii: What do you mean? Where should it go then? I have tested the edited scenario above and it is working in every case I tried. Please provide me with a more detailed description of what you mean by move it out of OnRequestStart. – Paolo Broccardo May 12 '11 at 08:28
  • I would put it between `` and `` at least as better coding practice. – Sergey Galashyn May 12 '11 at 11:14