Skip to content

Commit

Permalink
Merge pull request #1263 from OPUS4/v4.8.0.8
Browse files Browse the repository at this point in the history
Patch Release OPUS 4.8.0.8
  • Loading branch information
j3nsch authored Dec 4, 2024
2 parents 990fcd0 + 2bf6340 commit cd4c339
Show file tree
Hide file tree
Showing 31 changed files with 2,134 additions and 21 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# OPUS 4 Change Log

## Release 4.8.0.8 - 2024-12-04

https://github.com/OPUS4/application/issues/1253
https://github.com/OPUS4/application/issues/1258

## Release 4.8.0.7 - 2024-10-22

https://github.com/OPUS4/application/issues/1243
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mostly.

## OPUS 4

The current version of OPUS 4 is __4.8.0.7__. It is available on the [master][MASTER] branch and compatible with
The current version of OPUS 4 is __4.8.0.8__. It is available on the [master][MASTER] branch and compatible with
PHP 7.1 to 8.1.

[Documentation][DOC]
Expand Down
16 changes: 16 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# OPUS 4 Release Notes

## Patch Release 4.8.0.8 - 2024-12-04

Das Blockieren der Enter/Return-Taste wurde auf die Metadaten-Formulare
im Publish-Modul und in der Administration beschränkt. In allen anderen
Formularen verhält sich die Taste daher wieder wie vor OPUS 4.8.0.7.

https://github.com/OPUS4/application/issues/1258

Es wurden neue Konsolen-Kommandos für den Umgang mit Enrichments hinzugefügt.
Alle OPUS 4 Kommandos können mit `bin/opus4` angezeigt werden. Das Kommando
`enrichment:import` kann zum Beispiel verwendet werden, um in einer Yaml-Datei
definierte Enrichments anzulegen. Beispiele für solche Konfigurationen finden
sich in `tests/resources/enrichments`.

https://github.com/OPUS4/application/issues/1253

## Patch Release 4.8.0.7 - 2024-10-22

Ein Fehler beim Drücken der Enter/Return-Taste in einfachen Text-Feldern
Expand Down
2 changes: 1 addition & 1 deletion application/configs/application.ini
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ name = 'OPUS 4'
logoLink = home
security = 1
workspacePath = APPLICATION_PATH "/workspace"
version = 4.8.0.7
version = 4.8.0.8
update.latestVersionCheckUrl = "https://api.github.com/repos/opus4/application/releases/latest"

; Determines the implementation of the OPUS 4 data model
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"ext-fileinfo": "*",
"ext-readline": "*",
"ext-sockets": "*",
"ext-yaml": "*",
"opus4/zf1-future": "1.21.*",
"jpgraph/jpgraph": "dev-master",
"opus4-repo/opus4-common": "^4.8",
Expand All @@ -34,6 +35,7 @@
"components/jqueryui": "1.12.*",
"oomphinc/composer-installers-extender": "^2.0",
"symfony/console": "*",
"symfony/yaml": "*",
"pear/log": "*"
},
"require-dev": {
Expand Down
201 changes: 201 additions & 0 deletions library/Application/Configuration/EnrichmentConfigImporter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
<?php

/**
* This file is part of OPUS. The software OPUS has been originally developed
* at the University of Stuttgart with funding from the German Research Net,
* the Federal Department of Higher Education and Research and the Ministry
* of Science, Research and the Arts of the State of Baden-Wuerttemberg.
*
* OPUS 4 is a complete rewrite of the original OPUS software and was developed
* by the Stuttgart University Library, the Library Service Center
* Baden-Wuerttemberg, the Cooperative Library Network Berlin-Brandenburg,
* the Saarland University and State Library, the Saxon State Library -
* Dresden State and University Library, the Bielefeld University Library and
* the University Library of Hamburg University of Technology with funding from
* the German Research Foundation and the European Regional Development Fund.
*
* LICENCE
* OPUS is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the Licence, or any later version.
* OPUS is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details. You should have received a copy of the GNU General Public License
* along with OPUS; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright Copyright (c) 2024, OPUS 4 development team
* @license http://www.gnu.org/licenses/gpl.html General Public License
*/

use Opus\Common\EnrichmentKey;
use Opus\Common\EnrichmentKeyInterface;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Imports Yaml configuration for Enrichments.
*
* TODO support output over OutputInterface
*/
class Application_Configuration_EnrichmentConfigImporter
{
/** @var OutputInterface */
private $output;

/**
* @param string $filePath
* @param string|null $keyName
*/
public function import($filePath, $keyName = null)
{
$config = yaml_parse_file($filePath);

$this->processConfig($config, $keyName);
}

/**
* @param string $yaml
* @param string|null $keyName
*/
public function importYaml($yaml, $keyName = null)
{
$config = yaml_parse($yaml);

$this->processConfig($config, $keyName);
}

/**
* @param array $config
* @param string|null $keyName
*/
protected function processConfig($config, $keyName = null)
{
if (! $config || ! is_array($config)) {
throw new InvalidArgumentException('First parameter should be an array');
}

$config = $this->changeKeysTolowerCase($config);

if (isset($config['enrichments'])) {
$enrichmentConfigs = $config['enrichments'];
} else {
if ($keyName !== null) {
$config['name'] = $keyName;
}
$enrichmentConfigs = [$config];
}

foreach ($enrichmentConfigs as $enrichment) {
$enrichmentKey = $this->createEnrichment($enrichment);
if ($enrichmentKey !== null) {
$name = $enrichmentKey->getName();
$this->getOutput()->writeln("Created enrichment key '{$name}'");
}
}
}

/**
* @param array $config
* @return EnrichmentKeyInterface|null
*/
public function createEnrichment($config)
{
$name = $config['name'];

$enrichmentKey = EnrichmentKey::fetchByName($name);

if ($enrichmentKey !== null) {
$this->getOutput()->writeln("Enrichment '{$enrichmentKey}' already exists");
return null;
}

$enrichmentKey = EnrichmentKey::new();

$enrichmentKey->setName($name);

$type = null;

if (isset($config['type'])) {
$type = ucfirst($config['type'] . 'Type');
$enrichmentKey->setType($type); // TODO make 'Type' suffix unnecessary
}

if (isset($config['options']) && $type !== null) {
$typeClass = 'Opus\\Enrichment\\' . $type;
$enrichmentType = new $typeClass();
$options = $config['options'];
if (is_array($options)) {
$enrichmentType->setOptions($options);
$enrichmentKey->setOptions($enrichmentType->getOptions());
} else {
$enrichmentType->setOptionsFromString($options);
$enrichmentKey->setOptions($enrichmentType->getOptions());
}
}

$enrichmentKey->store();

if (isset($config['translations'])) {
$this->createTranslations($name, $config['translations']);
}

return $enrichmentKey;
}

/**
* @param string $name
* @param array $translations
*/
public function createTranslations($name, $translations)
{
$helper = new Admin_Model_EnrichmentKeys();
$keys = array_keys($translations);
$supportedKeys = $helper->getSupportedKeys();
$unsupportedKeys = array_diff($keys, $supportedKeys);

if (count($unsupportedKeys) > 0) {
foreach ($unsupportedKeys as $key) {
$this->getOutput()->writeln("Unsupported translation key: {$key}");
}
}

$helper->createTranslations($name, null, $translations);
}

/**
* @param OutputInterface $output
* @return $this
*/
public function setOutput($output)
{
$this->output = $output;
return $this;
}

/**
* @return OutputInterface
*/
public function getOutput()
{
if ($this->output === null) {
$this->output = new NullOutput();
}
return $this->output;
}

/**
* @param array $config
* @return array
*/
protected function changeKeysTolowerCase($config)
{
return array_map(function ($item) {
if (is_array($item)) {
$item = $this->changeKeysToLowerCase($item);
}
return $item;
}, array_change_key_case($config, CASE_LOWER));
}
}
7 changes: 7 additions & 0 deletions library/Application/Console/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ public function __construct()
$this->add(new Application_Console_Debug_DocumentXmlCommand());
$this->add(new CoverGenerateCommand());

// TODO use ModelCommandProvider (with OPUS 4.8.1)
$this->add(new Application_Console_Model_EnrichmentImportCommand());
$this->add(new Application_Console_Model_EnrichmentListCommand());
$this->add(new Application_Console_Model_EnrichmentExportCommand());
$this->add(new Application_Console_Model_EnrichmentRenameCommand());
$this->add(new Application_Console_Model_EnrichmentDeleteCommand());

$this->setDefaultCommand('list');
}
}
112 changes: 112 additions & 0 deletions library/Application/Console/Model/EnrichmentDeleteCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php

/**
* This file is part of OPUS. The software OPUS has been originally developed
* at the University of Stuttgart with funding from the German Research Net,
* the Federal Department of Higher Education and Research and the Ministry
* of Science, Research and the Arts of the State of Baden-Wuerttemberg.
*
* OPUS 4 is a complete rewrite of the original OPUS software and was developed
* by the Stuttgart University Library, the Library Service Center
* Baden-Wuerttemberg, the Cooperative Library Network Berlin-Brandenburg,
* the Saarland University and State Library, the Saxon State Library -
* Dresden State and University Library, the Bielefeld University Library and
* the University Library of Hamburg University of Technology with funding from
* the German Research Foundation and the European Regional Development Fund.
*
* LICENCE
* OPUS is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the Licence, or any later version.
* OPUS is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details. You should have received a copy of the GNU General Public License
* along with OPUS; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright Copyright (c) 2024, OPUS 4 development team
* @license http://www.gnu.org/licenses/gpl.html General Public License
*/

use Opus\Common\EnrichmentKey;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;

/**
* Command for deleting enrichments.
*
* TODO Should there be a command for just removing enrichment from documents?
* TODO Should there be a command for just removing the configuration without removing the values?
*/
class Application_Console_Model_EnrichmentDeleteCommand extends Command
{
public const ARGUMENT_KEY = 'key';

public const OPTION_FORCE = 'force';

protected function configure()
{
parent::configure();

$help = <<<EOT
The <fg=green>enrichment:delete</> command can be used to delete enrichments. The command
also removes the translations associated with the enrichment.
EOT;

$this->setName('enrichment:delete')
->setDescription('Rename enrichment')
->setHelp($help)
->addArgument(
self::ARGUMENT_KEY,
InputArgument::OPTIONAL,
'Enrichment key'
)->addOption(
self::OPTION_FORCE,
'f',
InputOption::VALUE_NONE,
'Do not prompt for confirmation.'
);
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$key = $input->getArgument(self::ARGUMENT_KEY);

if ($key === null) {
$output->writeln('<error>Enrichment key is required</error>');
return 1;
}

$enrichment = EnrichmentKey::fetchByName($key);

if ($enrichment === null) {
$output->writeln("<error>Enrichment key \"{$key}\" not found</error>");
return 1;
}

if (! $input->getOption(self::OPTION_FORCE)) {
$questionText = "<question>Do you want to remove enrichment key \"{$key}\" (Y/n)?</question>";
$confirmation = new ConfirmationQuestion($questionText, true);
$question = $this->getHelper('question');

if (! $question->ask($input, $output, $confirmation)) {
$output->writeln("Not removing enrichment key \"{$key}\".");
return 0;
}
}

$output->writeln("Removing enrichment key \"{$key}\".");
$enrichment->delete();

$output->writeln("Removing translations for enrichment key \"{$key}\".");
$helper = new Admin_Model_EnrichmentKeys();
$helper->removeTranslations($key);

return 0;
}
}
Loading

0 comments on commit cd4c339

Please sign in to comment.