组件和ColdFusion 8

时间:2015-11-24 20:52:21

标签: coldfusion lucee

我写了一个cfc来处理项目某个方面的所有功能。我通常用标签写,但选择学习新东西,所以我用脚本编写。我的所有测试和测试都是在运行Lucee的CommandBox上进行的,以便快速启动和开发环境。它就像一个魅力。现在,当我将其上传到运行ACF 8的生产服务器时,它将不会读取任何文件。我导航到cfc的地址,它通常会显示可访问的函数,我会在段落中获取代码。

在我在标签中重写之前,我想确保它与ACF 8的兼容性问题,而不是我的代码和/或任何工作。请不要因为没有使用参数而锤我。

这是我的代码:

component {
    DSN = 'xxxx';

    public function init(){
    }


    remote function BranchContact(MainContactID, BranchOfContactID, UserID) returnformat="plain"{

        data = IsBranch(BranchOfContactID);

        if(data.branchTotal == 0){
            // result = 'no branches';
            result = InsertBranch(MainContactID, BranchOfContactID, UserID);    
            //WriteBranchingHistory(MainContactID, BranchOfContactID, UserID);      
            result = 1;
        }
        else{
            // message = 'It appears that you are branching to an account is already a branch - from component';
            queryString = 'Select top 1 ParentCID from branches where ChildCID =' & BranchOfContactID;
            data = RunQuery(queryString);
            result = data.ParentCID;
        }
        return result;

    }

    private function IsBranch(BranchOfContactID){
        queryString = 'Select count(*) as branchTotal from branches where ChildCID = ' & BranchOfContactID;
        RunQuery(queryString);
        return data;
    }

    private function InsertBranch(ParentCID, ChildCID, UserID){
        // try{         
            queryString = 'Insert into Branches (ParentCID,  ChildCID, UserID) values (' & ChildCID  & ', ' & ParentCID & ', '& UserID & ')';
            data = RunQuery(queryString);
            //WriteBranchingHistory(MainContactID, BranchOfContactID, UserID);
            //need to write the branching history to the contact history table so that is can be tracked
            contactResultsID = 102;
            note = 'Account branched to - ' & ChildCID;
            quotedNote = ''''&note&'''';
            activityType = 'Branched';
            quotedActivity = ''''&activityType&'''';
            campaignID = 0;
            today = 'getdate()';

            AddContactHistory(ParentCID, today, contactresultsID, UserID, quotedActivity, quotedNote, campaignID);
            //return history;
            return data;
        // }
        // catch(e){
        //  errorMessage = 'While trying to branch account';
        //  message = error(errorMessage);
        //  return message;
        // }

    }

    remote function Delete(ChildCID, UserID) returnformat="plain"{
        // try{
            //have to use a query to get the parentcid since it will be empty when the ajax query is triggered
            Parent = GetParent(ChildCID);
            queryString = 'Delete from branches where ChildCID = ' & ChildCID;
            data = RunQuery(queryString);
            //WriteBranchingHistory(MainContactID, BranchOfContactID, UserID)

            contactResultsID = 103;
            note = 'Account unbranched from - ' & Parent.parentCID;
            quotedNote = ''''&note&'''';
            activityType = 'Removed Branch';
            quotedActivity = ''''&activityType&'''';
            campaignID = 0;
            today = 'getdate()';

            AddContactHistory(ChildCID, today, contactresultsID, UserID, quotedActivity, quotedNote, campaignID);




            return data;
        // }
        // catch(e){
        //  errorMessage = 'While trying to delete branching';
        //  message = error(errorMessage);
        //  return e;
        // }


    }

    private function Update(){

    }

    <!--- WriteBranchHistory has not been completed 
    public function WriteBranchingHistory(MainContactID, BranchOfContactID, UserID) returnformat="plain"{


        try{
            queryString = 'insert into BranchHistory(contactID, ChildContactID, UserID, InsertDate) values
             ('& MainContactiD &', '& BranchContactID & ', ' & UserID & ', getdate());';
            data = RunQuery(queryString);
            // return data;
            //oldMar = GetOldMar(MainContactID);
            // writeDump(oldMar);
            // writeDump(queryString);
            //return oldMar;

        }
        catch(e){
            errorMessage = 'While trying to add branch history';
            message = error(errorMessage);
            return message;
        }

    }

    --->

    public function GetParent(ChildCID) returnformat="html"{

        queryString = 'Select top 1 parentCID from branches where childCID =  ' & ChildCID;
        data = RunQuery(queryString);
        return data;
    }

    public function GetUserInfo(userid){
        myQuery = new Query();
        myQuery.addParam(name="userid", value=userid, cfsqltype="cf_sql_numeric");
        myQuery.setDataSource(DSN);
        myQuery.setSQL('select * from users where userid = :userid');
        data = myQuery.execute().getResult();
        return data;

    }

    private function RunQuery(queryString){
        myQuery = new Query();
        // myQuery.addParam(name="ContactID", value=ContactID, cfsqltype="cf_sql_numeric");
        myQuery.setDataSource(DSN);
        myQuery.setSQL(queryString);
        data = myQuery.execute().getResult();
        return data;
    }

    private function error(errorMessage){
        message = "Oops something went wrong <br/>" & errorMessage;
        return message;
    }

    private function AddContactHistory(ParentCID, today, contactresultsID, UserID, quotedActivity, quotedNote, campaignID) {
        InsertHistoryString = 'insert into contacthistory (contactid, historydate, contactresultID, userid, activitytype, note, campaignID) values 
                ('&ParentCID& ', ' &today& ', ' &contactresultsID& ', ' &UserID& ', ' &quotedActivity& ', ' &quotedNote& ', ' &CampaignID& ');';
        InsertHistory = RunQuery(InsertHistoryString);

    }

}

1 个答案:

答案 0 :(得分:4)

在CFF之前,cfscript不支持

component,所以是的,这是一个兼容性问题。

Pete Freitag在他的博客上有一份很好的cfscript兼容性备忘单,链接在这里:https://www.petefreitag.com/cheatsheets/coldfusion/cfscript/