From 8c4e92f555e79fc080f8d334279a891c37ae4ff6 Mon Sep 17 00:00:00 2001 From: Daniel Berthereau Date: Mon, 24 Oct 2022 00:00:00 +0000 Subject: [PATCH] Released version 3.3.35. --- config/module.ini | 2 +- data/scripts/upgrade.php | 82 +++++++++++++++++++++++- src/Processor/MetadataTransformTrait.php | 8 +-- 3 files changed, 85 insertions(+), 7 deletions(-) diff --git a/config/module.ini b/config/module.ini index efb8da14..8ce222a6 100644 --- a/config/module.ini +++ b/config/module.ini @@ -8,6 +8,6 @@ author_link = "https://gitlab.com/Daniel-KM" module_link = "https://gitlab.com/Daniel-KM/Omeka-S-module-BulkImport" support_link = "https://gitlab.com/Daniel-KM/Omeka-S-module-BulkImport/-/issues" configurable = true -version = "3.3.34" +version = "3.3.35" omeka_version_constraint = "^3.1.0" dependencies = "Log" diff --git a/data/scripts/upgrade.php b/data/scripts/upgrade.php index b27e2981..ccd9bfc9 100644 --- a/data/scripts/upgrade.php +++ b/data/scripts/upgrade.php @@ -455,7 +455,7 @@ $connection->executeStatement($sql); // Module resources are not available during upgrade. - // Update mapping files. + // Update importer files. $qb = $connection->createQueryBuilder(); $qb ->select('bulk_importer.id', 'bulk_importer.reader_config') @@ -555,7 +555,7 @@ $connection->executeStatement($sql); } -if (version_compare($oldVersion, '3.3.34.0', '<')) { +if (version_compare($oldVersion, '3.3.34', '<')) { require_once __DIR__ . '/upgrade_vocabulary.php'; $messenger = new Messenger(); @@ -569,3 +569,81 @@ ); $messenger->addSuccess($message); } + +if (version_compare($oldVersion, '3.3.35', '<')) { + $user = $services->get('Omeka\AuthenticationService')->getIdentity(); + + // The resource "bulk_importers" is not available during upgrade. + require_once dirname(__DIR__, 2) . '/src/Entity/Import.php'; + require_once dirname(__DIR__, 2) . '/src/Entity/Importer.php'; + + $filenames = [ + 'csv - assets.php', + 'ods - assets.php', + 'tsv - assets.php', + ]; + foreach ($filenames as $filename) { + $filepath = dirname(__DIR__) . '/importers/' . $filename; + $data = include $filepath; + $data['owner'] = $user; + $entity = new \BulkImport\Entity\Importer(); + foreach ($data as $key => $value) { + $method = 'set' . ucfirst($key); + $entity->$method($value); + } + $entityManager->persist($entity); + } + $entityManager->flush(); + + // Check configs for new formats. + // Module resources are not available during upgrade. + // Update mapping files. + $replaceIni = []; + $replaceXml = []; + $dataTypes = $services->get('Omeka\DataTypeManager')->getRegisteredNames(); + $dataTypes[] = 'customvocab:'; + foreach ($dataTypes as $dataType) { + $replaceIni[' ; ' . $dataType] = ' ^^' . $dataType; + $replaceIni['; ' . $dataType] = ' ^^' . $dataType; + $replaceIni[' ;' . $dataType] = ' ^^' . $dataType; + $replaceIni[';' . $dataType] = ' ^^' . $dataType; + $replaceXml[' ; ' . $dataType] = ' ' . $dataType; + $replaceXml['; ' . $dataType] = ' ' . $dataType; + $replaceXml[' ;' . $dataType] = ' ' . $dataType; + $replaceXml[';' . $dataType] = ' ' . $dataType; + } + $qb = $connection->createQueryBuilder(); + $qb + ->select('bulk_mapping.id', 'bulk_mapping.mapping') + ->from('bulk_mapping', 'bulk_mapping') + ->orderBy('bulk_mapping.id', 'asc'); + $mappingConfigs = $connection->executeQuery($qb)->fetchAllKeyValue(); + foreach ($mappingConfigs as $id => $mappingConfig) { + $mappingConfig = substr(trim($mappingConfigs), 0, 1) === '<' + ? str_replace(array_keys($replaceXml), array_values($replaceXml), $mappingConfig) + : str_replace(array_keys($replaceIni), array_values($replaceIni), $mappingConfig); + $sql = <<<'SQL' +UPDATE `bulk_importer` +SET + `reader_config` = ? +WHERE + `id` = ? +; +SQL; + $connection->executeStatement($sql, [ + $mappingConfig, + $id, + ]); + } + + $messenger = new Messenger(); + $message = new Message( + 'It’s now possible to import and update assets and to attach them to resources.' // @translate + ); + $messenger->addSuccess($message); + + $message = new Message( + 'The format of destination metadata has been improved: spaces after "^^", "@" and "§" are no more managed; for multiple datatypes, the ";" was replaced by "^^"; for custom vocab with a label, the label should be wrapped by quotes or double quotes. Check your custom configs if needed.' // @translate + ); + $messenger->addWarning($message); +} diff --git a/src/Processor/MetadataTransformTrait.php b/src/Processor/MetadataTransformTrait.php index 6bd1417e..80dadcf2 100644 --- a/src/Processor/MetadataTransformTrait.php +++ b/src/Processor/MetadataTransformTrait.php @@ -572,7 +572,7 @@ protected function operationFillResource(array $params): bool $list = $this->listDataValues([$sourceTerm => $sourceId], ['valuesuggest'], 'uri', false); $headers = [ - 'User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/96.0', + 'User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/116.0', 'Content-Type' => 'application/xml', 'Accept-Encoding' => 'gzip, deflate', ]; @@ -3252,7 +3252,7 @@ protected function valueSuggestQueryGeonames(string $value, string $datatype, ar // Don't use https, or add certificate to omeka config. $url = 'http://api.geonames.org/searchJSON'; $headers = [ - 'User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/96.0', + 'User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/116.0', 'Content-Type' => 'application/json', 'Accept-Encoding' => 'gzip, deflate', ]; @@ -3386,7 +3386,7 @@ protected function valueSuggestQueryIdRefAuthor(string $value, string $datatype, ]; $url = 'https://www.idref.fr/Sru/Solr'; $headers = [ - 'User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/96.0', + 'User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/116.0', 'Content-Type' => 'application/json', 'Accept-Encoding' => 'gzip, deflate', ]; @@ -3505,7 +3505,7 @@ protected function valueSuggestQueryIdRefRameau(string $value, string $datatype, ]; $url = 'https://www.idref.fr/Sru/Solr'; $headers = [ - 'User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/96.0', + 'User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/116.0', 'Content-Type' => 'application/json', 'Accept-Encoding' => 'gzip, deflate', ];