Skip to content

Commit

Permalink
Migrate transcriptions shell (script) to CakePHP3
Browse files Browse the repository at this point in the history
`cake transcriptions script contributions`

Refs #1784.
  • Loading branch information
jiru committed Mar 6, 2019
1 parent ac3bd97 commit 3fb8af3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/Shell/TranscriptionsShell.php
Expand Up @@ -82,20 +82,21 @@ protected function _autogen($sentences) {
return $generated;
}

private function setContributionsScript($lang) {
public function setContributionsScript($lang) {
$langs = $lang ?
array($lang) :
$this->Transcription->langsInNeedOfScriptAutodetection();
$this->Transcriptions->langsInNeedOfScriptAutodetection();
$proceeded = $this->batchOperation(
'Contribution',
'Contributions',
'_setScript',
array(
'conditions' => array('sentence_lang' => $langs),
'conditions' => array('sentence_lang IN' => $langs),
'fields' => array('id', 'sentence_lang', 'script', 'text'),
)
);
$langs = implode(', ', $langs);
echo "\nScript set for $proceeded contributions in lang(s) $langs.\n";
$this->out();
$this->out("Script set for $proceeded contributions in lang(s) $langs.");
}

public function setSentencesScript($lang) {
Expand Down
16 changes: 16 additions & 0 deletions tests/TestCase/Shell/TranscriptionsShellTest.php
Expand Up @@ -13,6 +13,7 @@ class TranscriptionsShellTest extends ConsoleIntegrationTestCase
'app.sentences',
'app.transcriptions',
'app.users',
'app.contributions',
];

public $io;
Expand Down Expand Up @@ -102,4 +103,19 @@ public function testSetSentencesScript()
$scripts = array_keys(array_flip($scripts));
$this->assertEquals($expectedScripts, $scripts);
}

public function testSetContributionsScript()
{
$expectedScripts = ['TEST'];

$this->TS->setContributionsScript('cmn');

$scripts = TableRegistry::get('Contributions')
->find('list', ['valueField' => 'script'])
->where(['sentence_lang' => 'cmn'])
->toArray();

$scripts = array_keys(array_flip($scripts));
$this->assertEquals($expectedScripts, $scripts);
}
}

0 comments on commit 3fb8af3

Please sign in to comment.