public function preFillFromSourceLanguage($useGoogleTranslateData = true) { $path = APPPATH . "resources/languageforge/semdomtrans/GoogleTranslateHarvester/semdom-google-translate-{$this->languageIsoCode}.txt.gz"; $googleTranslateData = []; if ($useGoogleTranslateData && file_exists($path)) { $lines = gzfile($path); foreach ($lines as $line) { $splitLine = explode("|", $line); if (count($splitLine) == 2) { $googleTranslateData[$splitLine[0]] = $splitLine[1]; } } } // cjh review: we may actually want to only prefill from English, if in the future we allow creating projects from incomplete source projects $sourceProject = new SemDomTransProjectModel($this->sourceLanguageProjectId->asString()); $this->_copyXmlToAssets($sourceProject->xmlFilePath); $sourceItems = new SemDomTransItemListModel($sourceProject); $sourceItems->read(); foreach ($sourceItems->entries as $item) { $newItem = new SemDomTransItemModel($this); // if Google translation exists for given name exists, use it if (array_key_exists($item['name']['translation'], $googleTranslateData)) { $newItem->name->translation = $googleTranslateData[$item['name']['translation']]; $newItem->name->status = SemDomTransStatus::Suggested; } // if Google translation exists for given description exists, use it if (array_key_exists($item['description']['translation'], $googleTranslateData)) { $newItem->description->translation = $googleTranslateData[$item['description']['translation']]; $newItem->description->status = SemDomTransStatus::Suggested; } $newItem->key = $item['key']; for ($x = 0; $x < count($item['questions']); $x++) { $q = new SemDomTransQuestion(); // if Google translation exists for given question, use it if (array_key_exists($item['questions'][$x]['question']['translation'], $googleTranslateData)) { $q->question->translation = $googleTranslateData[$item['questions'][$x]['question']['translation']]; $q->question->status = SemDomTransStatus::Suggested; } // if Google translation exists for given question term, use it if (array_key_exists($item['questions'][$x]['terms']['translation'], $googleTranslateData)) { $q->terms->translation = $googleTranslateData[$item['questions'][$x]['terms']['translation']]; $q->terms->status = SemDomTransStatus::Suggested; } $newItem->questions[] = $q; } for ($x = 0; $x < count($item['searchKeys']); $x++) { $sk = new SemDomTransTranslatedForm(); // if Google translation exists for given search key, use it if (array_key_exists($item['searchKeys'][$x]['translation'], $googleTranslateData)) { $sk->translation = $googleTranslateData[$item['searchKeys'][$x]['translation']]; $sk->status = SemDomTransStatus::Suggested; } $newItem->searchKeys[] = $sk; } $newItem->xmlGuid = $item['xmlGuid']; $newItem->write(); } }
function testCleanupFiles_4Files2Allowed_2Removed() { $environ = new MongoTestEnvironment(); $environ->clean(); $project = $environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $projectId = $project->write(); $text = new TextModel($project); $textId = $text->write(); $fakeId = new Id(); $fakeTextId = $fakeId->asString(); $folderPath = $project->getAssetsFolderPath(); FileUtilities::createAllFolders($folderPath); $allowedExtensions = array(".mp2", ".mp3"); // put a copy of the test files in the folderPath $fileName1 = 'TestAudio1.mp1'; $filePath1 = SfchecksUploadCommands::mediaFilePath($folderPath, $textId, $fileName1); copy(TestPath . 'common/TestAudio.mp3', $filePath1); $fileName2 = 'TestAudio2.mp2'; $filePath2 = SfchecksUploadCommands::mediaFilePath($folderPath, $textId, $fileName2); copy(TestPath . 'common/TestAudio.mp3', $filePath2); $fileName3 = 'TestAudio3.mp3'; $filePath3 = SfchecksUploadCommands::mediaFilePath($folderPath, $textId, $fileName3); copy(TestPath . 'common/TestAudio.mp3', $filePath3); $fileName4 = 'TestAudio4.mp3'; $filePath4 = SfchecksUploadCommands::mediaFilePath($folderPath, $fakeTextId, $fileName4); copy(TestPath . 'common/TestAudio.mp3', $filePath4); $this->assertTrue(file_exists($filePath1), 'File should exist before cleanup'); $this->assertTrue(file_exists($filePath2), 'File should exist before cleanup'); $this->assertTrue(file_exists($filePath3), 'File should exist before cleanup'); $this->assertTrue(file_exists($filePath4), 'File should exist before cleanup'); SfchecksUploadCommands::cleanupFiles($folderPath, $textId, $allowedExtensions); $this->assertTrue(file_exists($filePath1), 'File should exist after cleanup'); $this->assertFalse(file_exists($filePath2), 'File should not exist after cleanup'); $this->assertFalse(file_exists($filePath3), 'File should not exist after cleanup'); $this->assertTrue(file_exists($filePath4), 'File should exist after cleanup'); $environ->cleanupTestFiles($folderPath); }