Skip to content

Commit

Permalink
[MIG] website_cookie_notice: merged into website
Browse files Browse the repository at this point in the history
  • Loading branch information
MiquelRForgeFlow committed Nov 16, 2021
1 parent 86bd4ee commit cc848d0
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
6 changes: 4 additions & 2 deletions openupgrade_scripts/apriori.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@
# OCA/project
"project_description": "project",
"project_stage_closed": "project",
# OCA/web
"web_editor_background_color": "web_editor",
# OCA/survey
"survey_description": "survey",
# OCA/web
"web_editor_background_color": "web_editor",
# OCA/website
"website_cookie_notice": "website",
# OCA/...
}

Expand Down
23 changes: 23 additions & 0 deletions openupgrade_scripts/scripts/website/14.0.1.0/post-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,30 @@
from openupgradelib import openupgrade


def website_cookie_notice_post_migration(env):
cookie_message = env.ref("website.cookie_message", raise_if_not_found=False)
if cookie_message:
websites = env["website"].search([])
websites.write({"cookies_bar": True})
env.cr.execute(
"""WITH keys AS (
SELECT key
FROM ir_ui_view iuv
JOIN ir_model_data imd ON (imd.model = 'ir.ui.view'
AND imd.res_id = iuv.id AND module = 'website')
WHERE imd.name IN ('cookie_message', 'cookie_message_container')
)
SELECT iuv.id
FROM ir_ui_view iuv
JOIN keys ON iuv.key = keys.key""",
)
view_ids = [x[0] for x in env.cr.fetchall()]
if view_ids:
env["ir.ui.view"].browse(view_ids).unlink()


@openupgrade.migrate()
def migrate(env, version):
openupgrade.load_data(env.cr, "website", "14.0.1.0/noupdate_changes.xml")
openupgrade.delete_records_safely_by_xml_id(env, ["website.aboutus_page"])
website_cookie_notice_post_migration(env)
26 changes: 26 additions & 0 deletions openupgrade_scripts/scripts/website/14.0.1.0/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,31 @@ def assure_website_visitor_partner_is_set(env):
)


def website_cookie_notice_pre_migration(env):
openupgrade.logged_query(
env.cr,
"""
WITH keys AS (
SELECT key
FROM ir_ui_view iuv
JOIN ir_model_data imd ON (
imd.model = 'ir.ui.view' AND imd.res_id = iuv.id AND module = 'website')
WHERE imd.name IN ('legal_cookie_policy', 'cookie_banner')
)
DELETE FROM ir_ui_view iuv
USING keys
WHERE iuv.key = keys.key AND iuv.website_id IS NOT NULL""",
)
# rename xmlids
openupgrade.rename_xmlids(
env.cr,
[
("website.legal_cookie_policy", "website.cookie_policy"),
("website.cookie_banner", "website.cookies_bar"),
],
)


@openupgrade.migrate()
def migrate(env, version):
assure_website_visitor_partner_is_set(env)
Expand All @@ -29,3 +54,4 @@ def migrate(env, version):
],
True,
)
website_cookie_notice_pre_migration(env)

0 comments on commit cc848d0

Please sign in to comment.