Rushabh Mehta | 40182ba | 2012-06-19 14:15:13 +0530 | [diff] [blame] | 1 | def execute(): |
| 2 | import webnotes |
Rushabh Mehta | 40182ba | 2012-06-19 14:15:13 +0530 | [diff] [blame] | 3 | import webnotes.model.sync |
| 4 | |
Anand Doshi | 51146c0 | 2012-07-12 18:41:12 +0530 | [diff] [blame] | 5 | # sync doctypes required for the patch |
| 6 | webnotes.model.sync.sync('website', 'web_cache') |
Rushabh Mehta | 40182ba | 2012-06-19 14:15:13 +0530 | [diff] [blame] | 7 | webnotes.model.sync.sync('website', 'web_page') |
Anand Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame] | 8 | webnotes.model.sync.sync('website', 'blog') |
Anand Doshi | 51146c0 | 2012-07-12 18:41:12 +0530 | [diff] [blame] | 9 | webnotes.model.sync.sync('website', 'website_settings') |
| 10 | webnotes.model.sync.sync('stock', 'item') |
Anand Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame] | 11 | |
| 12 | cleanup() |
| 13 | |
| 14 | save_pages() |
Rushabh Mehta | 40182ba | 2012-06-19 14:15:13 +0530 | [diff] [blame] | 15 | |
Anand Doshi | c4eb9bf | 2012-07-12 19:15:52 +0530 | [diff] [blame^] | 16 | save_website_settings() |
| 17 | |
Anand Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame] | 18 | def 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 Doshi | e47def8 | 2012-07-09 15:56:12 +0530 | [diff] [blame] | 26 | # 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 Doshi | 40fce89 | 2012-07-09 20:02:52 +0530 | [diff] [blame] | 31 | |
| 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 Doshi | 51146c0 | 2012-07-12 18:41:12 +0530 | [diff] [blame] | 37 | |
| 38 | # delete deprecated pages |
| 39 | import webnotes.model |
| 40 | webnotes.model.delete_doc('Page', 'products') |
| 41 | webnotes.model.delete_doc('Page', 'contact') |
| 42 | webnotes.model.delete_doc('Page', 'blog') |
| 43 | webnotes.model.delete_doc('Page', 'about') |
| 44 | |
Anand Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame] | 45 | def save_pages(): |
| 46 | """save all web pages, blogs to create content""" |
Anand Doshi | 51146c0 | 2012-07-12 18:41:12 +0530 | [diff] [blame] | 47 | query_map = { |
| 48 | 'Web Page': """select name from `tabWeb Page` where docstatus=0""", |
| 49 | 'Blog': """\ |
| 50 | select name from `tabBlog` |
| 51 | where docstatus = 0 and ifnull(published, 0) = 1""", |
| 52 | 'Item': """\ |
| 53 | select name from `tabItem` |
| 54 | where docstatus = 0 and ifnull(show_in_website, 0) = 1""", |
| 55 | } |
| 56 | |
| 57 | import webnotes |
| 58 | from webnotes.model.doclist import DocList |
| 59 | |
| 60 | for dt in query_map: |
| 61 | for result in webnotes.conn.sql(query_map[dt], as_dict=1): |
Anand Doshi | c4eb9bf | 2012-07-12 19:15:52 +0530 | [diff] [blame^] | 62 | DocList(dt, result['name']).save() |
| 63 | |
| 64 | def save_website_settings(): |
| 65 | from webnotes.model.code import get_obj |
| 66 | |
| 67 | # rewrite pages |
| 68 | get_obj('Website Settings').on_update() |
| 69 | |
| 70 | ss = get_obj('Style Settings') |
| 71 | ss.validate() |
| 72 | ss.doc.save() |
| 73 | ss.on_update() |