Browse Source

refactor(core): Make AJAX cron script work without jQuery

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
pull/46009/head
Ferdinand Thiessen 1 year ago
parent
commit
4d6a21a379
No known key found for this signature in database GPG Key ID: 45FAE7268762B400
  1. 2
      core/Listener/BeforeTemplateRenderedListener.php
  2. 13
      core/js/backgroundjobs.js
  3. 1
      core/js/public/publicpage.js
  4. 18
      core/src/ajax-cron.ts
  5. 1
      webpack.modules.js

2
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');
}
}
}

13
core/js/backgroundjobs.js

@ -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'
});
});

1
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');

18
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 })
}
})

1
webpack.modules.js

@ -11,6 +11,7 @@ module.exports = {
init: path.join(__dirname, 'apps/comments/src', 'init.ts'),
},
core: {
'ajax-cron': path.join(__dirname, 'core/src', 'ajax-cron.ts'),
files_client: path.join(__dirname, 'core/src', 'files/client.js'),
files_fileinfo: path.join(__dirname, 'core/src', 'files/fileinfo.js'),
install: path.join(__dirname, 'core/src', 'install.js'),

Loading…
Cancel
Save