diff --git a/src/js/dictionaryManagement.js b/src/js/dictionaryManagement.js index e96547d..46c7226 100644 --- a/src/js/dictionaryManagement.js +++ b/src/js/dictionaryManagement.js @@ -133,6 +133,24 @@ export function importDictionary() { const textFromFileLoaded = fileLoadedEvent.target.result; const importedDictionary = JSON.parse(textFromFileLoaded); if (importedDictionary && importedDictionary.hasOwnProperty('words')) { + const timestamp = getTimestampInSeconds(); + if (!importedDictionary.hasOwnProperty('createdOn')) { + importedDictionary.createdOn = timestamp; + } + if (importedDictionary.words.some(word => !word.hasOwnProperty('createdOn'))) { + importedDictionary.words.forEach(word => { + if (!word.hasOwnProperty('createdOn')) { + word.createdOn = timestamp; + } + if (!word.hasOwnProperty('lastUpdated')) { + word.lastUpdated = timestamp; + } + }); + } + if (importedDictionary.hasOwnProperty('externalID')) { + delete importedDictionary.externalID; + } + window.currentDictionary = importedDictionary; saveDictionary(); renderAll(); @@ -252,11 +270,14 @@ export function migrateDictionary() { if (!window.currentDictionary.hasOwnProperty('version')) { const fixStupidOldNonsense = string => string.replace(/"/g, '"').replace(/'/g, "'").replace(/\/g, '\\').replace(/
/g, '\n'); window.currentDictionary.description = fixStupidOldNonsense(window.currentDictionary.description); + const timestamp = getTimestampInSeconds(); window.currentDictionary.words = window.currentDictionary.words.map(word => { word.definition = word.simpleDefinition; delete word.simpleDefinition; word.details = fixStupidOldNonsense(word.longDefinition); delete word.longDefinition; + word.lastUpdated = timestamp; + word.createdOn = timestamp; return word; }); window.currentDictionary = Object.assign({}, DEFAULT_DICTIONARY, window.currentDictionary); diff --git a/src/php/api/Dictionary.php b/src/php/api/Dictionary.php index df9e00d..8fb51cb 100644 --- a/src/php/api/Dictionary.php +++ b/src/php/api/Dictionary.php @@ -235,7 +235,7 @@ WHERE dictionary=$dictionary"; $word_ids = array(); $most_recent_word_update = 0; foreach($words as $word) { - $last_updated = is_null($word['lastUpdated']) ? $word['createdOn'] : $word['lastUpdated']; + $last_updated = isset($word['lastUpdated']) ? $word['createdOn'] : $word['lastUpdated']; if ($most_recent_word_update < $last_updated) { $most_recent_word_update = $last_updated; }