/** * Delete a contact * * @param Integer $c_id contact_id * @return Boolean */ function DeleteContact($c_id) { global $cdg_sql, $c_use_connectors; $sql_id = sql_parse_id($c_id, true); $this->logger->debug("Delete contact $c_id"); $obm_q = new DB_OBM; $query = "SELECT contact_company_id, contact_birthday_id, contact_usercreate, contact_addressbook_id FROM Contact WHERE contact_id $sql_id"; $this->logger->core($query); $obm_q->query($query); $obm_q->next_record(); $comp_id = $obm_q->f('contact_company_id'); $birthday_id = $obm_q->f('contact_birthday_id'); $uid = $obm_q->f('contact_usercreate'); $ad = $obm_q->f('contact_addressbook_id'); // Hook : Pre if (function_exists('hook_pre_run_query_contact_delete')) { if (! hook_pre_run_query_contact_delete($c_id)) { return false; } } run_query_global_delete_document_links($c_id, 'contact'); $ret = of_userdata_query_delete('contact', $c_id); // BEGIN birthday support $query = "DELETE FROM Event WHERE event_id = '$birthday_id'"; $this->logger->core($query); $obm_q->query($query); // END birthday support of_entity_delete('contact', $c_id); $query = "DELETE FROM Contact WHERE contact_id $sql_id"; $this->logger->core($query); $obm_q->query($query); // If connectors in use if ($c_use_connectors) { $query = "INSERT INTO DeletedContact (deletedcontact_contact_id, deletedcontact_addressbook_id, deletedcontact_timestamp, deletedcontact_origin) VALUES ($c_id, $ad, NOW(), '$GLOBALS[c_origin_cron]')"; $this->logger->core($query); $obm_q->query($query); } // After contact deletion to get correct number run_query_global_company_contact_number_update($comp_id); // Delete index OBM_IndexingService::delete('contact', $c_id); }
public static function delete($contact) { global $obm, $cdg_sql, $c_use_connectors; if (!$contact->id) return false; //else $obm_q = new DB_OBM; $multidomain = sql_multidomain('contact'); $sql_id = sql_parse_id($contact->id); $comp_id = sql_parse_id($contact->company_id); run_query_global_delete_document_links($contact->id, 'contact'); $ret = of_userdata_query_delete('contact', $contact->id); //FIXME: do it better // BEGIN birthday and anniversary support run_query_contact_birthday_update('birthday', null, null, $contact->birthday_event, null, null, null); run_query_contact_birthday_update('anniversary', null, null, $contact->anniversary_event, null, null, null); // END birthday and anniversary support of_entity_delete('contact', $contact->id); $query = "DELETE FROM Contact WHERE contact_id = $sql_id $multidomain"; display_debug_msg($query, $cdg_sql, 'OBM_Contact::delete(1)'); $retour = $obm_q->query($query); OBM_AddressBook::timestamp($contact->addressbook_id); // If connectors in use if ($c_use_connectors) { $uid = sql_parse_id($obm['uid']); $query = "INSERT INTO DeletedContact ( deletedcontact_contact_id, deletedcontact_addressbook_id, deletedcontact_timestamp, deletedcontact_origin) VALUES ( $contact->id, $contact->addressbook_id, NOW(), '$GLOBALS[c_origin_web]' ) "; display_debug_msg($query, $cdg_sql, 'OBM_Contact::delete(2)'); $retour = $obm_q->query($query); } // After contact deletion to get correct number run_query_global_company_contact_number_update($comp_id); // Delete index OBM_IndexingService::delete('contact', $contact->id); return $retour; }