Skip to content

Commit

Permalink
Merge pull request #344 from OPUS4/OPUSVIER-4304
Browse files Browse the repository at this point in the history
OPUSVIER-4304 Fixed import of customized help files without custom key.
  • Loading branch information
j3nsch authored Aug 27, 2020
2 parents 32fb54c + b479f4d commit 2822189
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 6 deletions.
4 changes: 2 additions & 2 deletions application/configs/help/metadata.en.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Metadata can be defined as

<ul>
<li>data describing one or more ressources or as</li>
<li>data describing one or more resources or as</li>
<li>data associated with an object and describing it</li>
</ul>

Expand All @@ -11,7 +11,7 @@ Bibliographic data sets and catalog entries in library catalogs can be seen as a

<p>
This repository is using metadata in the <a href="http://dublincore.org/" target="_blank">Dublin
Core Metedata Element Set</a> (short Dublin Core (DC)) which has fifteen basic elements. Dublin
Core Metadata Element Set</a> (short Dublin Core (DC)) which has fifteen basic elements. Dublin
Core is the result of international efforts to reach a collective consensus in describing electronic
objects (in the broadest sense). The Library of Congress (LoC), the Online Cataloging Library Center (OCLC)
and several national libraries are dealing with Dublin Core in many projects and are close to introduce the
Expand Down
2 changes: 1 addition & 1 deletion application/configs/help/publicationprocess.en.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Please click on the publication link on the start page.<br/>
First you are requested to choose a document type. Right beneath that you can upload your document files. Having done
so you may click on "send". What follows now is the actual form.
You have to fill in data about your publication here (so called metadata), which is used to describe your work in
catalouges and other bibliographic
cataloges and other bibliographic
directories. Describe the document you want to upload using the categories and fields on the publication form.
Depending on the document type, some of
these fields are <span class="required">mandatory</span> and therefore have to be filled in. Please describe your
Expand Down
17 changes: 17 additions & 0 deletions library/Application/Update/ImportHelpFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,23 @@ public function importFiles($key, $files, $module)
$content = file_get_contents($path);
$values[$lang] = $content;
$this->removeFile($path);
} else {
// OPUSVIER-4304 Try to see if there is a file after all.
$this->log("Trying to resolve default file for key '$key' in language '$lang'.");
$prefix = 'help_content_';
if (substr($key, 0, strlen($prefix)) == $prefix) {
$baseName = substr($key, strlen($prefix));
$fileName = "$baseName.{$lang}.txt";
$path = $helpPath . $fileName;
if (is_readable($path)) {
$this->log("Default file '$fileName' found.");
$content = trim(file_get_contents($path));
$values[$lang] = $content;
$this->removeFile($path);
} else {
$this->log("Default file '$fileName' not found.");
}
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions modules/help/language/help.tmx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ gestattet!</b> Dies können Sie zum Beispiel mit Hilfe der
First you are requested to choose a document type. Right beneath that you can upload your document files. Having done
so you may click on "send". What follows now is the actual form.
You have to fill in data about your publication here (so called metadata), which is used to describe your work in
catalouges and other bibliographic
cataloges and other bibliographic
directories. Describe the document you want to upload using the categories and fields on the publication form.
Depending on the document type, some of
these fields are <span class="required">mandatory</span> and therefore have to be filled in. Please describe your
Expand Down Expand Up @@ -197,7 +197,7 @@ Cookies müssen im Webbrowser eingeschaltet sein, um Dokumente über das Veröff
<seg><![CDATA[Metadata can be defined as
<ul>
<li>data describing one or more ressources or as</li>
<li>data describing one or more resources or as</li>
<li>data associated with an object and describing it</li>
</ul>
Expand All @@ -207,7 +207,7 @@ Bibliographic data sets and catalog entries in library catalogs can be seen as a
<p>
This repository is using metadata in the <a href="http://dublincore.org/" target="_blank">Dublin
Core Metedata Element Set</a> (short Dublin Core (DC)) which has fifteen basic elements. Dublin
Core Metadata Element Set</a> (short Dublin Core (DC)) which has fifteen basic elements. Dublin
Core is the result of international efforts to reach a collective consensus in describing electronic
objects (in the broadest sense). The Library of Congress (LoC), the Online Cataloging Library Center (OCLC)
and several national libraries are dealing with Dublin Core in many projects and are close to introduce the
Expand Down
92 changes: 92 additions & 0 deletions tests/library/Application/Update/ImportHelpFilesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,96 @@ public function testGetHelpFilesForDefaultSetup()
}
}
}

/**
* OPUSVIER-4304
*
* Sometimes help files have been changed directly without copying the keys to `language_custom`. In that case,
* it is not possible to detect the customization during the update. However we should assume that this might
* have happened and import the files anyway.
*/
public function testImportChangedHelpFilesWithoutCustomizedKeys()
{
$database = new Opus_Translate_Dao();
$database->removeAll();

$helpPath = $this->createTestFolder();

$generalDe = $this->createTestFile('general.de.txt', 'Allgemein', $helpPath);
$generalEn = $this->createTestFile('general.en.txt', 'General', $helpPath);
$policiesDe = $this->createTestFile('policies.de.txt', 'Leitlinien', $helpPath);
$policiesEn = $this->createTestFile('policies.en.txt', 'Policies', $helpPath);

$helpConfig = 'help_index_general[] = \'general\'' . PHP_EOL;
$helpConfig .= 'help_index_misc[] = \'policies\'' . PHP_EOL;
$helpIni = $this->createTestFile('help.ini', $helpConfig, $helpPath);

$database->setTranslation('help_content_general', [
'en' => 'general.en.txt',
'de' => 'general.de.txt'
], 'help');
// no custom key for `help_content_policies`

$update = new Application_Update_ImportHelpFiles();
$update->setHelpPath($helpPath);
$update->setQuietMode(true);
$update->run();

$this->assertFileNotExists($generalDe);
$this->assertFileExists($generalDe . '.imported');
$this->assertFileNotExists($generalEn);
$this->assertFileExists($generalEn . '.imported');
$this->assertFileNotExists($policiesDe);
$this->assertFileExists($policiesDe . '.imported');
$this->assertFileNotExists($policiesEn);
$this->assertFileExists($policiesEn . '.imported');

$translations = $database->getTranslations();
$this->assertArrayHasKey('help_content_general', $translations);
$this->assertArrayHasKey('help_content_policies', $translations);

$translations = $database->getTranslation('help_content_general');
$this->assertEquals([
'en' => 'General',
'de' => 'Allgemein'
], $translations);

$translations = $database->getTranslation('help_content_policies');
$this->assertEquals([
'en' => 'Policies',
'de' => 'Leitlinien'
], $translations);
}

/**
* The help content in txt files and defined in TMX files needs to match perfectly, so the default
* content will not be imported into the database.
*/
public function testTmxContentMatchesHelpFiles()
{
$database = new Opus_Translate_Dao();
$database->removeAll();

$update = new Application_Update_ImportHelpFiles();
$update->setRemoveFilesEnabled(false);
$update->setQuietMode(true);

$files = $update->getHelpFiles();
$helpPath = $update->getHelpPath();
$prefix = 'help_content_';

foreach ($files as $key => $translations) {
foreach ($translations as $lang => $value) {
if (substr($key, 0, strlen($prefix)) == $prefix) {
$baseName = substr($key, strlen($prefix));
$fileName = "$baseName.{$lang}.txt";
$path = $helpPath . $fileName;
if (is_readable($path)) {
$fileContent = trim(file_get_contents($path));
}
}
$this->assertEquals($fileContent, $value, "File and TMX for '$key' in '$lang' do not match.");
}
}
}
}

0 comments on commit 2822189

Please sign in to comment.