Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@

namespace VuFind\Config\Feature;

use VuFind\Config\Config;

/**
* Trait providing email settings.
*
Expand All @@ -47,16 +45,13 @@ trait EmailSettingsTrait
/**
* Get sender email address.
*
* @param array|Config $config VuFind configuration
* @param array $config VuFind configuration
* @param ?string $userEmail User's own email address that is used if permitted by settings
*
* @return string
*/
protected function getEmailSenderAddress(array|Config $config, ?string $userEmail = null): string
protected function getEmailSenderAddress(array $config, ?string $userEmail = null): string

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are calls to this method in \VuFind\Log\LoggerFactory::addMailHandler and \VuFindConsole\Command\ScheduledSearch\NotifyCommand that still pass a Config object. We'll need to update them before we can change the signature of this method.

{
if ($config instanceof Config) {
$config = $config->toArray();
}
if ($userEmail && ($config['Mail']['user_email_in_from'] ?? false)) {
return $userEmail;
}
Expand Down
9 changes: 2 additions & 7 deletions module/VuFind/src/VuFind/Config/Feature/SecretTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@

namespace VuFind\Config\Feature;

use VuFind\Config\Config;

/**
* Trait to import secret from file rather than a hardcoded config.
*
Expand All @@ -47,19 +45,16 @@ trait SecretTrait
* Will look for a _file-suffixed version of the key first,
* and load the data from a separate file if configured to do so.
*
* @param Config|array|null $config The config to read from
* @param array|null $config The config to read from
* @param string $key The key to retrieve
*
* @return string|null
*/
protected function getSecretFromConfig(Config|array|null $config, string $key): ?string
protected function getSecretFromConfig(array|null $config, string $key): ?string

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still being called with an object in \VuFind\Search\Factory\BrowZineBackendFactory and \VuFindSearch\Backend\EDS\Backend. Those calls will need to be updated to pass the right format -- this is the reason tests are failing.

{
if ($config === null) {
return null;
}
if ($config instanceof Config) {
$config = $config->toArray();
}
if ($secretFile = $config[$key . '_file'] ?? null) {
if (is_readable($secretFile)) {
$value = file_get_contents($secretFile);
Expand Down
61 changes: 30 additions & 31 deletions module/VuFind/src/VuFind/Log/LoggerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
use Psr\Container\ContainerInterface;
use Psr\Log\LogLevel;
use VuFind\Auth\Manager as AuthManager;
use VuFind\Config\Config;
use VuFind\Config\ConfigManagerInterface;
use VuFind\Config\Feature\EmailSettingsTrait;
use VuFind\Db\Connection;
Expand Down Expand Up @@ -84,14 +83,14 @@ class LoggerFactory implements FactoryInterface
* Configure Database handler.
*
* @param MonologLogger $logger The Monolog logger instance to add handlers to.
* @param Config $config Configuration
* @param array $config Configuration
* @param ContainerInterface $container Service manager
*
* @return void
*/
protected function addDbHandler(MonologLogger $logger, Config $config, ContainerInterface $container)
protected function addDbHandler(MonologLogger $logger, array $config, ContainerInterface $container)
{
$parts = explode(':', $config->Logging->database);
$parts = explode(':', $config['Logging']['database']);
$table_name = $parts[0];
$error_types = $parts[1] ?? '';
$filters = explode(',', $error_types);
Expand Down Expand Up @@ -133,14 +132,14 @@ protected function addFileHandler(MonologLogger $monologLogger, string $configSt
* Configure Mail handler.
*
* @param MonologLogger $monologLogger The Monolog logger instance to add handlers to.
* @param Config $config Configuration
* @param array $config Configuration
* @param ContainerInterface $container Service manager
*
* @return void
*/
protected function addMailHandler(MonologLogger $monologLogger, Config $config, ContainerInterface $container): void
protected function addMailHandler(MonologLogger $monologLogger, array $config, ContainerInterface $container): void
{
$parts = explode(':', $config->Logging->email);
$parts = explode(':', $config['Logging']['email']);
$email = $parts[0];
$error_types = $parts[1] ?? '';

Expand All @@ -158,22 +157,22 @@ protected function addMailHandler(MonologLogger $monologLogger, Config $config,
* Configure Office365 writers.
*
* @param Logger $logger Logger object
* @param Config $config Configuration
* @param array $config Configuration
* @param ContainerInterface $container Service manager
*
* @return void
*/
protected function addOffice365Handler(MonologLogger $logger, Config $config, ContainerInterface $container)
protected function addOffice365Handler(MonologLogger $logger, array $config, ContainerInterface $container)
{
$options = [];
$error_types = $config->Logging->office365;
if (isset($config->Logging->office365_title)) {
$options['title'] = $config->Logging->office365_title;
$error_types = $config['Logging']['office365'];
if (isset($config['Logging']['office365_title'])) {
$options['title'] = $config['Logging']['office365_title'];
}
$filters = explode(',', $error_types);

$handler = new Office365Handler(
$config->Logging->office365_url,
$config['Logging']['office365_url'],
$container->get(\VuFindHttp\HttpService::class)->createClient(),
$options
);
Expand All @@ -184,20 +183,20 @@ protected function addOffice365Handler(MonologLogger $logger, Config $config, Co
* Configure Slack webhook handler.
*
* @param MonologLogger $monologLogger The Monolog logger instance to add handlers to.
* @param Config $config VuFind configuration
* @param array $config VuFind configuration
*
* @return void
*/
protected function addSlackHandler(MonologLogger $monologLogger, Config $config): void
protected function addSlackHandler(MonologLogger $monologLogger, array $config): void
{
[$channel, $error_types] = explode(':', $config->Logging->slack);
[$channel, $error_types] = explode(':', $config['Logging']['slack']);
if ($error_types == null) {
$error_types = $channel;
$channel = null;
}

$username = $config->Logging->slackname;
$webhookUrl = $config->Logging->slackurl;
$username = $config['Logging']['slackname'];
$webhookUrl = $config['Logging']['slackurl'];

$baseSlackHandler = new SlackWebhookHandler(
$webhookUrl,
Expand Down Expand Up @@ -246,35 +245,35 @@ protected function hasDynamicDebug(ContainerInterface $container): bool
protected function configureMonologLogger(ContainerInterface $container, MonologLogger $monologLogger): void
{
$configManager = $container->get(ConfigManagerInterface::class);
$config = $configManager->getConfigObject('config');
$config = $configManager->getConfigArray('config');

// Add specific handlers based on config:
// DEBUGGER
if (!$config->System->debug == false || $this->hasDynamicDebug($container)) {
$this->addDebugHandler($monologLogger, $config->System->debug);
if (!$config['System']['debug'] == false || $this->hasDynamicDebug($container)) {
$this->addDebugHandler($monologLogger, $config['System']['debug']);
}

// Activate file logging, if applicable:
if (isset($config->Logging->file)) {
$this->addFileHandler($monologLogger, $config->Logging->file);
if (isset($config['Logging']['file'])) {
$this->addFileHandler($monologLogger, $config['Logging']['file']);
}

// Activate database logging, if applicable:
if (isset($config->Logging->database)) {
if (isset($config['Logging']['database'])) {
$this->addDbHandler($monologLogger, $config, $container);
}

// Activate email logging, if applicable:
if (isset($config->Logging->email)) {
if (isset($config['Logging']['email'])) {
$this->addMailHandler($monologLogger, $config, $container);
}
// Activate Slack logging, if applicable:
if (isset($config->Logging->slack)) {
if (isset($config['Logging']['slack'])) {
$this->addSlackHandler($monologLogger, $config);
}

// Activate Office365 logging, if applicable:
if (isset($config->Logging->office365) && isset($config->Logging->office365_url)) {
if (isset($config['Logging']['office365']) ?? false){
$this->addOffice365Handler($monologLogger, $config, $container);
}

Expand Down Expand Up @@ -308,19 +307,19 @@ protected function addDebugHandler(MonologLogger $monologLogger, $debug): void
* Add common Monolog processors to the logger.
*
* @param MonologLogger $monologLogger The Monolog logger instance
* @param Config $config VuFind configuration
* @param array $config VuFind configuration
* @param ContainerInterface $container Service manager
*
* @return void
*/
protected function addCommonProcessors(
MonologLogger $monologLogger,
Config $config,
array $config,
ContainerInterface $container
): void {
$monologLogger->pushProcessor(new PsrLogMessageProcessor());
$logConfig = $config->Logging;
if ($referenceId = $logConfig->reference_id ?? false) {
$logConfig = $config['Logging'];
if ($referenceId = $logConfig['reference_id'] ?? false) {
if ('username' === $referenceId) {
try {
$authManager = $container->get(AuthManager::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ class BrowZineBackendFactory extends AbstractBackendFactory
/**
* BrowZine configuration.
*
* @var Config
* @var array
*/
protected Config $browzineConfig;
protected array $browzineConfig;

/**
* Create an object.
Expand All @@ -91,7 +91,7 @@ public function __invoke(
) {
$this->setup($container);
$this->browzineConfig = $this->getService(\VuFind\Config\ConfigManagerInterface::class)
->getConfigObject('BrowZine');
->getConfigArray('BrowZine');
if ($this->serviceLocator->has(\VuFind\Log\Logger::class)) {
$this->logger = $this->getService(\VuFind\Log\Logger::class);
}
Expand Down Expand Up @@ -124,20 +124,20 @@ protected function createBackend(Connector $connector): Backend
*/
protected function createConnector(): Connector
{
$token = $this->getSecretFromConfig($this->browzineConfig?->General, 'access_token');
$token = $this->getSecretFromConfig($this->browzineConfig['General'], 'access_token');
// Validate configuration:
if ($token === null) {
throw new \Exception('Missing access token in BrowZine.ini');
}
if (empty($this->browzineConfig->General->library_id)) {
if (empty($this->browzineConfig['General']['library_id'])) {
throw new \Exception('Missing library ID in BrowZine.ini');
}

// Create connector:
$connector = new Connector(
$this->createHttpClient($this->browzineConfig->General->timeout ?? 30),
$this->createHttpClient($this->browzineConfig['General']['timeout'] ?? 30),
$token,
$this->browzineConfig->General->library_id
$this->browzineConfig['General']['library_id']
);
$connector->setLogger($this->logger);
return $connector;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use VuFind\Config\Config;
use VuFind\Config\Feature\EmailSettingsTrait;
use VuFind\Crypt\SecretCalculator;
use VuFind\Db\Entity\SearchEntityInterface;
Expand Down Expand Up @@ -112,7 +111,7 @@ class NotifyCommand extends Command implements TranslatorAwareInterface
* @param PhpRenderer $renderer View renderer
* @param ResultsManager $resultsManager Search results plugin manager
* @param array $scheduleOptions Configured schedule options
* @param Config $mainConfig Top-level VuFind configuration
* @param array $mainConfig Top-level VuFind configuration
* @param Mailer $mailer Mail service
* @param SearchServiceInterface $searchService Search table
* @param LocaleSettings $localeSettings Locale settings object
Expand All @@ -124,7 +123,7 @@ public function __construct(
protected PhpRenderer $renderer,
protected ResultsManager $resultsManager,
protected array $scheduleOptions,
protected Config $mainConfig,
protected array $mainConfig,
protected Mailer $mailer,
protected SearchServiceInterface $searchService,
protected LocaleSettings $localeSettings,
Expand Down Expand Up @@ -381,7 +380,7 @@ protected function buildEmail($s, $user, $searchObject, $newRecords)
$unsubscribeUrl = $s->getNotificationBaseUrl()
. ($this->urlHelper)('myresearch-unsubscribe')
. "?id={$s->getId()}&key=$secret";
$userInstitution = $this->mainConfig->Site->institution;
$userInstitution = $this->mainConfig['Site']['institution'];
$params = $searchObject->getParams();
// Filter function to only pass along selected checkboxes:
$selectedCheckboxes = function ($data) {
Expand Down Expand Up @@ -419,7 +418,7 @@ protected function buildEmail($s, $user, $searchObject, $newRecords)
*/
protected function sendEmail($user, $message)
{
$subject = $this->mainConfig->Site->title
$subject = $this->mainConfig['Site']['title']
. ': ' . $this->translate('Scheduled Alert Results');
$from = $this->getEmailSenderAddress($this->mainConfig);
$to = $user->getEmail();
Expand Down
17 changes: 8 additions & 9 deletions module/VuFindSearch/src/VuFindSearch/Backend/EDS/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
use Exception;
use Laminas\Cache\Storage\StorageInterface as CacheAdapter;
use Laminas\Session\Container as SessionContainer;
use VuFind\Config\Config;
use VuFind\Config\Feature\SecretTrait;
use VuFindSearch\Backend\AbstractBackend;
use VuFindSearch\Backend\EDS\Response\RecordCollection;
Expand Down Expand Up @@ -164,15 +163,15 @@ class Backend extends AbstractBackend
* @param RecordCollectionFactoryInterface $factory Record collection factory
* @param CacheAdapter $cache Object cache
* @param SessionContainer $session Session container
* @param ?Config $config Object representing EDS.ini
* @param ?array $config Object representing EDS.ini
* @param bool $isGuest Is the current user a guest?
*/
public function __construct(
Connector $client,
RecordCollectionFactoryInterface $factory,
CacheAdapter $cache,
SessionContainer $session,
?Config $config = null,
?array $config = null,
$isGuest = true
) {
// Save dependencies/incoming parameters:
Expand All @@ -183,12 +182,12 @@ public function __construct(
$this->isGuest = $isGuest;

// Extract key values from configuration:
$this->userName = $config->EBSCO_Account->user_name ?? null;
$this->password = $this->getSecretFromConfig($config->EBSCO_Account, 'password');
$this->ipAuth = $config->EBSCO_Account->ip_auth ?? false;
$this->profile = $config->EBSCO_Account->profile ?? null;
$this->orgId = $config->EBSCO_Account->organization_id ?? null;
$this->validationConfig = $config->Validation?->toArray() ?? [];
$this->userName = $config['EBSCO_Account']['user_name'] ?? null;
$this->password = $this->getSecretFromConfig($config['EBSCO_Account'], 'password');
$this->ipAuth = $config['EBSCO_Account']['ip_auth'] ?? false;
$this->profile = $config['EBSCO_Account']['profile'] ?? null;
$this->orgId = $config['EBSCO_Account']['organization_id'] ?? null;
$this->validationConfig = $config['Validation'] ?? [];

// Save default profile value, since profile property may be overridden:
$this->defaultProfile = $this->profile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,9 @@ protected function getBackend(
$container = $this->createMock(\Laminas\Session\Container::class);
}
if (null === $mock) {
return new Backend($connector, $factory, $cache, $container, new \VuFind\Config\Config($settings));
return new Backend($connector, $factory, $cache, $container, $settings);
} else {
$params = [$connector, $factory, $cache, $container, new \VuFind\Config\Config($settings)];
$params = [$connector, $factory, $cache, $container, $settings];
return $this->getMockBuilder(\VuFindSearch\Backend\EDS\Backend::class)
->onlyMethods($mock)
->setConstructorArgs($params)
Expand Down
Loading