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 | 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 |
| 38 | webnotes.model.delete_doc('Page', 'products') |
| 39 | webnotes.model.delete_doc('Page', 'contact') |
| 40 | webnotes.model.delete_doc('Page', 'blog') |
| 41 | webnotes.model.delete_doc('Page', 'about') |
| 42 | |
Anand Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame] | 43 | def save_pages(): |
| 44 | """save all web pages, blogs to create content""" |
Anand Doshi | 51146c0 | 2012-07-12 18:41:12 +0530 | [diff] [blame] | 45 | query_map = { |
| 46 | 'Web Page': """select name from `tabWeb Page` where docstatus=0""", |
| 47 | 'Blog': """\ |
| 48 | select name from `tabBlog` |
| 49 | where docstatus = 0 and ifnull(published, 0) = 1""", |
| 50 | 'Item': """\ |
| 51 | select name from `tabItem` |
| 52 | where docstatus = 0 and ifnull(show_in_website, 0) = 1""", |
| 53 | } |
| 54 | |
| 55 | import webnotes |
| 56 | from webnotes.model.doclist import DocList |
| 57 | |
| 58 | for dt in query_map: |
| 59 | for result in webnotes.conn.sql(query_map[dt], as_dict=1): |
| 60 | DocList(dt, result['name']).save() |