Beispiel #1
0
 /**
  * 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);
     // Dalete from categories
     $contact_categories_model = new waContactCategoriesModel();
     $category_ids = array_keys($contact_categories_model->getByField('contact_id', $id, 'category_id'));
     $contact_categories_model->deleteByField('contact_id', $id);
     // update counters in wa_contact_category
     $contact_category_model = new waContactCategoryModel();
     $contact_category_model->recalcCounters($category_ids);
     //        // 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);
 }
 /**
  * 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
         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);
     // 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);
 }
 public static function revokeUser($id)
 {
     // wa_contact
     $user = new waContact($id);
     $user['is_user'] = 0;
     $user['login'] = null;
     $user['password'] = '';
     $user->save();
     // user groups
     $ugm = new waUserGroupsModel();
     $ugm->delete($id);
     // Access rigths
     $right_model = new waContactRightsModel();
     $right_model->deleteByField('group_id', -$id);
     // Custom application access rigths
     foreach (wa()->getApps() as $aid => $app) {
         if (isset($app['rights']) && $app['rights']) {
             $app_config = SystemConfig::getAppConfig($aid);
             $class_name = $app_config->getPrefix() . "RightConfig";
             $file_path = $app_config->getAppPath('lib/config/' . $class_name . ".class.php");
             $right_config = null;
             if (!file_exists($file_path)) {
                 continue;
             }
             waSystem::getInstance($aid, $app_config);
             include_once $file_path;
             /**
              * @var waRightConfig $right_config
              */
             $right_config = new $class_name();
             $right_config->clearRights($id);
         }
     }
 }
 protected function deleteAction()
 {
     if ($this->sheet_model->deleteById($this->sheet_id)) {
         $this->response['sheet_id'] = $this->sheet_id;
         // Delete rights
         $right_model = new waContactRightsModel();
         $right_model->deleteByField(array('app_id' => wa()->getApp(), 'name' => 'sheet.' . $this->sheet_id));
         $this->log('board_delete', 1);
     } else {
         $this->errors = _w("Not enough rights to work with current board");
     }
 }