[Vtigercrm-developers] Oups ! Delete instead of Unlink

Asha asha at vtiger.com
Thu Jan 27 05:42:51 PST 2011


Hi David,

Thanks for pointing out to the loop hole in the code base. We shall think
and come up with a better solution to it.

With respect to the changes suggested by you, it will not be the correct one
as the return_action will not be CallRelatedList, when Single Pane View is
enabled. That is the reason to use the comparison between module and
return_module.

But I understand the special case when module is related to itself through
mxn relationship, needs to be handled here.

On Thu, Jan 27, 2011 at 5:49 PM, David V. <davidv.net at gmail.com> wrote:

> 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.
>
> _______________________________________________
> http://www.vtiger.com/
>



-- 
Regards,
Asha
vtiger Team
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20110127/f3a73c6f/attachment-0002.html 


More information about the vtigercrm-developers mailing list