MOBILE-2335 core: Fix issues with DB and restore media

main
Dani Palou 2018-02-02 08:11:29 +01:00
parent 7379ca3e71
commit 698e2cf8f6
4 changed files with 31 additions and 23 deletions

View File

@ -649,11 +649,11 @@ export class SQLiteDB {
* *
* @param {string} table The database table. * @param {string} table The database table.
* @param {object} data An object with the fields to insert/update: fieldname=>fieldvalue. * @param {object} data An object with the fields to insert/update: fieldname=>fieldvalue.
* @param {object} conditions The conditions to check if the record already exists. * @param {object} conditions The conditions to check if the record already exists (and to update it).
* @return {Promise<any>} Promise resolved with done. * @return {Promise<any>} Promise resolved with done.
*/ */
insertOrUpdateRecord(table: string, data: object, conditions: object): Promise<any> { insertOrUpdateRecord(table: string, data: object, conditions: object): Promise<any> {
return this.getRecord(table, conditions || data).then(() => { return this.getRecord(table, conditions).then(() => {
// It exists, update it. // It exists, update it.
return this.updateRecords(table, data, conditions); return this.updateRecords(table, data, conditions);
}).catch(() => { }).catch(() => {
@ -854,7 +854,7 @@ export class SQLiteDB {
// Create the list of params using the "data" object and the params for the where clause. // Create the list of params using the "data" object and the params for the where clause.
params = Object.keys(data).map((key) => data[key]); params = Object.keys(data).map((key) => data[key]);
if (where && whereParams) { if (where && whereParams) {
params = params.concat(whereParams[1]); params = params.concat(whereParams);
} }
return this.execute(sql, params); return this.execute(sql, params);
@ -868,7 +868,7 @@ export class SQLiteDB {
*/ */
whereClause(conditions: any = {}): any[] { whereClause(conditions: any = {}): any[] {
if (!conditions || !Object.keys(conditions).length) { if (!conditions || !Object.keys(conditions).length) {
return ['', []]; return ['1 = 1', []];
} }
const where = [], const where = [],

View File

@ -81,7 +81,7 @@ export class CoreLinkDirective implements OnInit {
protected navigate(href: string): void { protected navigate(href: string): void {
const contentLinksScheme = CoreConfigConstants.customurlscheme + '://link='; const contentLinksScheme = CoreConfigConstants.customurlscheme + '://link=';
if (href.indexOf('cdvfile://') === 0 || href.indexOf('file://') === 0) { if (href.indexOf('cdvfile://') === 0 || href.indexOf('file://') === 0 || href.indexOf('filesystem:') === 0) {
// We have a local file. // We have a local file.
this.utils.openFile(href).catch((error) => { this.utils.openFile(href).catch((error) => {
this.domUtils.showErrorModal(error); this.domUtils.showErrorModal(error);

View File

@ -477,7 +477,7 @@ export class CoreFilepoolProvider {
componentId: componentId || '' componentId: componentId || ''
}; };
return db.insertOrUpdateRecord(this.LINKS_TABLE, newEntry, undefined); return db.insertOrUpdateRecord(this.LINKS_TABLE, newEntry, { fileId: fileId });
}); });
} }
@ -1178,7 +1178,9 @@ export class CoreFilepoolProvider {
return this.downloadForPoolByUrl(siteId, fileUrl, options, filePath, onProgress); return this.downloadForPoolByUrl(siteId, fileUrl, options, filePath, onProgress);
}).then((response) => { }).then((response) => {
if (typeof component != 'undefined') { if (typeof component != 'undefined') {
this.addFileLink(siteId, fileId, component, componentId); this.addFileLink(siteId, fileId, component, componentId).catch(() => {
// Ignore errors.
});
} }
this.notifyFileDownloaded(siteId, fileId); this.notifyFileDownloaded(siteId, fileId);
@ -2237,9 +2239,11 @@ export class CoreFilepoolProvider {
}), }),
whereAndParams = db.getInOrEqual(fileIds); whereAndParams = db.getInOrEqual(fileIds);
whereAndParams[0] = 'fileId ' + whereAndParams[0];
if (onlyUnknown) { if (onlyUnknown) {
whereAndParams[0] += ' AND (isexternalfile = ? OR (revision < ? AND timemodified = ?))'; whereAndParams[0] += ' AND (isexternalfile = ? OR (revision < ? AND timemodified = ?))';
whereAndParams[1] = whereAndParams[1].params.concat([0, 1, 0]); whereAndParams[1] = whereAndParams[1].concat([0, 1, 0]);
} }
return db.updateRecordsWhere(this.FILES_TABLE, { stale: 1 }, whereAndParams[0], whereAndParams[1]); return db.updateRecordsWhere(this.FILES_TABLE, { stale: 1 }, whereAndParams[0], whereAndParams[1]);
@ -2443,8 +2447,12 @@ export class CoreFilepoolProvider {
if (entry && !this.isFileOutdated(entry, options.revision, options.timemodified)) { if (entry && !this.isFileOutdated(entry, options.revision, options.timemodified)) {
// We have the file, it is not stale, we can update links and remove from queue. // We have the file, it is not stale, we can update links and remove from queue.
this.logger.debug('Queued file already in store, ignoring...'); this.logger.debug('Queued file already in store, ignoring...');
this.addFileLinks(siteId, fileId, links); this.addFileLinks(siteId, fileId, links).catch(() => {
this.removeFromQueue(siteId, fileId).finally(() => { // Ignore errors.
});
this.removeFromQueue(siteId, fileId).catch(() => {
// Ignore errors.
}).finally(() => {
this.treatQueueDeferred(siteId, fileId, true); this.treatQueueDeferred(siteId, fileId, true);
}); });
this.notifyFileDownloaded(siteId, fileId); this.notifyFileDownloaded(siteId, fileId);
@ -2457,7 +2465,9 @@ export class CoreFilepoolProvider {
return this.downloadForPoolByUrl(siteId, fileUrl, options, filePath, onProgress, entry).then(() => { return this.downloadForPoolByUrl(siteId, fileUrl, options, filePath, onProgress, entry).then(() => {
// Success, we add links and remove from queue. // Success, we add links and remove from queue.
this.addFileLinks(siteId, fileId, links); this.addFileLinks(siteId, fileId, links).catch(() => {
// Ignore errors.
});
this.treatQueueDeferred(siteId, fileId, true); this.treatQueueDeferred(siteId, fileId, true);
this.notifyFileDownloaded(siteId, fileId); this.notifyFileDownloaded(siteId, fileId);

View File

@ -547,28 +547,26 @@ export class CoreDomUtilsProvider {
// Treat elements with src (img, audio, video, ...). // Treat elements with src (img, audio, video, ...).
media = this.element.querySelectorAll('img, video, audio, source, track'); media = this.element.querySelectorAll('img, video, audio, source, track');
for (const i in media) { media.forEach((media: HTMLElement) => {
const el = media[i]; let newSrc = paths[this.textUtils.decodeURIComponent(media.getAttribute('src'))];
let newSrc = paths[this.textUtils.decodeURIComponent(el.getAttribute('src'))];
if (typeof newSrc != 'undefined') { if (typeof newSrc != 'undefined') {
el.setAttribute('src', newSrc); media.setAttribute('src', newSrc);
} }
// Treat video posters. // Treat video posters.
if (el.tagName == 'VIDEO' && el.getAttribute('poster')) { if (media.tagName == 'VIDEO' && media.getAttribute('poster')) {
newSrc = paths[this.textUtils.decodeURIComponent(el.getAttribute('poster'))]; newSrc = paths[this.textUtils.decodeURIComponent(media.getAttribute('poster'))];
if (typeof newSrc !== 'undefined') { if (typeof newSrc !== 'undefined') {
el.setAttribute('poster', newSrc); media.setAttribute('poster', newSrc);
}
} }
} }
});
// Now treat links. // Now treat links.
anchors = this.element.querySelectorAll('a'); anchors = this.element.querySelectorAll('a');
for (const i in anchors) { anchors.forEach((anchor: HTMLElement) => {
const anchor = anchors[i], const href = this.textUtils.decodeURIComponent(anchor.getAttribute('href')),
href = this.textUtils.decodeURIComponent(anchor.getAttribute('href')),
newUrl = paths[href]; newUrl = paths[href];
if (typeof newUrl != 'undefined') { if (typeof newUrl != 'undefined') {
@ -578,7 +576,7 @@ export class CoreDomUtilsProvider {
anchorFn(anchor, href); anchorFn(anchor, href);
} }
} }
} });
return this.element.innerHTML; return this.element.innerHTML;
} }