Skip to content

Commit f682537

Browse files
committed
move it into a config
1 parent fca5fcd commit f682537

File tree

5 files changed

+67
-13
lines changed

5 files changed

+67
-13
lines changed

config/install/islandora.settings.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ broker_url: 'tcp://localhost:61613'
22
jwt_expiry: '+2 hour'
33
delete_media_and_files: TRUE
44
gemini_pseudo_bundles: []
5+
fast_term_queries: TRUE

islandora.post_update.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,13 @@ function islandora_post_update_delete_media_and_files() {
1414
$config->set('delete_media_and_files', TRUE);
1515
$config->save(TRUE);
1616
}
17+
18+
/**
19+
* Ensure `fast_term_queries` exists.
20+
*/
21+
function islandora_post_update_fast_term_queries() : void {
22+
$config_factory = \Drupal::configFactory();
23+
$config = $config_factory->getEditable('islandora.settings');
24+
$config->set('fast_term_queries', TRUE);
25+
$config->save(TRUE);
26+
}

islandora.services.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ services:
5454
arguments: ['@entity_type.manager', '@current_user', '@language_manager', '@file_system', '@islandora.utils']
5555
islandora.utils:
5656
class: Drupal\islandora\IslandoraUtils
57-
arguments: ['@entity_type.manager', '@entity_field.manager', '@context.manager', '@flysystem_factory', '@language_manager', '@current_user']
57+
arguments: ['@entity_type.manager', '@entity_field.manager', '@context.manager', '@flysystem_factory', '@language_manager', '@current_user', '@config.factory']
5858
islandora.entity_mapper:
5959
class: Islandora\EntityMapper\EntityMapper
6060
islandora.stomp.auth_header_listener:

src/Form/IslandoraSettingsForm.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class IslandoraSettingsForm extends ConfigFormBase {
4444
const GEMINI_PSEUDO_FIELD = 'field_gemini_uri';
4545
const NODE_DELETE_MEDIA_AND_FILES = 'delete_media_and_files';
4646
const REDIRECT_AFTER_MEDIA_SAVE = 'redirect_after_media_save';
47+
const FAST_TERM_QUERIES = 'fast_term_queries';
4748

4849
/**
4950
* To list the available bundle types.
@@ -79,7 +80,7 @@ class IslandoraSettingsForm extends ConfigFormBase {
7980
public function __construct(
8081
ConfigFactoryInterface $config_factory,
8182
EntityTypeBundleInfoInterface $entity_type_bundle_info,
82-
EntityTypeManagerInterface $entity_type_manager
83+
EntityTypeManagerInterface $entity_type_manager,
8384
) {
8485
$this->setConfigFactory($config_factory);
8586
$this->entityTypeBundleInfo = $entity_type_bundle_info;
@@ -228,6 +229,13 @@ public function buildForm(array $form, FormStateInterface $form_state) {
228229
'#default_value' => (bool) $config->get(self::REDIRECT_AFTER_MEDIA_SAVE),
229230
];
230231

232+
$form[self::FAST_TERM_QUERIES] = [
233+
'#type' => 'checkbox',
234+
'#title' => $this->t('Use multiple queries for term URI lookups.'),
235+
'#description' => $this->t('Using multiple queries to look up taxonomy terms by URI is faster in most setups. You may want to disable this if you have a term access protection module enabled.'),
236+
'#default_value' => (bool) $config->get(self::FAST_TERM_QUERIES),
237+
];
238+
231239
$form[self::FEDORA_URL] = [
232240
'#type' => 'textfield',
233241
'#title' => $this->t('Fedora URL'),
@@ -383,6 +391,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
383391
->set(self::UPLOAD_FORM_ALLOWED_MIMETYPES, $form_state->getValue(self::UPLOAD_FORM_ALLOWED_MIMETYPES))
384392
->set(self::GEMINI_PSEUDO, $new_pseudo_types)
385393
->set(self::NODE_DELETE_MEDIA_AND_FILES, $form_state->getValue(self::NODE_DELETE_MEDIA_AND_FILES))
394+
->set(self::FAST_TERM_QUERIES, $form_state->getValue(self::FAST_TERM_QUERIES))
386395
->set(self::REDIRECT_AFTER_MEDIA_SAVE, $form_state->getValue(self::REDIRECT_AFTER_MEDIA_SAVE))
387396
->save();
388397

src/IslandoraUtils.php

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
use Drupal\media\MediaInterface;
2424
use Drupal\node\NodeInterface;
2525
use Drupal\taxonomy\TermInterface;
26+
use Drupal\islandora\Form\IslandoraSettingsForm;
27+
use Drupal\Core\Config\ConfigFactoryInterface;
2628

2729
/**
2830
* Utility functions for figuring out when to fire derivative reactions.
@@ -81,6 +83,13 @@ class IslandoraUtils {
8183
*/
8284
protected AccountInterface $currentUser;
8385

86+
/**
87+
* Islandora config settings.
88+
*
89+
* @var \Drupal\Core\Config\ImmutableConfig
90+
*/
91+
protected $islandoraSettings;
92+
8493
/**
8594
* Constructor.
8695
*
@@ -96,21 +105,25 @@ class IslandoraUtils {
96105
* Language manager.
97106
* @param \Drupal\Core\Session\AccountInterface $current_user
98107
* The current user.
108+
* @param \Drupal\Core\Config\ConfigFactoryInterface $config
109+
* Config factory
99110
*/
100111
public function __construct(
101112
EntityTypeManagerInterface $entity_type_manager,
102113
EntityFieldManagerInterface $entity_field_manager,
103114
ContextManager $context_manager,
104115
FlysystemFactory $flysystem_factory,
105116
LanguageManagerInterface $language_manager,
106-
AccountInterface $current_user
117+
AccountInterface $current_user,
118+
ConfigFactoryInterface $config,
107119
) {
108120
$this->entityTypeManager = $entity_type_manager;
109121
$this->entityFieldManager = $entity_field_manager;
110122
$this->contextManager = $context_manager;
111123
$this->flysystemFactory = $flysystem_factory;
112124
$this->languageManager = $language_manager;
113125
$this->currentUser = $current_user;
126+
$this->islandoraSettings = $config->get(IslandoraSettingsForm::CONFIG_NAME);
114127
}
115128

116129
/**
@@ -261,19 +274,40 @@ public function getTermForUri($uri) {
261274
// Add field_external_uri.
262275
$fields[] = self::EXTERNAL_URI_FIELD;
263276

264-
$storage = $this->entityTypeManager->getStorage('taxonomy_term');
265-
foreach ($fields as $field) {
266-
$query = $storage->getQuery();
267-
$results = $query
268-
->accessCheck(TRUE)
269-
->condition("$field.uri", $uri)
270-
->execute();
271-
if (!empty($results)) {
272-
return $storage->load(reset($results));
277+
if ($this->islandoraSettings->get(IslandoraSettingsForm::FAST_TERM_QUERIES)) {
278+
$storage = $this->entityTypeManager->getStorage('taxonomy_term');
279+
foreach ($fields as $field) {
280+
$query = $storage->getQuery();
281+
$results = $query
282+
->accessCheck(TRUE)
283+
->condition("$field.uri", $uri)
284+
->execute();
285+
if (!empty($results)) {
286+
return $storage->load(reset($results));
287+
}
273288
}
289+
290+
return NULL;
274291
}
275292

276-
return NULL;
293+
$query = $this->entityTypeManager->getStorage('taxonomy_term')->getQuery();
294+
295+
$orGroup = $query->orConditionGroup();
296+
foreach ($fields as $field) {
297+
$orGroup->condition("$field.uri", $uri);
298+
}
299+
300+
$results = $query
301+
->accessCheck(TRUE)
302+
->condition($orGroup)
303+
->execute();
304+
305+
if (empty($results)) {
306+
return NULL;
307+
}
308+
309+
return $this->entityTypeManager->getStorage('taxonomy_term')
310+
->load(reset($results));
277311
}
278312

279313
/**

0 commit comments

Comments
 (0)