Anand Doshi | 486f9df | 2012-07-19 13:40:31 +0530 | [diff] [blame] | 1 | from __future__ import unicode_literals |
Rushabh Mehta | 40182ba | 2012-06-19 14:15:13 +0530 | [diff] [blame] | 2 | def execute(): |
| 3 | import webnotes |
Rushabh Mehta | 40182ba | 2012-06-19 14:15:13 +0530 | [diff] [blame] | 4 | |
Anand Doshi | 51146c0 | 2012-07-12 18:41:12 +0530 | [diff] [blame] | 5 | # sync doctypes required for the patch |
Anand Doshi | 4221814 | 2013-05-16 15:28:19 +0530 | [diff] [blame] | 6 | webnotes.reload_doc('website', 'doctype', 'web_page') |
Anand Doshi | 4221814 | 2013-05-16 15:28:19 +0530 | [diff] [blame] | 7 | webnotes.reload_doc('website', 'doctype', 'website_settings') |
| 8 | webnotes.reload_doc('stock', 'doctype', 'item') |
Anand Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame] | 9 | |
| 10 | cleanup() |
| 11 | |
| 12 | save_pages() |
Rushabh Mehta | 40182ba | 2012-06-19 14:15:13 +0530 | [diff] [blame] | 13 | |
Anand Doshi | c4eb9bf | 2012-07-12 19:15:52 +0530 | [diff] [blame] | 14 | save_website_settings() |
| 15 | |
Anand Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame] | 16 | def 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 Doshi | e47def8 | 2012-07-09 15:56:12 +0530 | [diff] [blame] | 24 | # 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 Doshi | 40fce89 | 2012-07-09 20:02:52 +0530 | [diff] [blame] | 29 | |
| 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 Doshi | 51146c0 | 2012-07-12 18:41:12 +0530 | [diff] [blame] | 35 | |
| 36 | # delete deprecated pages |
| 37 | import webnotes.model |
Anand Doshi | 6c3b622 | 2012-07-13 08:24:16 +0530 | [diff] [blame] | 38 | for page in ['products', 'contact', 'blog', 'about']: |
| 39 | try: |
| 40 | webnotes.model.delete_doc('Page', page) |
| 41 | except Exception, e: |
Anand Doshi | 255d58b | 2012-07-13 08:53:07 +0530 | [diff] [blame] | 42 | webnotes.modules.patch_handler.log(unicode(e)) |
Anand Doshi | 51146c0 | 2012-07-12 18:41:12 +0530 | [diff] [blame] | 43 | |
Anand Doshi | af1f437 | 2012-07-12 22:06:27 +0530 | [diff] [blame] | 44 | 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 Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame] | 54 | def save_pages(): |
| 55 | """save all web pages, blogs to create content""" |
Anand Doshi | 51146c0 | 2012-07-12 18:41:12 +0530 | [diff] [blame] | 56 | 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 Mehta | c53231a | 2013-02-18 18:24:28 +0530 | [diff] [blame] | 67 | from webnotes.model.bean import Bean |
Anand Doshi | 4659b1e | 2012-07-12 23:38:31 +0530 | [diff] [blame] | 68 | import webnotes.modules.patch_handler |
Anand Doshi | 51146c0 | 2012-07-12 18:41:12 +0530 | [diff] [blame] | 69 | |
| 70 | for dt in query_map: |
| 71 | for result in webnotes.conn.sql(query_map[dt], as_dict=1): |
Anand Doshi | 4659b1e | 2012-07-12 23:38:31 +0530 | [diff] [blame] | 72 | try: |
Rushabh Mehta | c53231a | 2013-02-18 18:24:28 +0530 | [diff] [blame] | 73 | Bean(dt, result['name'].encode('utf-8')).save() |
Anand Doshi | 4659b1e | 2012-07-12 23:38:31 +0530 | [diff] [blame] | 74 | except Exception, e: |
Anand Doshi | 255d58b | 2012-07-13 08:53:07 +0530 | [diff] [blame] | 75 | webnotes.modules.patch_handler.log(unicode(e)) |
Anand Doshi | c4eb9bf | 2012-07-12 19:15:52 +0530 | [diff] [blame] | 76 | |
| 77 | def 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() |