/**
  * Delete one or more contacts and fire event сontacts.delete
  *
  * @event contacts.delete
  *
  * @param int|array $id - contact id or array of contact ids
  * @return bool
  */
 public function delete($id, $send_event = true)
 {
     if ($send_event) {
         // Fire @event contacts.delete allowing other applications to clean up their data
         if (!is_array($id)) {
             $id = array($id);
         }
         wa()->event(array('contacts', 'delete'), $id);
     }
     if (is_array($id)) {
         $nid = array();
         foreach ($id as $i) {
             $nid[] = -(int) $i;
         }
     } else {
         $nid = -(int) $id;
     }
     // Delete rights
     $right_model = new waContactRightsModel();
     $right_model->deleteByField('group_id', $nid);
     // Delete settings
     $setting_model = new waContactSettingsModel();
     $setting_model->deleteByField('contact_id', $id);
     // Delete emails
     $contact_email_model = new waContactEmailsModel();
     $contact_email_model->deleteByField('contact_id', $id);
     // Delete from groups
     $user_groups_model = new waUserGroupsModel();
     $user_groups_model->deleteByField('contact_id', $id);
     // Delete from contact lists
     if (class_exists('contactsContactListsModel')) {
         // @todo: Use plugin for contacts
         $contact_lists_model = new contactsContactListsModel();
         $contact_lists_model->deleteByField('contact_id', $id);
     }
     // Delete from contact rights
     $contact_rights_model = new contactsRightsModel();
     $contact_rights_model->deleteByField('group_id', $nid);
     // Delete data
     $contact_data_model = new waContactDataModel();
     $contact_data_model->deleteByField('contact_id', $id);
     $contact_data_text_model = new waContactDataTextModel();
     $contact_data_text_model->deleteByField('contact_id', $id);
     //        // Delete contact from logs
     //        $login_log_model = new waLoginLogModel();
     //        $login_log_model->deleteByField('contact_id', $id);
     // Clear references
     $this->updateByField(array('company_contact_id' => $id), array('company_contact_id' => 0));
     // Delete contact
     return $this->deleteById($id);
 }
 public function uninstall()
 {
     // check uninstall.php
     $file = $this->getAppConfigPath('uninstall');
     if (file_exists($file)) {
         include $file;
     }
     $file_db = $this->getAppPath('lib/config/db.php');
     if (file_exists($file_db)) {
         $schema = (include $file_db);
         $model = new waModel();
         foreach ($schema as $table => $fields) {
             $sql = "DROP TABLE IF EXISTS " . $table;
             $model->exec($sql);
         }
     }
     // Remove all app settings
     $app_settings_model = new waAppSettingsModel();
     $app_settings_model->del($this->application);
     $contact_settings_model = new waContactSettingsModel();
     $contact_settings_model->deleteByField('app_id', $this->application);
     // Remove all rights to app
     $contact_rights_model = new waContactRightsModel();
     $contact_rights_model->deleteByField('app_id', $this->application);
     // Remove logs
     $log_model = new waLogModel();
     $log_model->deleteByField('app_id', $this->application);
     // Remove cache
     waFiles::delete($this->getPath('cache') . '/apps/' . $this->application);
 }