[Vtigercrm-developers] Oups ! Delete instead of Unlink

David V. davidv.net at gmail.com
Thu Jan 27 04:19:18 PST 2011


Hi !

I have a crm installation where the module Accounts is related to itself by
a related list.

It works very well and it's easy to manage a list of accounts related to any
specific account.

The problem is when we want to remove an account Z from the RelatedList of
account A.

Instead of just unlinking the account Z, Vtiger sends it to trash (deletes
it).

This is caused by the function DeleteEntity in /include/utils/Utils.php


function DeleteEntity($module,$return_module,$focus,$record,$return_id) {
global $log;
 $log->debug("Entering DeleteEntity method ($module, $return_module,
$record, $return_id)");
 if ($module != $return_module && !empty($return_module) &&
!empty($return_id)) {
$focus->unlinkRelationship($record, $return_module, $return_id);
 } else {
$focus->trash($module, $record);
}
 $log->debug("Exiting DeleteEntity method ...");
}

It is a smart function but since $module == $return_module in our case, this
function does not "unlinkRelationship" but Trashes the $record.

So far I've found no workaround since there is no trigger available to use
an event when deleting an entity. So I ended up modifiying the function. But
this is of course not a future proof (I mean update proof) solution as I'll
have to do it every time a new version of Vtiger is released.

My question :
Is there any specific reason to have this test here ( $module !=
$return_module ) ?

I think it was added to test if the deletion is occuring within a
RelatedList (in most cases in a related list $module != $return_module)

I have another suggestion :
We could test instead $_REQUEST['return_action'], if it contains
"CallRelatedList" then we are in a RelatedList and we can unlink instead of
sending to trash.

Here is my modified function :

function DeleteEntity($module,$return_module,$focus,$record,$return_id) {
global $log;
 $log->debug("Entering DeleteEntity method ($module, $return_module,
$record, $return_id)");
 if (isset($_REQUEST['return_action']){
$return_action = $_REQUEST['return_action'];
 } else {
$return_action = "";
}

if ($return_action == "CallRelatedList" && !empty($return_module) &&
!empty($return_id)) {
$focus->unlinkRelationship($record, $return_module, $return_id);
 } else {
$focus->trash($module, $record);
}
 $log->debug("Exiting DeleteEntity method ...");
}

What do you guys think ?

David V.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20110127/fe16ae60/attachment-0002.html 


More information about the vtigercrm-developers mailing list