Rushabh Mehta | e67d1fb | 2013-08-05 14:59:54 +0530 | [diff] [blame] | 1 | # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. |
| 2 | # License: GNU General Public License v3. See license.txt |
| 3 | |
Anand Doshi | 486f9df | 2012-07-19 13:40:31 +0530 | [diff] [blame] | 4 | from __future__ import unicode_literals |
Rushabh Mehta | 40182ba | 2012-06-19 14:15:13 +0530 | [diff] [blame] | 5 | def execute(): |
| 6 | import webnotes |
Rushabh Mehta | 40182ba | 2012-06-19 14:15:13 +0530 | [diff] [blame] | 7 | |
Anand Doshi | 51146c0 | 2012-07-12 18:41:12 +0530 | [diff] [blame] | 8 | # sync doctypes required for the patch |
Anand Doshi | 4221814 | 2013-05-16 15:28:19 +0530 | [diff] [blame] | 9 | webnotes.reload_doc('website', 'doctype', 'web_page') |
Anand Doshi | 4221814 | 2013-05-16 15:28:19 +0530 | [diff] [blame] | 10 | webnotes.reload_doc('website', 'doctype', 'website_settings') |
| 11 | webnotes.reload_doc('stock', 'doctype', 'item') |
Anand Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame] | 12 | |
| 13 | cleanup() |
| 14 | |
| 15 | save_pages() |
Rushabh Mehta | 40182ba | 2012-06-19 14:15:13 +0530 | [diff] [blame] | 16 | |
Anand Doshi | c4eb9bf | 2012-07-12 19:15:52 +0530 | [diff] [blame] | 17 | save_website_settings() |
| 18 | |
Anand Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame] | 19 | def cleanup(): |
| 20 | import webnotes |
| 21 | |
| 22 | # delete pages from `tabPage` of module Website or of type Webpage |
| 23 | webnotes.conn.sql("""\ |
| 24 | delete from `tabPage` |
| 25 | where module='Website' and ifnull(web_page, 'No') = 'Yes'""") |
| 26 | |
Anand Doshi | e47def8 | 2012-07-09 15:56:12 +0530 | [diff] [blame] | 27 | # change show_in_website value in item table to 0 or 1 |
| 28 | webnotes.conn.sql("""\ |
| 29 | update `tabItem` |
| 30 | set show_in_website = if(show_in_website = 'Yes', 1, 0) |
| 31 | where show_in_website is not null""") |
Anand Doshi | 40fce89 | 2012-07-09 20:02:52 +0530 | [diff] [blame] | 32 | |
| 33 | # move comments from comment_doctype Page to Blog |
| 34 | webnotes.conn.sql("""\ |
| 35 | update `tabComment` comm, `tabBlog` blog |
| 36 | set comm.comment_doctype = 'Blog', comm.comment_docname = blog.name |
| 37 | where comm.comment_docname = blog.page_name""") |
Anand Doshi | 51146c0 | 2012-07-12 18:41:12 +0530 | [diff] [blame] | 38 | |
| 39 | # delete deprecated pages |
| 40 | import webnotes.model |
Anand Doshi | 6c3b622 | 2012-07-13 08:24:16 +0530 | [diff] [blame] | 41 | for page in ['products', 'contact', 'blog', 'about']: |
| 42 | try: |
| 43 | webnotes.model.delete_doc('Page', page) |
| 44 | except Exception, e: |
Anand Doshi | 255d58b | 2012-07-13 08:53:07 +0530 | [diff] [blame] | 45 | webnotes.modules.patch_handler.log(unicode(e)) |
Anand Doshi | 51146c0 | 2012-07-12 18:41:12 +0530 | [diff] [blame] | 46 | |
Anand Doshi | af1f437 | 2012-07-12 22:06:27 +0530 | [diff] [blame] | 47 | import os |
| 48 | import conf |
| 49 | # delete other html files |
| 50 | exception_list = ['app.html', 'unsupported.html', 'blank.html'] |
| 51 | conf_dir = os.path.dirname(os.path.abspath(conf.__file__)) |
| 52 | public_path = os.path.join(conf_dir, 'public') |
| 53 | for f in os.listdir(public_path): |
| 54 | if f.endswith('.html') and f not in exception_list: |
| 55 | os.remove(os.path.join(public_path, f)) |
| 56 | |
Anand Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame] | 57 | def save_pages(): |
| 58 | """save all web pages, blogs to create content""" |
Anand Doshi | 51146c0 | 2012-07-12 18:41:12 +0530 | [diff] [blame] | 59 | query_map = { |
| 60 | 'Web Page': """select name from `tabWeb Page` where docstatus=0""", |
| 61 | 'Blog': """\ |
| 62 | select name from `tabBlog` |
| 63 | where docstatus = 0 and ifnull(published, 0) = 1""", |
| 64 | 'Item': """\ |
| 65 | select name from `tabItem` |
| 66 | where docstatus = 0 and ifnull(show_in_website, 0) = 1""", |
| 67 | } |
| 68 | |
| 69 | import webnotes |
Rushabh Mehta | c53231a | 2013-02-18 18:24:28 +0530 | [diff] [blame] | 70 | from webnotes.model.bean import Bean |
Anand Doshi | 4659b1e | 2012-07-12 23:38:31 +0530 | [diff] [blame] | 71 | import webnotes.modules.patch_handler |
Anand Doshi | 51146c0 | 2012-07-12 18:41:12 +0530 | [diff] [blame] | 72 | |
| 73 | for dt in query_map: |
| 74 | for result in webnotes.conn.sql(query_map[dt], as_dict=1): |
Anand Doshi | 4659b1e | 2012-07-12 23:38:31 +0530 | [diff] [blame] | 75 | try: |
Rushabh Mehta | c53231a | 2013-02-18 18:24:28 +0530 | [diff] [blame] | 76 | Bean(dt, result['name'].encode('utf-8')).save() |
Anand Doshi | 4659b1e | 2012-07-12 23:38:31 +0530 | [diff] [blame] | 77 | except Exception, e: |
Anand Doshi | 255d58b | 2012-07-13 08:53:07 +0530 | [diff] [blame] | 78 | webnotes.modules.patch_handler.log(unicode(e)) |
Anand Doshi | c4eb9bf | 2012-07-12 19:15:52 +0530 | [diff] [blame] | 79 | |
| 80 | def save_website_settings(): |
| 81 | from webnotes.model.code import get_obj |
| 82 | |
| 83 | # rewrite pages |
| 84 | get_obj('Website Settings').on_update() |
| 85 | |
| 86 | ss = get_obj('Style Settings') |
| 87 | ss.validate() |
| 88 | ss.doc.save() |
| 89 | ss.on_update() |