blob: 03a60ed6ea4512a47fe43cf7e491307d3f7bdc3b [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 Doshiaf1f4372012-07-12 22:06:27 +053045 import os
46 import conf
47 # delete other html files
48 exception_list = ['app.html', 'unsupported.html', 'blank.html']
49 conf_dir = os.path.dirname(os.path.abspath(conf.__file__))
50 public_path = os.path.join(conf_dir, 'public')
51 for f in os.listdir(public_path):
52 if f.endswith('.html') and f not in exception_list:
53 os.remove(os.path.join(public_path, f))
54
Anand Doshi72c945b2012-06-22 20:01:07 +053055def save_pages():
56 """save all web pages, blogs to create content"""
Anand Doshi51146c02012-07-12 18:41:12 +053057 query_map = {
58 'Web Page': """select name from `tabWeb Page` where docstatus=0""",
59 'Blog': """\
60 select name from `tabBlog`
61 where docstatus = 0 and ifnull(published, 0) = 1""",
62 'Item': """\
63 select name from `tabItem`
64 where docstatus = 0 and ifnull(show_in_website, 0) = 1""",
65 }
66
67 import webnotes
68 from webnotes.model.doclist import DocList
69
70 for dt in query_map:
71 for result in webnotes.conn.sql(query_map[dt], as_dict=1):
Anand Doshic4eb9bf2012-07-12 19:15:52 +053072 DocList(dt, result['name']).save()
73
74def save_website_settings():
75 from webnotes.model.code import get_obj
76
77 # rewrite pages
78 get_obj('Website Settings').on_update()
79
80 ss = get_obj('Style Settings')
81 ss.validate()
82 ss.doc.save()
83 ss.on_update()