ColdFusion 8 - Application.cfc干扰

问题描述 投票:1回答:2

我刚刚与客户的网站有一个奇怪的问题,我的实时域名正在使用我的开发域应用程序设置。我之前没有遇到过这个问题,并且在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>

coldfusion cfml coldfusion-8 application.cfc cfimport
2个回答
0
投票

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

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

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

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

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

我认为你的问题很可能是由你糟糕的应用程序框架设计引起的,而这个奇怪的事情是你在同一个源代码树中使用dev和prod(它违背了所有逻辑)。

对源代码进行排序,不会出现问题。


0
投票

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.