SuiteCRM中的Lead Save数据库错误

时间:2016-01-29 04:01:26

标签: php sugarcrm suitecrm sugarbean

我在Logic Hook模块中创建了Leads以保存到数据库中的字段。问题是,当我首先保存Lead时,它会显示一条重复的消息:

  

数据库故障错误检查SuiteCRM日志。

如果我注释掉此代码,则会保存Lead

LogicHook:

<?php

class LeadData
{
    public function leadSaveData(&$bean, $events, $arguments)
    {
        $stateId = $bean->state_c;

        if ($stateId != "") {
            $beanst_state = BeanFactory::getBean('s1_state', $stateId); 
            $StateName = $beanst_state->name;
            $bean->resstate_c = $StateName;
        } else {
            $bean->resstate_c = "Punjab";
        }

        if (!empty($bean->mediatype_c)) {
            $mediaType = $bean->mediatype_c;
            $callstatus = $bean->callstatus_c; //for follow up
            if ($mediaType == 'Selectmedia' && $mediaType != '') {
                $bean->refrence_c = 'null';
            } else if ($mediaType == 'Refrence') {
                $bean->eventname_c = 'null';
            } else {
                $bean->mediatype_c = 'null';
                $bean->refrence_c = 'null';
                $bean->eventname_c = 'null';
            }

            if ($callstatus != 'followup') {
                $bean->calllater_c = '0000-00-00 00:00:00';
            }
            $bean->save();
        }
    }
}

1 个答案:

答案 0 :(得分:2)

请在您的代码中按照以下步骤操作,以使此错误正确或正常工作。希望这会对你有所帮助。

<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

if (!defined('sugarEntry') || !sugarEntry)
    die('Not A Valid Entry Point');

class saveextradata_logic_hooks_class
{
    static $already_ran = false;

    function saveextradata_after_save_method(&$bean, $events, $arguments)
    {
        global $db;

        if (self::$already_ran == true) return;
        self::$already_ran = true;

        $lead_id = $bean->id;

        $stateId = $_POST['state_c'];
        $sql = "select name from s1_state where id='$stateId'";
        $query = $db->query($sql);
        $result = $db->fetchByAssoc($query);
        $statename = $result[name];

        if ($stateId != "") {
            $statename;
        } else {
            $statename = "Punjab";
        }
        if (!empty($_POST['mediatype_c'])) {
            $mediaType = $_POST['mediatype_c'];

            if ($mediaType == 'Selectmedia' && $mediaType != '') {
                $mediatype = 'Selectmedia';
                $reference = 'null';
                $eventname = $_POST['eventname_c'];
            } else if ($mediaType == 'Refrence') {
                $mediatype = 'Refrence';
                $reference = $_POST['refrence_c'];
                $eventname = 'null';
            } else {
                $mediatype = 'null';
                $reference = 'null';
                $eventname = 'null';
            }
        }

        $callstatus = $_POST['callstatus_c'];//for follow up
        if ($callstatus != 'followup') {
            $calllater = '0000-00-00 00:00:00';
        }

        /*$bean->eventname_c = $eventname;
        $bean->refrence_c = $reference;
        $bean->mediatype_c = $mediatype_c;
        $bean->calllater_c = $calllater;
        $bean->resstate_c = $statename;
        $bean->save();*/

        $leadupdate = "update leads_cstm set resstate_c='$statename',eventname_c='$eventname',refrence_c='$reference',mediatype_c='$mediatype',calllater_c='$calllater' WHERE id_c = '$lead_id'";
        $resultProductmasterdetail = $db->query($leadupdate);
    }
}