blob: c536ecbc41819c953e6183b1e8d509d9a55776f3 [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
Anand Doshi6c3b6222012-07-13 08:24:16 +053040 for page in ['products', 'contact', 'blog', 'about']:
41 try:
42 webnotes.model.delete_doc('Page', page)
43 except Exception, e:
44 webnotes.modules.patch_handler.log(str(e))
Anand Doshi51146c02012-07-12 18:41:12 +053045
Anand Doshiaf1f4372012-07-12 22:06:27 +053046 import os
47 import conf
48 # delete other html files
49 exception_list = ['app.html', 'unsupported.html', 'blank.html']
50 conf_dir = os.path.dirname(os.path.abspath(conf.__file__))
51 public_path = os.path.join(conf_dir, 'public')
52 for f in os.listdir(public_path):
53 if f.endswith('.html') and f not in exception_list:
54 os.remove(os.path.join(public_path, f))
55
Anand Doshi72c945b2012-06-22 20:01:07 +053056def save_pages():
57 """save all web pages, blogs to create content"""
Anand Doshi51146c02012-07-12 18:41:12 +053058 query_map = {
59 'Web Page': """select name from `tabWeb Page` where docstatus=0""",
60 'Blog': """\
61 select name from `tabBlog`
62 where docstatus = 0 and ifnull(published, 0) = 1""",
63 'Item': """\
64 select name from `tabItem`
65 where docstatus = 0 and ifnull(show_in_website, 0) = 1""",
66 }
67
68 import webnotes
69 from webnotes.model.doclist import DocList
Anand Doshi4659b1e2012-07-12 23:38:31 +053070 import webnotes.modules.patch_handler
Anand Doshi51146c02012-07-12 18:41:12 +053071
72 for dt in query_map:
73 for result in webnotes.conn.sql(query_map[dt], as_dict=1):
Anand Doshi4659b1e2012-07-12 23:38:31 +053074 try:
Anand Doshi6c3b6222012-07-13 08:24:16 +053075 DocList(dt, result['name'].encode('utf-8')).save()
Anand Doshi4659b1e2012-07-12 23:38:31 +053076 except Exception, e:
77 webnotes.modules.patch_handler.log(str(e))
Anand Doshic4eb9bf2012-07-12 19:15:52 +053078
79def save_website_settings():
80 from webnotes.model.code import get_obj
81
82 # rewrite pages
83 get_obj('Website Settings').on_update()
84
85 ss = get_obj('Style Settings')
86 ss.validate()
87 ss.doc.save()
88 ss.on_update()