blob: 721f8a7381935643cecb437a399f487f05493359 [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 Doshi72c945b2012-06-22 20:01:07 +053016def cleanup():
17 import webnotes
18
19 # delete pages from `tabPage` of module Website or of type Webpage
20 webnotes.conn.sql("""\
21 delete from `tabPage`
22 where module='Website' and ifnull(web_page, 'No') = 'Yes'""")
23
Anand Doshie47def82012-07-09 15:56:12 +053024 # change show_in_website value in item table to 0 or 1
25 webnotes.conn.sql("""\
26 update `tabItem`
27 set show_in_website = if(show_in_website = 'Yes', 1, 0)
28 where show_in_website is not null""")
Anand Doshi40fce892012-07-09 20:02:52 +053029
30 # move comments from comment_doctype Page to Blog
31 webnotes.conn.sql("""\
32 update `tabComment` comm, `tabBlog` blog
33 set comm.comment_doctype = 'Blog', comm.comment_docname = blog.name
34 where comm.comment_docname = blog.page_name""")
Anand Doshi51146c02012-07-12 18:41:12 +053035
36 # delete deprecated pages
37 import webnotes.model
38 webnotes.model.delete_doc('Page', 'products')
39 webnotes.model.delete_doc('Page', 'contact')
40 webnotes.model.delete_doc('Page', 'blog')
41 webnotes.model.delete_doc('Page', 'about')
42
Anand Doshi72c945b2012-06-22 20:01:07 +053043def save_pages():
44 """save all web pages, blogs to create content"""
Anand Doshi51146c02012-07-12 18:41:12 +053045 query_map = {
46 'Web Page': """select name from `tabWeb Page` where docstatus=0""",
47 'Blog': """\
48 select name from `tabBlog`
49 where docstatus = 0 and ifnull(published, 0) = 1""",
50 'Item': """\
51 select name from `tabItem`
52 where docstatus = 0 and ifnull(show_in_website, 0) = 1""",
53 }
54
55 import webnotes
56 from webnotes.model.doclist import DocList
57
58 for dt in query_map:
59 for result in webnotes.conn.sql(query_map[dt], as_dict=1):
60 DocList(dt, result['name']).save()