sugarcrm - 创建或更新任务时尝试向 suiteCRM 添加逻辑 Hook

标签 sugarcrm suitecrm

这是我第一次尝试进行 SugarCRM/suiteCRM 编码。

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

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

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

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

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

内部\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);
    }

}

?>

通过此设置, future 访问日期将填充计算出的日期。

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

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

但我无法让它发挥作用。

如果 LogicHooks 文件夹不存在,我是否必须创建该文件夹? 我应该为该文件指定哪个文件名? 我需要更改代码中的其他内容吗?

最佳答案

是,如果 LogicHooks 目录不存在,则创建该目录。 PHP 文件可以命名为您喜欢的任何名称。

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

像以前一样在此文件中定义逻辑 Hook 。

<?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 中找到。

关于sugarcrm - 创建或更新任务时尝试向 suiteCRM 添加逻辑 Hook ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38248214/

相关文章:

soa - Sugar CRM SOAP get_entry_list

sugarcrm - 在 suiteCRM 中,如何将地址字段国家和州文本字段更改为下拉菜单?

JavaScript 表单提交

php - SUITE CRM 7.5.3 - Windows 7/Apache 2.x/PHP 7/MYSQL5.6 上的安装在数据库配置后挂起

php - 仅选择 min(date) 时 SQL 返回各种日期

fatal-error - 调用未定义的函数iconv() fatal error -Suitecrm

kubernetes - SuiteCRM在Minikube/K8s上安装

sugarcrm - 升级到另一个版本

mysql - SuiteCRM - 多服务器设置