Create default format records in newTenant module.

This commit is contained in:
Alexander Bigga 2022-03-07 22:52:57 +01:00
parent a2de858bfd
commit 07ce39d452
11 changed files with 170 additions and 172 deletions

View File

@ -12,14 +12,17 @@
namespace Kitodo\Dlf\Controller;
use Kitodo\Dlf\Common\Helper;
use Kitodo\Dlf\Domain\Model\Format;
use Kitodo\Dlf\Domain\Repository\FormatRepository;
use Kitodo\Dlf\Domain\Repository\MetadataRepository;
use Kitodo\Dlf\Domain\Repository\StructureRepository;
use Kitodo\Dlf\Domain\Repository\SolrCoreRepository;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
use Kitodo\Dlf\Domain\Repository\StructureRepository;
use Kitodo\Dlf\Domain\Repository\MetadataRepository;
use Kitodo\Dlf\Domain\Repository\SolrCoreRepository;
class NewTenantController extends AbstractController
{
@ -41,16 +44,16 @@ class NewTenantController extends AbstractController
protected $defaultViewObjectName = \TYPO3\CMS\Backend\View\BackendTemplateView::class;
/**
* @var StructureRepository
* @var FormatRepository
*/
protected $structureRepository;
protected $formatRepository;
/**
* @param StructureRepository $structureRepository
* @param FormatRepository $formatRepository
*/
public function injectStructureRepository(StructureRepository $structureRepository)
public function injectFormatRepository(FormatRepository $formatRepository)
{
$this->structureRepository = $structureRepository;
$this->formatRepository = $formatRepository;
}
/**
@ -66,6 +69,19 @@ class NewTenantController extends AbstractController
$this->metadataRepository = $metadataRepository;
}
/**
* @var StructureRepository
*/
protected $structureRepository;
/**
* @param StructureRepository $structureRepository
*/
public function injectStructureRepository(StructureRepository $structureRepository)
{
$this->structureRepository = $structureRepository;
}
/**
* @var SolrCoreRepository
*/
@ -90,6 +106,39 @@ class NewTenantController extends AbstractController
$this->getLanguageService()->includeLLFile('EXT:dlf/Resources/Private/Language/locallang_mod_newtenant.xlf');
$this->getLanguageService()->includeLLFile('EXT:dlf/Resources/Private/Language/locallang_structure.xlf');
$this->getLanguageService()->includeLLFile('EXT:dlf/Resources/Private/Language/locallang_metadata.xlf');
}
/**
* Action adding formats records
*/
public function addFormatAction()
{
// Include formats definition file.
$formatsDefaults = include (ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/FormatDefaults.php');
$frameworkConfiguration = $this->configurationManager->getConfiguration($this->configurationManager::CONFIGURATION_TYPE_FRAMEWORK);
// tx_dlf_formats are stored on PID = 0
$frameworkConfiguration['persistence']['storagePid'] = 0;
$this->configurationManager->setConfiguration($frameworkConfiguration);
$allFormats = $this->formatRepository->findAll();
foreach ($formatsDefaults as $type => $values) {
if ($this->formatRepository->findOneByType($type) === null) {
$newFormat = GeneralUtility::makeInstance(Format::class);
$newFormat->setType($type);
$newFormat->setRoot($values['root']);
$newFormat->setNamespace($values['namespace']);
$newFormat->setClass($values['class']);
$this->formatRepository->add($newFormat);
}
}
$this->forward('index');
}
/**
@ -255,6 +304,8 @@ class NewTenantController extends AbstractController
{
$this->pid = (int) GeneralUtility::_GP('id');
$formatsDefaults = include (ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/FormatDefaults.php');
if ($this->pageInfo['doktype'] != 254) {
$this->addFlashMessage(
$this->getLanguageService()->getLL('flash.wrongPageTypeMsg'),
@ -264,6 +315,25 @@ class NewTenantController extends AbstractController
return;
}
$countFormats = $this->formatRepository->countAll();
if ($countFormats >= count($formatsDefaults)) {
// Fine.
$this->addFlashMessage(
$this->getLanguageService()->getLL('flash.formatOkayMsg'),
$this->getLanguageService()->getLL('flash.formatOkay'),
\TYPO3\CMS\Core\Messaging\FlashMessage::OK
);
} else {
// Configuration missing.
$this->addFlashMessage(
$this->getLanguageService()->getLL('flash.formatNotOkayMsg'),
$this->getLanguageService()->getLL('flash.formatNotOkay'),
\TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
);
$this->view->assign('format', 1);
}
$structures = $this->structureRepository->countByPid($this->pid);
if ($structures) {

View File

@ -15,4 +15,4 @@ namespace Kitodo\Dlf\Domain\Repository;
class FormatRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
{
}
}

View File

@ -58,138 +58,6 @@ class ConfigurationForm
return Helper::renderFlashMessages();
}
/**
* Make sure the essential namespaces are defined.
*
* @access public
*
* @return string Message informing the user of success or failure
*/
public function checkMetadataFormats()
{
if (explode('.', VersionNumberUtility::getCurrentTypo3Version())[0] < 10) {
// We need to do some bootstrapping manually in TYPO3 9.
// Load table configuration array into $GLOBALS['TCA'].
ExtensionManagementUtility::loadBaseTca(false);
// Get extension configuration from dlf/ext_localconf.php.
ExtensionManagementUtility::loadExtLocalconf(false);
// Initialize backend user into $GLOBALS['BE_USER'].
Bootstrap::initializeBackendUser();
// Initialize backend and ensure authenticated access.
Bootstrap::initializeBackendAuthentication();
}
$nsDefined = [
'MODS' => false,
'TEIHDR' => false,
'ALTO' => false,
'IIIF1' => false,
'IIIF2' => false,
'IIIF3' => false
];
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('tx_dlf_formats');
// Check existing format specifications.
$result = $queryBuilder
->select('tx_dlf_formats.type AS type')
->from('tx_dlf_formats')
->where(
'1=1'
)
->execute();
while ($resArray = $result->fetch()) {
$nsDefined[$resArray['type']] = true;
}
// Build data array.
$data = [];
// Add MODS namespace.
if (!$nsDefined['MODS']) {
$data['tx_dlf_formats'][uniqid('NEW')] = [
'pid' => 0,
'type' => 'MODS',
'root' => 'mods',
'namespace' => 'http://www.loc.gov/mods/v3',
'class' => 'Kitodo\\Dlf\\Format\\Mods'
];
}
// Add TEIHDR namespace.
if (!$nsDefined['TEIHDR']) {
$data['tx_dlf_formats'][uniqid('NEW')] = [
'pid' => 0,
'type' => 'TEIHDR',
'root' => 'teiHeader',
'namespace' => 'http://www.tei-c.org/ns/1.0',
'class' => 'Kitodo\\Dlf\\Format\\TeiHeader'
];
}
// Add ALTO namespace.
if (!$nsDefined['ALTO']) {
$data['tx_dlf_formats'][uniqid('NEW')] = [
'pid' => 0,
'type' => 'ALTO',
'root' => 'alto',
'namespace' => 'http://www.loc.gov/standards/alto/ns-v2#',
'class' => 'Kitodo\\Dlf\\Format\\Alto'
];
}
// Add IIIF Metadata API 1 context
if (!$nsDefined['IIIF1']) {
$data['tx_dlf_formats'][uniqid('NEW')] = [
'pid' => 0,
'type' => 'IIIF1',
'root' => 'IIIF1',
'namespace' => 'http://www.shared-canvas.org/ns/context.json',
'class' => ''
];
}
// Add IIIF Presentation 2 context
if (!$nsDefined['IIIF2']) {
$data['tx_dlf_formats'][uniqid('NEW')] = [
'pid' => 0,
'type' => 'IIIF2',
'root' => 'IIIF2',
'namespace' => 'http://iiif.io/api/presentation/2/context.json',
'class' => ''
];
}
// Add IIIF Presentation 3 context
if (!$nsDefined['IIIF3']) {
$data['tx_dlf_formats'][uniqid('NEW')] = [
'pid' => 0,
'type' => 'IIIF3',
'root' => 'IIIF3',
'namespace' => 'http://iiif.io/api/presentation/3/context.json',
'class' => ''
];
}
if (!empty($data)) {
// Process changes.
$substUid = Helper::processDBasAdmin($data);
if (!empty($substUid)) {
Helper::addMessage(
Helper::getLanguageService()->getLL('metadataFormats.nsCreatedMsg'),
Helper::getLanguageService()->getLL('metadataFormats.nsCreated'),
\TYPO3\CMS\Core\Messaging\FlashMessage::INFO
);
} else {
Helper::addMessage(
Helper::getLanguageService()->getLL('metadataFormats.nsNotCreatedMsg'),
Helper::getLanguageService()->getLL('metadataFormats.nsNotCreated'),
\TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
);
}
} else {
Helper::addMessage(
Helper::getLanguageService()->getLL('metadataFormats.nsOkayMsg'),
Helper::getLanguageService()->getLL('metadataFormats.nsOkay'),
\TYPO3\CMS\Core\Messaging\FlashMessage::OK
);
}
return Helper::renderFlashMessages();
}
/**
* This is the constructor.
*

View File

@ -10,7 +10,18 @@
-->
</f:comment>
<h1></h1>
<h1>New Tenant</h1>
<div style="padding: 5px;">
<f:if condition="{format}">
<f:then>
<f:form action="addFormat" name="format" addQueryString="1">
<f:form.submit name="submit" value="{f:translate(key: 'newTenant.createFormat')}" class="btn btn-primary"/>
</f:form>
</f:then>
</f:if>
</div>
<div style="padding: 5px;">
<f:if condition="{structure}">
<f:then>
@ -39,4 +50,4 @@
</f:form>
</f:then>
</f:if>
</div>
</div>

View File

@ -0,0 +1,44 @@
<?php
/**
* (c) Kitodo. Key to digital objects e.V. <contact@kitodo.org>
*
* This file is part of the Kitodo and TYPO3 projects.
*
* @license GNU General Public License version 3 or later.
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/
return [
'MODS' => [
'root' => 'mods',
'namespace' => 'http://www.loc.gov/mods/v3',
'class' => Kitodo\Dlf\Format\Mods::class,
],
'TEIHDR' => [
'root' => 'teiHeader',
'namespace' => 'http://www.tei-c.org/ns/1.0',
'class' => Kitodo\Dlf\Format\TeiHeader::class,
],
'ALTO' => [
'root' => 'alto',
'namespace' => 'http://www.loc.gov/standards/alto/ns-v2#',
'class' => Kitodo\Dlf\Format\Alto::class,
],
'IIIF1' => [
'root' => 'IIIF1',
'namespace' => 'http://www.shared-canvas.org/ns/context.json',
'class' => '',
],
'IIIF2' => [
'root' => 'IIIF2',
'namespace' => 'http://iiif.io/api/presentation/2/context.json',
'class' => '',
],
'IIIF3' => [
'root' => 'IIIF3',
'namespace' => 'http://iiif.io/api/presentation/3/context.json',
'class' => '',
],
];

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<xliff version="1.0">
<file source-language="en" target-language="de" datatype="plaintext" original="messages" date="2021-12-29T14:02:58Z">
<file source-language="en" target-language="de" datatype="plaintext" original="messages" date="2022-03-07T21:48:12Z">
<header>
<generator>LFEditor</generator>
</header>
@ -165,6 +165,14 @@
<source><![CDATA[descending]]></source>
<target><![CDATA[absteigend]]></target>
</trans-unit>
<trans-unit id="listview.form.orderBy" approved="yes">
<source><![CDATA[Order by:]]></source>
<target><![CDATA[Sortieren nach:]]></target>
</trans-unit>
<trans-unit id="listview.form.relevance" approved="yes">
<source><![CDATA[relevance]]></source>
<target><![CDATA[Relevanz]]></target>
</trans-unit>
<trans-unit id="listview.hits" approved="yes">
<source><![CDATA[%d hits found in %d documents.]]></source>
<target><![CDATA[Die Suche ergab %d Treffer in %d Dokumenten.]]></target>
@ -177,10 +185,6 @@
<source><![CDATA[Nothing found.]]></source>
<target><![CDATA[Keine Treffer.]]></target>
</trans-unit>
<trans-unit id="listview.form.orderBy" approved="yes">
<source><![CDATA[Order by:]]></source>
<target><![CDATA[Sortieren nach:]]></target>
</trans-unit>
<trans-unit id="listview.page" approved="yes">
<source><![CDATA[%d]]></source>
<target><![CDATA[%d]]></target>
@ -189,10 +193,6 @@
<source><![CDATA[&lt;]]></source>
<target><![CDATA[&lt;]]></target>
</trans-unit>
<trans-unit id="listview.form.relevance" approved="yes">
<source><![CDATA[relevance]]></source>
<target><![CDATA[Relevanz]]></target>
</trans-unit>
<trans-unit id="listview.separator" approved="yes">
<source><![CDATA[ - ]]></source>
<target><![CDATA[ - ]]></target>
@ -201,6 +201,10 @@
<source><![CDATA[...]]></source>
<target><![CDATA[...]]></target>
</trans-unit>
<trans-unit id="newTenant.createFormat" approved="yes">
<source><![CDATA[Create default namespaces]]></source>
<target><![CDATA[Standard-Namensräume anlegen]]></target>
</trans-unit>
<trans-unit id="newTenant.createMetadata" approved="yes">
<source><![CDATA[Create metadata]]></source>
<target><![CDATA[Metadaten Konfiguration anlegen]]></target>
@ -285,10 +289,6 @@
<source><![CDATA[Rotate Right]]></source>
<target><![CDATA[Ansicht nach rechts drehen]]></target>
</trans-unit>
<trans-unit id="search.operator.AND" approved="yes">
<source><![CDATA[and]]></source>
<target><![CDATA[und]]></target>
</trans-unit>
<trans-unit id="search.for" approved="yes">
<source><![CDATA[for "%s"]]></source>
<target><![CDATA[nach "%s"]]></target>
@ -309,6 +309,10 @@
<source><![CDATA[Page]]></source>
<target><![CDATA[Seite]]></target>
</trans-unit>
<trans-unit id="search.operator.AND" approved="yes">
<source><![CDATA[and]]></source>
<target><![CDATA[und]]></target>
</trans-unit>
<trans-unit id="search.operator.NOT" approved="yes">
<source><![CDATA[not]]></source>
<target><![CDATA[nicht]]></target>
@ -463,4 +467,4 @@
</trans-unit>
</body>
</file>
</xliff>
</xliff>

View File

@ -777,27 +777,27 @@
<source><![CDATA[Apache Solr not reachable with given configuration.]]></source>
<target><![CDATA[Apache Solr ist mit der gegebenen Konfiguration nicht erreichbar.]]></target>
</trans-unit>
<trans-unit id="metadataFormats.nsOkay" approved="yes">
<trans-unit id="flash.formatOkay" approved="yes">
<source><![CDATA[Default namespaces found!]]></source>
<target><![CDATA[Standard-Namensräume gefunden!]]></target>
</trans-unit>
<trans-unit id="metadataFormats.nsOkayMsg" approved="yes">
<trans-unit id="flash.formatOkayMsg" approved="yes">
<source><![CDATA[The namespace definitions for MODS, TEIHDR and ALTO do exist.]]></source>
<target><![CDATA[Die Standard-Namensräume für MODS, TEIHDR und ALTO sind definiert.]]></target>
</trans-unit>
<trans-unit id="metadataFormats.nsCreated" approved="yes">
<trans-unit id="flash.formatCreated" approved="yes">
<source><![CDATA[Default namespaces created successfully!]]></source>
<target><![CDATA[Standard-Namensräume erfolgreich angelegt!]]></target>
</trans-unit>
<trans-unit id="metadataFormats.nsCreatedMsg" approved="yes">
<trans-unit id="flash.formatCreatedMsg" approved="yes">
<source><![CDATA[The namespace definitions for MODS, TEIHDR and/or ALTO were created properly.]]></source>
<target><![CDATA[Die Standard-Namensräume für MODS, TEIHDR und/oder ALTO wurden erfolgreich definiert.]]></target>
</trans-unit>
<trans-unit id="metadataFormats.nsNotCreated" approved="yes">
<trans-unit id="flash.formatNotCreated" approved="yes">
<source><![CDATA[Default namespaces not found!]]></source>
<target><![CDATA[Standard-Namensräume nicht gefunden!]]></target>
</trans-unit>
<trans-unit id="metadataFormats.nsNotCreatedMsg" approved="yes">
<trans-unit id="flash.formatNotCreatedMsg" approved="yes">
<source><![CDATA[The namespace definitions for MODS, TEIHDR and/or ALTO do not exist and could not be created.]]></source>
<target><![CDATA[Die Standard-Namensräume für MODS, TEIHDR und/oder ALTO konnten nicht definiert werden.]]></target>
</trans-unit>

View File

@ -350,6 +350,9 @@
<trans-unit id="newTenant.createMetadata" approved="yes">
<source><![CDATA[Create metadata]]></source>
</trans-unit>
<trans-unit id="newTenant.createFormat" approved="yes">
<source><![CDATA[Create default namespaces]]></source>
</trans-unit>
</body>
</file>
</xliff>

View File

@ -596,22 +596,22 @@
<trans-unit id="solr.error" approved="yes">
<source><![CDATA[Apache Solr not reachable with given configuration.]]></source>
</trans-unit>
<trans-unit id="metadataFormats.nsOkay" approved="yes">
<trans-unit id="flash.formatOkay" approved="yes">
<source><![CDATA[Default namespaces found!]]></source>
</trans-unit>
<trans-unit id="metadataFormats.nsOkayMsg" approved="yes">
<trans-unit id="flash.formatOkayMsg" approved="yes">
<source><![CDATA[The namespace definitions for MODS, TEIHDR and ALTO do exist.]]></source>
</trans-unit>
<trans-unit id="metadataFormats.nsCreated" approved="yes">
<trans-unit id="flash.formatCreated" approved="yes">
<source><![CDATA[Default namespaces created successfully!]]></source>
</trans-unit>
<trans-unit id="metadataFormats.nsCreatedMsg" approved="yes">
<trans-unit id="flash.formatCreatedMsg" approved="yes">
<source><![CDATA[The namespace definitions for MODS, TEIHDR and/or ALTO were created properly.]]></source>
</trans-unit>
<trans-unit id="metadataFormats.nsNotCreated" approved="yes">
<trans-unit id="flash.formatNotOkay" approved="yes">
<source><![CDATA[Default namespaces not found!]]></source>
</trans-unit>
<trans-unit id="metadataFormats.nsNotCreatedMsg" approved="yes">
<trans-unit id="flash.formatNotOkayMsg" approved="yes">
<source><![CDATA[The namespace definitions for MODS, TEIHDR and/or ALTO do not exist and could not be created.]]></source>
</trans-unit>
</body>

View File

@ -1,5 +1,3 @@
# cat=Basic; type=user[Kitodo\Dlf\Hooks\ConfigurationForm->checkMetadataFormats]; label=LLL:EXT:dlf/Resources/Private/Language/Labels.xml:config.metadataFormats
metadataFormats = 0
# cat=Basic; type=boolean; label=LLL:EXT:dlf/Resources/Private/Language/Labels.xml:config.enableInternalProxy
enableInternalProxy = 0
# cat=Basic; type=string; label=LLL:EXT:dlf/Resources/Private/Language/Labels.xml:config.useragent

View File

@ -18,7 +18,7 @@ if (\TYPO3_MODE === 'BE') {
'newTenantModule', // Name of the module
'bottom', // Position of the module
[// Allowed controller action combinations
NewTenant::class => 'index,addMetadata,addSolrCore,addStructure',
NewTenant::class => 'index,addFormat,addMetadata,addSolrCore,addStructure',
],
[// Additional configuration
'access' => 'admin',