blob: f912f86278c5591e5d0834dcdeeccbe77cf92f66 [file] [log] [blame]
Anand Doshi486f9df2012-07-19 13:40:31 +05301from __future__ import unicode_literals
Rushabh Mehta40182ba2012-06-19 14:15:13 +05302def execute():
3 import webnotes
Rushabh Mehta40182ba2012-06-19 14:15:13 +05304
Anand Doshi51146c02012-07-12 18:41:12 +05305 # sync doctypes required for the patch
Anand Doshi42218142013-05-16 15:28:19 +05306 webnotes.reload_doc('website', 'doctype', 'web_cache')
7 webnotes.reload_doc('website', 'doctype', 'web_page')
8 webnotes.reload_doc('website', 'doctype', 'blog')
9 webnotes.reload_doc('website', 'doctype', 'website_settings')
10 webnotes.reload_doc('stock', 'doctype', '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:
Anand Doshi255d58b2012-07-13 08:53:07 +053044 webnotes.modules.patch_handler.log(unicode(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
Rushabh Mehtac53231a2013-02-18 18:24:28 +053069 from webnotes.model.bean import Bean
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:
Rushabh Mehtac53231a2013-02-18 18:24:28 +053075 Bean(dt, result['name'].encode('utf-8')).save()
Anand Doshi4659b1e2012-07-12 23:38:31 +053076 except Exception, e:
Anand Doshi255d58b2012-07-13 08:53:07 +053077 webnotes.modules.patch_handler.log(unicode(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()