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 {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.
*/
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.
return this.updateRecords(table, data, conditions);
}).catch(() => {
@ -854,7 +854,7 @@ export class SQLiteDB {
// Create the list of params using the "data" object and the params for the where clause.
params = Object.keys(data).map((key) => data[key]);
if (where && whereParams) {
params = params.concat(whereParams[1]);
params = params.concat(whereParams);
}
return this.execute(sql, params);
@ -868,7 +868,7 @@ export class SQLiteDB {
*/
whereClause(conditions: any = {}): any[] {
if (!conditions || !Object.keys(conditions).length) {
return ['', []];
return ['1 = 1', []];
}
const where = [],

View File

@ -81,7 +81,7 @@ export class CoreLinkDirective implements OnInit {
protected navigate(href: string): void {
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.
this.utils.openFile(href).catch((error) => {
this.domUtils.showErrorModal(error);

View File

@ -477,7 +477,7 @@ export class CoreFilepoolProvider {
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);
}).then((response) => {
if (typeof component != 'undefined') {
this.addFileLink(siteId, fileId, component, componentId);
this.addFileLink(siteId, fileId, component, componentId).catch(() => {
// Ignore errors.
});
}
this.notifyFileDownloaded(siteId, fileId);
@ -2237,9 +2239,11 @@ export class CoreFilepoolProvider {
}),
whereAndParams = db.getInOrEqual(fileIds);
whereAndParams[0] = 'fileId ' + whereAndParams[0];
if (onlyUnknown) {
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]);
@ -2443,8 +2447,12 @@ export class CoreFilepoolProvider {
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.
this.logger.debug('Queued file already in store, ignoring...');
this.addFileLinks(siteId, fileId, links);
this.removeFromQueue(siteId, fileId).finally(() => {
this.addFileLinks(siteId, fileId, links).catch(() => {
// Ignore errors.
});
this.removeFromQueue(siteId, fileId).catch(() => {
// Ignore errors.
}).finally(() => {
this.treatQueueDeferred(siteId, fileId, true);
});
this.notifyFileDownloaded(siteId, fileId);
@ -2457,7 +2465,9 @@ export class CoreFilepoolProvider {
return this.downloadForPoolByUrl(siteId, fileUrl, options, filePath, onProgress, entry).then(() => {
// 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.notifyFileDownloaded(siteId, fileId);

View File

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