Skip to content

Instantly share code, notes, and snippets.

@artshevtsov
Created August 29, 2017 12:15
Show Gist options
  • Save artshevtsov/81eee9ab8f16299a702b9e670bfc553f to your computer and use it in GitHub Desktop.
Save artshevtsov/81eee9ab8f16299a702b9e670bfc553f to your computer and use it in GitHub Desktop.
gdfgdf
/** Получить все выборки для удаления аккаунта
* @return array
*/
public function getDeleteQueries() {
//Source Object Attached
$q['crm_source_object_attached'] = "DELETE csoa FROM `crm_source_object_attached` csoa JOIN ``";
// Phone Attached
$account_type = ObjectType::ACCOUNT;
$q['crm_phone_attached'] = "DELETE FROM `crm_phone_attached` WHERE object_id = ?d AND object_type_id = $account_type";
$client_type = ObjectType::CRM_CLIENT;
$q['crm_phone_attached'] = "DELETE cpa FROM `crm_phone_attached` cpa JOIN `crm_clients` cc ON(cc.id = cpa.object_id) WHERE cc.account_id = ?d AND cpa.object_type_id=$client_type";
// Accounts
$q['accounts'] = "DELETE FROM `accounts` WHERE account_id = ?d";
// Account Limit
$q['account_limit'] = "DELETE FROM `account_limit` WHERE account_id = ?d";
//Counters
$q['counters'] = "DELETE FROM `counters` WHERE account_id = ?d";
// Notify
$q['crm_account_user_notify'] = "DELETE caun FROM `crm_account_user_notify` caun JOIN `users` u ON(u.id = caun.user_id) WHERE u.account_id = ?d";
$q['crm_account_notify'] = "DELETE FROM `crm_account_notify` WHERE account_id = ?d";
$q['crm_api_keys'] = "DELETE FROM `crm_api_keys` WHERE account_id = ?d";
// Bills
$q['crm_bills_products'] = "DELETE cbp FROM `crm_bills_products` JOIN `crm_bills` cb ON(cb.id = cbp.bill_id) WHERE cb.account_id = ?d";
$q['crm_bills_views'] = "DELETE cbv FROM `crm_bills_views` JOIN `crm_bills` cb ON(cb.id = cbv.bill_id) WHERE cb.account_id = ?d";
$q['crm_bills'] = "DELETE FROM `crm_bills` WHERE account_id = ?d";
// Calls
$q['crm_calls'] = "DELETE FROM `crm_calls` WHERE account_id = ?d";
// Chats
$q['crm_chats'] = "DELETE FROM `crm_chats` WHERE account_id = ?d";
$q['crm_chats_accounts'] = "DELETE FROM `crm_chats_accounts` WHERE account_id = ?d";
// Clients
$type_client = ObjectType::CRM_CLIENT;
$q['crm_email_attached'] = "DELETE cea FROM `crm_email_attached` cea JOIN `crm_clients` cc ON(cea.object_id = cc.id) WHERE cea.object_type_id=$type_client AND cc.account_id = ?d";
$q['crm_clients_groups'] = "DELETE FROM `crm_clients_groups` WHERE account_id = ?d";
$q['crm_clients_sources'] = "DELETE FROM `crm_clients_sources` WHERE account_id = ?d";
$q['crm_clients'] = "DELETE FROM `crm_clients` WHERE account_id = ?d";
// Comments
$q['crm_comments_attached'] = "DELETE cca FROM `crm_comments_attached` cca JOIN `crm_comments` cc ON(cca.comment_id = cc.id) WHERE cc.account_id = ?d";
$q['crm_comments'] = "DELETE FROM `crm_comments` WHERE account_id = ?d";
// Deals
$q['crm_deals_sources'] = "DELETE FROM `crm_deals_sources` WHERE account_id = ?d";
$q['crm_deals_statuses'] = "DELETE FROM `crm_deals_statuses` WHERE account_id = ?d";
$q['crm_deals_products'] = "DELETE cdp FROM `crm_deals_products` cdp JOIN `crm_deals` cd ON(cd.id = cdp.deal_id) WHERE cd.account_id = ?d";
$q['crm_deals'] = "DELETE FROM `crm_deals` WHERE account_id = ?d";
// Custom Fields
$q['crm_field'] = "DELETE cf FROM `crm_field` cf JOIN `crm_field_schema` cfs ON(cfs.id = cf.schema_id) WHERE cfs.account_id = ?d";
$q['crm_field_schema_element'] = "DELETE cfse FROM `crm_field_schema_element` cfse JOIN `crm_field_schema` cfs ON(cfs.id = cfse.schema_id) WHERE cfs.account_id = ?d";
$q['crm_field_value'] = "DELETE cfv FROM `crm_field_value` cfv JOIN `crm_field_schema` cfs ON(cfs.id = cfv.schema_id) WHERE cfs.account_id = ?d";
$q['crm_field_schema'] = "DELETE FROM `crm_field_schema` WHERE account_id = ?d";
// Files
$q['crm_file_object_attached'] = "DELETE cfoa FROM `crm_file_object_attached` cfoa JOIN `crm_file` cf ON(cf.id = cfoa.file_id) WHERE cf.account_id = ?d";
$q['crm_file'] = "DELETE FROM `crm_file` WHERE account_id = ?d";
// Firms
$q['crm_firms'] = "DELETE FROM `crm_firms` WHERE account_id = ?d";
// Message
$q['crm_message_attached'] = "DELETE FROM `crm_message_attached` WHERE account_id = ?d";
$q['crm_message_body'] = "DELETE FROM `crm_message_body` WHERE account_id = ?d";
// Notifications
$q['crm_notifications'] = "DELETE cn FROM `crm_notifications` cn JOIN `users` u ON(u.id = cn.user_id) WHERE u.account_id = ?d";
// Firms
$q['crm_our_firms'] = "DELETE FROM `crm_our_firms` WHERE account_id = ?d";
// Payment Type
$q['crm_payment_type'] = "DELETE FROM `crm_payment_type` WHERE account_id = ?d";
// Products
$q['crm_products_prices'] = "DELETE cpp FROM `crm_products_prices` cpp JOIN `crm_products` cp ON(cp.id = cpp.product_id) WHERE cp.account_id = ?d";
$q['crm_products_categories'] = "DELETE FROM `crm_products_categories` WHERE account_id = ?d";
$q['crm_products'] = "DELETE FROM `crm_products` WHERE account_id = ?d";
// Tags
$q['crm_tags_attached'] = "DELETE cta FROM `crm_tags_attached` cta JOIN `crm_tags` ct ON(ct.id = cta.tag_id) WHERE ct.account_id = ?d";
$q['crm_tags'] = "DELETE FROM `crm_tags` WHERE account_id = ?d";
// Tasks
$q['crm_task_comments'] = "DELETE FROM `crm_task_comments` WHERE account_id = ?d";
$q['crm_tasks_categories'] = "DELETE FROM `crm_tasks_categories` WHERE account_id = ?d";
$q['crm_tasks'] = "DELETE FROM `crm_tasks` WHERE account_id = ?d";
// User posts
$q['crm_user_posts'] = "DELETE FROM `crm_user_posts` WHERE account_id = ?d";
// Vat
$q['crm_vat'] = "DELETE FROM `crm_vat` WHERE account_id = ?d";
// Vox implant
$q['crm_vox_implant_phone_attached'] = "DELETE FROM `crm_vox_implant_phone_attached` WHERE account_id = ?d";
// Yandex direct stats cache
$q['crm_yandex_direct_stats_cache'] = "DELETE FROM `crm_yandex_direct_stats_cache` WHERE account_id = ?d";
// Yandex oauth
$q['crm_yandex_oauth'] = "DELETE FROM `crm_yandex_oauth` WHERE account_id = ?d";
// Users
$q['users'] = "DELETE FROM `users` WHERE account_id = ?d";
// Mail
$q['mail_remote_mailbox_credentials'] = "DELETE FROM `mail_remote_mailbox_credentials` WHERE account_id = ?d";
$q['mail_remote_mailbox_folder'] = "DELETE FROM `mail_remote_mailbox_folder` WHERE account_id = ?d";
$q['mail_template'] = "DELETE FROM `mail_template` WHERE account_id = ?d";
$q['mail_template_signature'] = "DELETE FROM `mail_template_signature` WHERE account_id = ?d";
$q['mail_address'] = "";
$q['mail_contact_stash'] = "";
$q['mail_message_flag'] = "";
$q['mail_part'] = "";
$q['mail_message_error'] = "";
$q['mail_message'] = "";
return $q;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment