From d4a51bebe2c2a06037e32944264c1b666b9318be Mon Sep 17 00:00:00 2001 From: Eli Zoller Date: Tue, 24 Nov 2020 12:58:41 -0700 Subject: [PATCH] more deprecations with upgrade_status 3.x version and more phpcs fixes --- drush.services.yml | 1 + .../src/Form/IslandoraIIIFConfigForm.php | 2 +- .../src/Controller/MediaSourceController.php | 10 ++-- .../Field/FieldFormatter/OcrTextFormatter.php | 2 +- src/Commands/IslandoraCommands.php | 48 +++++++++++++++---- src/Controller/MediaSourceController.php | 3 +- src/Flysystem/Adapter/FedoraAdapter.php | 3 +- src/GeminiLookup.php | 4 +- src/Plugin/Condition/NodeHasParent.php | 2 +- .../IslandoraImageFormatter.php | 2 +- 10 files changed, 55 insertions(+), 22 deletions(-) diff --git a/drush.services.yml b/drush.services.yml index fb36bda7..a733ecd2 100644 --- a/drush.services.yml +++ b/drush.services.yml @@ -1,5 +1,6 @@ services: islandora.commands: class: \Drupal\islandora\Commands\IslandoraCommands + arguments: ['@entity_type.manager', '@current_user', '@account_switcher'] tags: - { name: drush.command } diff --git a/modules/islandora_iiif/src/Form/IslandoraIIIFConfigForm.php b/modules/islandora_iiif/src/Form/IslandoraIIIFConfigForm.php index d80453ce..aecb7706 100644 --- a/modules/islandora_iiif/src/Form/IslandoraIIIFConfigForm.php +++ b/modules/islandora_iiif/src/Form/IslandoraIIIFConfigForm.php @@ -41,7 +41,7 @@ class IslandoraIIIFConfigForm extends ConfigFormBase { public static function create(ContainerInterface $container) { return new static( $container->get('http_client'), - $container->get('config.factory'), + $container->get('config.factory') ); } diff --git a/modules/islandora_text_extraction/src/Controller/MediaSourceController.php b/modules/islandora_text_extraction/src/Controller/MediaSourceController.php index 576f2a43..14c36ebd 100644 --- a/modules/islandora_text_extraction/src/Controller/MediaSourceController.php +++ b/modules/islandora_text_extraction/src/Controller/MediaSourceController.php @@ -3,11 +3,13 @@ namespace Drupal\islandora_text_extraction\Controller; use Drupal\Core\Controller\ControllerBase; -use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\Core\File\FileSystem; +use Drupal\Core\File\FileSystemInterface; use Drupal\media\Entity\Media; +use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Drupal\Core\File\FileSystem; +use Symfony\Component\HttpKernel\Exception\HttpException; /** * Controller for Media Source. @@ -93,10 +95,10 @@ class MediaSourceController extends ControllerBase { if ($contents) { $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"); } - $file = file_save_data($contents, $content_location, FILE_EXISTS_REPLACE); + $file = file_save_data($contents, $content_location, FileSystemInterface::EXISTS_REPLACE); if ($media->hasField($destination_field)) { $media->{$destination_field}->setValue([ 'target_id' => $file->id(), diff --git a/modules/islandora_text_extraction/src/Plugin/Field/FieldFormatter/OcrTextFormatter.php b/modules/islandora_text_extraction/src/Plugin/Field/FieldFormatter/OcrTextFormatter.php index 7532a7bc..2e066943 100644 --- a/modules/islandora_text_extraction/src/Plugin/Field/FieldFormatter/OcrTextFormatter.php +++ b/modules/islandora_text_extraction/src/Plugin/Field/FieldFormatter/OcrTextFormatter.php @@ -75,7 +75,7 @@ class OcrTextFormatter extends FormatterBase implements ContainerFactoryPluginIn $configuration['third_party_settings'], $container->get('renderer'), $container->get('config.factory'), - $container->get('entity_type.manager'), + $container->get('entity_type.manager') ); } diff --git a/src/Commands/IslandoraCommands.php b/src/Commands/IslandoraCommands.php index c13f3623..00580ad3 100644 --- a/src/Commands/IslandoraCommands.php +++ b/src/Commands/IslandoraCommands.php @@ -3,8 +3,10 @@ namespace Drupal\islandora\Commands; use Consolidation\AnnotatedCommand\CommandData; +use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\Core\Session\AccountProxy; +use Drupal\Core\Session\AccountSwitcherInterface; use Drupal\Core\Session\UserSession; -use Drupal\user\Entity\User; use Drush\Commands\DrushCommands; /** @@ -13,6 +15,35 @@ use Drush\Commands\DrushCommands; * ... because the --user option was removed from drush 9. */ class IslandoraCommands extends DrushCommands { + /** + * Entity type manager object. + * + * @var \Drupal\Core\Entity\EntityTypeManagerInterface + */ + protected $entityTypeManager; + + /** + * Drupal\Core\Session\AccountProxy definition. + * + * @var \Drupal\Core\Session\AccountProxy + */ + protected $currentUser; + + /** + * The account switcher service. + * + * @var \Drupal\Core\Session\AccountSwitcherInterface + */ + protected $accountSwitcher; + + /** + * {@inheritdoc} + */ + public function __construct(EntityTypeManagerInterface $entity_type_manager, AccountProxy $current_user, AccountSwitcherInterface $account_switcher) { + $this->entityTypeManager = $entity_type_manager; + $this->currentUser = $current_user; + $this->accountSwitcher = $account_switcher; + } /** * Add the userid option. @@ -56,7 +87,8 @@ class IslandoraCommands extends DrushCommands { protected function validateUser(CommandData $commandData) { $userid = $commandData->input()->getOption('userid'); if ($userid) { - $account = User::load($userid); + $account = + $this->entityTypeManager->getStorage('user')->load($userid); if (!$account) { throw new \Exception("User ID does not match an existing user."); } @@ -87,18 +119,17 @@ class IslandoraCommands extends DrushCommands { protected function switchUser(CommandData $commandData) { $userid = $commandData->input()->getOption('userid'); if ($userid) { - $account = User::load($userid); - $accountSwitcher = \Drupal::service('account_switcher'); + $account = $this->entityTypeManager->getStorage('user')->load($userid); $userSession = new UserSession([ 'uid' => $account->id(), 'name' => $account->getUsername(), 'roles' => $account->getRoles(), ]); - $accountSwitcher->switchTo($userSession); + $this->accountSwitcher->switchTo($userSession); $this->logger()->notice( dt( 'Now acting as user ID @id', - ['@id' => \Drupal::currentUser()->id()] + ['@id' => $this->currentUser->id()] ) ); } @@ -127,12 +158,11 @@ class IslandoraCommands extends DrushCommands { */ protected function switchUserBack(CommandData $commandData) { if ($commandData->input()->getOption('userid')) { - $accountSwitcher = \Drupal::service('account_switcher'); $this->logger()->notice(dt( 'Switching back from user @uid.', - ['@uid' => \Drupal::currentUser()->id()] + ['@uid' => $this->currentUser->id()] )); - $accountSwitcher->switchBack(); + $this->accountSwitcher->switchBack(); } } diff --git a/src/Controller/MediaSourceController.php b/src/Controller/MediaSourceController.php index c32b8079..29ff9412 100644 --- a/src/Controller/MediaSourceController.php +++ b/src/Controller/MediaSourceController.php @@ -5,6 +5,7 @@ namespace Drupal\islandora\Controller; use Drupal\Core\Access\AccessResult; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Database\Connection; +use Drupal\Core\File\FileSystemInterface; use Drupal\Core\Routing\RouteMatch; use Drupal\Core\Session\AccountInterface; use Drupal\media\Entity\Media; @@ -234,7 +235,7 @@ class MediaSourceController extends ControllerBase { $content_location = $request->headers->get('Content-Location', ""); $contents = $request->getContent(); if ($contents) { - $file = file_save_data($contents, $content_location, FILE_EXISTS_REPLACE); + $file = file_save_data($contents, $content_location, FileSystemInterface::EXISTS_REPLACE); if ($media->hasField($destination_field)) { $media->{$destination_field}->setValue([ 'target_id' => $file->id(), diff --git a/src/Flysystem/Adapter/FedoraAdapter.php b/src/Flysystem/Adapter/FedoraAdapter.php index 737d7152..3fbfa8ab 100644 --- a/src/Flysystem/Adapter/FedoraAdapter.php +++ b/src/Flysystem/Adapter/FedoraAdapter.php @@ -7,7 +7,6 @@ use League\Flysystem\AdapterInterface; use League\Flysystem\Adapter\Polyfill\NotSupportingVisibilityTrait; use League\Flysystem\Adapter\Polyfill\StreamedCopyTrait; use League\Flysystem\Config; -use GuzzleHttp\Psr7; use GuzzleHttp\Psr7\Header; use GuzzleHttp\Psr7\Response; use GuzzleHttp\Psr7\StreamWrapper; @@ -378,7 +377,7 @@ class FedoraAdapter implements AdapterInterface { $return = NULL; if ($response->getStatusCode() == 410) { $return = FALSE; - $link_headers = Psr7\parse_header($response->getHeader('Link')); + $link_headers = Header::parse($response->getHeader('Link')); if ($link_headers) { $tombstones = array_filter($link_headers, function ($o) { return (isset($o['rel']) && $o['rel'] == 'hasTombstone'); diff --git a/src/GeminiLookup.php b/src/GeminiLookup.php index 657b3a4b..e753c88c 100644 --- a/src/GeminiLookup.php +++ b/src/GeminiLookup.php @@ -5,7 +5,7 @@ namespace Drupal\islandora; use Drupal\Core\Entity\EntityInterface; use Drupal\islandora\MediaSource\MediaSourceService; use Drupal\jwt\Authentication\Provider\JwtAuth; -use GuzzleHttp\Psr7; +use GuzzleHttp\Psr7\Header; use GuzzleHttp\Client; use GuzzleHttp\Exception\RequestException; use Islandora\Crayfish\Commons\Client\GeminiClient; @@ -136,7 +136,7 @@ class GeminiLookup { $urls['fedora'], ['allow_redirects' => FALSE, 'headers' => ['Authorization' => $token]] ); - $links = Psr7\parse_header($head->getHeader("Link")); + $links = Header::parse($head->getHeader("Link")); foreach ($links as $link) { if ($link['rel'] == 'describedby') { return trim($link[0], '<>'); diff --git a/src/Plugin/Condition/NodeHasParent.php b/src/Plugin/Condition/NodeHasParent.php index ac3821d8..f9ef0cbf 100644 --- a/src/Plugin/Condition/NodeHasParent.php +++ b/src/Plugin/Condition/NodeHasParent.php @@ -93,7 +93,7 @@ class NodeHasParent extends ConditionPluginBase implements ContainerFactoryPlugi $options = array_combine($node_fields, $node_fields); $form['parent_reference_field'] = [ '#type' => 'select', - '#title' => $this->('Field that contains reference to parents'), + '#title' => $this->t('Field that contains reference to parents'), '#options' => $options, '#default_value' => $this->configuration['parent_reference_field'], '#required' => TRUE, diff --git a/src/Plugin/Field/FieldFormatter/IslandoraImageFormatter.php b/src/Plugin/Field/FieldFormatter/IslandoraImageFormatter.php index a3ee788e..6c6e87da 100644 --- a/src/Plugin/Field/FieldFormatter/IslandoraImageFormatter.php +++ b/src/Plugin/Field/FieldFormatter/IslandoraImageFormatter.php @@ -96,7 +96,7 @@ class IslandoraImageFormatter extends ImageFormatter { $configuration['view_mode'], $configuration['third_party_settings'], $container->get('current_user'), - $container->get('entity.manager')->getStorage('image_style'), + $container->get('entity_type.manager')->getStorage('image_style'), $container->get('islandora.utils') ); }