1

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

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

如果我注释掉这段代码,Lead然后保存。

逻辑钩:

<?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();
        }
    }
}
4

1 回答 1

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);
    }
}
于 2016-02-05T05:59:53.467 回答