1

我编写了一个 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);

    }

}
4

1 回答 1

4

componentcfscript 直到 CF9 才支持,所以是的,这是一个兼容性问题。

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

于 2015-11-24T21:03:23.757 回答