Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions www/addons/calendar/services/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ angular.module('mm.addons.calendar')
* @return {Promise} Promise resolved when the event data is retrieved.
*/
self.getEventFromLocalDb = function(id) {
if (!$mmSite.isLoggedIn()) {
// Not logged in, we can't get the site DB. User logged out or session expired while an operation was ongoing.
return $q.reject();
}
return $mmSite.getDb().get(mmaCalendarEventsStore, id);
};

Expand Down Expand Up @@ -426,6 +430,11 @@ angular.module('mm.addons.calendar')
* @return {Promise} Promise resolved when the notification is updated.
*/
self.updateNotificationTime = function(event, time) {
if (!$mmSite.isLoggedIn()) {
// Not logged in, we can't get the site DB. User logged out or session expired while an operation was ongoing.
return $q.reject();
}

var db = $mmSite.getDb();

event.notificationtime = time;
Expand Down
5 changes: 5 additions & 0 deletions www/addons/mod_scorm/services/scorm_offline.js
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,11 @@ angular.module('mm.addons.mod_scorm')
userId = userId || $mmSite.getUserId();
scoData = scoData || {};

if (!$mmSite.isLoggedIn()) {
// Not logged in, we can't get the site DB. User logged out or session expired while an operation was ongoing.
return false;
}

var lessonStatusInserted = false,
scoUserData = scoData.userdata || {},
db = $mmSite.getDb();
Expand Down
23 changes: 17 additions & 6 deletions www/core/components/user/services/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ angular.module('mm.core.user')
* @return {Promise} Promise resolve when the user is deleted.
*/
self.deleteStoredUser = function(id) {
var db = $mmSite.getDb();
if (!$mmSite.isLoggedIn()) {
// Not logged in, we can't get the site DB. User logged out or session expired while an operation was ongoing.
return $q.reject();
}

self.invalidateUserCache(id); // Invalidate WS calls.
return db.remove(mmCoreUsersStore, parseInt(id));
return $mmSite.getDb().remove(mmCoreUsersStore, parseInt(id));
};

/**
Expand Down Expand Up @@ -155,8 +159,11 @@ angular.module('mm.core.user')
* @return {Promise} Promise resolve when the user is retrieved.
*/
self.getUserFromLocal = function(id) {
var db = $mmSite.getDb();
return db.get(mmCoreUsersStore, parseInt(id));
if (!$mmSite.isLoggedIn()) {
// Not logged in, we can't get the site DB. User logged out or session expired while an operation was ongoing.
return $q.reject();
}
return $mmSite.getDb().get(mmCoreUsersStore, parseInt(id));
};

/**
Expand Down Expand Up @@ -239,8 +246,12 @@ angular.module('mm.core.user')
* @return {Promise} Promise resolve when the user is stored.
*/
self.storeUser = function(id, fullname, avatar) {
var db = $mmSite.getDb();
return db.insert(mmCoreUsersStore, {
if (!$mmSite.isLoggedIn()) {
// Not logged in, we can't get the site DB. User logged out or session expired while an operation was ongoing.
return $q.reject();
}

return $mmSite.getDb().insert(mmCoreUsersStore, {
id: parseInt(id),
fullname: fullname,
profileimageurl: avatar
Expand Down
5 changes: 4 additions & 1 deletion www/core/lib/sitesmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,10 @@ angular.module('mm.core')
* @return {Promise}
*/
self.getSite = function(siteId) {
if (currentSite && currentSite.getId() === siteId) {
if (!siteId) {
// Site ID not valid, reject.
return $q.reject();
} else if (currentSite && currentSite.getId() === siteId) {
return $q.when(currentSite);
} else if (typeof sites[siteId] != 'undefined') {
return $q.when(sites[siteId]);
Expand Down