Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
single_content_sync-3255233
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
single_content_sync-3255233
Commits
48c17754
Commit
48c17754
authored
3 years ago
by
Oleksandr Kuzava
Browse files
Options
Downloads
Patches
Plain Diff
Fix node alias issue. Improve file importing.
parent
608ea1ec
No related branches found
Branches containing commit
Tags
1.1.0-rc4
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
single_content_sync.services.yml
+1
-1
1 addition, 1 deletion
single_content_sync.services.yml
src/ContentExporter.php
+2
-1
2 additions, 1 deletion
src/ContentExporter.php
src/ContentImporter.php
+30
-8
30 additions, 8 deletions
src/ContentImporter.php
with
33 additions
and
10 deletions
single_content_sync.services.yml
+
1
−
1
View file @
48c17754
...
...
@@ -4,4 +4,4 @@ services:
arguments
:
[
'
@entity_type.manager'
,
'
@module_handler'
]
single_content_sync.importer
:
class
:
Drupal\single_content_sync\ContentImporter
arguments
:
[
'
@entity_type.manager'
,
'
@entity.repository'
,
'
@module_handler'
]
arguments
:
[
'
@entity_type.manager'
,
'
@entity.repository'
,
'
@module_handler'
,
'
@file_system'
]
This diff is collapsed.
Click to expand it.
src/ContentExporter.php
+
2
−
1
View file @
48c17754
...
...
@@ -8,6 +8,7 @@ use Drupal\Core\Entity\EntityTypeManagerInterface;
use
Drupal\Core\Entity\FieldableEntityInterface
;
use
Drupal\Core\Extension\ModuleHandlerInterface
;
use
Drupal\Core\Field\FieldItemListInterface
;
use
Drupal\Core\Language\LanguageInterface
;
use
Drupal\Core\Serialization\Yaml
;
use
Drupal\field\FieldConfigInterface
;
use
Drupal\media\MediaInterface
;
...
...
@@ -67,7 +68,7 @@ class ContentExporter implements ContentExporterInterface {
'created'
=>
$entity
->
getCreatedTime
(),
'changed'
=>
$entity
->
getChangedTime
(),
'author'
=>
$owner
?
$owner
->
getEmail
()
:
NULL
,
'url'
=>
$entity
->
toUrl
()
->
toString
()
,
'url'
=>
$entity
->
get
(
'path'
)
->
alias
??
NULL
,
];
}
break
;
...
...
This diff is collapsed.
Click to expand it.
src/ContentImporter.php
+
30
−
8
View file @
48c17754
...
...
@@ -32,6 +32,13 @@ class ContentImporter implements ContentImporterInterface {
*/
protected
$moduleHandler
;
/**
* The file system.
*
* @var \Drupal\Core\File\FileSystemInterface
*/
protected
$fileSystem
;
/**
* ContentExporter constructor.
*
...
...
@@ -41,11 +48,14 @@ class ContentImporter implements ContentImporterInterface {
* The entity repository.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\File\FileSystemInterface $file_system
* The file system.
*/
public
function
__construct
(
EntityTypeManagerInterface
$entity_type_manager
,
EntityRepositoryInterface
$entity_repository
,
ModuleHandlerInterface
$module_handler
)
{
public
function
__construct
(
EntityTypeManagerInterface
$entity_type_manager
,
EntityRepositoryInterface
$entity_repository
,
ModuleHandlerInterface
$module_handler
,
FileSystemInterface
$file_system
)
{
$this
->
entityTypeManager
=
$entity_type_manager
;
$this
->
entityRepository
=
$entity_repository
;
$this
->
moduleHandler
=
$module_handler
;
$this
->
fileSystem
=
$file_system
;
}
/**
...
...
@@ -70,7 +80,7 @@ class ContentImporter implements ContentImporterInterface {
'status'
=>
$content
[
'base_fields'
][
'status'
],
'path'
=>
[
'alias'
=>
$content
[
'base_fields'
][
'url'
],
'pathauto'
=>
0
,
'pathauto'
=>
empty
(
$content
[
'base_fields'
][
'url'
])
,
],
]);
}
...
...
@@ -181,13 +191,22 @@ class ContentImporter implements ContentImporterInterface {
break
;
case
'paragraph'
:
$entity
=
$this
->
entityRepository
->
loadEntityByUuid
(
'paragraph'
,
$content
[
'uuid'
]);
$paragraph_storage
=
$this
->
entityTypeManager
->
getStorage
(
'paragraph'
);
$entity
=
$paragraph_storage
->
create
([
'type'
=>
$content
[
'bundle'
],
'langcode'
=>
$content
[
'base_fields'
][
'langcode'
],
'created'
=>
$content
[
'base_fields'
][
'created'
],
'status'
=>
$content
[
'base_fields'
][
'status'
],
]);
if
(
!
$entity
)
{
$entity
=
$paragraph_storage
->
create
([
'uuid'
=>
$content
[
'uuid'
],
'type'
=>
$content
[
'bundle'
],
'langcode'
=>
$content
[
'base_fields'
][
'langcode'
],
'created'
=>
$content
[
'base_fields'
][
'created'
],
'status'
=>
$content
[
'base_fields'
][
'status'
],
]);
}
else
{
$entity
->
set
(
'status'
,
$content
[
'base_fields'
][
'status'
]);
$entity
->
set
(
'langcode'
,
$content
[
'base_fields'
][
'langcode'
]);
}
break
;
}
...
...
@@ -292,6 +311,9 @@ class ContentImporter implements ContentImporterInterface {
}
$content
=
file_get_contents
(
$file_item
[
'url'
]);
$directory
=
$this
->
fileSystem
->
dirname
(
$file_item
[
'uri'
]);
$this
->
fileSystem
->
prepareDirectory
(
$directory
,
FileSystemInterface
::
CREATE_DIRECTORY
|
FileSystemInterface
::
MODIFY_PERMISSIONS
);
if
(
$file
=
file_save_data
(
$content
,
$file_item
[
'uri'
],
FileSystemInterface
::
EXISTS_REPLACE
))
{
$file
->
setOwnerId
(
1
);
$file
->
setPermanent
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment