大结局:修改 PHP 代码解决 SuiteCRM ERR_CACHE_MISS 错误

更新日期: 2024-10-14 阅读次数: 41 字数: 697 分类: 管理

书接上回,了解了浏览器 ERR_CACHE_MISS 的触发机制之后,对于这种列表页来说,最简单粗暴的做法就是把请求由 POST 改成 GET。

改哪里

SuiteCRM 代码量巨大,茫茫人海,去哪里寻找对应的修改点呢?

首先查看列表页的翻页按钮:

<button type="button" id="listViewEndButton_bottom"
	name="listViewEndButton" title="End"
	class="list-view-pagination-button"
	onclick="return sListView.save_checks('end', 'Contacts2_CONTACT_offset';)">
	<span class="suitepicon suitepicon-action-last"></span>
</button>

会看到点击事件,对应的是一个 save_checks 的 js 函数。

save_checks 在哪个 js 文件中

$ grep "save_checks" --include="*.js" -r .
./include/javascript/sugar_3.js:sugarListView.prototype.save_checks=function(offset,moduleString){checks=sugarListView.get_checks();if(typeof document.MassUpdate!='undefined'){document.MassUpdate.elements[moduleString].value=offset
./jssource/src_files/include/javascript/sugar_3.js:sugarListView.prototype.save_checks = function (offset, moduleString) {
./cache/include/javascript/sugar_grp1.js:sugarListView.prototype.save_checks=function(offset,moduleString){checks=sugarListView.get_checks();if(typeof document.MassUpdate!='undefined'){document.MassUpdate.elements[moduleString].value=offset

在浏览器的开发者工具里,也能看到这个 sugar_grp1.js 文件。例如:

https://crm.sunzhongwei.com/cache/include/javascript/sugar_grp1.js?v=2CLfOcmKgis8y7pHzk8zVA

sugarListView.prototype.save_checks = function(offset, moduleString) {
    checks = sugarListView.get_checks();
    if (typeof document.MassUpdate != 'undefined') {
        document.MassUpdate.elements[moduleString].value = offset
        if (typeof document.MassUpdate.massupdate != 'undefined') {
            document.MassUpdate.massupdate.value = 'false';
        }
        document.MassUpdate.action.value = document.MassUpdate.return_action.value;
        document.MassUpdate.return_module.value = '';
        document.MassUpdate.return_action.value = '';
        document.MassUpdate.submit();
        return !checks;
    } else
        return false;
}

Form 所在的 php 代码

通过 MassUpdate 关键词来搜索 form 所在的 PHP 文件:

$ grep 'id="MassUpdate"' --include="*.php" --exclude-dir="cache" -r .
./include/MassUpdate.php:            $form = '<form action="index.php" method="post" name="MassUpdate" id="MassUpdate">' . "\n";
./modules/MergeRecords/Step2.php:echo '<form onsubmit="return check_form(\'MassUpdate\');" id="MassUpdate" name="MassUpdate" method="post" action="index.php">'

很显然就是 include/MassUpdate.php 了。

135 if ($multi_select_popup) {
136     $tempString = '';
137 } else {
138     $tempString = "<form action='index.php' method='get' name='MassUpdate'  id='MassUpdate' onsubmit=\"return check_form('MassUpdate');\">\n"
139 . "<input type='hidden' name='return_action' value='{$action}' />\n"
140 . "<input type='hidden' name='return_module' value='{$module}' />\n"

138 行的 method 由 post 改成 get 即可。

修改之前,最好备份一下原 php 文件。避免改出其他的 bug (没错,兄弟就是在线上服务器里改代码 😊 )

sudo cp MassUpdate.php MassUpdate.php.bak20241014

解决了

再次测试,确实点击回退按钮,触发 ERR_CACHE_MISS 错误的问题解决了。

只是,列表页的链接,由 index.php 变成了这么长。即,把 post 的数据,全部搞到了 url 查询参数里。

https://crm.sunzhongwei.com/index.php?return_action=&return_module=&massupdate=false&delete=false&merge=false&current_query_by_page=%7B%22module%22%3A%22Contacts%22%2C%22action%22%3A%22index%22%2C%22parentTab%22%3A%22All%22%2C%22ajax_load%22%3A%221%22%2C%22loadLanguageJS%22%3A%221%22%2C%22searchFormTab%22%3A%22basic_search%22%7D&module=Contacts&action=index&lvso=&Contacts2_CONTACT_ORDER_BY=&uid=&select_entire_list=0&Contacts2_CONTACT_offset=20&show_plus=&selectCount%5B%5D=0&selectCount%5B%5D=0&Sync=&assigned_user_name=&assigned_user_id=&do_not_call=&lawful_basis=&date_reviewed=&lawful_basis_source=&lead_source=&account_name=&account_id=&opportunity_role=&report_to_name=&reports_to_id=&portal_account_disabled=&portal_user_type=&optout_primary=

共 753 个字符

url 最长支持多少个字符

  • 浏览器限制:不同的浏览器对 URL 长度有不同的限制。例如,IE 浏览器(旧版本)对 URL 长度限制较为严格,大约在 2083 个字符左右。而现代浏览器如 Chrome、Firefox 等通常能支持更长的 URL,但也没有一个固定的非常大的限制。实际上,它们可能会受到其他因素的影响,如系统资源、网络性能等。一般来说,当 URL 长度过长时,浏览器可能会出现加载问题或者截断 URL 的情况。
  • 服务器限制:服务器软件也会对 URL 长度有限制。例如,Apache HTTP Server 通常默认限制 URL 长度为 8190 字节左右,但这个限制可以通过配置文件进行修改。而微软的 IIS(Internet Information Services)服务器也有自己的限制,一般来说,它对 URL 的长度限制相对较为严格,具体限制取决于版本和配置,通常在 2048 字节左右。

参考:

https://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers

看起来,暂时是没啥问题了。简单测试了几个功能,都没有问题,一切正常。

非常好,收工。

微信关注我哦 👍

大象工具微信公众号

我是来自山东烟台的一名开发者,有敢兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊, 查看更多联系方式

tags: CRM 企业数字化