1

我刚刚遇到了一个客户网站的奇怪问题,我的实时域正在使用我的开发域应用程序设置。我以前没有遇到过这个问题,并且删除(cflockApplication.dsn其他设置中)解决了这个问题。

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

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

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

这是我的 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>

4

2 回答 2

0

为什么要根据应用程序所处的环境更改应用程序名称?这是没有意义的。该应用程序仍然是同一个应用程序,无论它是在生产中,还是您正在暂存或开发它。

同样,与源代码相同。您的实时网站中有您的开发网站吗?这有什么意义?

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

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

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

我认为您的问题很可能是由于您糟糕的应用程序框架设计造成的,并且您正在做的这件奇怪的事情让 dev 和 prod 在同一个源代码树中(这违背了所有逻辑)。

把你的源代码整理出来,问题就不会出现了。

于 2013-06-13T21:04:07.483 回答
0

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

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

在现实生活中,您的 if 条件将与实际环境和测试环境不同。cgi.http_host 是一个不错的选择。

于 2013-06-13T18:03:42.503 回答