Skip to content
Snippets Groups Projects
Commit 46c69952 authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

dev #72435 : authority refacto + patch resilience

parent ff427758
Branches
Tags
2 merge requests!2894Dev#72435 3 explo autorite etape 1 minsoc09 communaute importer un fichier autorite,!2874Dev#72435 3 explo autorite etape 1 minsoc09 communaute importer un fichier autorite
Pipeline #4910 passed with stage
in 48 minutes and 22 seconds
<?php
$adapter = Zend_Db_Table_Abstract::getDefaultAdapter();
try {
$adapter->query('ALTER TABLE notices add column type int not null default 1');
$adapter->query('ALTER TABLE notices add KEY type (type)');
$adapter->query('ALTER TABLE exemplaires add column type int not null default 1');
$adapter->query('ALTER TABLE exemplaires add KEY type (type)');
} catch(Exception $e) {
echo $e->getMessage();
}
$try = function ($query) use($adapter) {
try {
$adapter->query($query);
} catch(Exception $e) {}
};
$try('ALTER TABLE notices add column type int not null default 1');
$try('ALTER TABLE notices add KEY type (type)');
$try('ALTER TABLE exemplaires add column type int not null default 1');
$try('ALTER TABLE exemplaires add KEY type (type)');
\ No newline at end of file
......@@ -225,142 +225,3 @@ class Class_Cosmogramme_Integration_Record_Authority {
return $this;
}
}
class Class_Cosmogramme_Integration_Record_AuthorityRelation {
const
FIELD_ID = '3',
FIELD_TYPE = '5',
FIELD_LABEL = 'a';
protected
$_id,
$_type = 'z',
$_label,
$_authority_type;
public static function possibleFields() {
return (new Class_Cosmogramme_Integration_Record_AuthorityType)
->variantsOf(['4', '5']);
}
public function __construct($datas, $field) {
if (!$datas)
return;
$map = [static::FIELD_ID => '_id',
static::FIELD_TYPE => '_type',
static::FIELD_LABEL => '_label'];
foreach($datas as $pair)
if (array_key_exists($pair['code'], $map))
$this->{$map[$pair['code']]} = $pair['valeur'];
$this->_authority_type = (new Class_Cosmogramme_Integration_Record_AuthorityType)
->codeFromField($field);
}
public function isValid() {
return $this->_id && $this->_label;
}
public function id() {
return $this->_id;
}
public function label() {
return $this->_label;
}
public function facet() {
return $this->_type . $this->_id;
}
public function authorityType() {
return $this->_authority_type;
}
}
class Class_Cosmogramme_Integration_Record_AuthorityType {
protected $_map =
[
'00' => 'a',// = nom de personne
'10' => 'b',// = nom de collectivité
'15' => 'c',// = nom de territoire ou nom géographique
'16' => 'd',// = marque
'20' => 'e',// = famille
'30' => 'f',// = titre uniforme
'35' => 'g',// = rubrique de classement
'40' => 'h',// = auteur / titre
'45' => 'i',// = auteur / rubrique de classement
'50' => 'j',// = matière nom commun
'60' => 'k',// = lieu d’édition
'80' => 'l',// = forme, genre ou caractéristiques physiques
];
public function codeFromField($field) {
if (!$field)
return '';
$key = substr($field, 1);
return array_key_exists($key, $this->_map)
? $this->_map[$key]
: '';
}
public function codeFromFirstIn($prefix, $reader) {
foreach($this->_map as $zone => $type)
if ($reader->get_subfield($prefix . $zone))
return $type;
}
public function valueFromFirstIn($prefix, $subfield, $reader) {
foreach($this->_variantsOfOne($prefix) as $field)
if ($result = $reader->get_subfield($field, $subfield))
return current($result);
}
public function valuesFrom($prefix, $subfield, $reader) {
$values = [];
foreach($this->_variantsOfOne($prefix) as $field)
if ($result = $reader->get_subfield($field, $subfield))
$values = array_merge($values, $result);
return $values;
}
public function variantsOf($prefixes) {
$variants = [];
foreach($prefixes as $prefix)
$variants = array_merge($variants, $this->_variantsOfOne($prefix));
return $variants;
}
protected function _variantsOfOne($prefix) {
return array_map(function($zone) use($prefix) { return $prefix . $zone; },
array_keys($this->_map));
}
public function withZonesDo($closure) {
foreach($this->_map as $zone => $type)
$closure($zone, $type);
}
}
\ No newline at end of file
<?php
/**
* Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH 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 AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class Class_Cosmogramme_Integration_Record_AuthorityRelation {
const
FIELD_ID = '3',
FIELD_TYPE = '5',
FIELD_LABEL = 'a';
protected
$_id,
$_type = 'z',
$_label,
$_authority_type;
public static function possibleFields() {
return (new Class_Cosmogramme_Integration_Record_AuthorityType)
->variantsOf(['4', '5']);
}
public function __construct($datas, $field) {
if (!$datas)
return;
$map = [static::FIELD_ID => '_id',
static::FIELD_TYPE => '_type',
static::FIELD_LABEL => '_label'];
foreach($datas as $pair)
if (array_key_exists($pair['code'], $map))
$this->{$map[$pair['code']]} = $pair['valeur'];
$this->_authority_type = (new Class_Cosmogramme_Integration_Record_AuthorityType)
->codeFromField($field);
}
public function isValid() {
return $this->_id && $this->_label;
}
public function id() {
return $this->_id;
}
public function label() {
return $this->_label;
}
public function facet() {
return $this->_type . $this->_id;
}
public function authorityType() {
return $this->_authority_type;
}
}
<?php
/**
* Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH 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 AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class Class_Cosmogramme_Integration_Record_AuthorityType {
protected $_map =
[
'00' => 'a',// = nom de personne
'10' => 'b',// = nom de collectivité
'15' => 'c',// = nom de territoire ou nom géographique
'16' => 'd',// = marque
'20' => 'e',// = famille
'30' => 'f',// = titre uniforme
'35' => 'g',// = rubrique de classement
'40' => 'h',// = auteur / titre
'45' => 'i',// = auteur / rubrique de classement
'50' => 'j',// = matière nom commun
'60' => 'k',// = lieu d’édition
'80' => 'l',// = forme, genre ou caractéristiques physiques
];
public function codeFromField($field) {
if (!$field)
return '';
$key = substr($field, 1);
return array_key_exists($key, $this->_map)
? $this->_map[$key]
: '';
}
public function codeFromFirstIn($prefix, $reader) {
foreach($this->_map as $zone => $type)
if ($reader->get_subfield($prefix . $zone))
return $type;
}
public function valueFromFirstIn($prefix, $subfield, $reader) {
foreach($this->_variantsOfOne($prefix) as $field)
if ($result = $reader->get_subfield($field, $subfield))
return current($result);
}
public function valuesFrom($prefix, $subfield, $reader) {
$values = [];
foreach($this->_variantsOfOne($prefix) as $field)
if ($result = $reader->get_subfield($field, $subfield))
$values = array_merge($values, $result);
return $values;
}
public function variantsOf($prefixes) {
$variants = [];
foreach($prefixes as $prefix)
$variants = array_merge($variants, $this->_variantsOfOne($prefix));
return $variants;
}
protected function _variantsOfOne($prefix) {
return array_map(function($zone) use($prefix) { return $prefix . $zone; },
array_keys($this->_map));
}
public function withZonesDo($closure) {
foreach($this->_map as $zone => $type)
$closure($zone, $type);
}
}
\ No newline at end of file
......@@ -16,7 +16,7 @@
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class Class_Systeme_Include {
protected static $_instance;
......@@ -42,5 +42,3 @@ class Class_Systeme_Include {
return true;
}
}
?>
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment