<commit_before>def execute():
	import webnotes
	import webnotes.model.sync
	
	# sync doctypes required for the patch
	webnotes.model.sync.sync('website', 'web_cache')
	webnotes.model.sync.sync('website', 'web_page')
	webnotes.model.sync.sync('website', 'blog')
	webnotes.model.sync.sync('website', 'website_settings')
	webnotes.model.sync.sync('stock', 'item')

	cleanup()

	save_pages()
	
	save_website_settings()
	
def cleanup():
	import webnotes
		
	# delete pages from `tabPage` of module Website or of type Webpage
	webnotes.conn.sql("""\
		delete from `tabPage`
		where module='Website' and ifnull(web_page, 'No') = 'Yes'""")
	
	# change show_in_website value in item table to 0 or 1
	webnotes.conn.sql("""\
		update `tabItem`
		set show_in_website = if(show_in_website = 'Yes', 1, 0)
		where show_in_website is not null""")
		
	# move comments from comment_doctype Page to Blog
	webnotes.conn.sql("""\
		update `tabComment` comm, `tabBlog` blog
		set comm.comment_doctype = 'Blog', comm.comment_docname = blog.name
		where comm.comment_docname = blog.page_name""")
		
	# delete deprecated pages
	import webnotes.model
	webnotes.model.delete_doc('Page', 'products')
	webnotes.model.delete_doc('Page', 'contact')
	webnotes.model.delete_doc('Page', 'blog')
	webnotes.model.delete_doc('Page', 'about')

	import os
	import conf
	# delete other html files
	exception_list = ['app.html', 'unsupported.html', 'blank.html']
	conf_dir = os.path.dirname(os.path.abspath(conf.__file__))
	public_path = os.path.join(conf_dir, 'public')
	for f in os.listdir(public_path):
		if f.endswith('.html') and f not in exception_list:
			os.remove(os.path.join(public_path, f))

def save_pages():
	"""save all web pages, blogs to create content"""
	query_map = {
		'Web Page': """select name from `tabWeb Page` where docstatus=0""",
		'Blog': """\
			select name from `tabBlog`
			where docstatus = 0 and ifnull(published, 0) = 1""",
		'Item': """\
			select name from `tabItem`
			where docstatus = 0 and ifnull(show_in_website, 0) = 1""",
	}

	import webnotes
	from webnotes.model.doclist import DocList

	for dt in query_map:
		for result in webnotes.conn.sql(query_map[dt], as_dict=1):
			DocList(dt, result['name']).save()
			
def save_website_settings():
	from webnotes.model.code import get_obj
	
	# rewrite pages
	get_obj('Website Settings').on_update()
	
	ss = get_obj('Style Settings')
	ss.validate()
	ss.doc.save()
	ss.on_update()<commit_msg>log error on saving doclist in cms2 patch<commit_after>def execute():
	import webnotes
	import webnotes.model.sync
	
	# sync doctypes required for the patch
	webnotes.model.sync.sync('website', 'web_cache')
	webnotes.model.sync.sync('website', 'web_page')
	webnotes.model.sync.sync('website', 'blog')
	webnotes.model.sync.sync('website', 'website_settings')
	webnotes.model.sync.sync('stock', 'item')

	cleanup()

	save_pages()
	
	save_website_settings()
	
def cleanup():
	import webnotes
		
	# delete pages from `tabPage` of module Website or of type Webpage
	webnotes.conn.sql("""\
		delete from `tabPage`
		where module='Website' and ifnull(web_page, 'No') = 'Yes'""")
	
	# change show_in_website value in item table to 0 or 1
	webnotes.conn.sql("""\
		update `tabItem`
		set show_in_website = if(show_in_website = 'Yes', 1, 0)
		where show_in_website is not null""")
		
	# move comments from comment_doctype Page to Blog
	webnotes.conn.sql("""\
		update `tabComment` comm, `tabBlog` blog
		set comm.comment_doctype = 'Blog', comm.comment_docname = blog.name
		where comm.comment_docname = blog.page_name""")
		
	# delete deprecated pages
	import webnotes.model
	webnotes.model.delete_doc('Page', 'products')
	webnotes.model.delete_doc('Page', 'contact')
	webnotes.model.delete_doc('Page', 'blog')
	webnotes.model.delete_doc('Page', 'about')

	import os
	import conf
	# delete other html files
	exception_list = ['app.html', 'unsupported.html', 'blank.html']
	conf_dir = os.path.dirname(os.path.abspath(conf.__file__))
	public_path = os.path.join(conf_dir, 'public')
	for f in os.listdir(public_path):
		if f.endswith('.html') and f not in exception_list:
			os.remove(os.path.join(public_path, f))

def save_pages():
	"""save all web pages, blogs to create content"""
	query_map = {
		'Web Page': """select name from `tabWeb Page` where docstatus=0""",
		'Blog': """\
			select name from `tabBlog`
			where docstatus = 0 and ifnull(published, 0) = 1""",
		'Item': """\
			select name from `tabItem`
			where docstatus = 0 and ifnull(show_in_website, 0) = 1""",
	}

	import webnotes
	from webnotes.model.doclist import DocList
	import webnotes.modules.patch_handler

	for dt in query_map:
		for result in webnotes.conn.sql(query_map[dt], as_dict=1):
			try:
				DocList(dt, result['name']).save()
			except Exception, e:
				webnotes.modules.patch_handler.log(str(e))
			
def save_website_settings():
	from webnotes.model.code import get_obj
	
	# rewrite pages
	get_obj('Website Settings').on_update()
	
	ss = get_obj('Style Settings')
	ss.validate()
	ss.doc.save()
	ss.on_update()
{'fraction_non_alphanumeric': 0.14060944035052778, 'fraction_numerical': 0.004979087831109341, 'mean_word_length': 4.642696629213483, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4990564', 'n_tokens_mistral': 1895, 'n_tokens_neox': 1721, 'n_words': 443}