function testCleanupFiles_4Files2Allowed_2Removed()
 {
     $project = self::$environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE);
     $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(TestPhpPath . 'common/TestAudio.mp3', $filePath1);
     $fileName2 = 'TestAudio2.mp2';
     $filePath2 = SfchecksUploadCommands::mediaFilePath($folderPath, $textId, $fileName2);
     copy(TestPhpPath . 'common/TestAudio.mp3', $filePath2);
     $fileName3 = 'TestAudio3.mp3';
     $filePath3 = SfchecksUploadCommands::mediaFilePath($folderPath, $textId, $fileName3);
     copy(TestPhpPath . 'common/TestAudio.mp3', $filePath3);
     $fileName4 = 'TestAudio4.mp3';
     $filePath4 = SfchecksUploadCommands::mediaFilePath($folderPath, $fakeTextId, $fileName4);
     copy(TestPhpPath . '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');
     self::$environ->cleanupTestFiles($folderPath);
 }
 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();
     }
 }
コード例 #3
0
 /**
  * @param IdReference $model
  * @return string
  */
 public function encodeIdReference($model)
 {
     if (Id::isEmpty($model)) {
         return null;
     }
     $mongoId = MongoMapper::mongoID($model->id);
     return $mongoId;
 }
コード例 #4
0
 /**
  * Adds / updates an answer to the given question.
  * @param AnswerModel $answer
  * @return string $id
  */
 public function writeAnswer($answer)
 {
     $id = $answer->id->asString();
     if (empty($id)) {
         $id = $answer->id->id = QuestionModelMongoMapper::makeId();
         $answerToWrite = $answer;
     } else {
         $answerToWrite = $this->answers[$id];
         $properties = get_object_vars($answer);
         $exclude = array('comments');
         foreach ($properties as $key => $value) {
             if (!in_array($key, $exclude)) {
                 $answerToWrite->{$key} = $value;
             }
         }
     }
     $this->_mapper->write($answerToWrite, $id, MongoMapper::ID_IN_KEY, $this->id->asString(), 'answers');
     return $id;
 }
コード例 #5
0
 /**
  * Writes the model to the mongo collection
  * @return string The unique id of the object written
  * @see MongoMapper::write()
  */
 public function write()
 {
     CodeGuard::checkTypeAndThrow($this->id, 'Api\\Model\\Shared\\Mapper\\Id');
     $now = UniversalTimestamp::now();
     $this->dateModified = $now;
     if (Id::isEmpty($this->id)) {
         $this->dateCreated = $now;
     }
     $this->id->id = $this->_mapper->write($this, $this->id->id);
     return $this->id->id;
 }
コード例 #6
0
 public function listUsers()
 {
     $userList = new UserListProjectModel($this->id->asString());
     $userList->read();
     for ($i = 0, $l = count($userList->entries); $i < $l; $i++) {
         $userId = $userList->entries[$i]['id'];
         if (!array_key_exists($userId, $this->users)) {
             continue;
         }
         $userList->entries[$i]['role'] = $this->users[$userId]->role;
     }
     return $userList;
 }
コード例 #7
0
 public function cleanPreviousProject($languageCode)
 {
     $p = new SemDomTransProjectModel();
     $p->readByCode($languageCode, self::TESTVERSION);
     if (!Id::isEmpty($p->id)) {
         $this->cleanProjectEnvironment($p);
     } else {
         // create the project and then clean the project environment
         $p = new SemDomTransProjectModel();
         $p->projectCode = SemDomTransProjectModel::projectCode($languageCode, self::TESTVERSION);
         $p->write();
         $this->cleanProjectEnvironment($p);
     }
     $p->remove();
 }
コード例 #8
0
 /**
  * @param \SimpleXMLElement $sxeNode
  * @param LexEntryModel $entry
  * @param string $mergeRule
  * @throws \Exception
  */
 public function readEntry($sxeNode, $entry, $mergeRule = LiftMergeRule::CREATE_DUPLICATES)
 {
     $this->nodeErrors = array();
     $this->nodeErrors[] = new LiftImportNodeError(LiftImportNodeError::ENTRY, (string) $sxeNode['guid']);
     /** @var \SimpleXMLElement $element */
     foreach ($sxeNode as $element) {
         switch ($element->getName()) {
             case 'lexical-unit':
                 if ($mergeRule != LiftMergeRule::IMPORT_LOSES || Id::isEmpty($entry->id)) {
                     $entry->guid = (string) $sxeNode['guid'];
                     $entry->authorInfo->createdDate = UniversalTimestamp::fromStringTimestamp((string) $sxeNode['dateCreated']);
                     $entry->authorInfo->modifiedDate = UniversalTimestamp::fromStringTimestamp((string) $sxeNode['dateModified']);
                     $entry->lexeme = $this->readMultiText($element, $this->project->config->entry->fields[LexConfig::LEXEME]->inputSystems);
                 }
                 break;
             case 'citation':
                 $entry->citationForm = $this->readMultiText($element, $this->project->config->entry->fields[LexConfig::CITATIONFORM]->inputSystems);
                 break;
             case 'note':
                 if ($element['type'] == '') {
                     $entry->note = $this->readMultiText($element, $this->project->config->entry->fields[LexConfig::NOTE]->inputSystems);
                 } else {
                     $this->addKnownUnhandledElement('Note: ' . $element['type']);
                 }
                 break;
             case 'etymology':
                 $entry->etymology = $this->readMultiText($element, $this->project->config->entry->fields[LexConfig::ETYMOLOGY]->inputSystems, true);
                 if ($element->{'gloss'}) {
                     $this->readMultiTextGloss($element->{'gloss'}[0], $entry->etymologyGloss, $this->project->config->entry->fields[LexConfig::ETYMOLOGYGLOSS]->inputSystems);
                 }
                 foreach ($element->{'field'} as $field) {
                     if ($field['type'] == 'comment') {
                         $entry->etymologyComment = $this->readMultiText($field, $this->project->config->entry->fields[LexConfig::ETYMOLOGYCOMMENT]->inputSystems);
                     } else {
                         $this->currentNodeError()->addUnhandledField('etymology: ' . $field['type']);
                     }
                 }
                 break;
             case 'pronunciation':
                 $entry->pronunciation = $this->readMultiText($element, $this->project->config->entry->fields[LexConfig::PRONUNCIATION]->inputSystems, true);
                 if ($element->{'media'}) {
                     $this->addKnownUnhandledElement('pronunciation: media');
                 }
                 break;
             case 'field':
                 switch ($element['type']) {
                     case 'literal-meaning':
                         $entry->literalMeaning = $this->readMultiText($element, $this->project->config->entry->fields[LexConfig::LITERALMEANING]->inputSystems);
                         break;
                     case 'summary-definition':
                         $entry->summaryDefinition = $this->readMultiText($element, $this->project->config->entry->fields[LexConfig::SUMMARYDEFINITION]->inputSystems);
                         break;
                     case 'import-residue':
                         // Currently ignored in LanguageForge
                         break;
                     default:
                         if ($this->isEntryCustomField($element['type'])) {
                             $this->addEntryCustomField($element, $element['type'], $entry);
                         } else {
                             $this->currentNodeError()->addUnhandledField($element['type']);
                         }
                 }
                 break;
             case 'trait':
                 switch ($element['name']) {
                     case 'morph-type':
                         $entry->morphologyType = (string) $element['value'];
                         break;
                     case 'do-not-publish-in':
                     case 'DoNotUseForParsing':
                         $this->addKnownUnhandledElement('trait: ' . $element['name']);
                         break;
                     default:
                         if ($this->isEntryCustomField($element['name'])) {
                             $this->addEntryCustomField($element, $element['name'], $entry);
                         } else {
                             $this->currentNodeError()->addUnhandledTrait($element['name']);
                         }
                 }
                 break;
             case 'sense':
                 $liftId = '';
                 if (isset($element['id'])) {
                     $liftId = (string) $element['id'];
                 }
                 $existingSenseIndex = $entry->searchSensesFor('liftId', $liftId);
                 if ($existingSenseIndex >= 0) {
                     switch ($mergeRule) {
                         case LiftMergeRule::CREATE_DUPLICATES:
                             $sense = new LexSense('');
                             $entry->senses[] = $this->readSense($element, $sense);
                             break;
                         case LiftMergeRule::IMPORT_WINS:
                             $sense = new LexSense($liftId, Guid::extract($liftId));
                             $entry->senses[$existingSenseIndex] = $this->readSense($element, $sense);
                             break;
                         case LiftMergeRule::IMPORT_LOSES:
                             break;
                         default:
                             throw new \Exception("unknown LiftMergeRule " . $mergeRule);
                     }
                 } else {
                     $sense = new LexSense($liftId, Guid::extract($liftId));
                     $entry->senses[] = $this->readSense($element, $sense);
                 }
                 break;
             case 'variant':
             case 'relation':
                 $this->addKnownUnhandledElement('Element: ' . $element->getName());
                 break;
             default:
                 $this->currentNodeError()->addUnhandledElement($element->getName());
         }
     }
     if (!$this->currentNodeError()->hasErrors()) {
         unset($this->nodeErrors[count($this->nodeErrors) - 1]);
     }
 }
 /**
  * Determines if project with given langauge code exists
  * @param string $languageCode
  * @return boolean
  */
 public static function checkProjectExists($languageCode)
 {
     $project = new SemDomTransProjectModel();
     $project->readByCode($languageCode);
     if (Id::isEmpty($project->id)) {
         return true;
     } else {
         return false;
     }
 }
コード例 #10
0
 public function listQuestionsWithAnswers()
 {
     $questionList = new QuestionAnswersListModel($this->_projectModel, $this->id->asString());
     $questionList->read();
     return $questionList;
 }