Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
simple_access
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
project
simple_access
Merge requests
!4
Resolve
#3448960
"Provide migration plugins"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Resolve
#3448960
"Provide migration plugins"
issue/simple_access-3448960:3448960-provide-migration-plugins
into
4.x
Overview
0
Commits
2
Pipelines
1
Changes
4
Open
Adam Bramley
requested to merge
issue/simple_access-3448960:3448960-provide-migration-plugins
into
4.x
11 months ago
Overview
0
Commits
2
Pipelines
1
Changes
4
Expand
Closes
#3448960
0
0
Merge request reports
Compare
4.x
4.x (HEAD)
and
latest version
latest version
d0e1b2e0
2 commits,
11 months ago
4 files
+
188
−
43
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
4
Search (e.g. *.vue) (Ctrl+P)
src/Plugin/migrate/destination/SimpleAccessNodeGroup.php
0 → 100644
+
128
−
0
Options
<?php
declare
(
strict_types
=
1
);
namespace
Drupal\simple_access\Plugin\migrate\destination
;
use
Drupal\Core\Database\Connection
;
use
Drupal\Core\Plugin\ContainerFactoryPluginInterface
;
use
Drupal\migrate\MigrateException
;
use
Drupal\migrate\Plugin\migrate\destination\DestinationBase
;
use
Drupal\migrate\Plugin\MigrationInterface
;
use
Drupal\migrate\Row
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
/**
* Destination for Simple Access Node Groups.
*
* Use the following migration configuration to migrate Simple Access Groups.
*
* @code
* source:
* plugin: d7_simple_access_node_groups
* process:
* nid: nid
* gid: gid
* grant_view: sa_view
* grant_update: sa_update
* grant_delete: sa_delete
* destination:
* plugin: simple_access_node_group
* group_map:
* '1': 'group_one'
* '2': 'group_two'
* '3': 'group_three'
* @endcode
*
* @MigrateDestination(
* id = "simple_access_node_group"
* )
*/
class
SimpleAccessNodeGroup
extends
DestinationBase
implements
ContainerFactoryPluginInterface
{
/**
* SimpleAccessNodeGroup constructor.
*/
public
function
__construct
(
array
$configuration
,
$plugin_id
,
$plugin_definition
,
MigrationInterface
$migration
,
protected
Connection
$database
,
)
{
parent
::
__construct
(
$configuration
,
$plugin_id
,
$plugin_definition
,
$migration
);
}
/**
* {@inheritdoc}
*/
public
static
function
create
(
ContainerInterface
$container
,
array
$configuration
,
$plugin_id
,
$plugin_definition
,
MigrationInterface
$migration
=
NULL
)
{
return
new
static
(
$configuration
,
$plugin_id
,
$plugin_definition
,
$migration
,
$container
->
get
(
'database'
),
);
}
/**
* {@inheritdoc}
*/
public
function
getIds
()
{
return
[
'nid'
=>
[
'type'
=>
'integer'
],
'gid'
=>
[
'type'
=>
'string'
],
];
}
/**
* {@inheritdoc}
*/
public
function
fields
()
{
return
[
'nid'
=>
$this
->
t
(
'The node id.'
),
'gid'
=>
$this
->
t
(
'The group id.'
),
'grant_view'
=>
$this
->
t
(
'Whether view is granted.'
),
'grant_update'
=>
$this
->
t
(
'Whether update is granted.'
),
'grant_delete'
=>
$this
->
t
(
'Whether delete is granted.'
),
];
}
/**
* {@inheritdoc}
*/
public
function
import
(
Row
$row
,
array
$old_destination_id_values
=
[])
{
$gid
=
(
string
)
$row
->
getDestinationProperty
(
'gid'
);
$groupMap
=
$this
->
configuration
[
'group_map'
]
??
[];
if
(
!
isset
(
$groupMap
[
$gid
]))
{
throw
new
MigrateException
(
sprintf
(
'Group id "%s" is missing from the group_map config'
,
$gid
));
}
$group
=
$groupMap
[
$gid
];
$this
->
database
->
insert
(
'simple_access_node_group'
)
->
fields
([
'nid'
=>
$row
->
getDestinationProperty
(
'nid'
),
'gid'
=>
$group
,
'grant_view'
=>
$row
->
getDestinationProperty
(
'grant_view'
),
'grant_update'
=>
$row
->
getDestinationProperty
(
'grant_update'
),
'grant_delete'
=>
$row
->
getDestinationProperty
(
'grant_delete'
),
])
->
execute
();
return
[
'nid'
=>
$row
->
getDestinationProperty
(
'nid'
),
'gid'
=>
$group
,
];
}
/**
* {@inheritdoc}
*/
public
function
rollback
(
array
$destination_identifier
)
{
$this
->
database
->
delete
(
'simple_access_node_group'
)
->
condition
(
'nid'
,
$destination_identifier
[
'nid'
])
->
condition
(
'gid'
,
$destination_identifier
[
'gid'
])
->
execute
();
}
}
Loading