blob: fee7b0199daca2ed01df572da67b80d2e21ad8c1 [file] [log] [blame]
Rushabh Mehta40182ba2012-06-19 14:15:13 +05301def execute():
2 import webnotes
Rushabh Mehta40182ba2012-06-19 14:15:13 +05303 import webnotes.model.sync
4
Anand Doshi51146c02012-07-12 18:41:12 +05305 # sync doctypes required for the patch
6 webnotes.model.sync.sync('website', 'web_cache')
Rushabh Mehta40182ba2012-06-19 14:15:13 +05307 webnotes.model.sync.sync('website', 'web_page')
Anand Doshi72c945b2012-06-22 20:01:07 +05308 webnotes.model.sync.sync('website', 'blog')
Anand Doshi51146c02012-07-12 18:41:12 +05309 webnotes.model.sync.sync('website', 'website_settings')
10 webnotes.model.sync.sync('stock', 'item')
Anand Doshi72c945b2012-06-22 20:01:07 +053011
12 cleanup()
13
14 save_pages()
Rushabh Mehta40182ba2012-06-19 14:15:13 +053015
Anand Doshic4eb9bf2012-07-12 19:15:52 +053016 save_website_settings()
17
Anand Doshi72c945b2012-06-22 20:01:07 +053018def cleanup():
19 import webnotes
20
21 # delete pages from `tabPage` of module Website or of type Webpage
22 webnotes.conn.sql("""\
23 delete from `tabPage`
24 where module='Website' and ifnull(web_page, 'No') = 'Yes'""")
25
Anand Doshie47def82012-07-09 15:56:12 +053026 # change show_in_website value in item table to 0 or 1
27 webnotes.conn.sql("""\
28 update `tabItem`
29 set show_in_website = if(show_in_website = 'Yes', 1, 0)
30 where show_in_website is not null""")
Anand Doshi40fce892012-07-09 20:02:52 +053031
32 # move comments from comment_doctype Page to Blog
33 webnotes.conn.sql("""\
34 update `tabComment` comm, `tabBlog` blog
35 set comm.comment_doctype = 'Blog', comm.comment_docname = blog.name
36 where comm.comment_docname = blog.page_name""")
Anand Doshi51146c02012-07-12 18:41:12 +053037
38 # delete deprecated pages
39 import webnotes.model
40 webnotes.model.delete_doc('Page', 'products')
41 webnotes.model.delete_doc('Page', 'contact')
42 webnotes.model.delete_doc('Page', 'blog')
43 webnotes.model.delete_doc('Page', 'about')
44
Anand Doshi72c945b2012-06-22 20:01:07 +053045def save_pages():
46 """save all web pages, blogs to create content"""
Anand Doshi51146c02012-07-12 18:41:12 +053047 query_map = {
48 'Web Page': """select name from `tabWeb Page` where docstatus=0""",
49 'Blog': """\
50 select name from `tabBlog`
51 where docstatus = 0 and ifnull(published, 0) = 1""",
52 'Item': """\
53 select name from `tabItem`
54 where docstatus = 0 and ifnull(show_in_website, 0) = 1""",
55 }
56
57 import webnotes
58 from webnotes.model.doclist import DocList
59
60 for dt in query_map:
61 for result in webnotes.conn.sql(query_map[dt], as_dict=1):
Anand Doshic4eb9bf2012-07-12 19:15:52 +053062 DocList(dt, result['name']).save()
63
64def save_website_settings():
65 from webnotes.model.code import get_obj
66
67 # rewrite pages
68 get_obj('Website Settings').on_update()
69
70 ss = get_obj('Style Settings')
71 ss.validate()
72 ss.doc.save()
73 ss.on_update()