[terminology] script to copy flags and images from polish

This commit is contained in:
Avris 2021-10-15 22:20:37 +02:00
parent 61cab320d0
commit faa1f80a1b
1 changed files with 24 additions and 0 deletions

24
server/termsImages.js Normal file
View File

@ -0,0 +1,24 @@
require('../src/dotenv')();
const dbConnection = require('./db');
(async () => {
const db = await dbConnection();
const terms = {};
for (let term of await db.all(`SELECT id, key, locale, flags, images FROM terms WHERE approved = 1 AND deleted = 0 AND key IS NOT NULL`)) {
if (terms[term.locale] === undefined) { terms[term.locale] = {}; }
terms[term.locale][term.key] = term;
}
for (let locale in terms) {
if (!terms.hasOwnProperty(locale)) { continue; }
if (locale === 'pl') { continue; }
for (let key in terms[locale]) {
if (!terms[locale].hasOwnProperty(key)) { continue; }
const term = terms[locale][key];
if (terms['pl'][term.key] === undefined) { continue; }
const sql = `UPDATE terms SET flags = '${terms['pl'][term.key].flags.replace(/'/g, `''`)}', images = '${terms['pl'][term.key].images}' WHERE id = '${term.id}';`;
console.log(sql);
await db.get(sql);
}
}
})();