/** * Analyze a lexicon project and migrate the semantic domain keys in the senses * @param ProjectModelForUseWithSemanticDomainMigration $project * @param string $projectId * @param string $testMode * @param string $message */ private function analyzeProject($project, $projectId, $testMode, &$message) { $entryModifiedCount = 0; $entryList = LexEntryCommands::listEntries($projectId); foreach ($entryList->entries as $entryListItem) { $entry = new LexEntryModel($project, $entryListItem['id']); $entryModified = false; if ($entry->hasSenses()) { /** @var LexSense $sense */ foreach ($entry->senses as $sense) { $this->migrateSemDomKey($sense, $project->projectName, $message, $entryModified); } } if ($entryModified) { $entryModifiedCount++; if (!$testMode) { $entry->write(); } } } if (!$testMode) { $project->hasMigratedSemanticDomainKeys = true; $project->write(); } if ($entryModifiedCount > 0) { print "{$entryModifiedCount} entries with semantic domains were migrated\n"; } }
/** * Analyze a lexicon project and create Sense, Example and Picture guids. Remove id from Sense and Example * @param LexProjectModelForUseWithSenseGuidMigration $project * @param string $projectId * @param string $testMode */ private static function analyzeProject($project, $projectId, $testMode) { $entryModifiedCount = 0; $exampleModifiedCount = 0; $pictureModifiedCount = 0; $entryList = LexEntryCommands::listEntries($projectId); foreach ($entryList->entries as $entryListItem) { $entry = new LexEntryModel($project, $entryListItem['id']); $entryModified = false; if ($entry->hasSenses()) { /** @var LexSense $sense */ foreach ($entry->senses as $sense) { self::createSenseGuids($sense, $entryModified, $exampleModifiedCount, $pictureModifiedCount); } if ($entryModified) { $entryModifiedCount++; } if (!$testMode) { $entry->write(); } } } if (!$testMode) { $project->hasHadSenseGuidsMigrated = true; $project->write(); } print "{$exampleModifiedCount} example and {$pictureModifiedCount} picture guids created.\n"; print "{$entryModifiedCount} of {$entryList->count} entries had sense guids created.\n"; }
/** * Analyze a lexicon project and migrate MultiParagraph data structure and config * @param LexProjectModelForUseWithMultiParagraphMigration $project * @param string $testMode */ private static function analyzeProject($project, $testMode) { $entryModifiedCount = 0; $multiParagraphCount = 0; $senseModifiedCount = 0; $exampleModifiedCount = 0; $entryList = LexEntryCommands::listEntries($project->id->asString()); foreach ($entryList->entries as $entryListItem) { $entryModified = false; $entryConfig = $project->config->entry; $senseConfig = $entryConfig->fields['senses']; $exampleConfig = $senseConfig->fields['examples']; $entry = new LexEntryModel($project, $entryListItem['id']); self::migrateMultiParagraphs($entry, $entryConfig, $multiParagraphCount, $entryModified); if ($entry->hasSenses()) { /** @var LexSense $sense */ foreach ($entry->senses as $sense) { $senseModified = false; self::migrateMultiParagraphs($sense, $senseConfig, $multiParagraphCount, $senseModified); if (isset($sense->examples)) { /** @var LexExample $example */ foreach ($sense->examples as $example) { $exampleModified = false; self::migrateMultiParagraphs($example, $exampleConfig, $multiParagraphCount, $exampleModified); if ($exampleModified) { $entryModified = true; $senseModified = true; $exampleModifiedCount++; } } } if ($senseModified) { $entryModified = true; $senseModifiedCount++; } } } if ($entryModified) { $entryModifiedCount++; if (!$testMode) { $entry->write(); } } } if (!$testMode) { $project->hasHadMultiParagraphsMigrated = true; $project->write(); } print "{$multiParagraphCount} multi paragraphs found.\n"; print "{$senseModifiedCount} senses and {$exampleModifiedCount} examples modified.\n"; print "{$entryModifiedCount} of {$entryList->count} entries had multi paragraphs.\n"; }
/** * * @param ProjectModel $projectModel * @param string $userId * @param string $id entry id * @return string activity id */ public static function deleteEntry($projectModel, $userId, $id) { $activity = new ActivityModel($projectModel); $activity->userRef->id = $userId; $activity->action = ActivityModel::DELETE_ENTRY; $lexeme = LexEntryCommands::getEntryLexeme($projectModel->id->asString(), $id); $activity->addContent(ActivityModel::ENTRY, $lexeme); return $activity->write(); }
public function lex_entry_remove($entryId) { return LexEntryCommands::removeEntry($this->projectId, $entryId, $this->userId); }
public function testListEntries_someEntriesWithNoDefinition_Ok() { $e = new LexiconMongoTestEnvironment(); $e->clean(); $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $projectId = $project->id->asString(); for ($i = 0; $i < 10; $i++) { $entry = new LexEntryModel($project); $entry->lexeme->form('th', 'Apfel' . $i); if ($i % 2 == 0) { $sense = new Sense(); $entry->senses[] = $sense; } if ($i % 3 == 0) { $sense = new Sense(); $sense->definition->form('en', 'apple'); $sense->partOfSpeech->value = 'noun'; $entry->senses[] = $sense; } $entry->write(); } $result = LexEntryCommands::listEntries($projectId); $this->assertEqual($result->entries[0]['lexeme']['th']['value'], 'Apfel0'); $this->assertTrue(!array_key_exists('definition', $result->entries[0]['senses'][0])); $this->assertEqual($result->entries[3]['senses'][0]['definition']['en']['value'], 'apple'); }
$file = array(); $file['name'] = $fileName; $_FILES['file'] = $file; // put a copy of the test file in tmp $tmpFilePath = sys_get_temp_dir() . "/CopyOf{$fileName}"; copy(TestPath . "php/common/{$fileName}", $tmpFilePath); $response = LexUploadCommands::uploadImageFile($testProjectId, 'sense-image', $tmpFilePath); // cleanup tmp file if it still exists if (file_exists($tmpFilePath) and !is_dir($tmpFilePath)) { @unlink($tmpFilePath); } // put uploaded file into entry1 $constants['testEntry1']['senses'][0]['pictures'][0]['fileName'] = $response->data->fileName; $entry1 = LexEntryCommands::updateEntry($testProjectId, array('id' => '', 'lexeme' => $constants['testEntry1']['lexeme'], 'senses' => $constants['testEntry1']['senses']), $managerUserId); $entry2 = LexEntryCommands::updateEntry($testProjectId, array('id' => '', 'lexeme' => $constants['testEntry2']['lexeme'], 'senses' => $constants['testEntry2']['senses']), $managerUserId); $multipleMeaningEntry1 = LexEntryCommands::updateEntry($testProjectId, array('id' => '', 'lexeme' => $constants['testMultipleMeaningEntry1']['lexeme'], 'senses' => $constants['testMultipleMeaningEntry1']['senses']), $managerUserId); // put mock uploaded zip import (jpg file) $fileName = $constants['testMockJpgImportFile']['name']; $tmpFilePath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $fileName; copy(TestPath . "php/common/{$fileName}", $tmpFilePath); // put mock uploaded zip import (zip file) $fileName = $constants['testMockZipImportFile']['name']; $tmpFilePath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $fileName; copy(TestPath . "php/common/{$fileName}", $tmpFilePath); // put mock uploaded audio (png file) $fileName = $constants['testMockPngUploadFile']['name']; $tmpFilePath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $fileName; copy(TestPath . "php/common/{$fileName}", $tmpFilePath); // put mock uploaded audio (mp3 file) $fileName = $constants['testMockMp3UploadFile']['name']; $tmpFilePath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $fileName;
function testReadEntry_NoComments_ReadBackOk() { $e = new LexiconMongoTestEnvironment(); $e->clean(); $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $projectId = $project->id->asString(); $entry = new LexEntryModel($project); $entry->lexeme->form('th', 'apple'); $sense = new Sense(); $sense->definition->form('en', 'red fruit'); $sense->partOfSpeech = new LexiconField('noun'); $example = new Example(); $example->sentence->form('th', 'example1'); $example->translation->form('en', 'trans1'); $sense->examples[] = $example; $entry->senses[] = $sense; $entryId = $entry->write(); $newEntry = LexEntryCommands::readEntry($projectId, $entryId); $this->assertEqual($newEntry['lexeme']['th']['value'], 'apple'); $this->assertEqual($newEntry['senses'][0]['definition']['en']['value'], 'red fruit'); $this->assertEqual($newEntry['senses'][0]['partOfSpeech']['value'], 'noun'); $this->assertEqual($newEntry['senses'][0]['examples'][0]['sentence']['th']['value'], 'example1'); $this->assertEqual($newEntry['senses'][0]['examples'][0]['translation']['en']['value'], 'trans1'); }