diff --git a/.travis.yml b/.travis.yml index a2940ca..ee67398 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,9 +24,8 @@ env: before_install: - composer global require thunder/travis - script: - - test-drupal-module + - test-drupal-project notifications: email: false diff --git a/nexx_integration.info.yml b/nexx_integration.info.yml index a6f2504..8764c30 100644 --- a/nexx_integration.info.yml +++ b/nexx_integration.info.yml @@ -2,7 +2,7 @@ name: Nexx video integration type: module description: 'Integration of nexxOMNIA and nexxPLAY' package: Field types -core: 8.x +core_version_requirement: ^8.7.7 configure: nexx_integration.admin_settings dependencies: diff --git a/nexx_integration.install b/nexx_integration.install index 62ab526..68ed74b 100644 --- a/nexx_integration.install +++ b/nexx_integration.install @@ -6,6 +6,7 @@ */ use Drupal\Core\Database\Database; +use Drupal\Core\File\FileSystemInterface; /** * Implements hook_schema(). @@ -46,7 +47,7 @@ function nexx_integration_schema() { function nexx_integration_install() { $source = drupal_get_path('module', 'nexx_integration') . '/images/icons'; $destination = \Drupal::config('media.settings')->get('icon_base_uri'); - file_prepare_directory($destination, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); + \Drupal::service('file_system')->prepareDirectory($destination, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS); $files = file_scan_directory($source, '/.*\.(svg|png|jpg|jpeg|gif)$/'); foreach ($files as $file) { @@ -57,7 +58,7 @@ function nexx_integration_install() { // referenced somewhere else. Since showing an error that it was not // possible to copy the files is also confusing, we silently do nothing. if (!file_exists($destination . DIRECTORY_SEPARATOR . $file->filename)) { - file_unmanaged_copy($file->uri, $destination, FILE_EXISTS_ERROR); + \Drupal::service('file_system')->copy($file->uri, $destination, FileSystemInterface::EXISTS_ERROR); } } } diff --git a/nexx_integration.module b/nexx_integration.module index e359fd1..09b5b9f 100644 --- a/nexx_integration.module +++ b/nexx_integration.module @@ -267,8 +267,8 @@ function nexx_integration_cron() { // Check videos, that could be activated. /** @var \Drupal\Core\Entity\Query\QueryInterface $ids */ $ids = $storage->getQuery() - ->condition($video_field . '.validfrom_ssc', REQUEST_TIME, '<=') - ->condition($video_field . '.validto_ssc', REQUEST_TIME, '>') + ->condition($video_field . '.validfrom_ssc', \Drupal::time()->getRequestTime(), '<=') + ->condition($video_field . '.validto_ssc', \Drupal::time()->getRequestTime(), '>') ->condition("status", FALSE) ->execute(); @@ -285,7 +285,7 @@ function nexx_integration_cron() { /** @var \Drupal\Core\Entity\Query\QueryInterface $ids */ $ids = $storage->getQuery() ->condition($video_field . '.validto_ssc', 0, '<>') - ->condition($video_field . '.validto_ssc', REQUEST_TIME, '<=') + ->condition($video_field . '.validto_ssc', \Drupal::time()->getRequestTime(), '<=') ->condition("status", TRUE) ->execute(); diff --git a/nexx_integration.services.yml b/nexx_integration.services.yml index a478406..48a1afd 100644 --- a/nexx_integration.services.yml +++ b/nexx_integration.services.yml @@ -1,7 +1,7 @@ services: nexx_integration.notification: class: Drupal\nexx_integration\NexxNotification - arguments: ['@config.factory', '@logger.factory', '@http_client', '@string_translation'] + arguments: ['@config.factory', '@logger.factory', '@http_client', '@string_translation', '@messenger'] nexx_integration.videomanager: class: Drupal\nexx_integration\VideoManagerService diff --git a/src/Controller/OmniaController.php b/src/Controller/OmniaController.php index 0af325f..9160392 100644 --- a/src/Controller/OmniaController.php +++ b/src/Controller/OmniaController.php @@ -6,6 +6,7 @@ use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Drupal\Core\Database\Connection; +use Drupal\Core\File\FileSystemInterface; use Drupal\Core\Utility\Token; use Drupal\media\MediaInterface; use Psr\Log\LoggerInterface; @@ -35,27 +36,6 @@ class OmniaController extends ControllerBase { */ protected $entityTypeBundleInfo; - /** - * The media entity. - * - * @var \Drupal\media\MediaInterface - */ - protected $mediaEntity; - - /** - * The media entity storage. - * - * @var \Drupal\Core\Entity\EntityStorageInterface - */ - protected $mediaEntityStorage; - - /** - * The media entity definition. - * - * @var \Drupal\Core\Entity\EntityTypeInterface - */ - protected $mediaEntityDefinition; - /** * The entity field manager. * @@ -91,6 +71,13 @@ class OmniaController extends ControllerBase { */ protected $nexxVideoData = []; + /** + * The file system service. + * + * @var \Drupal\Core\File\FileSystemInterface + */ + protected $fileSystem; + /** * OmniaController constructor. * @@ -104,6 +91,8 @@ class OmniaController extends ControllerBase { * The logger service. * @param \Drupal\Core\Utility\Token $token * Token service. + * @param \Drupal\Core\File\FileSystemInterface $file_system + * The file system service. * * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException. */ @@ -112,13 +101,15 @@ public function __construct( EntityTypeBundleInfoInterface $entity_type_bundle_info, EntityFieldManagerInterface $entity_field_manager, LoggerInterface $logger, - Token $token + Token $token, + FileSystemInterface $file_system ) { $this->database = $database; $this->entityTypeBundleInfo = $entity_type_bundle_info; $this->entityFieldManager = $entity_field_manager; $this->logger = $logger; $this->token = $token; + $this->fileSystem = $file_system; } /** @@ -130,7 +121,8 @@ public static function create(ContainerInterface $container) { $container->get('entity_type.bundle.info'), $container->get('entity_field.manager'), $container->get('logger.factory')->get('nexx_integration'), - $container->get('token') + $container->get('token'), + $container->get('file_system') ); } @@ -569,8 +561,8 @@ protected function mapTeaserImage(MediaInterface $media, $teaserImageField) { $destination_directory = dirname($destination_file); if ($destination_directory) { // Import file. - file_prepare_directory($destination_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); - $thumbnail = file_save_data(file_get_contents($thumb_uri), $destination_file, FILE_EXISTS_REPLACE); + $this->fileSystem->prepareDirectory($destination_directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS); + $thumbnail = file_save_data(file_get_contents($thumb_uri), $destination_file, FileSystemInterface::EXISTS_REPLACE); // Add this file to thumbnail field of the nexx media entity. $thumbnail_entity->$thumbnail_upload_field->appendItem([ 'target_id' => $thumbnail->id(), @@ -667,10 +659,10 @@ protected function setState(MediaInterface $media) { ); } else { - $this->logger->info('Unpublished video "@title" (Drupal id: @id)... States: - active:@active - isSSC:@isSSC - validfrom_ssc:@validfrom_ssc + $this->logger->info('Unpublished video "@title" (Drupal id: @id)... States: + active:@active + isSSC:@isSSC + validfrom_ssc:@validfrom_ssc validto_ssc:@validto_ssc ', [ '@title' => $this->nexxVideoData['title'], diff --git a/src/Form/SettingsForm.php b/src/Form/SettingsForm.php index 646231f..2804369 100644 --- a/src/Form/SettingsForm.php +++ b/src/Form/SettingsForm.php @@ -4,13 +4,14 @@ use Drupal\Core\Ajax\AjaxResponse; use Drupal\Core\Ajax\ReplaceCommand; +use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Drupal\Core\Entity\EntityTypeInterface; +use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\Core\Entity\EntityTypeRepositoryInterface; use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; -use Drupal\Core\Entity\EntityManagerInterface; /** * Class SettingsForm. @@ -21,40 +22,65 @@ */ class SettingsForm extends ConfigFormBase { /** - * The entity manager service. + * The entity type manager service. * - * @var \Drupal\Core\Entity\EntityManagerInterface + * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ - protected $entityManager; + protected $entityTypeManager; /** - * The display plugin manager. + * The entity type repository service. * - * @var \Drupal\entity_embed\EntityEmbedDisplay\EntityEmbedDisplayManager + * @var \Drupal\Core\Entity\EntityTypeRepositoryInterface */ - protected $displayPluginManager; + protected $entityTypeRepository; /** - * {@inheritdoc} + * The entity type bundle info service. * - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * The config factory. - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager - * The entity manager service. + * @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface */ - public function __construct(ConfigFactoryInterface $config_factory, EntityManagerInterface $entity_manager) { - parent::__construct($config_factory); - $this->entityManager = $entity_manager; - } + protected $entityTypeBundleInfo; /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { - return new static( - $container->get('config.factory'), - $container->get('entity.manager') - ); + $form = parent::create($container); + $form->setEntityTypeManager($container->get('entity_type.manager')); + $form->setEntityTypeRepository($container->get('entity_type.repository')); + $form->setEntityTypeBundleInfo($container->get('entity_type.bundle.info')); + return $form; + } + + /** + * Set the entity type manager service. + * + * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager + * The entity type manager service. + */ + protected function setEntityTypeManager(EntityTypeManagerInterface $entityTypeManager) { + $this->entityTypeManager = $entityTypeManager; + } + + /** + * Set the entity type repository service. + * + * @param \Drupal\Core\Entity\EntityTypeRepositoryInterface $entityTypeRepository + * The entity type repository service. + */ + protected function setEntityTypeRepository(EntityTypeRepositoryInterface $entityTypeRepository) { + $this->entityTypeRepository = $entityTypeRepository; + } + + /** + * Set the entity type bundle info service. + * + * @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entityTypeBundleInfo + * The entity type bundle info service. + */ + protected function setEntityTypeBundleInfo(EntityTypeBundleInfoInterface $entityTypeBundleInfo) { + $this->entityTypeBundleInfo = $entityTypeBundleInfo; } /** @@ -132,7 +158,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#suffix' => '', ]; - $entity_type = $this->entityManager->getDefinition('media'); + $entity_type = $this->entityTypeManager->getDefinition('media'); $bundle = !empty($values['type_settings']['video_bundle']) ? $values['type_settings']['video_bundle'] : $settings->get('video_bundle'); $form['type_settings']['video_bundle'] = [ '#type' => 'select', @@ -218,12 +244,12 @@ protected function getEditableConfigNames() { * An array of entity type labels, keyed by entity type name. */ protected function getEntityTypeOptions() { - $options = $this->entityManager->getEntityTypeLabels(TRUE); + $options = $this->entityTypeRepository->getEntityTypeLabels(TRUE); foreach ($options as $group => $group_types) { foreach (array_keys($group_types) as $entity_type_id) { // Filter out entity types that do not have a view builder class. - if (!$this->entityManager->getDefinition($entity_type_id)->hasViewBuilderClass()) { + if (!$this->entityTypeManager->getDefinition($entity_type_id)->hasViewBuilderClass()) { unset($options[$group][$entity_type_id]); } } @@ -268,7 +294,7 @@ protected function getEntityBundleOptions(EntityTypeInterface $entity_type) { $bundle_options = []; // If the entity has bundles, allow option to restrict to bundle(s). if ($entity_type->hasKey('bundle')) { - foreach ($this->entityManager->getBundleInfo($entity_type->id()) as $bundle_id => $bundle_info) { + foreach ($this->entityTypeBundleInfo->getBundleInfo($entity_type->id()) as $bundle_id => $bundle_info) { $bundle_options[$bundle_id] = $bundle_info['label']; } natsort($bundle_options); diff --git a/src/NexxNotification.php b/src/NexxNotification.php index 33b25bc..6f1a345 100644 --- a/src/NexxNotification.php +++ b/src/NexxNotification.php @@ -5,6 +5,7 @@ use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Logger\LoggerChannelFactoryInterface; use Drupal\Component\Serialization\Json; +use Drupal\Core\Messenger\MessengerInterface; use GuzzleHttp\Client; use GuzzleHttp\Exception\RequestException; use Drupal\Core\StringTranslation\TranslationInterface; @@ -40,6 +41,13 @@ class NexxNotification implements NexxNotificationInterface { */ protected $httpClient; + /** + * The messenger service. + * + * @var \Drupal\Core\Messenger\MessengerInterface + */ + protected $messenger; + /** * Notify nexxOMNIA video CMS. * @@ -54,17 +62,21 @@ class NexxNotification implements NexxNotificationInterface { * The HTTP client. * @param \Drupal\Core\StringTranslation\TranslationInterface $translation * The translation service. + * @param \Drupal\Core\Messenger\MessengerInterface $messenger + * The messenger service. */ public function __construct( ConfigFactoryInterface $config_factory, LoggerChannelFactoryInterface $logger_factory, Client $http_client, - TranslationInterface $translation + TranslationInterface $translation, + MessengerInterface $messenger ) { $this->config = $config_factory->get('nexx_integration.settings'); $this->logger = $logger_factory->get('nexx_integration'); $this->httpClient = $http_client; $this->stringTranslation = $translation; + $this->messenger = $messenger; } /** @@ -169,7 +181,7 @@ protected function notificateNexx( if ($api_url == '' || $api_authkey == '' || $omnia_id == '') { $this->logger->error("Missing configuration for API Url and/or Installation Code (API Key) and/or Omnia ID."); - drupal_set_message($this->t("Item wasn't exported to Nexx due to missing configuration for API Url and/or Installation Code (API Key) and/or Omnia ID."), 'error'); + $this->messenger->addError($this->t("Item wasn't exported to Nexx due to missing configuration for API Url and/or Installation Code (API Key) and/or Omnia ID.")); return FALSE; } diff --git a/tests/modules/nexx_integration_test/nexx_integration_test.info.yml b/tests/modules/nexx_integration_test/nexx_integration_test.info.yml index f5afd83..c04175c 100644 --- a/tests/modules/nexx_integration_test/nexx_integration_test.info.yml +++ b/tests/modules/nexx_integration_test/nexx_integration_test.info.yml @@ -1,7 +1,8 @@ name: Nexx video integration test module type: module description: 'Module used in tests for the nexx integration module' -core: 8.x +package: Testing +core_version_requirement: ^8.7.7 || ^9 dependencies: - drupal:file diff --git a/tests/src/Functional/NexxIntegrationVideoTest.php b/tests/src/Functional/NexxIntegrationVideoTest.php index 6c9e040..e3fc212 100644 --- a/tests/src/Functional/NexxIntegrationVideoTest.php +++ b/tests/src/Functional/NexxIntegrationVideoTest.php @@ -3,7 +3,7 @@ namespace Drupal\Tests\nexx_integration\Functional; use Drupal\Tests\BrowserTestBase; -use Drupal\field_ui\Tests\FieldUiTestTrait; +use Drupal\Tests\field_ui\Traits\FieldUiTestTrait; use Drupal\Tests\nexx_integration\FunctionalJavascript\NexxTestTrait; /** @@ -19,7 +19,7 @@ class NexxIntegrationVideoTest extends BrowserTestBase { /** * {@inheritdoc} */ - public static $modules = [ + protected static $modules = [ 'taxonomy', 'nexx_integration', 'nexx_integration_test', @@ -27,6 +27,11 @@ class NexxIntegrationVideoTest extends BrowserTestBase { 'field', ]; + /** + * {@inheritdoc} + */ + protected $defaultTheme = 'stark'; + /** * Test the endpoint. */ @@ -188,7 +193,7 @@ public function testDeletedVideoUpdate() { $videoEntity = $this->loadVideoEntity($videoData->value); $this->assertNull($videoEntity, "Video id $id should be deleted."); - $this->assertEquals($count - 1, $this->countVideos(), "Counting all videos + $this->assertEquals($count - 1, $this->countVideos(), "Counting all videos after deletion. Video id $id should be deleted."); } @@ -197,8 +202,8 @@ public function testDeletedVideoUpdate() { */ public function testCronExpiration() { $id = 9; - $pastDate = REQUEST_TIME - 10000; - $futureDate = REQUEST_TIME + 10000; + $pastDate = \Drupal::time()->getRequestTime() - 10000; + $futureDate = \Drupal::time()->getRequestTime() + 10000; $videoFieldName = $this->videoManager->videoFieldName(); // First create a new entity that should be created as an active entity @@ -256,7 +261,7 @@ public function testDeletedVideoTrigger() { $videoEntity = $this->loadVideoEntity($videoData->value); $this->assertNull($videoEntity, "Video id $id should be deleted."); - $this->assertEquals($count - 1, $this->countVideos(), "Counting all videos + $this->assertEquals($count - 1, $this->countVideos(), "Counting all videos after deletion. Video id $id should be deleted."); } diff --git a/tests/src/FunctionalJavascript/NexxTestTrait.php b/tests/src/FunctionalJavascript/NexxTestTrait.php index ff4e8ea..490158e 100644 --- a/tests/src/FunctionalJavascript/NexxTestTrait.php +++ b/tests/src/FunctionalJavascript/NexxTestTrait.php @@ -154,7 +154,7 @@ protected function getTestVideoData($videoId) { $itemData->general->uploaded = 1463997938; $itemData->general->copyright = "Copyright notice"; $itemData->publishingdata->isEncoded = "1"; - $itemData->imagedata->thumb = "http://nx-i.akamaized.net/201605/G750452J1M6XAOWxL.jpg"; + $itemData->imagedata->thumb = "https://via.placeholder.com/300.jpg"; $itemData->general->runtime = "00:02:45"; $itemData->channeldata->ID = $channel; $itemData->general->persons_raw = implode(',', $actors);