"use strict";(self.webpackChunkapp=self.webpackChunkapp||[]).push([[8728],{8728:(i,e,r)=>{r.r(e),r.d(e,{AddonModWikiSyncCronHandler:()=>c,AddonModWikiSyncCronHandlerLazyService:()=>s});var n=r(79555),t=r(22357),d=r(80629),o=r(54438);let s=(()=>{var i;class AddonModWikiSyncCronHandlerLazyService extends d.l{execute(i,e){return t.i.syncAllWikis(i,e)}getInterval(){return t.i.syncInterval}}return(i=AddonModWikiSyncCronHandlerLazyService).ɵfac=(()=>{let e;return function AddonModWikiSyncCronHandlerLazyService_Factory(r){return(e||(e=o.xGo(i)))(r||i)}})(),i.ɵprov=o.jDH({token:i,factory:i.ɵfac,providedIn:"root"}),AddonModWikiSyncCronHandlerLazyService})();const c=(0,n.Qd)(s)},22357:(i,e,r)=>{r.d(e,{i:()=>f});var n=r(10467),t=r(42008),d=r(49446),o=r(97254),s=r(94455),c=r(15221),u=r(52749),a=r(48966),l=r(43411),y=r(79555),k=r(49882),g=r(67981),w=r(59379),p=r(51069),S=r(55554),v=r(54438);let b=(()=>{var i;class AddonModWikiSyncProvider extends t.l{constructor(){super("AddonModWikiSyncProvider"),this.componentTranslatableString="wiki"}getSubwikiBlockId(i,e,r,n){return(i=w.W.convertToPositiveNumber(i))&&i>0?String(i):`${e=w.W.convertToPositiveNumber(e)}:${r=w.W.convertToPositiveNumber(r)}:${n=w.W.convertToPositiveNumber(n)}`}syncAllWikis(i,e){return this.syncOnSites("all wikis",(i=>this.syncAllWikisFunc(!!e,i)),i)}syncAllWikisFunc(i,e){var r=this;return(0,n.A)((function*(){const t=yield w.W.getAllNewPages(e),d={};yield Promise.all(t.map(function(){var t=(0,n.A)((function*(n){const t=r.getSubwikiBlockId(n.subwikiid,n.wikiid,n.userid,n.groupid);if(d[t])return;d[t]=!0;const o=i?yield r.syncSubwiki(n.subwikiid,n.wikiid,n.userid,n.groupid,e):yield r.syncSubwikiIfNeeded(n.subwikiid,n.wikiid,n.userid,n.groupid,e);null!=o&&o.updated&&k.z.trigger(p.mb,{siteId:e,subwikiId:n.subwikiid,wikiId:n.wikiid,userId:n.userid,groupId:n.groupid,created:o.created,discarded:o.discarded,warnings:o.warnings})}));return function(i){return t.apply(this,arguments)}}()))}))()}syncSubwikiIfNeeded(i,e,r,t,d){var o=this;return(0,n.A)((function*(){const n=o.getSubwikiBlockId(i,e,r,t);if(yield o.isSyncNeeded(n,d))return o.syncSubwiki(i,e,r,t,d)}))()}syncSubwiki(i,e,r,n,d){d=d||u.CoreSites.getCurrentSiteId();const o=this.getSubwikiBlockId(i,e,r,n),s=this.getOngoingSync(o,d);if(s)return s;if(a.CoreSync.isBlocked(p.Rv,o,d))throw this.logger.debug(`Cannot sync subwiki ${o} because it is blocked.`),new t.D(y.HT.instant("core.errorsyncblocked",{$a:this.componentTranslate}));return this.logger.debug(`Try to sync subwiki ${o}`),this.addOngoingSync(o,this.performSyncSubwiki(i,e,r,n,d),d)}performSyncSubwiki(i,e,r,t,o){var c=this;return(0,n.A)((function*(){const u={warnings:[],updated:!1,created:[],discarded:[]},a=c.getSubwikiBlockId(i,e,r,t),y=yield S.g.ignoreErrors(w.W.getSubwikiNewPages(i,e,r,t,o),[]);if(!y||!y.length)return yield S.g.ignoreErrors(c.setSyncTime(a,o)),u;if(!s.WE.isOnline())throw new d.CoreNetworkError;return yield Promise.all(y.map(function(){var d=(0,n.A)((function*(n){try{const d=yield g.N.newPageOnline(n.title,n.cachedcontent,{subwikiId:i,wikiId:e,userId:r,groupId:t,siteId:o});u.updated=!0,u.created.push({pageId:d,title:n.title}),yield w.W.deleteNewPage(n.title,i,e,r,t,o)}catch(d){if(!l.CoreWSError.isWebServiceError(d))throw d;yield w.W.deleteNewPage(n.title,i,e,r,t,o),u.updated=!0;const s=c.getOfflineDataDeletedWarning(n.title,d);u.discarded.push({title:n.title,warning:s}),u.warnings.push(s)}}));return function(i){return d.apply(this,arguments)}}())),yield S.g.ignoreErrors(c.setSyncTime(a,o)),u}))()}syncWiki(i,e,r,t){var d=this;return(0,n.A)((function*(){t=t||u.CoreSites.getCurrentSiteId(),yield S.g.ignoreErrors(o.CoreCourseLogHelper.syncActivity(p.dD,i,t));const s=yield g.N.getSubwikis(i,{cmId:r,siteId:t}),a={warnings:[],updated:!1,subwikis:{},siteId:t};if(yield Promise.all(s.map(function(){var i=(0,n.A)((function*(i){const e=yield d.syncSubwiki(i.id,i.wikiid,i.userid,i.groupid,t);e&&e.updated&&(a.warnings=a.warnings.concat(e.warnings),a.updated=!0,a.subwikis[i.id]={created:e.created,discarded:e.discarded})}));return function(e){return i.apply(this,arguments)}}())),a.updated){const n=[];i&&(n.push(g.N.invalidateSubwikis(i)),n.push(g.N.invalidateSubwikiPages(i)),n.push(g.N.invalidateSubwikiFiles(i))),e&&n.push(g.N.invalidateWikiData(e)),r&&(n.push(c.CoreGroups.invalidateActivityAllowedGroups(r)),n.push(c.CoreGroups.invalidateActivityGroupMode(r))),yield S.g.ignoreErrors(Promise.all(n))}return a}))()}}return(i=AddonModWikiSyncProvider).ɵfac=function AddonModWikiSyncProvider_Factory(e){return new(e||i)},i.ɵprov=v.jDH({token:i,factory:i.ɵfac,providedIn:"root"}),AddonModWikiSyncProvider})();const f=(0,y.Qd)(b)}}]);