blob: 414af73c0079b44530e6ff6720c0d23939527c63 [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 import webnotes.model.sync
5
Anand Doshi51146c02012-07-12 18:41:12 +05306 # sync doctypes required for the patch
7 webnotes.model.sync.sync('website', 'web_cache')
Rushabh Mehta40182ba2012-06-19 14:15:13 +05308 webnotes.model.sync.sync('website', 'web_page')
Anand Doshi72c945b2012-06-22 20:01:07 +05309 webnotes.model.sync.sync('website', 'blog')
Anand Doshi51146c02012-07-12 18:41:12 +053010 webnotes.model.sync.sync('website', 'website_settings')
11 webnotes.model.sync.sync('stock', 'item')
Anand Doshi72c945b2012-06-22 20:01:07 +053012
13 cleanup()
14
15 save_pages()
Rushabh Mehta40182ba2012-06-19 14:15:13 +053016
Anand Doshic4eb9bf2012-07-12 19:15:52 +053017 save_website_settings()
18
Anand Doshi72c945b2012-06-22 20:01:07 +053019def cleanup():
20 import webnotes
21
22 # delete pages from `tabPage` of module Website or of type Webpage
23 webnotes.conn.sql("""\
24 delete from `tabPage`
25 where module='Website' and ifnull(web_page, 'No') = 'Yes'""")
26
Anand Doshie47def82012-07-09 15:56:12 +053027 # change show_in_website value in item table to 0 or 1
28 webnotes.conn.sql("""\
29 update `tabItem`
30 set show_in_website = if(show_in_website = 'Yes', 1, 0)
31 where show_in_website is not null""")
Anand Doshi40fce892012-07-09 20:02:52 +053032
33 # move comments from comment_doctype Page to Blog
34 webnotes.conn.sql("""\
35 update `tabComment` comm, `tabBlog` blog
36 set comm.comment_doctype = 'Blog', comm.comment_docname = blog.name
37 where comm.comment_docname = blog.page_name""")
Anand Doshi51146c02012-07-12 18:41:12 +053038
39 # delete deprecated pages
40 import webnotes.model
Anand Doshi6c3b6222012-07-13 08:24:16 +053041 for page in ['products', 'contact', 'blog', 'about']:
42 try:
43 webnotes.model.delete_doc('Page', page)
44 except Exception, e:
Anand Doshi255d58b2012-07-13 08:53:07 +053045 webnotes.modules.patch_handler.log(unicode(e))
Anand Doshi51146c02012-07-12 18:41:12 +053046
Anand Doshiaf1f4372012-07-12 22:06:27 +053047 import os
48 import conf
49 # delete other html files
50 exception_list = ['app.html', 'unsupported.html', 'blank.html']
51 conf_dir = os.path.dirname(os.path.abspath(conf.__file__))
52 public_path = os.path.join(conf_dir, 'public')
53 for f in os.listdir(public_path):
54 if f.endswith('.html') and f not in exception_list:
55 os.remove(os.path.join(public_path, f))
56
Anand Doshi72c945b2012-06-22 20:01:07 +053057def save_pages():
58 """save all web pages, blogs to create content"""
Anand Doshi51146c02012-07-12 18:41:12 +053059 query_map = {
60 'Web Page': """select name from `tabWeb Page` where docstatus=0""",
61 'Blog': """\
62 select name from `tabBlog`
63 where docstatus = 0 and ifnull(published, 0) = 1""",
64 'Item': """\
65 select name from `tabItem`
66 where docstatus = 0 and ifnull(show_in_website, 0) = 1""",
67 }
68
69 import webnotes
Rushabh Mehtac53231a2013-02-18 18:24:28 +053070 from webnotes.model.bean import Bean
Anand Doshi4659b1e2012-07-12 23:38:31 +053071 import webnotes.modules.patch_handler
Anand Doshi51146c02012-07-12 18:41:12 +053072
73 for dt in query_map:
74 for result in webnotes.conn.sql(query_map[dt], as_dict=1):
Anand Doshi4659b1e2012-07-12 23:38:31 +053075 try:
Rushabh Mehtac53231a2013-02-18 18:24:28 +053076 Bean(dt, result['name'].encode('utf-8')).save()
Anand Doshi4659b1e2012-07-12 23:38:31 +053077 except Exception, e:
Anand Doshi255d58b2012-07-13 08:53:07 +053078 webnotes.modules.patch_handler.log(unicode(e))
Anand Doshic4eb9bf2012-07-12 19:15:52 +053079
80def save_website_settings():
81 from webnotes.model.code import get_obj
82
83 # rewrite pages
84 get_obj('Website Settings').on_update()
85
86 ss = get_obj('Style Settings')
87 ss.validate()
88 ss.doc.save()
89 ss.on_update()