From 4d6a21a3795355a4e94d60dcc468db81fdc4a47e Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Thu, 20 Jun 2024 00:34:43 +0200 Subject: refactor(core): Make AJAX cron script work without jQuery Signed-off-by: Ferdinand Thiessen --- core/Listener/BeforeTemplateRenderedListener.php | 2 +- core/js/backgroundjobs.js | 13 ------------- core/js/public/publicpage.js | 1 - core/src/ajax-cron.ts | 18 ++++++++++++++++++ 4 files changed, 19 insertions(+), 15 deletions(-) delete mode 100644 core/js/backgroundjobs.js create mode 100644 core/src/ajax-cron.ts (limited to 'core') diff --git a/core/Listener/BeforeTemplateRenderedListener.php b/core/Listener/BeforeTemplateRenderedListener.php index 0eff924d1f8..664138518e0 100644 --- a/core/Listener/BeforeTemplateRenderedListener.php +++ b/core/Listener/BeforeTemplateRenderedListener.php @@ -54,7 +54,7 @@ class BeforeTemplateRenderedListener implements IEventListener { // If installed and background job is set to ajax, add dedicated script if ($this->config->getAppValue('core', 'backgroundjobs_mode', 'ajax') == 'ajax') { - Util::addScript('core', 'backgroundjobs'); + Util::addScript('core', 'ajax-cron'); } } } diff --git a/core/js/backgroundjobs.js b/core/js/backgroundjobs.js deleted file mode 100644 index ec5ae24d262..00000000000 --- a/core/js/backgroundjobs.js +++ /dev/null @@ -1,13 +0,0 @@ -/** - * SPDX-FileCopyrightText: 2012 Jakob Sack owncloud@jakobsack.de - * SPDX-License-Identifier: AGPL-3.0-or-later - */ - -// start worker once page has loaded -window.addEventListener('DOMContentLoaded', function(){ - $.get( OC.getRootPath()+'/cron.php' ); - - $('.section .icon-info').tooltip({ - placement: 'right' - }); -}); diff --git a/core/js/public/publicpage.js b/core/js/public/publicpage.js index af473045413..340fb56d9f1 100644 --- a/core/js/public/publicpage.js +++ b/core/js/public/publicpage.js @@ -14,7 +14,6 @@ window.addEventListener('DOMContentLoaded', function () { $('#remote_address').focus(); }); - $(document).mouseup(function(e) { var toggle = $('#body-public').find('.header-right .menutoggle'); var container = toggle.next('.popovermenu'); diff --git a/core/src/ajax-cron.ts b/core/src/ajax-cron.ts new file mode 100644 index 00000000000..d903a3596ea --- /dev/null +++ b/core/src/ajax-cron.ts @@ -0,0 +1,18 @@ +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +import { getRootUrl } from '@nextcloud/router' +import logger from './logger' + +window.addEventListener('DOMContentLoaded', async () => { + // When the page is loaded send GET to the cron endpoint to trigger background jobs + try { + logger.debug('Running web cron') + await window.fetch(`${getRootUrl()}/cron.php`) + logger.debug('Web cron successfull') + } catch (e) { + logger.debug('Running web cron failed', { error: e }) + } +}) -- cgit v1.2.3