def migrate(context, rebuild_website=False): "Run patches, sync schema and rebuild files/translations" import frappe.modules.patch_handler import frappe.model.sync from frappe.utils.fixtures import sync_fixtures import frappe.translate from frappe.desk.notifications import clear_notifications for site in context.sites: print 'Migrating', site frappe.init(site=site) frappe.connect() try: prepare_for_update() # run patches frappe.modules.patch_handler.run_all() # sync frappe.model.sync.sync_all(verbose=context.verbose) frappe.translate.clear_cache() sync_fixtures() clear_notifications() finally: frappe.destroy() if rebuild_website: call_command(build_website, context) else: call_command(sync_www, context)
def delete_company_transactions(company_name): frappe.only_for("System Manager") doc = frappe.get_doc("Company", company_name) if frappe.session.user != doc.owner: frappe.throw( _("Transactions can only be deleted by the creator of the Company" ), frappe.PermissionError) delete_bins(company_name) delete_time_logs(company_name) delete_lead_addresses(company_name) for doctype in frappe.db.sql_list("""select parent from tabDocField where fieldtype='Link' and options='Company'"""): if doctype not in ("Account", "Cost Center", "Warehouse", "Budget Detail", "Party Account", "Employee", "Sales Taxes and Charges Template", "Purchase Taxes and Charges Template", "POS Profile", 'BOM'): delete_for_doctype(doctype, company_name) else: # un-set company frappe.db.sql( 'update `tab{0}` set company="" where company=%s'.format( doctype), company_name) # Clear notification counts clear_notifications()
def clear_cache(): import frappe.sessions from frappe.desk.notifications import clear_notifications frappe.connect() frappe.clear_cache() clear_notifications() frappe.destroy()
def delete_company_transactions(company_name): frappe.only_for("System Manager") doc = frappe.get_doc("Company", company_name) if frappe.session.user != doc.owner: frappe.throw(_("Transactions can only be deleted by the creator of the Company"), frappe.PermissionError) delete_bins(company_name) delete_time_logs(company_name) delete_lead_addresses(company_name) for doctype in frappe.db.sql_list( """select parent from tabDocField where fieldtype='Link' and options='Company'""" ): if doctype not in ( "Account", "Cost Center", "Warehouse", "Budget Detail", "Party Account", "Employee", "Sales Taxes and Charges Template", "Purchase Taxes and Charges Template", "POS Profile", ): delete_for_doctype(doctype, company_name) # Clear notification counts clear_notifications()
def on_update(self): # clear new password self.share_with_self() new_password = self.clear_new_password() clear_notifications(user=self.name) frappe.clear_cache(user=self.name) self.send_password_notifcation(new_password)
def latest(rebuild_website=True, quiet=False): import frappe.modules.patch_handler import frappe.model.sync from frappe.utils.fixtures import sync_fixtures import frappe.translate from frappe.desk.notifications import clear_notifications verbose = not quiet frappe.connect() try: # run patches frappe.modules.patch_handler.run_all() # sync frappe.model.sync.sync_all(verbose=verbose) frappe.translate.clear_cache() sync_fixtures() clear_notifications() if rebuild_website: build_website() finally: frappe.destroy()
def on_update(self): # clear new password self.validate_user_limit() self.share_with_self() clear_notifications(user=self.name) frappe.clear_cache(user=self.name) self.send_password_notification(self.__new_password)
def on_update(self): # owner is always name frappe.db.set(self, 'owner', self.name) # clear new password new_password = self.new_password self.db_set("new_password", "") clear_notifications(user=self.name) frappe.clear_cache(user=self.name) try: if self.in_insert: if self.name not in STANDARD_USERS: if new_password: # new password given, no email required _update_password(self.name, new_password) if not getattr(self, "no_welcome_mail", False): self.send_welcome_mail() msgprint(_("Welcome email sent")) return else: self.email_new_password(new_password) except frappe.OutgoingEmailError: pass # email server not set, don't send email
def migrate(verbose=True, rebuild_website=False): '''Migrate all apps to the latest version, will: - run patches - sync doctypes (schema) - sync fixtures - sync desktop icons - sync web pages (from /www)''' clear_global_cache() # run patches frappe.modules.patch_handler.run_all() # sync frappe.model.sync.sync_all(verbose=verbose) frappe.translate.clear_cache() sync_fixtures() sync_desktop_icons() sync_languages() frappe.get_doc('Portal Settings', 'Portal Settings').sync_menu() # syncs statics render.clear_cache() frappe.db.commit() if not frappe.conf.get('global_help_setup'): # sync help if not set as global frappe.utils.help.sync() clear_notifications() frappe.publish_realtime("version-update")
def on_update(self): # clear new password self.share_with_self() clear_notifications(user=self.name) frappe.clear_cache(user=self.name) now=frappe.flags.in_test or frappe.flags.in_install self.send_password_notification(self.__new_password) frappe.enqueue( 'frappe.core.doctype.user.user.create_contact', user=self, ignore_mandatory=True, now=now ) if self.name not in ('Administrator', 'Guest') and not self.user_image: frappe.enqueue('frappe.core.doctype.user.user.update_gravatar', name=self.name, now=now) # Set user selected timezone if self.time_zone: frappe.defaults.set_default("time_zone", self.time_zone, self.name) if self.has_value_changed('allow_in_mentions') or self.has_value_changed('user_type'): frappe.cache().delete_key('users_for_mentions') if self.has_value_changed('enabled'): frappe.cache().delete_key('enabled_users')
def delete_company_transactions(company_name): frappe.only_for("System Manager") doc = frappe.get_doc("Company", company_name) if frappe.session.user != doc.owner and frappe.session.user != 'Administrator': frappe.throw( _("Transactions can only be deleted by the creator of the Company" ), frappe.PermissionError) delete_bins(company_name) delete_lead_addresses(company_name) for doctype in frappe.db.sql_list("""select parent from tabDocField where fieldtype='Link' and options='Company'"""): if doctype not in ("Account", "Cost Center", "Warehouse", "Budget", "Party Account", "Employee", "Sales Taxes and Charges Template", "Purchase Taxes and Charges Template", "POS Profile", "BOM", "Company", "Bank Account", "Item Tax Template", "Mode Of Payment", "Mode of Payment Account", "Item Default", "Customer", "Supplier", "GST Account"): delete_for_doctype(doctype, company_name) # reset company values doc.total_monthly_sales = 0 doc.sales_monthly_history = None doc.save() # Clear notification counts clear_notifications()
def migrate(verbose=True, rebuild_website=False): '''Migrate all apps to the latest version, will: - run patches - sync doctypes (schema) - sync fixtures - sync desktop icons - sync web pages (from /www)''' clear_global_cache() # run patches frappe.modules.patch_handler.run_all() # sync frappe.model.sync.sync_all(verbose=verbose) frappe.translate.clear_cache() sync_fixtures() sync_desktop_icons() # syncs statics render.clear_cache() if rebuild_website: statics.sync(verbose=verbose).start(True) else: statics.sync_statics() frappe.db.commit() clear_notifications() frappe.publish_realtime("version-update")
def migrate(verbose=True, rebuild_website=False): '''Migrate all apps to the latest version, will: - run before migrate hooks - run patches - sync doctypes (schema) - sync fixtures - sync desktop icons - sync web pages (from /www) - sync web pages (from /www) - run after migrate hooks ''' touched_tables_file = frappe.get_site_path('touched_tables.json') if os.path.exists(touched_tables_file): os.remove(touched_tables_file) try: frappe.flags.touched_tables = set() frappe.flags.in_migrate = True clear_global_cache() #run before_migrate hooks for app in frappe.get_installed_apps(): for fn in frappe.get_hooks('before_migrate', app_name=app): frappe.get_attr(fn)() # run patches frappe.modules.patch_handler.run_all() # sync frappe.model.sync.sync_all(verbose=verbose) frappe.translate.clear_cache() sync_fixtures() sync_customizations() sync_languages() frappe.get_doc('Portal Settings', 'Portal Settings').sync_menu() # syncs statics render.clear_cache() # add static pages to global search global_search.update_global_search_for_all_web_pages() #run after_migrate hooks for app in frappe.get_installed_apps(): for fn in frappe.get_hooks('after_migrate', app_name=app): frappe.get_attr(fn)() frappe.db.commit() clear_notifications() frappe.publish_realtime("version-update") frappe.flags.in_migrate = False finally: with open(touched_tables_file, 'w') as f: json.dump(list(frappe.flags.touched_tables), f, sort_keys=True, indent=4) frappe.flags.touched_tables.clear()
def migrate(verbose=True, rebuild_website=False): '''Migrate all apps to the latest version, will: - run before migrate hooks - run patches - sync doctypes (schema) - sync fixtures - sync desktop icons - sync web pages (from /www) - sync web pages (from /www) - run after migrate hooks ''' touched_tables_file = frappe.get_site_path('touched_tables.json') if os.path.exists(touched_tables_file): os.remove(touched_tables_file) try: frappe.flags.touched_tables = set() frappe.flags.in_migrate = True clear_global_cache() #run before_migrate hooks for app in frappe.get_installed_apps(): for fn in frappe.get_hooks('before_migrate', app_name=app): frappe.get_attr(fn)() # run patches frappe.modules.patch_handler.run_all() # sync frappe.model.sync.sync_all(verbose=verbose) frappe.translate.clear_cache() sync_fixtures() sync_customizations() sync_desktop_icons() sync_languages() frappe.get_doc('Portal Settings', 'Portal Settings').sync_menu() # syncs statics render.clear_cache() # add static pages to global search router.sync_global_search() #run after_migrate hooks for app in frappe.get_installed_apps(): for fn in frappe.get_hooks('after_migrate', app_name=app): frappe.get_attr(fn)() frappe.db.commit() clear_notifications() frappe.publish_realtime("version-update") frappe.flags.in_migrate = False finally: with open(touched_tables_file, 'w') as f: json.dump(list(frappe.flags.touched_tables), f, sort_keys=True, indent=4) frappe.flags.touched_tables.clear()
def on_update(self): # clear new password self.share_with_self() clear_notifications(user=self.name) frappe.clear_cache(user=self.name) self.send_password_notifcation(self.__new_password) if not self.user_id and self.user_type=="System User": self.user_id = "USR-" + cstr(int(time.time())) + '-' + cstr(random.randint(1000,9999))
def on_update(self): # clear new password self.validate_user_limit() self.share_with_self() clear_notifications(user=self.name) frappe.clear_cache(user=self.name) self.send_password_notification(self.__new_password) if self.name not in ('Administrator', 'Guest') and not self.user_image: frappe.enqueue('frappe.core.doctype.user.user.update_gravatar', name=self.name)
def on_update(self): # clear new password self.share_with_self() clear_notifications(user=self.name) frappe.clear_cache(user=self.name) self.send_password_notifcation(self.__new_password) if not self.user_id and self.user_type == "System User": self.user_id = "USR-" + cstr(int(time.time())) + '-' + cstr( random.randint(1000, 9999))
def before_submit(self): if not self.doctypes_to_be_ignored: self.populate_doctypes_to_be_ignored_table() self.delete_bins() self.delete_lead_addresses() self.reset_company_values() clear_notifications() self.delete_company_transactions()
def clear_cache(): check_if_admin() # the following is a copy from frappe.commands.utils import frappe.website.render from frappe.desk.notifications import clear_notifications frappe.clear_cache() clear_notifications() frappe.website.render.clear_cache() return "cache-cleared"
def on_update(self): # clear new password self.share_with_self() clear_notifications(user=self.name) frappe.clear_cache(user=self.name) if self.__new_password: self.send_password_notification(self.__new_password) self.reset_password_key = '' create_contact(self, ignore_mandatory=True) if self.name not in ('Administrator', 'Guest') and not self.user_image: frappe.enqueue('frappe.core.doctype.user.user.update_gravatar', name=self.name)
def migrate(verbose=True, rebuild_website=False): '''Migrate all apps to the latest version, will: - run before migrate hooks - run patches - sync doctypes (schema) - sync fixtures - sync desktop icons - sync web pages (from /www) - sync web pages (from /www) - run after migrate hooks ''' frappe.flags.in_migrate = True clear_global_cache() #run before_migrate hooks for app in frappe.get_installed_apps(): for fn in frappe.get_hooks('before_migrate', app_name=app): frappe.get_attr(fn)() # run patches frappe.modules.patch_handler.run_all() # sync frappe.model.sync.sync_all(verbose=verbose) frappe.translate.clear_cache() sync_fixtures() sync_customizations() sync_desktop_icons() sync_languages() frappe.get_doc('Portal Settings', 'Portal Settings').sync_menu() # syncs statics render.clear_cache() # add static pages to global search router.sync_global_search() #run after_migrate hooks for app in frappe.get_installed_apps(): for fn in frappe.get_hooks('after_migrate', app_name=app): frappe.get_attr(fn)() frappe.db.commit() if not frappe.conf.get('global_help_setup'): # sync help if not set as global frappe.utils.help.sync() clear_notifications() frappe.publish_realtime("version-update") frappe.flags.in_migrate = False
def clear_cache(context): "Clear cache, doctype cache and defaults" import frappe.sessions import frappe.website.render from frappe.desk.notifications import clear_notifications for site in context.sites: try: frappe.connect(site) frappe.clear_cache() clear_notifications() frappe.website.render.clear_cache() finally: frappe.destroy()
def on_update(self): # clear new password self.share_with_self() clear_notifications(user=self.name) frappe.clear_cache(user=self.name) self.send_password_notification(self.__new_password) create_contact(self, ignore_mandatory=True) if self.name not in ('Administrator', 'Guest') and not self.user_image: frappe.enqueue('frappe.core.doctype.user.user.update_gravatar', name=self.name) if self.has_value_changed('enabled'): frappe.cache().delete_key('enabled_users')
def on_update(self): # clear new password self.share_with_self() clear_notifications(user=self.name) frappe.clear_cache(user=self.name) self.send_password_notification(self.__new_password) frappe.enqueue('frappe.core.doctype.user.user.create_contact', user=self, ignore_mandatory=True, now=frappe.flags.in_test or frappe.flags.in_install) if self.name not in ('Administrator', 'Guest') and not self.user_image: frappe.enqueue('frappe.core.doctype.user.user.update_gravatar', name=self.name)
def clear_cache(context): "Clear cache, doctype cache and defaults" import frappe.sessions from frappe.website.utils import clear_website_cache from frappe.desk.notifications import clear_notifications for site in context.sites: try: frappe.connect(site) frappe.clear_cache() clear_notifications() clear_website_cache() finally: frappe.destroy() if not context.sites: raise SiteNotSpecifiedError
def on_update(self): frappe.defaults.set_user_default("company", self.default_company, user=self.name) # clear new password self.validate_user_limit() self.share_with_self() clear_notifications(user=self.name) frappe.clear_cache(user=self.name) self.send_password_notification(self.__new_password) create_contact(self, ignore_mandatory=True) if self.name not in ('Administrator', 'Guest') and not self.user_image: frappe.enqueue('frappe.core.doctype.user.user.update_gravatar', name=self.name)
def migrate(verbose=True, rebuild_website=False): '''Migrate all apps to the latest version, will: - run before migrate hooks - run patches - sync doctypes (schema) - sync fixtures - sync desktop icons - sync web pages (from /www) - sync web pages (from /www) - run after migrate hooks ''' frappe.flags.in_migrate = True clear_global_cache() #run before_migrate hooks for app in frappe.get_installed_apps(): for fn in frappe.get_hooks('before_migrate', app_name=app): frappe.get_attr(fn)() # run patches frappe.modules.patch_handler.run_all() # sync frappe.model.sync.sync_all(verbose=verbose) frappe.translate.clear_cache() sync_fixtures() sync_customizations() sync_desktop_icons() sync_languages() frappe.get_doc('Portal Settings', 'Portal Settings').sync_menu() # syncs statics render.clear_cache() # add static pages to global search router.sync_global_search() #run after_migrate hooks for app in frappe.get_installed_apps(): for fn in frappe.get_hooks('after_migrate', app_name=app): frappe.get_attr(fn)() frappe.db.commit() clear_notifications() frappe.publish_realtime("version-update") frappe.flags.in_migrate = False
def clear_user_cache(user=None): cache = frappe.cache() # this will automatically reload the global cache # so it is important to clear this first clear_notifications(user) if user: for name in user_cache_keys: cache.hdel(name, user) cache.delete_keys("user:" + user) clear_defaults_cache(user) else: for name in user_cache_keys: cache.delete_key(name) clear_defaults_cache() clear_global_cache()
def clear_cache(user=None): cache = frappe.cache() groups = ("bootinfo", "user_recent", "roles", "user_doc", "lang", "defaults", "user_permissions", "roles", "home_page", "linked_with", "desktop_icons", 'portal_menu_items') if user: for name in groups: cache.hdel(name, user) cache.delete_keys("user:" + user) frappe.defaults.clear_cache(user) else: for name in groups: cache.delete_key(name) clear_global_cache() frappe.defaults.clear_cache() clear_notifications(user)
def clear_cache(user=None): cache = frappe.cache() groups = ("bootinfo", "user_recent", "user_roles", "user_doc", "lang", "defaults", "user_permissions", "roles", "home_page", "linked_with", "desktop_icons", 'portal_menu_items') if user: for name in groups: cache.hdel(name, user) cache.delete_keys("user:" + user) frappe.defaults.clear_cache(user) else: for name in groups: cache.delete_key(name, user) clear_global_cache() frappe.defaults.clear_cache() clear_notifications(user)
def clear_user_cache(user=None): cache = frappe.cache() groups = ("bootinfo", "user_recent", "roles", "user_doc", "lang", "defaults", "user_permissions", "home_page", "linked_with", "desktop_icons", 'portal_menu_items') # this will automatically reload the global cache # so it is important to clear this first clear_notifications(user) if user: for name in groups: cache.hdel(name, user) cache.delete_keys("user:" + user) clear_defaults_cache(user) else: for name in groups: cache.delete_key(name) clear_defaults_cache() clear_global_cache()
def delete_company_transactions(company_name): frappe.only_for("System Manager") doc = frappe.get_doc("Company", company_name) if frappe.session.user != doc.owner: frappe.throw( _("Transactions can only be deleted by the creator of the Company" ), frappe.PermissionError) delete_bins(company_name) delete_time_logs(company_name) for doctype in frappe.db.sql_list("""select parent from tabDocField where fieldtype='Link' and options='Company'"""): if doctype not in ("Account", "Cost Center", "Warehouse", "Budget Detail", "Party Account", "Employee"): delete_for_doctype(doctype, company_name) # Clear notification counts clear_notifications()
def migrate(verbose=True, rebuild_website=False): '''Migrate all apps to the latest version, will: - run patches - sync doctypes (schema) - sync fixtures - sync desktop icons - sync web pages (from /www)''' frappe.flags.in_migrate = True clear_global_cache() # run patches frappe.modules.patch_handler.run_all() # sync frappe.model.sync.sync_all(verbose=verbose) frappe.translate.clear_cache() sync_fixtures() sync_customizations() sync_desktop_icons() sync_languages() frappe.get_doc('Portal Settings', 'Portal Settings').sync_menu() # syncs statics render.clear_cache() # add static pages to global search router.sync_global_search() frappe.db.commit() if not frappe.conf.get('global_help_setup'): # sync help if not set as global frappe.utils.help.sync() clear_notifications() frappe.publish_realtime("version-update") frappe.flags.in_migrate = False
def delete_company_transactions(company_name): frappe.only_for("System Manager") doc = frappe.get_doc("Company", company_name) if frappe.session.user != doc.owner: frappe.throw( _("Transactions can only be deleted by the creator of the Company" ), frappe.PermissionError) delete_bins(company_name) delete_lead_addresses(company_name) for doctype in frappe.db.sql_list("""select parent from tabDocField where fieldtype='Link' and options='Company'"""): if doctype not in ("Account", "Party Account"): delete_for_doctype(doctype, company_name) # reset company values doc.total_monthly_sales = 0 doc.sales_monthly_history = None doc.save() # Clear notification counts clear_notifications()
def _migrate(site, verbose=False): import frappe.modules.patch_handler import frappe.model.sync from frappe.utils.fixtures import sync_fixtures import frappe.translate from frappe.desk.notifications import clear_notifications frappe.init(site=site) frappe.connect() try: prepare_for_update() # run patches frappe.modules.patch_handler.run_all() # sync frappe.model.sync.sync_all(verbose=verbose) frappe.translate.clear_cache() sync_fixtures() clear_notifications() finally: frappe.publish_realtime("version-update") frappe.destroy()
def _clear_cache(parent): if parent in common_keys: frappe.clear_cache() else: clear_notifications(user=parent) frappe.clear_cache(user=parent)
def migrate(verbose=True, skip_failing=False, skip_search_index=False): '''Migrate all apps to the current version, will: - run before migrate hooks - run patches - sync doctypes (schema) - sync dashboards - sync fixtures - sync desktop icons - sync web pages (from /www) - sync web pages (from /www) - run after migrate hooks ''' service_status = check_connection(redis_services=["redis_cache"]) if False in service_status.values(): for service in service_status: if not service_status.get(service, True): print("{} service is not running.".format(service)) print("""Cannot run bench migrate without the services running. If you are running bench in development mode, make sure that bench is running: $ bench start Otherwise, check the server logs and ensure that all the required services are running.""" ) sys.exit(1) touched_tables_file = frappe.get_site_path('touched_tables.json') if os.path.exists(touched_tables_file): os.remove(touched_tables_file) try: frappe.flags.touched_tables = set() frappe.flags.in_migrate = True clear_global_cache() #run before_migrate hooks for app in frappe.get_installed_apps(): for fn in frappe.get_hooks('before_migrate', app_name=app): frappe.get_attr(fn)() # run patches frappe.modules.patch_handler.run_all(skip_failing) # sync frappe.model.sync.sync_all(verbose=verbose) frappe.translate.clear_cache() sync_jobs() sync_fixtures() sync_dashboards() sync_customizations() sync_languages() frappe.get_doc('Portal Settings', 'Portal Settings').sync_menu() # syncs statics render.clear_cache() # updating installed applications data frappe.get_single('Installed Applications').update_versions() #run after_migrate hooks for app in frappe.get_installed_apps(): for fn in frappe.get_hooks('after_migrate', app_name=app): frappe.get_attr(fn)() # build web_routes index if not skip_search_index: # Run this last as it updates the current session print('Building search index for {}'.format(frappe.local.site)) build_index_for_all_routes() frappe.db.commit() clear_notifications() frappe.publish_realtime("version-update") frappe.flags.in_migrate = False finally: with open(touched_tables_file, 'w') as f: json.dump(list(frappe.flags.touched_tables), f, sort_keys=True, indent=4) frappe.flags.touched_tables.clear()