diff --git a/config.xml b/config.xml
index b2055031e..57488f7ba 100644
--- a/config.xml
+++ b/config.xml
@@ -37,6 +37,7 @@
+
diff --git a/src/addon/mod/book/components/index/index.ts b/src/addon/mod/book/components/index/index.ts
index 1dd820508..1b154d373 100644
--- a/src/addon/mod/book/components/index/index.ts
+++ b/src/addon/mod/book/components/index/index.ts
@@ -186,7 +186,7 @@ export class AddonModBookIndexComponent extends CoreCourseModuleMainResourceComp
// Chapter loaded, log view. We don't return the promise because we don't want to block the user for this.
this.bookProvider.logView(this.module.instance, chapterId, this.module.name).then(() => {
// Module is completed when last chapter is viewed, so we only check completion if the last is reached.
- if (!this.nextChapter) {
+ if (this.nextChapter == '0') {
this.courseProvider.checkModuleCompletion(this.courseId, this.module.completiondata);
}
}).catch(() => {
diff --git a/src/classes/site.ts b/src/classes/site.ts
index afafeada4..9253f83e6 100644
--- a/src/classes/site.ts
+++ b/src/classes/site.ts
@@ -680,6 +680,8 @@ export class CoreSite {
(error.errorcode == 'accessexception' && error.message.indexOf('Invalid token - token expired') > -1)) {
if (initialToken !== this.token && !retrying) {
// Token has changed, retry with the new token.
+ preSets.getFromCache = false; // Don't check cache now. Also, it will skip ongoingRequests.
+
return this.request(method, data, preSets, true);
} else if (this.appProvider.isSSOAuthenticationOngoing()) {
// There's an SSO authentication ongoing, wait for it to finish and try again.
diff --git a/src/providers/sites.ts b/src/providers/sites.ts
index de7424c1b..19f117a6a 100644
--- a/src/providers/sites.ts
+++ b/src/providers/sites.ts
@@ -582,22 +582,48 @@ export class CoreSitesProvider {
}
// Create a "candidate" site to fetch the site info.
- const candidateSite = this.sitesFactory.makeSite(undefined, siteUrl, token, undefined, privateToken);
+ let candidateSite = this.sitesFactory.makeSite(undefined, siteUrl, token, undefined, privateToken),
+ isNewSite = true;
return candidateSite.fetchSiteInfo().then((info) => {
const result = this.isValidMoodleVersion(info);
if (result == this.VALID_VERSION) {
- // Set site ID and info.
const siteId = this.createSiteID(info.siteurl, info.username);
- candidateSite.setId(siteId);
- candidateSite.setInfo(info);
- // Create database tables before login and before any WS call.
- return this.migrateSiteSchemas(candidateSite).then(() => {
+ // Check if the site already exists.
+ return this.getSite(siteId).catch(() => {
+ // Not exists.
+ }).then((site) => {
+ if (site) {
+ // Site already exists, update its data and use it.
+ isNewSite = false;
+ candidateSite = site;
+ candidateSite.setToken(token);
+ candidateSite.setPrivateToken(privateToken);
+ candidateSite.setInfo(info);
+
+ } else {
+ // New site, set site ID and info.
+ isNewSite = true;
+ candidateSite.setId(siteId);
+ candidateSite.setInfo(info);
+
+ // Create database tables before login and before any WS call.
+ return this.migrateSiteSchemas(candidateSite);
+ }
+
+ }).then(() => {
// Try to get the site config.
- return this.getSiteConfig(candidateSite).then((config) => {
- candidateSite.setConfig(config);
+ return this.getSiteConfig(candidateSite).catch((error) => {
+ // Ignore errors if it's not a new site, we'll use the config already stored.
+ if (isNewSite) {
+ return Promise.reject(error);
+ }
+ }).then((config) => {
+ if (typeof config != 'undefined') {
+ candidateSite.setConfig(config);
+ }
// Add site to sites list.
this.addSite(siteId, siteUrl, token, info, privateToken, config);