MOBILE-3713 login: Migrate login cron handler
parent
c99487ef5e
commit
49f2043f42
|
@ -45,17 +45,17 @@ export class AddonNotesSyncProvider extends CoreSyncBaseProvider<AddonNotesSyncR
|
||||||
* @return Promise resolved if sync is successful, rejected if sync fails.
|
* @return Promise resolved if sync is successful, rejected if sync fails.
|
||||||
*/
|
*/
|
||||||
syncAllNotes(siteId?: string, force?: boolean): Promise<void> {
|
syncAllNotes(siteId?: string, force?: boolean): Promise<void> {
|
||||||
return this.syncOnSites('all notes', this.syncAllNotesFunc.bind(this, siteId, force), siteId);
|
return this.syncOnSites('all notes', this.syncAllNotesFunc.bind(this, !!force), siteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Synchronize all the notes in a certain site
|
* Synchronize all the notes in a certain site
|
||||||
*
|
*
|
||||||
* @param siteId Site ID to sync.
|
|
||||||
* @param force Wether to force sync not depending on last execution.
|
* @param force Wether to force sync not depending on last execution.
|
||||||
|
* @param siteId Site ID to sync.
|
||||||
* @return Promise resolved if sync is successful, rejected if sync fails.
|
* @return Promise resolved if sync is successful, rejected if sync fails.
|
||||||
*/
|
*/
|
||||||
protected async syncAllNotesFunc(siteId: string, force: boolean): Promise<void> {
|
protected async syncAllNotesFunc(force: boolean, siteId: string): Promise<void> {
|
||||||
const notesArray = await Promise.all([
|
const notesArray = await Promise.all([
|
||||||
AddonNotesOffline.getAllNotes(siteId),
|
AddonNotesOffline.getAllNotes(siteId),
|
||||||
AddonNotesOffline.getAllDeletedNotes(siteId),
|
AddonNotesOffline.getAllDeletedNotes(siteId),
|
||||||
|
|
|
@ -44,17 +44,17 @@ export class CoreCommentsSyncProvider extends CoreSyncBaseProvider<CoreCommentsS
|
||||||
* @return Promise resolved if sync is successful, rejected if sync fails.
|
* @return Promise resolved if sync is successful, rejected if sync fails.
|
||||||
*/
|
*/
|
||||||
syncAllComments(siteId?: string, force?: boolean): Promise<void> {
|
syncAllComments(siteId?: string, force?: boolean): Promise<void> {
|
||||||
return this.syncOnSites('all comments', this.syncAllCommentsFunc.bind(this, siteId, force), siteId);
|
return this.syncOnSites('all comments', this.syncAllCommentsFunc.bind(this, !!force), siteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Synchronize all the comments in a certain site
|
* Synchronize all the comments in a certain site
|
||||||
*
|
*
|
||||||
* @param siteId Site ID to sync.
|
|
||||||
* @param force Wether to force sync not depending on last execution.
|
* @param force Wether to force sync not depending on last execution.
|
||||||
|
* @param siteId Site ID to sync.
|
||||||
* @return Promise resolved if sync is successful, rejected if sync fails.
|
* @return Promise resolved if sync is successful, rejected if sync fails.
|
||||||
*/
|
*/
|
||||||
private async syncAllCommentsFunc(siteId: string, force: boolean): Promise<void> {
|
private async syncAllCommentsFunc(force: boolean, siteId: string): Promise<void> {
|
||||||
const comments = await CoreCommentsOffline.getAllComments(siteId);
|
const comments = await CoreCommentsOffline.getAllComments(siteId);
|
||||||
|
|
||||||
const commentsUnique: { [syncId: string]: (CoreCommentsDBRecord | CoreCommentsDeletedDBRecord) } = {};
|
const commentsUnique: { [syncId: string]: (CoreCommentsDBRecord | CoreCommentsDeletedDBRecord) } = {};
|
||||||
|
|
|
@ -12,12 +12,14 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { NgModule } from '@angular/core';
|
import { APP_INITIALIZER, NgModule } from '@angular/core';
|
||||||
import { Routes } from '@angular/router';
|
import { Routes } from '@angular/router';
|
||||||
|
|
||||||
import { AppRoutingModule } from '@/app/app-routing.module';
|
import { AppRoutingModule } from '@/app/app-routing.module';
|
||||||
import { CoreLoginHelperProvider } from './services/login-helper';
|
import { CoreLoginHelperProvider } from './services/login-helper';
|
||||||
import { CoreRedirectGuard } from '@guards/redirect';
|
import { CoreRedirectGuard } from '@guards/redirect';
|
||||||
|
import { CoreLoginCronHandler } from './services/handlers/cron';
|
||||||
|
import { CoreCronDelegate } from '@services/cron';
|
||||||
|
|
||||||
export const CORE_LOGIN_SERVICES = [
|
export const CORE_LOGIN_SERVICES = [
|
||||||
CoreLoginHelperProvider,
|
CoreLoginHelperProvider,
|
||||||
|
@ -34,5 +36,15 @@ const appRoutes: Routes = [
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [AppRoutingModule.forChild(appRoutes)],
|
imports: [AppRoutingModule.forChild(appRoutes)],
|
||||||
|
providers: [
|
||||||
|
{
|
||||||
|
provide: APP_INITIALIZER,
|
||||||
|
multi: true,
|
||||||
|
deps: [],
|
||||||
|
useFactory: () => async () => {
|
||||||
|
CoreCronDelegate.register(CoreLoginCronHandler.instance);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
})
|
})
|
||||||
export class CoreLoginModule {}
|
export class CoreLoginModule {}
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
// (C) Copyright 2015 Moodle Pty Ltd.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { CoreSitePublicConfigResponse } from '@classes/site';
|
||||||
|
import { CoreCronHandler } from '@services/cron';
|
||||||
|
import { CoreSites } from '@services/sites';
|
||||||
|
import { CoreUtils } from '@services/utils/utils';
|
||||||
|
import { makeSingleton } from '@singletons';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cron handler to log out sites when does not meet the app requirements.
|
||||||
|
*/
|
||||||
|
@Injectable({ providedIn: 'root' })
|
||||||
|
export class CoreLoginCronHandlerService implements CoreCronHandler {
|
||||||
|
|
||||||
|
name = 'CoreLoginCronHandler';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
async execute(siteId?: string): Promise<void> {
|
||||||
|
siteId = siteId || CoreSites.getCurrentSiteId();
|
||||||
|
if (!siteId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check logged in site minimun required version.
|
||||||
|
// Do not check twice in the same 10 minutes.
|
||||||
|
const site = await CoreSites.getSite(siteId);
|
||||||
|
|
||||||
|
const config = await CoreUtils.ignoreErrors(site.getPublicConfig(), <Partial<CoreSitePublicConfigResponse>> {});
|
||||||
|
|
||||||
|
CoreUtils.ignoreErrors(CoreSites.checkApplication(<any> config));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
isSync(): boolean {
|
||||||
|
// Defined to true to be checked on sync site.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export const CoreLoginCronHandler = makeSingleton(CoreLoginCronHandlerService);
|
Loading…
Reference in New Issue