ColdFusion 8 - Application.cfc干扰

时间:2013-06-13 16:08:41

标签: coldfusion cfml coldfusion-8 application.cfc cfimport

我在客户的网站上遇到了一个奇怪的问题,我的实时域名正在使用我的开发域应用程序设置。我之前没有遇到此问题,并且cflock(以及其他设置)中的Application.dsn已移除,解决了此问题。

如前所述,我有一个实时网站*www.*和开发网站*dev.*,我的开发网站位于实际网站/dev/的子文件夹中,并拥有自己的Application.cfc

我的第一个问题是,如果我在dev文件夹中的Application范围中有变量,那么这会覆盖上面文件夹中的Application范围变量吗?它会认为它是同一个范围吗?如果是这样,那么这可能解释了什么问题,如果没有,那么我很难过。

我的第二个问题是,我应该如何更正application.cfc中的cflock应用范围变量?我应该这样做吗?

这是我的Application.cfc,建议将不胜感激:

<cfcomponent output="true">

<cfimport taglib="taglib" prefix="func">

<!---

        Check staging directory exists

--->

<cfset THIS.env = "staging">

<!---

        Set application vars

--->

<cfset THIS.applicationTimeout = createTimeSpan(0,0,0,0)>
<cfset THIS.sessionManagement="Yes">
<cfset THIS.clientManagement = true>
<cfset THIS.clientStorage = "cookie">
<cfset THIS.loginStorage = "cookie">
<cfset THIS.setDomainCookies = false>
<cfset THIS.setClientCookies = true>
<cfset THIS.scriptProtect = true>
<cfset THIS.secureJSON = true> <!--- Added 12.06.13 --->

<!---

        Check environment
        Set application name

--->

<cfif THIS.env EQ "staging">
    <cfset THIS.applicationName = "devenv">
    <cfset THIS.dsn = "devenv">
<cfelse>
    <cfset THIS.applicationName = "liveenv">
    <cfset THIS.dsn = "liveenv">
</cfif>

<cfif #cgi.HTTP_HOST# NEQ "localhost">
    <cfset THIS.dirpath = "http://#cgi.http_host#">
    <cfset THIS.componentPath = "cfcs.">
<cfelse>
    <cfset urlString = #mid(cgi.PATH_INFO, 2, 200)#>
    <cfset THIS.localhostFolderName = #spanexcluding(urlString, "/")#>
    <cfset THIS.dirpath = "http://localhost/#THIS.localhostFolderName#">
    <cfset THIS.componentPath = "#THIS.localhostFolderName#.cfcs.">
</cfif>
<cfset THIS.name = THIS.applicationName>
<cfset THIS.sessiontimeout = createtimespan(0,0,20,0)>
<cfset THIS.setClientCookies = true>
<cfset THIS.visitor = true>


<cffunction name="onApplicationStart" returntype="void">

    <cfset APPLICATION.name = THIS.applicationName>
    <cfset APPLICATION.dsn = THIS.dsn>
    <cfset APPLICATION.DSN = THIS.dsn>
    <cfset APPLICATION.dirpath = THIS.dirpath>
    <cfset APPLICATION.componentPath = THIS.componentPath>
    <cfif #cgi.HTTP_HOST# EQ "localhost">
        <cfset APPLICATION.localhostFolderName = THIS.localhostFolderName>
    </cfif>

    <!--- USED FOR PATHS AND URLS --->  

    <!--- Property image upload paths ---->
    <cfset APPLICATION.paths = StructNew()>

    <!---

            Check environment
            Set local root

    --->

    <cfif THIS.env EQ "staging">

        <cfset APPLICATION.paths.localRoot = "c:\websites\foobar.co.uk\dev\">

    <cfelse>

        <cfset APPLICATION.paths.localRoot = "c:\websites\foobar.co.uk\">

    </cfif>


    <cfset APPLICATION.paths.logs = APPLICATION.paths.localRoot & "logs\">
    <cfset APPLICATION.paths.logFile = APPLICATION.paths.logs & "site_log.txt">       
    <cfset APPLICATION.paths.property = StructNew()>
    <cfset APPLICATION.paths.property.image = APPLICATION.paths.localRoot & "images\property\">
    <cfset APPLICATION.paths.property.large = APPLICATION.paths.property.image & "large\">
    <cfset APPLICATION.paths.property.thumb = APPLICATION.paths.property.image & "thumbs\">
    <cfset APPLICATION.paths.property.cmsThumb = APPLICATION.paths.property.image & "thumbs\cms\">
    <cfset APPLICATION.paths.property.pdf = APPLICATION.paths.localRoot & "pdf\">
    <cfset APPLICATION.paths.property.pdfGenerated = APPLICATION.paths.property.pdf & "generated\">
    <cfset APPLICATION.newsUploadPath = APPLICATION.paths.localRoot & "images\news\">
    <cfset APPLICATION.articlesUploadPath = APPLICATION.paths.localRoot & "images\articles\">

    <cfset APPLICATION.articlesThumbsDir = "../images/articles/thumbs/">
    <cfset APPLICATION.articlesContentDir = "../images/articles/assets/">
    <cfset APPLICATION.articlesAssetsDir = "../articles/assets/">

    <!--- Site URLS ---->
    <cfset APPLICATION.urls = StructNew()>
    <cfset APPLICATION.urls.root = "http://" & CGI.server_name & "/">
    <cfset APPLICATION.urls.com = "com">
    <cfset APPLICATION.urls.tagLib = APPLICATION.urls.root & "taglib/">
    <cfset APPLICATION.urls.cms.tagLib = "http://" & CGI.server_name & ":" & CGI.server_port & "/admin/tagLib/">
    <cfset APPLICATION.RowsPerPage = 10>

    <!--- Property URLS --->
    <cfset APPLICATION.urls.property.pdf = APPLICATION.urls.root & "pdf/">
    <cfset APPLICATION.urls.property.image = APPLICATION.urls.root & "images/property/">
    <cfset APPLICATION.urls.property.large = APPLICATION.urls.root & "images/property/large/">
    <cfset APPLICATION.urls.property.thumb = APPLICATION.urls.root & "images/property/thumbs/">
    <cfset APPLICATION.urls.property.cmsThumb = APPLICATION.urls.root & "images/property/thumbs/cms/">
    <cfset APPLICATION.urls.news.image = APPLICATION.urls.root & "images/news/">
    <cfset APPLICATION.urls.articles.image = APPLICATION.urls.root & "images/articles/">

    <cflock scope="Application" timeout="5" type="Exclusive">

        <cfscript>

            /* Commonly used objects and queries */

            // DAOs 
            APPLICATION.propertyDAO = CreateObject("component", "cfcs.dataobjects.propertyDAO").init(APPLICATION.dsn);

            APPLICATION.propertyImageDAO = CreateObject("component", "cfcs.dataobjects.property_imageDAO").init(APPLICATION.dsn);
            APPLICATION.propertyToPropertyImageDAO = CreateObject("component", "cfcs.dataobjects.property_to_property_imageDAO").init(APPLICATION.dsn);
            APPLICATION.propertyToPropertyLocationDAO = CreateObject("component", "cfcs.dataobjects.property_to_property_locationDAO").init(APPLICATION.dsn);
            APPLICATION.propertyToPropertyTypeDAO = CreateObject("component", "cfcs.dataobjects.property_to_property_typeDAO").init(APPLICATION.dsn);
            APPLICATION.propertyToPropertyTenureDAO = CreateObject("component", "cfcs.dataobjects.property_to_property_tenureDAO").init(APPLICATION.dsn);     
            APPLICATION.propertyGroupDAO = CreateObject("component", "cfcs.dataobjects.property_groupDAO").init(APPLICATION.dsn);     

            // Gateways
            APPLICATION.propertyGateway = CreateObject("component", "cfcs.dataobjects.propertyGateway").init(APPLICATION.dsn);
            APPLICATION.propertyImageGateway = CreateObject("component", "cfcs.dataobjects.property_imageGateway").init(APPLICATION.dsn); 
            APPLICATION.propertyToPropertyImageGateway = CreateObject("component", "cfcs.dataobjects.property_to_property_imageGateway").init(APPLICATION.dsn);
            APPLICATION.propertyLocationGateway = CreateObject("component", "cfcs.dataobjects.property_locationGateway").init(APPLICATION.dsn);
            APPLICATION.propertyImageGateway = CreateObject("component", "cfcs.dataobjects.property_imageGateway").init(APPLICATION.dsn);
            APPLICATION.propertyTypeGateway = CreateObject("component", "cfcs.dataobjects.property_typeGateway").init(APPLICATION.dsn);
            APPLICATION.propertyToPropertyTypeGateway = CreateObject("component", "cfcs.dataobjects.property_typeGateway").init(APPLICATION.dsn);
            APPLICATION.propertyTenureGateway = CreateObject("component", "cfcs.dataobjects.property_tenureGateway").init(APPLICATION.dsn);
            APPLICATION.propertyToPropertyTenureGateway = CreateObject("component", "cfcs.dataobjects.property_to_property_tenureGateway").init(APPLICATION.dsn);
            APPLICATION.partnerGateway = CreateObject("component", "cfcs.dataobjects.partnerGateway").init(APPLICATION.dsn);

            // Business Objects
            APPLICATION.propertyBO = CreateObject("component", "cfcs.businessobjects.propertyBO").init(APPLICATION.dsn);

            // Common queries
            APPLICATION.qPartners = APPLICATION.partnerGateway.getAllRecords();    
            APPLICATION.qPropertyTypes = APPLICATION.propertyTypeGateway.getAllRecords(); 
            APPLICATION.qPropertyTenures = APPLICATION.propertyTenureGateway.getAllRecords(); 
            APPLICATION.qPropertyMinMaxSize = APPLICATION.propertyGateway.getMinMaxSize();
            APPLICATION.qPropertyLocations = APPLICATION.propertyLocationGateway.getAllRecords();

        </cfscript>
    </cflock>
</cffunction>
<cffunction name="onSessionStart" returntype="void">
    <cflock scope="Session" timeout="5" type="Exclusive">       
        <cfscript>
            SESSION.propertySearchCriteria = CreateObject("component", "cfcs.beans.property_search_criteria").init();
            SESSION.propertySearch = CreateObject("component", "cfcs.beans.property_search").init(SESSION.propertySearchCriteria);
        </cfscript>    
    </cflock>
</cffunction>

2 个答案:

答案 0 :(得分:0)

您可以使用条件逻辑来设置应用程序名称。

if ( YouAreHappy and YouKnowIt ) {
This.name = "ClapYourHands";
}
else {
This.name = "StompYourFeet"; 
}

在现实生活中,你的if条件会使现场和测试环境变得不同。 cgi.http_host是一个很好的候选人。

答案 1 :(得分:0)

为什么要根据其所处的环境更改应用程序名称?这是没有意义的。该应用程序仍然是相同的应用程序,无论它是在prod,或你正在进行,或开发它。

同样,与源代码相同。您的实时网站中有自己的开发网站?这有什么用呢?

我不知道您的应用程序变量发生了什么,但它们与应用程序名称(this.name)绑定,而不是Application.cfc在目录结构中的位置。

我怀疑你的零applicationTimeout在这里没有多大帮助。这基本上意味着您的应用程序永远不会持续存在......它将超时每个请求。这没有任何意义。

<cflock>您无需onApplicationStart()该代码。 ColdFusion只允许一个请求运行onApplicationStart():所有其他请求将排队,直到它完成,此时应用程序已启动,因此排队的请求甚至不会尝试运行它。

我认为您的问题很可能是由于您的应用程序框架设计不佳造成的,而且您正在使用dev和prod在相同的源代码树中进行这种奇怪的事情(这违反了所有逻辑)。

排除源代码,不会出现问题。