Skip to content

Commit

Permalink
Merge branch 'dev' into folio-bound-with
Browse files Browse the repository at this point in the history
  • Loading branch information
maccabeelevine committed Nov 28, 2023
2 parents 6346533 + 3e2a704 commit 2b82cb9
Show file tree
Hide file tree
Showing 18 changed files with 185 additions and 111 deletions.
21 changes: 11 additions & 10 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<property name="vufinddbpass" value="vufindtestpass" />
<property name="dbtype" value="mysql" /><!-- use pgsql for PostgreSQL -->
<property name="mysqlhost" value="localhost" />
<property name="mysqlport" value="3306" />
<property name="mysqlrootuser" value="root" />
<property name="mysqlrootpass" value="password" />
<property name="pgsqlhost" value="localhost" />
Expand Down Expand Up @@ -498,7 +499,7 @@
<property name="db_connection_string" value="pgsql://${vufinddbuser}:${vufinddbpass}@${pgsqlhost}/${vufinddb}" />
</then>
<else>
<property name="db_connection_string" value="mysql://${vufinddbuser}:${vufinddbpass}@${mysqlhost}/${vufinddb}" />
<property name="db_connection_string" value="mysql://${vufinddbuser}:${vufinddbpass}@${mysqlhost}:${mysqlport}/${vufinddb}" />
</else>
</if>

Expand Down Expand Up @@ -562,13 +563,13 @@
</then>
<else>
<!-- build database -->
<exec command="mysqladmin -f -h ${mysqlhost} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} drop ${vufinddb}" />
<exec command="mysqladmin -h ${mysqlhost} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} create ${vufinddb}" checkreturn="true" />
<exec command="mysql -h ${mysqlhost} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} -e &quot;DROP USER '${vufinddbuser}'@'${mysqlhost}'&quot;" />
<exec command="mysql -h ${mysqlhost} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} -e &quot;CREATE USER '${vufinddbuser}'@'${mysqlhost}' IDENTIFIED BY '${vufinddbpass}'&quot;" checkreturn="true" />
<exec command="mysql -h ${mysqlhost} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} -e &quot;GRANT SELECT,INSERT,UPDATE,DELETE ON ${vufinddb}.* TO '${vufinddbuser}'@'${mysqlhost}' WITH GRANT OPTION&quot;" checkreturn="true" />
<exec command="mysql -h ${mysqlhost} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} -e &quot;FLUSH PRIVILEGES&quot;" checkreturn="true" />
<exec command="mysql -h ${mysqlhost} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} -D ${vufinddb} &lt; ${srcdir}/module/VuFind/sql/mysql.sql" checkreturn="true" />
<exec command="mysqladmin -f -h ${mysqlhost} -P ${mysqlport} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} drop ${vufinddb}" />
<exec command="mysqladmin -h ${mysqlhost} -P ${mysqlport} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} create ${vufinddb}" checkreturn="true" />
<exec command="mysql -h ${mysqlhost} -P ${mysqlport} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} -e &quot;DROP USER '${vufinddbuser}'@'%'&quot;" />
<exec command="mysql -h ${mysqlhost} -P ${mysqlport} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} -e &quot;CREATE USER '${vufinddbuser}'@'%' IDENTIFIED BY '${vufinddbpass}'&quot;" checkreturn="true" />
<exec command="mysql -h ${mysqlhost} -P ${mysqlport} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} -e &quot;GRANT SELECT,INSERT,UPDATE,DELETE ON ${vufinddb}.* TO '${vufinddbuser}'@'%' WITH GRANT OPTION&quot;" checkreturn="true" />
<exec command="mysql -h ${mysqlhost} -P ${mysqlport} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} -e &quot;FLUSH PRIVILEGES&quot;" checkreturn="true" />
<exec command="mysql -h ${mysqlhost} -P ${mysqlport} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} -D ${vufinddb} &lt; ${srcdir}/module/VuFind/sql/mysql.sql" checkreturn="true" />
</else>
</if>
</target>
Expand Down Expand Up @@ -654,8 +655,8 @@ ${git_status}
<exec command="sudo su -c &quot;psql -c \&quot;DROP USER ${vufinddbuser};\&quot;&quot; ${pgsqlrootuser}" checkreturn="true" />
</then>
<else>
<exec command="mysql -h ${mysqlhost} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} -e &quot;DROP USER '${vufinddbuser}'@'${mysqlhost}'&quot;" />
<exec command="mysqladmin -f -h ${mysqlhost} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} drop ${vufinddb}" />
<exec command="mysql -h ${mysqlhost} -P ${mysqlport} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} -e &quot;DROP USER '${vufinddbuser}'@'%'&quot;" />
<exec command="mysqladmin -f -h ${mysqlhost} -P ${mysqlport} -u ${mysqlrootuser} ${mysqlpwswitch}${mysqlrootpass} drop ${vufinddb}" />
</else>
</if>

Expand Down
4 changes: 4 additions & 0 deletions config/vufind/EDS.ini
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,10 @@ AU = None
; Requires configuration in LibGuidesAPI.ini.
;useLibGuides = true

; Find database URLs by the LibGuides alternate names field in addition
; to the primary name. Default is true. Requires useLibGuides = true.
;useLibGuidesAlternateNames = false

; Map of database name (matching EDS API 'DbLabel' value) to website URL.
; These databases are added to any retrieved from LibGuides, and override
; the LibGuides URLs if the same name is present here.
Expand Down
2 changes: 1 addition & 1 deletion module/VuFind/src/VuFind/Connection/LibGuides.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function getAZ()
}

$result = $this->doGet(
$this->baseUrl . '/az'
$this->baseUrl . '/az?expand=az_props'
);

if (isset($result->errorCode)) {
Expand Down
78 changes: 48 additions & 30 deletions module/VuFind/src/VuFind/Recommend/Databases.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,57 +74,58 @@ class Databases implements RecommendInterface, \Laminas\Log\LoggerAwareInterface
*
* @var int
*/
protected $limit;

/**
* Name of the configuration file for databases config (minus ".ini").
*
* @var string
*/
protected $databasesConfigFile;
protected $limit = 5;

/**
* The result facet with the list of databases. Each value in the
* array is a level of the facet hierarchy.
*
* @var array
*/
protected $resultFacet;
protected $resultFacet = [];

/**
* For each database facet, the key to the database name.
*
* @var string
*/
protected $resultFacetNameKey;
protected $resultFacetNameKey = 'value';

/**
* Databases listed in configuration file
*
* @var array
*/
protected $configFileDatabases;
protected $configFileDatabases = [];

/**
* Configuration of whether to use the query string as a match point
*
* @var bool
*/
protected $useQuery;
protected $useQuery = true;

/**
* Minimum string length of a query to use as a match point
*
* @var bool
*/
protected $useQueryMinLength;
protected $useQueryMinLength = 3;

/**
* Configuration of whether to use LibGuides as a data source
*
* @var bool
*/
protected $useLibGuides;
protected $useLibGuides = false;

/**
* Configuration of whether to match on the alt_names field in LibGuides
* in addition to the primary name
*
* @var bool
*/
protected $useLibGuidesAlternateNames = true;

/**
* Callable for LibGuides connector
Expand Down Expand Up @@ -159,33 +160,43 @@ public function __construct(
*/
public function setConfig($settings)
{
// Only change settings from current values if they are defined in $settings or .ini

$settings = explode(':', $settings);
$this->limit
= (isset($settings[0]) && is_numeric($settings[0]) && $settings[0] > 0)
? intval($settings[0]) : 5;
? intval($settings[0]) : $this->limit;
$databasesConfigFile = $settings[1] ?? 'EDS';

$databasesConfig = $this->configManager->get($databasesConfigFile)->Databases;
if (!$databasesConfig) {
throw new \Exception("Databases config file $databasesConfigFile must have section 'Databases'.");
}
$configUrls = isset($databasesConfig->url) ? $databasesConfig->url->toArray() : [];
$this->configFileDatabases = array_map(function ($url) {
return ['url' => $url];
}, $configUrls);

$this->resultFacet = isset($databasesConfig->resultFacet)
? $databasesConfig->resultFacet->toArray() : [];
$this->resultFacetNameKey = $databasesConfig->resultFacetNameKey ?? 'value';

$this->useQuery = $databasesConfig->useQuery ?? true;
$this->useQueryMinLength = $databasesConfig->useQueryMinLength ?? 3;

$this->useLibGuides = $databasesConfig->useLibGuides ?? false;
$this->configFileDatabases = $databasesConfig->url?->toArray()
?? $this->configFileDatabases;
array_walk($this->configFileDatabases, function (&$value, $name) {
$value = [
'name' => $name,
'url' => $value,
];
});

$this->resultFacet = $databasesConfig->resultFacet?->toArray() ?? $this->resultFacet;
$this->resultFacetNameKey = $databasesConfig->resultFacetNameKey
?? $this->resultFacetNameKey;

$this->useQuery = $databasesConfig->useQuery ?? $this->useQuery;
$this->useQueryMinLength = $databasesConfig->useQueryMinLength
?? $this->useQueryMinLength;

$this->useLibGuides = $databasesConfig->useLibGuides ?? $this->useLibGuides;
if ($this->useLibGuides) {
// Cache the data related to profiles for up to 10 minutes:
$libGuidesApiConfig = $this->configManager->get('LibGuidesAPI');
$this->cacheLifetime = intval($libGuidesApiConfig->GetAZ->cache_lifetime ?? 600);

$this->useLibGuidesAlternateNames = $databasesConfig->useLibGuidesAlternateNames
?? $this->useLibGuidesAlternateNames;
}
}

Expand Down Expand Up @@ -247,6 +258,9 @@ public function getResults()
return [];
}
$nameToDatabase = $this->getDatabases();

// Array of url => [name, url]. Key by URL so that the same database (under alternate
// names) is not duplicated.
$databases = [];

// Add databases from search query
Expand All @@ -255,7 +269,7 @@ public function getResults()
if (strlen($query) >= $this->useQueryMinLength) {
foreach ($nameToDatabase as $name => $databaseInfo) {
if (str_contains(strtolower($name), $query)) {
$databases[$name] = $databaseInfo;
$databases[$databaseInfo['url']] = $databaseInfo;
}
if (count($databases) >= $this->limit) {
return $databases;
Expand All @@ -274,7 +288,7 @@ public function getResults()
}
$databaseInfo = $nameToDatabase[$name] ?? null;
if ($databaseInfo) {
$databases[$name] = $databaseInfo;
$databases[$databaseInfo['url']] = $databaseInfo;
}
if (count($databases) >= $this->limit) {
return $databases;
Expand Down Expand Up @@ -316,6 +330,10 @@ protected function getLibGuidesDatabases()
$nameToDatabase = [];
foreach ($databases as $database) {
$nameToDatabase[$database->name] = (array)$database;
// The alt_names field is single-valued free text
if ($this->useLibGuidesAlternateNames && ($database->alt_names ?? false)) {
$nameToDatabase[$database->alt_names] = (array)$database;
}
}

$this->putCachedData('libGuidesAZ-nameToDatabase', $nameToDatabase);
Expand Down
13 changes: 11 additions & 2 deletions module/VuFind/src/VuFind/View/Helper/Root/RecordDataFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,19 +281,28 @@ public function setDefaults($key, $values)
protected function addOptions($context, $field, $options)
{
if ($globalOptions = ($this->config->Global ?? false)) {
$options = array_filter($options, function ($val) {
return $val !== null;
});
$options = array_merge($globalOptions->toArray(), $options);
}

$section = 'Field_' . $field;
if ($fieldOptions = ($this->config->$section ?? false)) {
$options = array_merge($options, $fieldOptions->toArray());
$fieldOptions = array_filter($fieldOptions->toArray(), function ($val) {
return $val !== null;
});
$options = array_merge($options, $fieldOptions);
}

$contextSection = $options['overrideContext'][$context] ?? false;
if (
$contextOptions = $this->config->$contextSection ?? false
) {
$options = array_merge($options, $contextOptions->toArray());
$contextOptions = array_filter($contextOptions->toArray(), function ($val) {
return $val !== null;
});
$options = array_merge($options, $contextOptions);
}

return $options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@

namespace VuFind\View\Helper\Root\RecordDataFormatter;

use function array_key_exists;

/**
* Specification builder for record driver data formatting view helper
*
Expand All @@ -56,11 +54,6 @@ class SpecBuilder
*/
protected $maxPos = 0;

/**
* If alternative script should be prioritized by combine alt render method
*/
protected $defaultPrioritizeAlt = false;

/**
* Constructor
*
Expand Down Expand Up @@ -124,10 +117,6 @@ public function setMultiLine($key, $dataMethod, $callback, $options = [])
*/
public function setCombineAltLine($key, $dataMethod, $options = [])
{

if ($this->defaultPrioritizeAlt && !array_key_exists('prioritizeAlt', $options)) {
$options['prioritizeAlt'] = true;
}
$this->setLine($key, $dataMethod, 'CombineAlt', $options);
}

Expand All @@ -147,18 +136,6 @@ public function setTemplateLine($key, $dataMethod, $template, $options = [])
$this->setLine($key, $dataMethod, 'RecordDriverTemplate', $options);
}

/**
* Set default prioritize alternative scripts
*
* @param bool $defaultPeferAlt Default prioritize alt
*
* @return void
*/
public function setDefaultPrioritizeAlt($defaultPeferAlt)
{
$this->defaultPrioritizeAlt = $defaultPeferAlt;
}

/**
* Reorder the specs to match the provided array of keys.
*
Expand Down
Loading

0 comments on commit 2b82cb9

Please sign in to comment.