Unable to delete account from Target

More
04 Nov 2014 11:18 #3205 by cpvt
Hi, is not possible to delete an accoutn from a target, the click on the X doesn't do nothing.

I probably find some bug in code, in data/CRMEntity.php in function delete_related_module() LOOK AT ****:

function delete_related_module($module, $crmid, $with_module, $with_crmid) {
global $adb,$table_prefix;
$withInstance = CRMEntity::getInstance($with_module);
if(!is_array($with_crmid)) $with_crmid = Array($with_crmid);
foreach($with_crmid as $relcrmid) {
if ($with_module == 'Messages') {
$relcrmid = getSingleFieldValue($withInstance->table_name, 'messagehash', $withInstance->table_index, $relcrmid);
}

$query = "DELETE FROM {$withInstance->relation_table} WHERE {$withInstance->relation_table_id} = ? AND {$withInstance->relation_table_otherid} = ?";
**** $params = array($crmid, $relcrmid); **** THE 2 VARIABLE ARE INVERTED

if (!empty($withInstance->relation_table_module)) {
$query .= " AND {$withInstance->relation_table_module} = ?";
$params[] = $module;
}
if (!empty($withInstance->relation_table_othermodule)) {
$query .= " AND {$withInstance->relation_table_othermodule} = ?";
**** $params[] = $module; **** THE RIGHT VARIABLE IS $with_module
}
$res = $adb->pquery($query, $params);

// just to be sure, delete also from standard table
if ($withInstance->relation_table != $table_prefix."_crmentityrel") {
$adb->pquery("DELETE FROM ".$table_prefix."_crmentityrel WHERE crmid=? AND module=? AND relcrmid=? AND relmodule=?", array($crmid, $module, $relcrmid, $with_module));
}

}
}

Could you check and confirm me the right way?

thank you

cp

Please Log in to join the conversation.

More
11 Nov 2014 16:58 #3206 by mapokid
Hi, thank you for the tip. We have solved by adding this method in modules/Targets/Targets.php


function delete_related_module($module, $crmid, $with_module, $with_crmid) {
parent::delete_related_module($module, $crmid, $with_module, $with_crmid);
if (in_array($with_module,array('Leads','Accounts','Contacts'))) {
global $adb, $table_prefix;
$withInstance = CRMEntity::getInstance($with_module);
if(!is_array($with_crmid)) $with_crmid = Array($with_crmid);
foreach($with_crmid as $relcrmid) {
$query = "DELETE FROM {$withInstance->relation_table} WHERE {$withInstance->relation_table_id} = ? AND {$withInstance->relation_table_otherid} = ?";
$params = array($crmid, $relcrmid);
if (!empty($withInstance->relation_table_module)) {
$query .= " AND {$withInstance->relation_table_module} = ?";
$params[] = $module;
}
if (!empty($withInstance->relation_table_othermodule)) {
$query .= " AND {$withInstance->relation_table_othermodule} = ?";
$params[] = $with_module;
}
$res = $adb->pquery($query, $params);
}
}
}


Try with this.

Please Log in to join the conversation.

Time to create page: 0.078 seconds