Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2014
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 2.65 KB | None | 0 0
  1. # Clear has_parameters flag
  2. UPDATE shopcenter_products
  3. SET has_parameters = 0
  4. WHERE has_parameters = 1;
  5.  
  6. # SET NEW proper has_parameters flag
  7. UPDATE shopcenter_products
  8. SET has_parameters = 1
  9. WHERE products_id IN (
  10.     SELECT DISTINCT products_id
  11.     FROM products_has_params_values
  12. );
  13.  
  14. # DELETE ALL products WITH no parameters, NOT CREATE BY companies AND NOT edited BY admin
  15. DELETE
  16. FROM shopcenter_products
  17. WHERE has_parameters = 0
  18.     AND is_edited_by_admin = 0
  19.     AND companies_id IS NULL
  20.     AND products_id NOT IN (
  21.         SELECT DISTINCT products_id
  22.         FROM shopcenter_products_has_shopcenter_xml_feeds
  23.         WHERE feeds_id = 1
  24.     );
  25.  
  26. # DELETE ALL xml_products that has been deleted IN pevious step
  27. DELETE FROM shopcenter_products_has_shopcenter_xml_feeds
  28. WHERE products_id NOT IN (
  29.     SELECT DISTINCT products_id
  30.     FROM products_has_params_values
  31. );
  32.  
  33. # CREATE VIEW OF products that have been linked together FROM wrong reson (name = "")
  34. CREATE VIEW _tmp_debug AS (
  35.     SELECT products_id
  36.     FROM shopcenter_products_has_shopcenter_xml_feeds AS x
  37.     LEFT JOIN shopcenter_products AS s
  38.         USING(products_id)
  39.     GROUP BY product_name_override, categories_id_main
  40.     HAVING COUNT(products_id) > 1
  41.         AND products_id NOT IN (
  42.             # Product groups groupped BY name (has been linekd together OR should have been)
  43.             SELECT DISTINCT products_id
  44.             FROM shopcenter_products_has_shopcenter_xml_feeds AS x
  45.             LEFT JOIN shopcenter_products AS s
  46.                 USING(products_id)
  47.             GROUP BY products_id, categories_id_main
  48.             HAVING COUNT(products_id) > 1  
  49.         )
  50. );
  51.  
  52. # DELETE products FROM VIEW we have created ina previous step
  53. DELETE FROM shopcenter_products_has_shopcenter_xml_feeds
  54. WHERE products_id IN (
  55.     SELECT products_id FROM _tmp_debug
  56. )
  57.  
  58. # Creal ALL traces
  59. DROP VIEW _tmp_debug;
  60.  
  61. # CREATE VIEW OF products that have been linked together FROM wrong reson (code = "")
  62. CREATE VIEW _tmp_debug AS (
  63.     SELECT products_id
  64.     FROM shopcenter_products_has_shopcenter_xml_feeds AS x
  65.     LEFT JOIN shopcenter_products AS s
  66.         USING(products_id)
  67.     GROUP BY product_code_override, categories_id_main
  68.     HAVING COUNT(products_id) > 1
  69.         AND products_id NOT IN (
  70.             # Product groups groupped BY code (has been linekd together OR should have been)
  71.             SELECT DISTINCT products_id
  72.             FROM shopcenter_products_has_shopcenter_xml_feeds AS x
  73.             LEFT JOIN shopcenter_products AS s
  74.                 USING(products_id)
  75.             GROUP BY products_id, categories_id_main
  76.             HAVING COUNT(products_id) > 1  
  77.         )
  78. );
  79.  
  80. # DELETE products FROM VIEW we have created ina previous step
  81. DELETE FROM shopcenter_products_has_shopcenter_xml_feeds
  82. WHERE products_id IN (
  83.     SELECT products_id FROM _tmp_debug
  84. )
  85.  
  86. # Creal ALL traces
  87. DROP VIEW _tmp_debug;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement