【问题标题】:Trying to add a logic hook to suiteCRM when creating or updating a task在创建或更新任务时尝试向 suiteCRM 添加逻辑挂钩
【发布时间】:2016-11-09 22:24:59
【问题描述】:

这是我第一次尝试为 sugarCRM / suiteCRM 编码。

我应该说我已经为 Wordpress 编码近 10 年了,但现在我完全迷失了,我开始深入研究 suiteCRM。

我读到你可以在将数据保存到数据库后添加一个逻辑挂钩来修改数据,但我不知道从哪里开始......

假设我为今天(7 月 7 日)创建了一个任务,该任务与我每 2 个月访问一次的客户相关,因此帐户中有一个名为“访问频率”的字段。我想在任务的“未来访问日期”字段中添加一个未来日期(7 月 7 日 + 60 天 = 9 月 7 日左右),这样我就可以使用它通过 Workflow 创建特定的未来任务。

我要做的是计算任务中的一个字段(未来访问日期),它等于添加到任务自己的日期字段的帐户模块字段(访问频率)上的天数。

我已经能够使用以下布局使其工作:

内部\custom\modules\Tasks\logic_hooks.php

<?php

$hook_version = 1; 
$hook_array['before_save'] = Array();

$hook_array['before_save'][] = Array(
    1, //Processing index. For sorting the array.
    'future_task_date_on_task_creation', //Label. A string value to identify the hook.
    'custom/modules/Tasks/future_visit_date.php', //The PHP file where your class is located.
    'before_save_class', //The class the method is in.
    'future_visit_date' //The method to call.
);

?>

在 \custom\modules\Tasks\future_visit_date.php 中

<?php

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

class before_save_class {

    function future_visit_date($bean, $event, $arguments) {
        $bean->rhun_fecha_sig_c = date("Y-m-d H:i:s", $date);
    }

}

?>

通过此设置,未来访问日期将填充计算日期。

我还了解到不建议使用此设置,我应该使用扩展框架并将第一个文件放在此路径中:

/custom/Extension/modules/Tasks/Ext/LogicHooks/<file>.php

但我不能让它工作。

如果没有 LogicHooks 文件夹,我是否必须创建它? 我应该为这个文件分配哪个文件名? 我是否必须更改代码中的其他内容?

【问题讨论】:

    标签: sugarcrm suitecrm


    【解决方案1】:

    是的,如果 LogicHooks 目录不存在,请创建它。 PHP 文件可以任意命名。

    /custom/Extension/modules/Tasks/Ext/LogicHooks/MyLogicHookFile.php

    像以前一样在这个文件中定义你的逻辑钩子。

    <?php
    
    $hook_version = 1; 
    $hook_array['before_save'] = Array();
    
    $hook_array['before_save'][] = Array(
        1, //Processing index. For sorting the array.
        'future_task_date_on_task_creation', //Label. A string value to identify the hook.
        'custom/modules/Tasks/future_visit_date.php', //The PHP file where your class is located.
        'before_save_class', //The class the method is in.
        'future_visit_date' //The method to call.
    );
    

    然后从管理面板运行修复和重建。

    使用扩展框架的主要优点是它允许多个开发人员将组件添加到 Sugar 实例,而不必担心覆盖现有代码。
    更多信息可以在Developer Guide

    中找到

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-30
      • 1970-01-01
      相关资源
      最近更新 更多