Browse Source

remove deprecated entity query

d9_islandora
Eli Zoller 4 years ago
parent
commit
2b726b9446
  1. 4
      islandora.services.yml
  2. 32
      src/IslandoraUtils.php
  3. 14
      src/MediaSource/MediaSourceService.php

4
islandora.services.yml

@ -48,10 +48,10 @@ services:
- { name: 'context_provider' } - { name: 'context_provider' }
islandora.media_source_service: islandora.media_source_service:
class: Drupal\islandora\MediaSource\MediaSourceService class: Drupal\islandora\MediaSource\MediaSourceService
arguments: ['@entity_type.manager', '@current_user', '@language_manager', '@entity.query', '@file_system', '@islandora.utils'] arguments: ['@entity_type.manager', '@current_user', '@language_manager', '@file_system', '@islandora.utils']
islandora.utils: islandora.utils:
class: Drupal\islandora\IslandoraUtils class: Drupal\islandora\IslandoraUtils
arguments: ['@entity_type.manager', '@entity_field.manager', '@entity.query', '@context.manager', '@flysystem_factory', '@language_manager'] arguments: ['@entity_type.manager', '@entity_field.manager', '@context.manager', '@flysystem_factory', '@language_manager']
islandora.gemini.client: islandora.gemini.client:
class: Islandora\Crayfish\Commons\Client\GeminiClient class: Islandora\Crayfish\Commons\Client\GeminiClient
factory: ['Drupal\islandora\GeminiClientFactory', create] factory: ['Drupal\islandora\GeminiClientFactory', create]

32
src/IslandoraUtils.php

@ -8,7 +8,6 @@ use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\Query\QueryException; use Drupal\Core\Entity\Query\QueryException;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\Entity\Query\QueryInterface; use Drupal\Core\Entity\Query\QueryInterface;
use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Site\Settings; use Drupal\Core\Site\Settings;
@ -48,13 +47,6 @@ class IslandoraUtils {
*/ */
protected $entityFieldManager; protected $entityFieldManager;
/**
* Entity query.
*
* @var \Drupal\Core\Entity\Query\QueryFactory
*/
protected $entityQuery;
/** /**
* Context manager. * Context manager.
* *
@ -83,8 +75,6 @@ class IslandoraUtils {
* The entity type manager. * The entity type manager.
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
* The entity field manager. * The entity field manager.
* @param \Drupal\Core\Entity\Query\QueryFactory $entity_query
* Entity query.
* @param \Drupal\context\ContextManager $context_manager * @param \Drupal\context\ContextManager $context_manager
* Context manager. * Context manager.
* @param \Drupal\flysystem\FlysystemFactory $flysystem_factory * @param \Drupal\flysystem\FlysystemFactory $flysystem_factory
@ -95,14 +85,12 @@ class IslandoraUtils {
public function __construct( public function __construct(
EntityTypeManagerInterface $entity_type_manager, EntityTypeManagerInterface $entity_type_manager,
EntityFieldManagerInterface $entity_field_manager, EntityFieldManagerInterface $entity_field_manager,
QueryFactory $entity_query,
ContextManager $context_manager, ContextManager $context_manager,
FlysystemFactory $flysystem_factory, FlysystemFactory $flysystem_factory,
LanguageManagerInterface $language_manager LanguageManagerInterface $language_manager
) { ) {
$this->entityTypeManager = $entity_type_manager; $this->entityTypeManager = $entity_type_manager;
$this->entityFieldManager = $entity_field_manager; $this->entityFieldManager = $entity_field_manager;
$this->entityQuery = $entity_query;
$this->contextManager = $context_manager; $this->contextManager = $context_manager;
$this->flysystemFactory = $flysystem_factory; $this->flysystemFactory = $flysystem_factory;
$this->languageManager = $language_manager; $this->languageManager = $language_manager;
@ -157,7 +145,7 @@ class IslandoraUtils {
->load('media.' . self::MEDIA_OF_FIELD)) { ->load('media.' . self::MEDIA_OF_FIELD)) {
return []; return [];
} }
$mids = $this->entityQuery->get('media') $mids = $this->entityTypeManager->getStorage('media')->getQuery()
->condition(self::MEDIA_OF_FIELD, $node->id()) ->condition(self::MEDIA_OF_FIELD, $node->id())
->execute(); ->execute();
if (empty($mids)) { if (empty($mids)) {
@ -217,10 +205,12 @@ class IslandoraUtils {
); );
// Query for media that reference this file. // Query for media that reference this file.
$query = $this->entityQuery->get('media', 'OR'); $query = $this->entityTypeManager->getStorage('media')->getQuery();
$group = $query->orConditionGroup();
foreach ($conditions as $condition) { foreach ($conditions as $condition) {
$query->condition($condition, $fid); $group->condition($condition, $fid);
} }
$query->condition($group);
return $this->entityTypeManager->getStorage('media') return $this->entityTypeManager->getStorage('media')
->loadMultiple($query->execute()); ->loadMultiple($query->execute());
@ -252,7 +242,7 @@ class IslandoraUtils {
// Add field_external_uri. // Add field_external_uri.
$fields[] = self::EXTERNAL_URI_FIELD; $fields[] = self::EXTERNAL_URI_FIELD;
$query = $this->entityQuery->get('taxonomy_term'); $query = $this->entityTypeManager->getStorage('taxonomy_term')->getQuery();
$orGroup = $query->orConditionGroup(); $orGroup = $query->orConditionGroup();
foreach ($fields as $field) { foreach ($fields as $field) {
@ -504,7 +494,7 @@ class IslandoraUtils {
array_walk($term_fields, $remove_entity); array_walk($term_fields, $remove_entity);
array_walk($node_fields, $remove_entity); array_walk($node_fields, $remove_entity);
$query = $this->entityQuery->get('media'); $query = $this->entityTypeManager->getStorage('media')->getQuery();
$taxon_condition = $this->getEntityQueryOrCondition($query, $term_fields, $term->id()); $taxon_condition = $this->getEntityQueryOrCondition($query, $term_fields, $term->id());
$query->condition($taxon_condition); $query->condition($taxon_condition);
$node_condition = $this->getEntityQueryOrCondition($query, $node_fields, $node->id()); $node_condition = $this->getEntityQueryOrCondition($query, $node_fields, $node->id());
@ -531,7 +521,7 @@ class IslandoraUtils {
* Array of fields. * Array of fields.
*/ */
public function getReferencingFields($entity_type, $target_type) { public function getReferencingFields($entity_type, $target_type) {
$fields = $this->entityQuery->get('field_storage_config') $fields = $this->entityTypeManager->getStorage('field_storage_config')->getQuery()
->condition('entity_type', $entity_type) ->condition('entity_type', $entity_type)
->condition('settings.target_type', $target_type) ->condition('settings.target_type', $target_type)
->execute(); ->execute();
@ -593,11 +583,7 @@ class IslandoraUtils {
* The file URL. * The file URL.
*/ */
public function getDownloadUrl(FileInterface $file) { public function getDownloadUrl(FileInterface $file) {
$undefined = $this->languageManager->getLanguage('und'); return $file->createFileUrl(FALSE);
return $file->url('canonical', [
'absolute' => TRUE,
'language' => $undefined,
]);
} }
/** /**

14
src/MediaSource/MediaSourceService.php

@ -3,7 +3,6 @@
namespace Drupal\islandora\MediaSource; namespace Drupal\islandora\MediaSource;
use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\File\FileSystemInterface; use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AccountInterface;
@ -43,13 +42,6 @@ class MediaSourceService {
*/ */
protected $languageManager; protected $languageManager;
/**
* Entity query.
*
* @var \Drupal\Core\Entity\Query\QueryFactory
*/
protected $entityQuery;
/** /**
* File system service. * File system service.
* *
@ -73,8 +65,6 @@ class MediaSourceService {
* The current user. * The current user.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* Language manager. * Language manager.
* @param \Drupal\Core\Entity\Query\QueryFactory $entity_query
* Entity query.
* @param \Drupal\Core\File\FileSystemInterface $file_system * @param \Drupal\Core\File\FileSystemInterface $file_system
* File system service. * File system service.
* @param \Drupal\islandora\IslandoraUtils $islandora_utils * @param \Drupal\islandora\IslandoraUtils $islandora_utils
@ -84,14 +74,12 @@ class MediaSourceService {
EntityTypeManagerInterface $entity_type_manager, EntityTypeManagerInterface $entity_type_manager,
AccountInterface $account, AccountInterface $account,
LanguageManagerInterface $language_manager, LanguageManagerInterface $language_manager,
QueryFactory $entity_query,
FileSystemInterface $file_system, FileSystemInterface $file_system,
IslandoraUtils $islandora_utils IslandoraUtils $islandora_utils
) { ) {
$this->entityTypeManager = $entity_type_manager; $this->entityTypeManager = $entity_type_manager;
$this->account = $account; $this->account = $account;
$this->languageManager = $language_manager; $this->languageManager = $language_manager;
$this->entityQuery = $entity_query;
$this->fileSystem = $file_system; $this->fileSystem = $file_system;
$this->islandoraUtils = $islandora_utils; $this->islandoraUtils = $islandora_utils;
} }
@ -293,7 +281,7 @@ class MediaSourceService {
} }
$directory = $this->fileSystem->dirname($content_location); $directory = $this->fileSystem->dirname($content_location);
if (!file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) { if (!$this->fileSystem->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS)) {
throw new HttpException(500, "The destination directory does not exist, could not be created, or is not writable"); throw new HttpException(500, "The destination directory does not exist, could not be created, or is not writable");
} }

Loading…
Cancel
Save