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 | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame] | 5 | # sync web page, blog doctype |
Rushabh Mehta | 40182ba | 2012-06-19 14:15:13 +0530 | [diff] [blame] | 6 | webnotes.model.sync.sync('website', 'web_page') |
Anand Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame] | 7 | webnotes.model.sync.sync('website', 'blog') |
| 8 | |
| 9 | cleanup() |
| 10 | |
| 11 | save_pages() |
Rushabh Mehta | 40182ba | 2012-06-19 14:15:13 +0530 | [diff] [blame] | 12 | |
Anand Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame] | 13 | def cleanup(): |
| 14 | import webnotes |
| 15 | |
| 16 | # delete pages from `tabPage` of module Website or of type Webpage |
| 17 | webnotes.conn.sql("""\ |
| 18 | delete from `tabPage` |
| 19 | where module='Website' and ifnull(web_page, 'No') = 'Yes'""") |
| 20 | |
Anand Doshi | e47def8 | 2012-07-09 15:56:12 +0530 | [diff] [blame] | 21 | # change show_in_website value in item table to 0 or 1 |
| 22 | webnotes.conn.sql("""\ |
| 23 | update `tabItem` |
| 24 | set show_in_website = if(show_in_website = 'Yes', 1, 0) |
| 25 | where show_in_website is not null""") |
Anand Doshi | 40fce89 | 2012-07-09 20:02:52 +0530 | [diff] [blame] | 26 | |
| 27 | # move comments from comment_doctype Page to Blog |
| 28 | webnotes.conn.sql("""\ |
| 29 | update `tabComment` comm, `tabBlog` blog |
| 30 | set comm.comment_doctype = 'Blog', comm.comment_docname = blog.name |
| 31 | where comm.comment_docname = blog.page_name""") |
| 32 | |
Anand Doshi | e47def8 | 2012-07-09 15:56:12 +0530 | [diff] [blame] | 33 | |
Anand Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame] | 34 | def save_pages(): |
| 35 | """save all web pages, blogs to create content""" |
| 36 | import webnotes |
| 37 | from webnotes.model.doclist import DocList |
| 38 | save_list = [ |
| 39 | { |
| 40 | 'doctype': 'Web Page', |
| 41 | 'query': """select name from `tabWeb Page` where docstatus=0""" |
| 42 | }, |
| 43 | { |
| 44 | 'doctype': 'Blog', |
| 45 | 'query': """\ |
| 46 | select name from `tabBlog` |
| 47 | where docstatus = 0 and ifnull(published, 0) = 1""" |
| 48 | }, |
Anand Doshi | 10bcf5e | 2012-06-26 18:54:10 +0530 | [diff] [blame] | 49 | { |
| 50 | 'doctype': 'Item', |
| 51 | 'query': """\ |
| 52 | select name from `tabItem` |
| 53 | where docstatus = 0 and ifnull(show_in_website, 'No') = 'Yes'""" |
| 54 | } |
Anand Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame] | 55 | ] |
| 56 | |
| 57 | for s in save_list: |
| 58 | for p in webnotes.conn.sql(s['query'], as_dict=1): |
| 59 | DocList(s['doctype'], p['name']).save() |