Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
jobs:
build:

runs-on: ubuntu-22.04
runs-on: ubuntu-24.04

strategy:
matrix:
Expand All @@ -21,7 +21,7 @@ jobs:
name: PHP ${{ matrix.php-versions }} Test

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v5

- name: Setup PHP ${{ matrix.php-versions }}
uses: shivammathur/setup-php@v2
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"opus4/zf1-future": "1.25.*",
"opus4-repo/opus4-common": "^4.9",
"opus4-repo/opus4-doi": "^4.9",
"opus4-repo/opus4-i18n": "*",
"symfony/console": "*",
"doctrine/dbal": "*",
"doctrine/orm": "*",
Expand Down
12 changes: 12 additions & 0 deletions db/schema/025-Remove-languages-table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
START TRANSACTION;

-- Remove table languages

DROP TABLE `languages`;

-- Update database version

TRUNCATE TABLE `schema_version`;
INSERT INTO `schema_version` (`version`) VALUES (25);

COMMIT;
80 changes: 71 additions & 9 deletions library/Opus/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@
* 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) 2014-2018, OPUS 4 development team
* @license http://www.gnu.org/licenses/gpl.html General Public License
*
* @category Framework
* @package Opus
* @author Jens Schwidder <schwidder@zib.de>
* @copyright Copyright (c) 2014, OPUS 4 development team
* @license http://www.gnu.org/licenses/gpl.html General Public License*
*/

namespace Opus;
Expand All @@ -41,8 +37,12 @@
use Opus\Common\Log;
use Opus\Common\LoggingTrait;
use Opus\Update\Plugin\DatabaseSchema;
use Opus\Update\Plugin\MigrateLanguages;
use Opus\Update\SchemaUpdatePluginInterface;
use PDO;
use PDOException;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Zend_Config;
use Zend_Exception;
use Zend_Log;
Expand Down Expand Up @@ -72,6 +72,8 @@
*
* TODO more logging
* TODO is admin level access to schema always necessary? distinguish?
* TODO use factory method (singleton)
* TODO switch to Doctrine
*
* phpcs:disable
*/
Expand Down Expand Up @@ -103,6 +105,15 @@ class Database
/** @var int */
private $_latestVersion = 0;

/** @var OutputInterface */
private $output;

/** @var bool */
private $quiet = false;

/** @var array */
private static $plugins;

/**
* @return string Name of database
*/
Expand Down Expand Up @@ -184,21 +195,23 @@ public function import($path)
$files[] = $path;
}

$output = $this->getOutput();

foreach ($files as $file) {
// TODO make output optional
$name = basename($file);
echo "Importing '$name' ... ";
$output->write("Importing '{$name}' ... ");
$sql = file_get_contents($file);
$this->getLogger()->info("Import SQL file: $name");
$this->exec($sql);
echo 'done' . PHP_EOL;
$output->writeln('done');
}
}

/**
* Loads and executes SQL file.
*
* @param $path Path to SQL file
* @param string $path Path to SQL file
*/
public function execScript($path)
{
Expand Down Expand Up @@ -455,6 +468,8 @@ public function getLatestVersion()
*/
public function update($targetVersion = null)
{
$this->registerPlugin(25, new MigrateLanguages());

$schemaUpdate = new DatabaseSchema();
$schemaUpdate->setTargetVersion($targetVersion);
$schemaUpdate->run();
Expand Down Expand Up @@ -496,4 +511,51 @@ public function getUpdateScripts($version = null, $targetVersion = null)

return $files;
}

public function getOutput(): OutputInterface
{
if ($this->output === null) {
$this->output = new ConsoleOutput();
if ($this->isQuiet()) {
$this->output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
}
}

return $this->output;
}

public function setQuiet(bool $quiet)
{
$this->quiet = $quiet;
}

public function isQuiet()
{
return $this->quiet;
}

public function registerPlugin(int $version, SchemaUpdatePluginInterface $plugin): self
{
if (isset(self::$plugins[$version])) {
$registeredPlugins = self::$plugins[$version];
if (! in_array($plugin, $registeredPlugins)) {
$registeredPlugins[] = $plugin;
self::$plugins[$version] = $registeredPlugins;
}
} else {
self::$plugins[$version] = [$plugin];
}

return $this;
}

public function getPlugins(int $version)
{
return self::$plugins[$version] ?? [];
}

public function clearPlugins()
{
self::$plugins = [];
}
}
2 changes: 1 addition & 1 deletion library/Opus/Doi/DataCiteXmlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function getXml($doc, $allowInvalidXml = false, $skipTestOfRequiredFields
}

$proc = new XSLTProcessor();
$proc->registerPHPFunctions('Opus\Common\Language::getLanguageCode');
$proc->registerPHPFunctions('Opus\I18n\Languages::getPart1');
$proc->importStyleSheet($xslt);

if (! $skipTestOfRequiredFields && ! $allowInvalidXml && ! $this->checkRequiredFields($doc)) {
Expand Down
8 changes: 4 additions & 4 deletions library/Opus/Doi/datacite.xslt
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@
<xsl:template match="TitleMain">
<xsl:element name="title">
<xsl:attribute name="xml:lang">
<xsl:value-of select="php:functionString('Opus\Common\Language::getLanguageCode', @Language, 'part1')" />
<xsl:value-of select="php:functionString('Opus\I18n\Languages::getPart1', @Language)" />
</xsl:attribute>
<xsl:value-of select="@Value"/>
</xsl:element>
Expand All @@ -245,7 +245,7 @@
<xsl:template match="TitleSub">
<xsl:element name="title">
<xsl:attribute name="xml:lang">
<xsl:value-of select="php:functionString('Opus\Common\Language::getLanguageCode', @Language, 'part1')" />
<xsl:value-of select="php:functionString('Opus\I18n\Languages::getPart1', @Language)" />
</xsl:attribute>
<xsl:attribute name="titleType">
<xsl:text>Subtitle</xsl:text>
Expand All @@ -257,7 +257,7 @@
<xsl:template match="TitleAbstract">
<xsl:element name="description">
<xsl:attribute name="xml:lang">
<xsl:value-of select="php:functionString('Opus\Common\Language::getLanguageCode', @Language, 'part1')" />
<xsl:value-of select="php:functionString('Opus\I18n\Languages::getPart1', @Language)" />
</xsl:attribute>
<xsl:attribute name="descriptionType">
<xsl:text>Abstract</xsl:text>
Expand Down Expand Up @@ -400,7 +400,7 @@

<xsl:template match="@Language">
<xsl:element name="language">
<xsl:value-of select="php:functionString('Opus\Common\Language::getLanguageCode', ., 'part1')" />
<xsl:value-of select="php:functionString('Opus\I18n\Languages::getPart1', .)" />
</xsl:element>
</xsl:template>

Expand Down
Loading