Skip to content

Commit c3ddf6e

Browse files
authored
Merge pull request #1958 from dpalou/MOBILE-3039
Mobile 3039
2 parents a92f4b8 + d0beca0 commit c3ddf6e

File tree

4 files changed

+38
-9
lines changed

4 files changed

+38
-9
lines changed

config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
<preference name="SplashMaintainAspectRatio" value="true" />
3838
<preference name="SplashShowOnlyFirstTime" value="false" />
3939
<preference name="LoadUrlTimeoutValue" value="60000" />
40+
<preference name="CustomURLSchemePluginClearsAndroidIntent" value="true" />
4041
<feature name="StatusBar">
4142
<param name="ios-package" onload="true" value="CDVStatusBar" />
4243
</feature>

src/addon/mod/book/components/index/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export class AddonModBookIndexComponent extends CoreCourseModuleMainResourceComp
186186
// Chapter loaded, log view. We don't return the promise because we don't want to block the user for this.
187187
this.bookProvider.logView(this.module.instance, chapterId, this.module.name).then(() => {
188188
// Module is completed when last chapter is viewed, so we only check completion if the last is reached.
189-
if (!this.nextChapter) {
189+
if (this.nextChapter == '0') {
190190
this.courseProvider.checkModuleCompletion(this.courseId, this.module.completiondata);
191191
}
192192
}).catch(() => {

src/classes/site.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,8 @@ export class CoreSite {
680680
(error.errorcode == 'accessexception' && error.message.indexOf('Invalid token - token expired') > -1)) {
681681
if (initialToken !== this.token && !retrying) {
682682
// Token has changed, retry with the new token.
683+
preSets.getFromCache = false; // Don't check cache now. Also, it will skip ongoingRequests.
684+
683685
return this.request(method, data, preSets, true);
684686
} else if (this.appProvider.isSSOAuthenticationOngoing()) {
685687
// There's an SSO authentication ongoing, wait for it to finish and try again.

src/providers/sites.ts

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -582,22 +582,48 @@ export class CoreSitesProvider {
582582
}
583583

584584
// Create a "candidate" site to fetch the site info.
585-
const candidateSite = this.sitesFactory.makeSite(undefined, siteUrl, token, undefined, privateToken);
585+
let candidateSite = this.sitesFactory.makeSite(undefined, siteUrl, token, undefined, privateToken),
586+
isNewSite = true;
586587

587588
return candidateSite.fetchSiteInfo().then((info) => {
588589
const result = this.isValidMoodleVersion(info);
589590
if (result == this.VALID_VERSION) {
590-
// Set site ID and info.
591591
const siteId = this.createSiteID(info.siteurl, info.username);
592-
candidateSite.setId(siteId);
593-
candidateSite.setInfo(info);
594592

595-
// Create database tables before login and before any WS call.
596-
return this.migrateSiteSchemas(candidateSite).then(() => {
593+
// Check if the site already exists.
594+
return this.getSite(siteId).catch(() => {
595+
// Not exists.
596+
}).then((site) => {
597+
if (site) {
598+
// Site already exists, update its data and use it.
599+
isNewSite = false;
600+
candidateSite = site;
601+
candidateSite.setToken(token);
602+
candidateSite.setPrivateToken(privateToken);
603+
candidateSite.setInfo(info);
604+
605+
} else {
606+
// New site, set site ID and info.
607+
isNewSite = true;
608+
candidateSite.setId(siteId);
609+
candidateSite.setInfo(info);
610+
611+
// Create database tables before login and before any WS call.
612+
return this.migrateSiteSchemas(candidateSite);
613+
}
614+
615+
}).then(() => {
597616

598617
// Try to get the site config.
599-
return this.getSiteConfig(candidateSite).then((config) => {
600-
candidateSite.setConfig(config);
618+
return this.getSiteConfig(candidateSite).catch((error) => {
619+
// Ignore errors if it's not a new site, we'll use the config already stored.
620+
if (isNewSite) {
621+
return Promise.reject(error);
622+
}
623+
}).then((config) => {
624+
if (typeof config != 'undefined') {
625+
candidateSite.setConfig(config);
626+
}
601627

602628
// Add site to sites list.
603629
this.addSite(siteId, siteUrl, token, info, privateToken, config);

0 commit comments

Comments
 (0)