Skip to content
Snippets Groups Projects
Commit 69df5e9e authored by Oleksandr Kuzava's avatar Oleksandr Kuzava
Browse files

Issue #3298084: Automated Drupal 10 compatibility fixes

parent 1ec16609
Branches
Tags
No related merge requests found
......@@ -59,7 +59,7 @@ Yes! Please use the importer service and hook_update_N or similar to do it. Chec
```php
function example_update_8001() {
$file_path = drupal_get_path('module', 'example') . '/assets/homepage.yml';
$file_path = \Drupal::service('extension.list.module')->getPath('example') . '/assets/homepage.yml';
\Drupal::service('single_content_sync.importer')->importFromFile($file_path);
}
```
......@@ -68,7 +68,7 @@ If you would like to import content from a generated zip file, use the following
```php
function example_update_8001() {
$file_path = drupal_get_path('module', 'example') . '/assets/homepage.zip';
$file_path = \Drupal::service('extension.list.module')->getPath('example') . '/assets/homepage.zip';
\Drupal::service('single_content_sync.importer')->importFromZip($file_path);
}
```
......
name: Single Content Sync
type: module
description: 'Export/import a single content between different environments.'
core_version_requirement: ^8.8 || ^9
core_version_requirement: ^9.3 || ^10
package: Content
configure: single_content_sync.settings
......@@ -12,7 +12,7 @@ use Drupal\Core\Config\FileStorage;
*/
function single_content_sync_update_9121(&$sandbox) {
// Get file storage of optional configs in the module.
$config_path = drupal_get_path('module', 'single_content_sync') . '/config/install';
$config_path = \Drupal::service('extension.list.module')->getPath('single_content_sync') . '/config/install';
$source = new FileStorage($config_path);
/** @var \Drupal\Core\Config\StorageInterface $config_storage */
......@@ -32,7 +32,7 @@ function single_content_sync_update_9121(&$sandbox) {
*/
function single_content_sync_update_9130(&$sandbox) {
// Get file storage of optional configs in the module.
$config_path = drupal_get_path('module', 'single_content_sync') . '/config/install';
$config_path = \Drupal::service('extension.list.module')->getPath('single_content_sync') . '/config/install';
$source = new FileStorage($config_path);
/** @var \Drupal\Core\Config\StorageInterface $config_storage */
......
......@@ -15,6 +15,7 @@ services:
- '@entity.repository'
- '@module_handler'
- '@file_system'
- '@file.repository'
- '@single_content_sync.helper'
single_content_sync.file_generator:
......@@ -30,6 +31,7 @@ services:
arguments:
- '@uuid'
- '@file_system'
- '@file.repository'
- '@plugin.manager.archiver'
- '@entity_type.manager'
- '@config.factory'
......
......@@ -12,6 +12,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\TypedData\TranslatableInterface;
use Drupal\file\FileRepositoryInterface;
use Drupal\layout_builder\Plugin\Block\InlineBlock;
class ContentImporter implements ContentImporterInterface {
......@@ -46,6 +47,13 @@ class ContentImporter implements ContentImporterInterface {
*/
protected $fileSystem;
/**
* The file repository.
*
* @var \Drupal\file\FileRepositoryInterface
*/
protected $fileRepository;
/**
* The content sync helper.
*
......@@ -71,14 +79,17 @@ class ContentImporter implements ContentImporterInterface {
* The module handler.
* @param \Drupal\Core\File\FileSystemInterface $file_system
* The file system.
* @param \Drupal\file\FileRepositoryInterface $file_repository
* The file repository.
* @param \Drupal\single_content_sync\ContentSyncHelperInterface $content_sync_helper
* The content sync helper.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityRepositoryInterface $entity_repository, ModuleHandlerInterface $module_handler, FileSystemInterface $file_system, ContentSyncHelperInterface $content_sync_helper) {
public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityRepositoryInterface $entity_repository, ModuleHandlerInterface $module_handler, FileSystemInterface $file_system, FileRepositoryInterface $file_repository, ContentSyncHelperInterface $content_sync_helper) {
$this->entityTypeManager = $entity_type_manager;
$this->entityRepository = $entity_repository;
$this->moduleHandler = $module_handler;
$this->fileSystem = $file_system;
$this->fileRepository = $file_repository;
$this->contentSyncHelper = $content_sync_helper;
}
......@@ -342,7 +353,7 @@ class ContentImporter implements ContentImporterInterface {
$directory = $this->fileSystem->dirname($file_item['uri']);
$this->contentSyncHelper->prepareFilesDirectory($directory);
if ($file = file_save_data($content, $file_item['uri'], FileSystemInterface::EXISTS_REPLACE)) {
if ($file = $this->fileRepository->writeData($content, $file_item['uri'], FileSystemInterface::EXISTS_REPLACE)) {
$file->setOwnerId(1);
$file->setPermanent();
$file->save();
......
......@@ -13,6 +13,7 @@ use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Serialization\Yaml;
use Drupal\file\FileInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\file\FileRepositoryInterface;
use Symfony\Component\HttpFoundation\ParameterBag;
class ContentSyncHelper implements ContentSyncHelperInterface {
......@@ -26,6 +27,13 @@ class ContentSyncHelper implements ContentSyncHelperInterface {
*/
protected $fileSystem;
/**
* The file system.
*
* @var \Drupal\file\FileRepositoryInterface
*/
protected $fileRepository;
/**
* The entity type manager.
*
......@@ -68,16 +76,21 @@ class ContentSyncHelper implements ContentSyncHelperInterface {
* The uuid generator.
* @param \Drupal\Core\File\FileSystemInterface $file_system
* The file system service.
* @param \Drupal\file\FileRepositoryInterface $file_repository
* The file repository.
* @param \Drupal\Core\Archiver\ArchiverManager $archiver_manager
* The archive manager.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
* The entity repository.
*/
public function __construct(UuidInterface $uuid, FileSystemInterface $file_system, ArchiverManager $archiver_manager, EntityTypeManagerInterface $entity_type_manager, ConfigFactoryInterface $config_factory, EntityRepositoryInterface $entity_repository) {
public function __construct(UuidInterface $uuid, FileSystemInterface $file_system, FileRepositoryInterface $file_repository, ArchiverManager $archiver_manager, EntityTypeManagerInterface $entity_type_manager, ConfigFactoryInterface $config_factory, EntityRepositoryInterface $entity_repository) {
$this->uuid = $uuid;
$this->fileSystem = $file_system;
$this->fileRepository = $file_repository;
$this->archiverManager = $archiver_manager;
$this->entityTypeManager = $entity_type_manager;
$this->configFactory = $config_factory;
......@@ -95,7 +108,7 @@ class ContentSyncHelper implements ContentSyncHelperInterface {
* {@inheritdoc}
*/
public function saveFileContentTemporary(string $content, string $destination): FileInterface {
$file = file_save_data($content, $destination);
$file = $this->fileRepository->writeData($content, $destination);
$file->setTemporary();
$file->save();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment