/** * Imports a translation memory into the database. * * @since 0.4 * * @param LTTranslationMemory $tm * @param integer $memoryId */ protected function doTMImport(LTTranslationMemory $tm, $memoryId) { $dbw = wfGetDB(DB_MASTER); // Delete the memory from the db if already there. $dbw->delete('live_translate', array('memory_id' => $memoryId)); $idOffset = ($memoryId - 1) * 100000; $wordId = 0; $dbw->begin(); // Insert the memory in the db. foreach ($tm->getTranslationUnits() as $tu) { if ($GLOBALS['egLTRequireSignificance'] && !$tu->isSignificant()) { continue; } foreach ($tu->getVariants() as $language => $translations) { $primary = 1; foreach ($translations as $translation) { $dbw->insert('live_translate', array('word_id' => $idOffset + $wordId, 'word_language' => $this->cleanLanguage($language), 'word_translation' => $translation, 'word_primary' => $primary, 'memory_id' => $memoryId)); $primary = 0; } } $wordId++; if ($wordId % 500 == 0) { $dbw->commit(); $dbw->begin(); } } $dbw->update('live_translate_memories', array('memory_lang_count' => $tm->getLanguageAmount(), 'memory_tu_count' => $wordId, 'memory_version_hash' => uniqid()), array('memory_id' => $memoryId)); $dbw->commit(); }