Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/var/tools/migration/migrations/20180411075710_delete_companies_spammers.php b/var/tools/migration/migrations/20180411075710_delete_companies_spammers.php
- new file mode 100644
- index 0000000..7ae30f3
- --- /dev/null
- +++ b/var/tools/migration/migrations/20180411075710_delete_companies_spammers.php
- @@ -0,0 +1,199 @@
- +<?php
- +
- +use Migration\MigrationHelper;
- +
- +class DeleteCompaniesSpammers extends MigrationHelper
- +{
- + /**
- + * Migrate Up.
- + */
- + public function up()
- + {
- + $pr = $this->prefix;
- +
- + $email_all = $this->getEmailList();
- +
- + foreach ($email_all as $email_list) {
- + $companies = $this->fetchAll(
- + "SELECT c.company_id, c.email,"
- + . " COUNT(t.ticket_id) AS t_count, COUNT(m.message_id) AS m_count, COUNT(l.license_id) as l_count"
- + . " FROM {$pr}companies"
- + . " LEFT JOIN {$pr}hd_tickets AS t ON t.company_id = c.company_id"
- + . " LEFT JOIN {$pr}hd_messages AS m ON m.ticket_id = t.ticket_id"
- + . " LEFT JOIN {$pr}hd_licenses AS l ON l.company_id = c.company_id"
- + . " WHERE c.email IN " . implode(',', $email_list)
- + . " GROUP BY c.company_id, t.ticket_id"
- + . " HAVING t_count <= 1"
- + . " AND m_count <= 1"
- + . " AND l_count = 0"
- + );
- +
- + if (!$companies) {
- + return;
- + }
- +
- + $companies_ids = array_column($companies, 'company_id');
- + $companies_list = implode(',', $companies_ids);
- +
- + $this->query("DELETE FROM {$pr}companies WHERE company_id IN " . $companies_list);
- + $this->query("DELETE FROM {$pr}company_descriptions WHERE company_id IN " . $companies_list);
- + $this->query("DELETE FROM {$pr}seo_names WHERE type = 'M' AND object_id IN " . $companies_list);
- +
- + $this->query("DELETE FROM {$pr}hd_companies WHERE company_id IN " . $companies_list);
- + $this->query("DELETE FROM {$pr}hd_company_addresses WHERE company_id IN " . $companies_list);
- + $this->query("DELETE FROM {$pr}hd_company_access WHERE company_id IN " . $companies_list);
- + $this->query("DELETE FROM {$pr}hd_company_user_links WHERE company_id IN " . $companies_list);
- + $this->query("DELETE FROM {$pr}hd_license_tracking_stats WHERE company_id IN " . $companies_list);
- + $this->query("DELETE FROM {$pr}hd_support_periods WHERE company_id IN " . $companies_list);
- + $this->query("DELETE FROM {$pr}hd_support_periods_history WHERE company_id IN " . $companies_list);
- + $this->query("DELETE FROM {$pr}hd_rebrand WHERE company_id IN " . $companies_list);
- +
- + $products = $this->fetchAll("SELECT product_id FROM {$pr}products WHERE company_id IN " . $companies_list);
- +
- + if ($products) {
- + $products_ids = array_column($products, 'product_id');
- + $products_ids = implode(',', $products_ids);
- +
- + $this->query("DELETE FROM {$pr}products_categories WHERE product_id IN " . $products_ids);
- + $this->query("DELETE FROM {$pr}products WHERE product_id IN " . $products_ids);
- + $this->query("DELETE FROM {$pr}product_descriptions WHERE product_id IN " . $products_ids);
- + $this->query("DELETE FROM {$pr}product_prices WHERE product_id IN " . $products_ids);
- + $this->query("DELETE FROM {$pr}product_features_values WHERE product_id IN " . $products_ids);
- + $this->query("DELETE FROM {$pr}product_options_exceptions WHERE product_id IN " . $products_ids);
- + $this->query("DELETE FROM {$pr}product_popularity WHERE product_id IN " . $products_ids);
- +
- + //images
- +
- + /*$_opts = db_get_fields("SELECT option_id FROM {$pr}product_options WHERE product_id = ?i", $product_id);
- + if (!fn_is_empty($_opts)) {
- + foreach ($_opts as $k => $v) {
- + $_vars = db_get_fields("SELECT variant_id FROM {$pr}product_option_variants WHERE option_id = ?i", $v);
- + db_query("DELETE FROM {$pr}product_options_descriptions WHERE option_id = ?i", $v);
- + if (!fn_is_empty($_vars)) {
- + foreach ($_vars as $k1 => $v1) {
- + db_query("DELETE FROM {$pr}product_option_variants_descriptions WHERE variant_id = ?i", $v1);
- + }
- + db_query("DELETE FROM {$pr}product_option_variants WHERE option_id = ?i", $v);
- + }
- + }
- + }*/
- +
- + $this->query("DELETE FROM {$pr}product_options WHERE product_id IN " . $products_ids);
- + $this->query("DELETE FROM {$pr}product_options_exceptions WHERE product_id IN " . $products_ids);
- + $this->query("DELETE FROM {$pr}product_options_inventory WHERE product_id IN " . $products_ids);
- +
- + //fn_build_products_cache
- + }
- +
- + $shippings = $this->fetchAll("SELECT shipping_id FROM {$pr}shippings WHERE company_id IN " . $companies_list);
- + if ($shippings) {
- + $shippings_ids = array_column($shippings, 'shipping_id');
- + $shippings_ids = implode(',', $shippings_ids);
- +
- + $this->query("DELETE FROM {$pr}shipping_rates WHERE shipping_id IN " . $shippings_ids);
- + $this->query("DELETE FROM {$pr}shipping_descriptions WHERE shipping_id IN " . $shippings_ids);
- + $this->query("DELETE FROM {$pr}shippings WHERE shipping_id IN " . $shippings_ids);
- + }
- +
- + //fn_delete_product_option($option_id)
- +
- + //fn_delete_user($user_id);
- +
- + //fn_delete_page($page_id)
- +
- + //fn_delete_promotions($promotion_ids);
- +
- + $thread = $this->fetchAll(
- + "SELECT thread_id FROM {$pr}discussion"
- + . " WHERE object_type = 'M' object_id IN " . $companies_list
- + );
- +
- + if ($thread) {
- + $thread_ids = array_column($thread, 'thread_id');
- + $thread_ids = implode(',', $thread_ids);
- +
- + $this->query("DELETE FROM {$pr}discussion_messages WHERE thread_id IN " . $thread_ids);
- + $this->query("DELETE FROM {$pr}discussion_posts WHERE thread_id IN " . $thread_ids);
- + $this->query("DELETE FROM {$pr}discussion_rating WHERE thread_id IN " . $thread_ids);
- + $this->query("DELETE FROM {$pr}discussion WHERE thread_id IN " . $thread_ids);
- + }
- +
- + $license = $this->fetchAll("SELECT license_id FROM {$pr}hd_licenses WHERE company_id IN " . $companies_list);
- + if ($license) {
- + $license_ids = array_column($license, 'license_id');
- + $license_ids = implode(',', $license_ids);
- +
- + $this->query(
- + "DELETE l, t, p, s, pl FROM {$pr}hd_licenses as l "
- + . " LEFT JOIN {$pr}hd_license_csrf_tokens as t USING(license_id)"
- + . " LEFT JOIN {$pr}hd_license_prolongations as p ON l.license_id = p.object_id AND (p.type = 'license' OR p.type = 'updates')"
- + . " LEFT JOIN {$pr}hd_license_status_log as s USING(license_id)"
- + . " LEFT JOIN {$pr}hd_project_licenses as pl USING(license_id)"
- + . " WHERE l.license_id IN " . $license_ids
- + );
- + }
- +
- + $projects = $this->fetchAll("SELECT project_id FROM {$pr}hd_projects WHERE company_id IN " . $companies_list);
- + if ($projects) {
- + $project_ids = array_column($projects, 'project_id');
- + $project_ids = implode(',', $project_ids);
- +
- + $this->query("DELETE FROM {$pr}hd_projects WHERE project_id IN ", $project_ids);
- + $this->query("DELETE FROM {$pr}hd_project_licenses WHERE project_id IN ", $project_ids);
- + }
- +
- + $tasks = $this->fetchAll("SELECT task_id FROM {$pr}hd_tasks WHERE company_id IN " . $companies_list);
- + if ($tasks) {
- + $tasks_ids = array_column($tasks, 'task_id');
- + $tasks_ids = implode(',', $tasks_ids);
- +
- + $this->query("DELETE FROM {$pr}hd_tasks WHERE task_id IN " . $tasks_ids);
- + $this->query("DELETE FROM {$pr}hd_tasks_users WHERE task_id IN " . $tasks_ids);
- + $this->query("DELETE FROM {$pr}hd_task_status_log WHERE task_id IN " . $tasks_ids);
- +
- + $attachments = $this->fetchAll("SELECT attachment_id FROM {$pr}attachments WHERE object_type = 'task' AND object_id IN " . $tasks_ids);
- + if ($attachments) {
- + $attachments_ids = array_column($attachments, 'attachment_id');
- + $attachments_ids = implode(',', $attachments_ids);
- +
- + $this->query("DELETE FROM {$pr}hd_task_attachment_descriptions WHERE attachment_id IN " . $attachments_ids);
- + }
- +
- + //attachments
- + }
- +
- + $tickets = $this->fetchAll("SELECT ticket_id FROM {$pr}hd_tickets WHERE company_id IN ", $companies_list);
- + if ($tickets) {
- + $ticket_ids = array_column($tickets, 'ticket_id');
- + $ticket_ids = implode(',', $ticket_ids);
- +
- + $this->query("DELETE FROM {$pr}hd_ticket_support WHERE ticket_id IN ", $ticket_ids);
- + $this->query("DELETE FROM {$pr}hd_ticket_bugs WHERE ticket_id IN ", $ticket_ids);
- + $this->query("DELETE FROM {$pr}hd_ticket_quote WHERE ticket_id IN ", $ticket_ids);
- + $this->query("DELETE FROM {$pr}hd_ticket_responsible WHERE ticket_id IN " . $ticket_ids);
- + $this->query("DELETE FROM {$pr}hd_ticket_respondents WHERE ticket_id IN " . $ticket_ids);
- + $this->query("DELETE FROM {$pr}hd_tickets WHERE ticket_id IN " . $ticket_ids);
- + }
- +
- +
- + $attachments = $this->fetchAll(
- + "SELECT attachment_id FROM {$pr}attachments"
- + . " WHERE object_type = 'company' AND object_id IN " . $companies_list
- + );
- + if ($attachments) {
- + $attachments_ids = array_column($attachments, 'attachment_id');
- + $attachments_ids = implode(',', $attachments_ids);
- +
- + $this->query("DELETE FROM {$pr}hd_task_attachment_descriptions WHERE attachment_id IN " . $attachments_ids);
- + }
- + }
- + }
- +
- + protected function getEmailList()
- + {
- + return array(
- + array(),
- + array()
- + );
- + }
- +}
- \ No newline at end of file
Add Comment
Please, Sign In to add comment