Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
migrate_plus
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
migrate_plus
Commits
adbd5eac
Commit
adbd5eac
authored
8 years ago
by
Lucas Hedding
Committed by
Mike Ryan
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2711949
by heddn: Migrate Skip on Value (or non Value)
parent
bb546170
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Plugin/migrate/process/SkipOnValue.php
+92
-0
92 additions, 0 deletions
src/Plugin/migrate/process/SkipOnValue.php
tests/src/Unit/process/SkipOnValueTest.php
+117
-0
117 additions, 0 deletions
tests/src/Unit/process/SkipOnValueTest.php
with
209 additions
and
0 deletions
src/Plugin/migrate/process/SkipOnValue.php
0 → 100644
+
92
−
0
View file @
adbd5eac
<?php
/**
* @file
* Contains \Drupal\migrate_plus\Plugin\migrate\process\SkipOnValue.
*/
namespace
Drupal\migrate_plus\Plugin\migrate\process
;
use
Drupal\migrate\MigrateException
;
use
Drupal\migrate\MigrateExecutableInterface
;
use
Drupal\migrate\MigrateSkipProcessException
;
use
Drupal\migrate\MigrateSkipRowException
;
use
Drupal\migrate\ProcessPluginBase
;
use
Drupal\migrate\Row
;
/**
* If the source evaluates to a configured value, skip processing or whole row.
*
* @MigrateProcessPlugin(
* id = "skip_on_value"
* )
*/
class
SkipOnValue
extends
ProcessPluginBase
{
/**
* {@inheritdoc}
*/
public
function
row
(
$value
,
MigrateExecutableInterface
$migrate_executable
,
Row
$row
,
$destination_property
)
{
if
(
empty
(
$this
->
configuration
[
'value'
])
&&
!
array_key_exists
(
'value'
,
$this
->
configuration
))
{
throw
new
MigrateException
(
'Skip on value plugin is missing value configuration.'
);
}
if
(
is_array
(
$this
->
configuration
[
'value'
]))
{
foreach
(
$this
->
configuration
[
'value'
]
as
$skipValue
)
{
if
(
$this
->
compareValue
(
$value
,
$skipValue
,
!
isset
(
$this
->
configuration
[
'not_equals'
])))
{
throw
new
MigrateSkipRowException
();
}
}
}
elseif
(
$this
->
compareValue
(
$value
,
$this
->
configuration
[
'value'
],
!
isset
(
$this
->
configuration
[
'not_equals'
])))
{
throw
new
MigrateSkipRowException
();
}
return
$value
;
}
/**
* {@inheritdoc}
*/
public
function
process
(
$value
,
MigrateExecutableInterface
$migrate_executable
,
Row
$row
,
$destination_property
)
{
if
(
empty
(
$this
->
configuration
[
'value'
])
&&
!
array_key_exists
(
'value'
,
$this
->
configuration
))
{
throw
new
MigrateException
(
'Skip on value plugin is missing value configuration.'
);
}
if
(
is_array
(
$this
->
configuration
[
'value'
]))
{
foreach
(
$this
->
configuration
[
'value'
]
as
$skipValue
)
{
if
(
$this
->
compareValue
(
$value
,
$skipValue
,
!
isset
(
$this
->
configuration
[
'not_equals'
])))
{
throw
new
MigrateSkipProcessException
();
}
}
}
elseif
(
$this
->
compareValue
(
$value
,
$this
->
configuration
[
'value'
],
!
isset
(
$this
->
configuration
[
'not_equals'
])))
{
throw
new
MigrateSkipProcessException
();
}
return
$value
;
}
/**
* Compare values to see if they are equal.
*
* @param $value
* Actual value
* @param $skipValue
* Value to compare against.
* @param $equal
* Compare as equal or not equal.
*
* @return bool
* True if the compare successfully, FALSE otherwise.
*/
protected
function
compareValue
(
$value
,
$skipValue
,
$equal
=
TRUE
)
{
if
(
$equal
)
{
return
(
string
)
$value
==
(
string
)
$skipValue
;
}
return
(
string
)
$value
!=
(
string
)
$skipValue
;
}
}
This diff is collapsed.
Click to expand it.
tests/src/Unit/process/SkipOnValueTest.php
0 → 100644
+
117
−
0
View file @
adbd5eac
<?php
/**
* @file
* Contains \Drupal\Tests\migrate_plus\Unit\process\SkipOnValueTest.
*/
namespace
Drupal\Tests\migrate_plus\Unit\process
;
use
Drupal\migrate_plus
\Plugin\migrate\process\SkipOnValue
;
use
Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase
;
/**
* Tests the skip on value process plugin.
*
* @group migrate
* @coversDefaultClass \Drupal\migrate_plus\Plugin\migrate\process\SkipOnValue
*/
class
SkipOnValueTest
extends
MigrateProcessTestCase
{
/**
* @covers ::process
* @expectedException \Drupal\migrate\MigrateSkipProcessException
*/
public
function
testProcessSkipsOnValue
()
{
$configuration
[
'method'
]
=
'process'
;
$configuration
[
'value'
]
=
86
;
(
new
SkipOnValue
(
$configuration
,
'skip_on_value'
,
[]))
->
transform
(
'86'
,
$this
->
migrateExecutable
,
$this
->
row
,
'destinationproperty'
);
}
/**
* @covers ::process
* @expectedException \Drupal\migrate\MigrateSkipProcessException
*/
public
function
testProcessSkipsOnMultipleValue
()
{
$configuration
[
'method'
]
=
'process'
;
$configuration
[
'value'
]
=
[
1
,
1
,
2
,
3
,
5
,
8
];
(
new
SkipOnValue
(
$configuration
,
'skip_on_value'
,
[]))
->
transform
(
'5'
,
$this
->
migrateExecutable
,
$this
->
row
,
'destinationproperty'
);
}
/**
* @covers ::process
*/
public
function
testProcessBypassesOnNonValue
()
{
$configuration
[
'method'
]
=
'process'
;
$configuration
[
'value'
]
=
'sourcevalue'
;
$configuration
[
'not_equals'
]
=
TRUE
;
$value
=
(
new
SkipOnValue
(
$configuration
,
'skip_on_value'
,
[]))
->
transform
(
'sourcevalue'
,
$this
->
migrateExecutable
,
$this
->
row
,
'destinationproperty'
);
$this
->
assertEquals
(
$value
,
'sourcevalue'
);
$configuration
[
'value'
]
=
86
;
$value
=
(
new
SkipOnValue
(
$configuration
,
'skip_on_value'
,
[]))
->
transform
(
'86'
,
$this
->
migrateExecutable
,
$this
->
row
,
'destinationproperty'
);
$this
->
assertEquals
(
$value
,
'86'
);
}
/**
* @covers ::process
*/
public
function
testProcessSkipsOnMultipleNonValue
()
{
$configuration
[
'method'
]
=
'process'
;
$configuration
[
'value'
]
=
[
1
,
1
,
2
,
3
,
5
,
8
];
$value
=
(
new
SkipOnValue
(
$configuration
,
'skip_on_value'
,
[]))
->
transform
(
4
,
$this
->
migrateExecutable
,
$this
->
row
,
'destinationproperty'
);
$this
->
assertEquals
(
$value
,
'4'
);
}
/**
* @covers ::row
* @expectedException \Drupal\migrate\MigrateSkipRowException
*/
public
function
testRowSkipsOnValue
()
{
$configuration
[
'method'
]
=
'row'
;
$configuration
[
'value'
]
=
86
;
(
new
SkipOnValue
(
$configuration
,
'skip_on_value'
,
[]))
->
transform
(
'86'
,
$this
->
migrateExecutable
,
$this
->
row
,
'destinationproperty'
);
}
/**
* @covers ::row
*/
public
function
testRowBypassesOnNonValue
()
{
$configuration
[
'method'
]
=
'row'
;
$configuration
[
'value'
]
=
'sourcevalue'
;
$configuration
[
'not_equals'
]
=
TRUE
;
$value
=
(
new
SkipOnValue
(
$configuration
,
'skip_on_value'
,
[]))
->
transform
(
'sourcevalue'
,
$this
->
migrateExecutable
,
$this
->
row
,
'destinationproperty'
);
$this
->
assertEquals
(
$value
,
'sourcevalue'
);
$configuration
[
'value'
]
=
86
;
$value
=
(
new
SkipOnValue
(
$configuration
,
'skip_on_value'
,
[]))
->
transform
(
'86'
,
$this
->
migrateExecutable
,
$this
->
row
,
'destinationproperty'
);
$this
->
assertEquals
(
$value
,
86
);
}
/**
* @covers ::row
* @expectedException \Drupal\migrate\MigrateException
*/
public
function
testRequiredRowConfiguration
()
{
$configuration
[
'method'
]
=
'row'
;
(
new
SkipOnValue
(
$configuration
,
'skip_on_value'
,
[]))
->
transform
(
'sourcevalue'
,
$this
->
migrateExecutable
,
$this
->
row
,
'destinationproperty'
);
}
/**
* @covers ::process
* @expectedException \Drupal\migrate\MigrateException
*/
public
function
testRequiredProcessConfiguration
()
{
$configuration
[
'method'
]
=
'process'
;
(
new
SkipOnValue
(
$configuration
,
'skip_on_value'
,
[]))
->
transform
(
'sourcevalue'
,
$this
->
migrateExecutable
,
$this
->
row
,
'destinationproperty'
);
}
}
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