blob: 17b7d23cc1b48d9852707e263a4d71a04c234ee9 [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_page')
Anand Doshi42218142013-05-16 15:28:19 +05307 webnotes.reload_doc('website', 'doctype', 'website_settings')
8 webnotes.reload_doc('stock', 'doctype', 'item')
Anand Doshi72c945b2012-06-22 20:01:07 +05309
10 cleanup()
11
12 save_pages()
Rushabh Mehta40182ba2012-06-19 14:15:13 +053013
Anand Doshic4eb9bf2012-07-12 19:15:52 +053014 save_website_settings()
15
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
Anand Doshi6c3b6222012-07-13 08:24:16 +053038 for page in ['products', 'contact', 'blog', 'about']:
39 try:
40 webnotes.model.delete_doc('Page', page)
41 except Exception, e:
Anand Doshi255d58b2012-07-13 08:53:07 +053042 webnotes.modules.patch_handler.log(unicode(e))
Anand Doshi51146c02012-07-12 18:41:12 +053043
Anand Doshiaf1f4372012-07-12 22:06:27 +053044 import os
45 import conf
46 # delete other html files
47 exception_list = ['app.html', 'unsupported.html', 'blank.html']
48 conf_dir = os.path.dirname(os.path.abspath(conf.__file__))
49 public_path = os.path.join(conf_dir, 'public')
50 for f in os.listdir(public_path):
51 if f.endswith('.html') and f not in exception_list:
52 os.remove(os.path.join(public_path, f))
53
Anand Doshi72c945b2012-06-22 20:01:07 +053054def save_pages():
55 """save all web pages, blogs to create content"""
Anand Doshi51146c02012-07-12 18:41:12 +053056 query_map = {
57 'Web Page': """select name from `tabWeb Page` where docstatus=0""",
58 'Blog': """\
59 select name from `tabBlog`
60 where docstatus = 0 and ifnull(published, 0) = 1""",
61 'Item': """\
62 select name from `tabItem`
63 where docstatus = 0 and ifnull(show_in_website, 0) = 1""",
64 }
65
66 import webnotes
Rushabh Mehtac53231a2013-02-18 18:24:28 +053067 from webnotes.model.bean import Bean
Anand Doshi4659b1e2012-07-12 23:38:31 +053068 import webnotes.modules.patch_handler
Anand Doshi51146c02012-07-12 18:41:12 +053069
70 for dt in query_map:
71 for result in webnotes.conn.sql(query_map[dt], as_dict=1):
Anand Doshi4659b1e2012-07-12 23:38:31 +053072 try:
Rushabh Mehtac53231a2013-02-18 18:24:28 +053073 Bean(dt, result['name'].encode('utf-8')).save()
Anand Doshi4659b1e2012-07-12 23:38:31 +053074 except Exception, e:
Anand Doshi255d58b2012-07-13 08:53:07 +053075 webnotes.modules.patch_handler.log(unicode(e))
Anand Doshic4eb9bf2012-07-12 19:15:52 +053076
77def save_website_settings():
78 from webnotes.model.code import get_obj
79
80 # rewrite pages
81 get_obj('Website Settings').on_update()
82
83 ss = get_obj('Style Settings')
84 ss.validate()
85 ss.doc.save()
86 ss.on_update()