示例#1
0
def install_app(name, verbose=False, set_as_patched=True):
    frappe.flags.in_install = name
    frappe.flags.ignore_in_install = False

    frappe.clear_cache()
    app_hooks = frappe.get_hooks(app_name=name)
    installed_apps = frappe.get_installed_apps()

    # install pre-requisites
    if app_hooks.required_apps:
        for app in app_hooks.required_apps:
            install_app(app, verbose=verbose)

    frappe.flags.in_install = name
    frappe.clear_cache()

    if name not in frappe.get_all_apps():
        raise Exception("App not in apps.txt")

    if name in installed_apps:
        frappe.msgprint(_("App {0} already installed").format(name))
        return

    print("\nInstalling {0}...".format(name))

    if name != "frappe":
        frappe.only_for("System Manager")

    for before_install in app_hooks.before_install or []:
        out = frappe.get_attr(before_install)()
        if out == False:
            return

    if name != "frappe":
        add_module_defs(name)

    sync_for(name,
             force=True,
             sync_everything=True,
             verbose=verbose,
             reset_permissions=True)

    add_to_installed_apps(name)

    frappe.get_doc('Portal Settings', 'Portal Settings').sync_menu()

    if set_as_patched:
        set_all_patches_as_completed(name)

    for after_install in app_hooks.after_install or []:
        frappe.get_attr(after_install)()

    sync_jobs()
    sync_fixtures(name)
    sync_customizations(name)

    for after_sync in app_hooks.after_sync or []:
        frappe.get_attr(after_sync)()  #

    frappe.flags.in_install = False
示例#2
0
def migrate(verbose=True, rebuild_website=False, skip_failing=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(skip_failing)
		# sync
		frappe.model.sync.sync_all(verbose=verbose)
		frappe.translate.clear_cache()
		sync_jobs()
		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 test_sync_jobs(self):
        all_job = frappe.get_doc('Scheduled Job Type',
                                 dict(method='frappe.email.queue.flush'))
        self.assertEqual(all_job.frequency, 'All')

        daily_job = frappe.get_doc(
            'Scheduled Job Type',
            dict(method='frappe.email.queue.set_expiry_for_email_queue'))
        self.assertEqual(daily_job.frequency, 'Daily')

        # check if cron jobs are synced
        cron_job = frappe.get_doc(
            'Scheduled Job Type',
            dict(method='frappe.oauth.delete_oauth2_data'))
        self.assertEqual(cron_job.frequency, 'Cron')
        self.assertEqual(cron_job.cron_format, '0/15 * * * *')

        # check if jobs are synced after change in hooks
        updated_scheduler_events = {"hourly": ["frappe.email.queue.flush"]}
        sync_jobs(updated_scheduler_events)
        updated_scheduled_job = frappe.get_doc(
            "Scheduled Job Type", {"method": "frappe.email.queue.flush"})
        self.assertEqual(updated_scheduled_job.frequency, "Hourly")
示例#4
0
 def setUp(self):
     purge_pending_jobs()
     if not frappe.get_all('Scheduled Job Type', limit=1):
         sync_jobs()
示例#5
0
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()
 def setUp(self):
     frappe.db.rollback()
     frappe.db.sql('truncate `tabScheduled Job Type`')
     sync_jobs()
     frappe.db.commit()
示例#7
0
	def setUp(self):
		if not frappe.get_all('Scheduled Job Type', limit=1):
			sync_jobs()
 def setUp(self):
     if not frappe.get_all('Scheduled Job Type', limit=1):
         frappe.db.rollback()
         frappe.db.sql('truncate `tabScheduled Job Type`')
         sync_jobs()
         frappe.db.commit()