Vtiger 7.2 对 REST API 的查询操作返回 500 个错误

Vtiger 7.2 query operations to REST API returning 500 errors

我最近从 Vtiger 6 升级到 7.2(全新安装),我对使用 query 操作的 REST API 的所有请求都不再有效。请求针对哪个模块并不重要,例如联系人、潜在客户、客户。所有其他类型的操作都在工作,例如检索,描述,但是诸如 select * from Contacts where email = 'foo@bar.com'; 之类的查询将失败,并出现来自 Vtiger 服务器的 500 内部服务器错误 return。

这是我的 HTTP 请求的示例(为了便于阅读,查询参数未编码):

https://crm.myendpoint.com/webservice.php?sessionName=[mysession]&operation=query&query=select * from Contacts where email = 'foo@bar.com';

我用来进行查询的代码与我使用 Vtiger 版本 6 时完全没有修改,那时请求工作正常。我已经在服务器上打开调试日志记录,但没有错误。

服务器正在接收和处理请求。有一次,它将数据转储到我正在查询的联系人的日志中(看起来都正确),然后这是日志记录结束前的最后几行:

Mon Jan 20 17:13:41 2020,292 [8010] DEBUG webservice - Entering isPermitted(Contacts,DetailView,) method ...
Mon Jan 20 17:13:41 2020,292 [8010] DEBUG webservice - Entering getActionid(DetailView) method ...
Mon Jan 20 17:13:41 2020,292 [8010] INFO webservice - get Actionid DetailView
Mon Jan 20 17:13:41 2020,292 [8010] INFO webservice - action id selected is 4
Mon Jan 20 17:13:41 2020,292 [8010] DEBUG webservice - Exiting getActionid method ...
Mon Jan 20 17:13:41 2020,292 [8010] DEBUG webservice - Exiting isPermitted method ...
Mon Jan 20 17:13:41 2020,293 [8010] DEBUG webservice - Entering getColumnFields(Accounts) method ...
Mon Jan 20 17:13:41 2020,293 [8010] DEBUG webservice - in getColumnFields Accounts
Mon Jan 20 17:13:41 2020,293 [8010] DEBUG webservice - Prepared sql query being executed : SELECT tabid, fieldname, fieldid, fieldlabel, columnname, tablename, uitype, typeofdata, presence
        FROM vtiger_field WHERE tabid in (?)
Mon Jan 20 17:13:41 2020,293 [8010] DEBUG webservice - Prepared sql query parameters : [6]
Mon Jan 20 17:13:41 2020,293 [8010] DEBUG webservice - Exiting getColumnFields method ...
Mon Jan 20 17:13:41 2020,294 [8010] DEBUG webservice - Entering getColumnFields(Accounts) method ...
Mon Jan 20 17:13:41 2020,294 [8010] DEBUG webservice - in getColumnFields Accounts
Mon Jan 20 17:13:41 2020,294 [8010] DEBUG webservice - Exiting getColumnFields method ...
Mon Jan 20 17:13:41 2020,294 [8010] DEBUG webservice - Prepared sql query being executed : select 1 from vtiger_crmentity where crmid=? and deleted=0 and setype='Accounts'
Mon Jan 20 17:13:41 2020,294 [8010] DEBUG webservice - Prepared sql query parameters : [9637]
Mon Jan 20 17:13:41 2020,294 [8010] DEBUG user - Entering Users() method ...
Mon Jan 20 17:13:41 2020,294 [8010] DEBUG webservice - Entering getColumnFields(Users) method ...
Mon Jan 20 17:13:41 2020,294 [8010] DEBUG webservice - in getColumnFields Users
Mon Jan 20 17:13:41 2020,294 [8010] DEBUG webservice - Exiting getColumnFields method ...
Mon Jan 20 17:13:41 2020,295 [8010] DEBUG user - Exiting Users() method ...
Mon Jan 20 17:13:41 2020,295 [8010] DEBUG webservice - Entering getColumnFields(Users) method ...
Mon Jan 20 17:13:41 2020,295 [8010] DEBUG webservice - in getColumnFields Users
Mon Jan 20 17:13:41 2020,295 [8010] DEBUG webservice - Exiting getColumnFields method ...
Mon Jan 20 17:13:41 2020,295 [8010] DEBUG webservice - Prepared sql query being executed : select 1 from vtiger_users where id=? and deleted=0 and status='Active'
Mon Jan 20 17:13:41 2020,295 [8010] DEBUG webservice - Prepared sql query parameters : [1]
Mon Jan 20 17:13:41 2020,295 [8010] DEBUG webservice - Prepared sql query being executed : select groupname from vtiger_groups where groupid = ?
Mon Jan 20 17:13:41 2020,295 [8010] DEBUG webservice - Prepared sql query parameters : [1]
Mon Jan 20 17:13:41 2020,295 [8010] DEBUG webservice - Prepared sql query being executed : select first_name from vtiger_users where id = ?
Mon Jan 20 17:13:41 2020,295 [8010] DEBUG webservice - Prepared sql query parameters : [1]

我认为这可能是某种权限问题,但在那种情况下服务器肯定不会 return 500。无论如何,我已经尝试 运行 查询 2 个不同的用户,这两个用户都具有管理员角色。

这个问题发生在查询操作中,与被查询的模块无关。有什么办法可以进一步调试吗?

This fix 成功了。

综上所述,include/Webservices/VtigerModuleOperation.php 中第 199 行调用的不存在的方法 getAllAccessibleTags 需要更改为 getAllAccessible

此错误已由问题 #1217 Fetch tag details of records for requests made via Webservices and the fix should be included in Vtiger 7.2.1 which has not yet been released at the time of writing. Here are the changes implemented in commits 7881fde4 and 072b5cee 解决:

include/Webservices/VtigerModuleOperation.php [176]

        $result = $this->pearDB->pquery($mysql_query, array());
+        $tableIdColumn = $meta->getIdColumn();
        $error = $this->pearDB->hasFailedTransaction();

include/Webservices/VtigerModuleOperation.php [191]

-           if(!$meta->hasPermission(EntityMeta::$RETRIEVE,$row["crmid"])){
+           if(!$meta->hasPermission(EntityMeta::$RETRIEVE,$row[$tableIdColumn])){

include/Webservices/VtigerModuleOperation.php [194]

-           $output[] = DataTransform::sanitizeDataWithColumn($row,$meta);
+           $output[$row[$tableIdColumn]] = DataTransform::sanitizeDataWithColumn($row,$meta);

modules/Vtiger/models/Tag.php [302]

+    
+    /**
+     * Function used to return tags for list for records
+     * @param <Array> $records - record ids
+     * @return <Array> tags
+     */
+    public static function getAllAccessibleTags($records) {
+        $tagsList = array();
+        if(count($records) == 0) return $tagsList;
+        
+        $currentUser = Users_Record_Model::getCurrentUserModel();
+        
+        $db = PearDatabase::getInstance();
+        $query = "SELECT tag,object_id FROM vtiger_freetags 
+                    INNER JOIN vtiger_freetagged_objects ON vtiger_freetags.id = vtiger_freetagged_objects.tag_id 
+                    WHERE (vtiger_freetagged_objects.tagger_id = ? OR vtiger_freetags.visibility='public') 
+                    AND vtiger_freetagged_objects.object_id IN 
+                    (" . generateQuestionMarks($records) . ")";
+        $params = array($currentUser->getId());
+        $params = array_merge($params, $records);
+        
+        $result = $db->pquery($query , $params);
+        $num_rows = $db->num_rows($result);
+
+        
+        for($i=0; $i<$num_rows; $i++) {
+            $tagName = decode_html($db->query_result($result, $i, 'tag'));
+            $record = decode_html($db->query_result($result, $i, 'object_id'));
+            
+            if(empty($tagsList[$record])) {
+                $tagsList[$record] = $tagName;
+            } else {
+                $tagsList[$record] .= ','.$tagName;
+            }
+        }
+        return $tagsList;
+    }