Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
feeds
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
drupal.org
feeds
Commits
d0ac307e
Commit
d0ac307e
authored
9 years ago
by
MegaChriz
Browse files
Options
Downloads
Patches
Plain Diff
Issue #2556461 by MegaChriz: Fixed importing two hierarchical vocabularies with overlapping id's.
parent
72e0e009
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
plugins/FeedsTermProcessor.inc
+12
-2
12 additions, 2 deletions
plugins/FeedsTermProcessor.inc
tests/feeds/terms.csv
+3
-0
3 additions, 0 deletions
tests/feeds/terms.csv
tests/feeds_processor_term.test
+228
-0
228 additions, 0 deletions
tests/feeds_processor_term.test
with
243 additions
and
2 deletions
plugins/FeedsTermProcessor.inc
+
12
−
2
View file @
d0ac307e
...
@@ -112,11 +112,21 @@ class FeedsTermProcessor extends FeedsProcessor {
...
@@ -112,11 +112,21 @@ class FeedsTermProcessor extends FeedsProcessor {
case
'parentguid'
:
case
'parentguid'
:
// value is parent_guid field value
// value is parent_guid field value
$parent_tid
=
0
;
$query
=
db_select
(
'feeds_item'
)
$query
=
db_select
(
'feeds_item'
)
->
fields
(
'feeds_item'
,
array
(
'entity_id'
))
->
fields
(
'feeds_item'
,
array
(
'entity_id'
))
->
condition
(
'entity_type'
,
$this
->
entityType
());
->
condition
(
'entity_type'
,
$this
->
entityType
());
$parent_tid
=
$query
->
condition
(
'guid'
,
$value
)
->
execute
()
->
fetchField
();
$term_ids
=
array_keys
(
$query
->
condition
(
'guid'
,
$value
)
->
execute
()
->
fetchAllAssoc
(
'entity_id'
));
$target_term
->
parent
[]
=
(
$parent_tid
)
?
$parent_tid
:
0
;
if
(
!
empty
(
$term_ids
))
{
$terms
=
entity_load
(
$this
->
entityType
(),
$term_ids
);
foreach
(
$terms
as
$term
)
{
if
(
$term
->
vid
==
$target_term
->
vid
)
{
$parent_tid
=
$term
->
tid
;
break
;
}
}
}
$target_term
->
parent
[]
=
$parent_tid
;
break
;
break
;
case
'weight'
:
case
'weight'
:
...
...
This diff is collapsed.
Click to expand it.
tests/feeds/terms.csv
0 → 100644
+
3
−
0
View file @
d0ac307e
guid,name,parent,parentguid
1,Europe,,
2,Belgium,Europe,1
\ No newline at end of file
This diff is collapsed.
Click to expand it.
tests/feeds_processor_term.test
+
228
−
0
View file @
d0ac307e
...
@@ -120,4 +120,232 @@ class FeedsCSVtoTermsTest extends FeedsWebTestCase {
...
@@ -120,4 +120,232 @@ class FeedsCSVtoTermsTest extends FeedsWebTestCase {
$this
->
assertText
(
t
(
'No vocabulary defined for Taxonomy Term processor.'
));
$this
->
assertText
(
t
(
'No vocabulary defined for Taxonomy Term processor.'
));
}
}
/**
* Tests that terms mapped to their parent by GUID are from the same vocabulary.
*/
public
function
testParentTargetByGUID
()
{
// Create an other vocabulary.
$vocabulary1
=
'addams'
;
$vocabulary2
=
strtolower
(
$this
->
randomName
());
$edit
=
array
(
'name'
=>
$this
->
randomString
(),
'machine_name'
=>
$vocabulary2
,
);
$this
->
drupalPost
(
'admin/structure/taxonomy/add'
,
$edit
,
t
(
'Save'
));
// Add mappings for the first importer.
$this
->
addMappings
(
'term_import'
,
array
(
0
=>
array
(
'source'
=>
'guid'
,
'target'
=>
'guid'
,
'unique'
=>
TRUE
,
),
1
=>
array
(
'source'
=>
'name'
,
'target'
=>
'name'
,
),
2
=>
array
(
'source'
=>
'parentguid'
,
'target'
=>
'parentguid'
,
),
)
);
// Create a second importer.
$this
->
createImporterConfiguration
(
'Term import 2'
,
'term_import2'
);
$this
->
setSettings
(
'term_import2'
,
NULL
,
array
(
'content_type'
=>
''
));
// Set and configure plugins and mappings.
$this
->
setPlugin
(
'term_import2'
,
'FeedsFileFetcher'
);
$this
->
setPlugin
(
'term_import2'
,
'FeedsCSVParser'
);
$this
->
setPlugin
(
'term_import2'
,
'FeedsTermProcessor'
);
$this
->
setSettings
(
'term_import2'
,
'FeedsTermProcessor'
,
array
(
'bundle'
=>
$vocabulary2
));
// Add mappings for the second importer.
$this
->
addMappings
(
'term_import2'
,
array
(
0
=>
array
(
'source'
=>
'guid'
,
'target'
=>
'guid'
,
'unique'
=>
TRUE
,
),
1
=>
array
(
'source'
=>
'name'
,
'target'
=>
'name'
,
),
2
=>
array
(
'source'
=>
'parentguid'
,
'target'
=>
'parentguid'
,
),
)
);
$values
=
array
(
1
=>
'Europe'
,
2
=>
'Belgium'
,
);
// Import file using the first importer.
$this
->
importFile
(
'term_import'
,
$this
->
absolutePath
()
.
'/tests/feeds/terms.csv'
);
$this
->
assertText
(
'Created 2 terms.'
);
// Assert that two terms were created in the first vocabulary.
$terms
=
entity_load
(
'taxonomy_term'
,
array_keys
(
$values
));
foreach
(
$terms
as
$tid
=>
$term
)
{
$this
->
assertEqual
(
$values
[
$tid
],
$term
->
name
);
$this
->
assertEqual
(
$vocabulary1
,
$term
->
vocabulary_machine_name
);
}
// Assert that the second term's parent is the first term.
$parents
=
taxonomy_get_parents
(
$terms
[
2
]
->
tid
);
$message
=
format_string
(
'The term @term is correctly linked to its parent.'
,
array
(
'@term'
=>
$terms
[
2
]
->
name
));
if
(
!
empty
(
$parents
))
{
$parent
=
current
(
$parents
);
$this
->
assertEqual
(
1
,
$parent
->
tid
,
$message
);
}
else
{
$this
->
fail
(
$message
);
}
$values
=
array
(
3
=>
'Europe'
,
4
=>
'Belgium'
,
);
// Now import the file using the second importer.
$this
->
importFile
(
'term_import2'
,
$this
->
absolutePath
()
.
'/tests/feeds/terms.csv'
);
$this
->
assertText
(
'Created 2 terms.'
);
// Assert that two terms were created in the second vocabulary.
$terms
=
entity_load
(
'taxonomy_term'
,
array_keys
(
$values
));
foreach
(
$terms
as
$tid
=>
$term
)
{
$this
->
assertEqual
(
$values
[
$tid
],
$term
->
name
);
$this
->
assertEqual
(
$vocabulary2
,
$term
->
vocabulary_machine_name
);
}
// Assert that the second term's parent is the first term.
$parents
=
taxonomy_get_parents
(
$terms
[
4
]
->
tid
);
$message
=
format_string
(
'The term @term is correctly linked to its parent.'
,
array
(
'@term'
=>
$terms
[
4
]
->
name
));
if
(
!
empty
(
$parents
))
{
$parent
=
current
(
$parents
);
$this
->
assertEqual
(
3
,
$parent
->
tid
,
$message
);
}
else
{
$this
->
fail
(
$message
);
}
}
/**
* Tests that terms mapped to their parent by GUID are from the same vocabulary.
*/
public
function
testParentTargetByName
()
{
// Create an other vocabulary.
$vocabulary1
=
'addams'
;
$vocabulary2
=
strtolower
(
$this
->
randomName
());
$edit
=
array
(
'name'
=>
$this
->
randomString
(),
'machine_name'
=>
$vocabulary2
,
);
$this
->
drupalPost
(
'admin/structure/taxonomy/add'
,
$edit
,
t
(
'Save'
));
// Add mappings for the first importer.
$this
->
addMappings
(
'term_import'
,
array
(
0
=>
array
(
'source'
=>
'guid'
,
'target'
=>
'guid'
,
'unique'
=>
TRUE
,
),
1
=>
array
(
'source'
=>
'name'
,
'target'
=>
'name'
,
),
2
=>
array
(
'source'
=>
'parent'
,
'target'
=>
'parent'
,
),
)
);
// Create a second importer.
$this
->
createImporterConfiguration
(
'Term import 2'
,
'term_import2'
);
$this
->
setSettings
(
'term_import2'
,
NULL
,
array
(
'content_type'
=>
''
));
// Set and configure plugins and mappings.
$this
->
setPlugin
(
'term_import2'
,
'FeedsFileFetcher'
);
$this
->
setPlugin
(
'term_import2'
,
'FeedsCSVParser'
);
$this
->
setPlugin
(
'term_import2'
,
'FeedsTermProcessor'
);
$this
->
setSettings
(
'term_import2'
,
'FeedsTermProcessor'
,
array
(
'bundle'
=>
$vocabulary2
));
// Add mappings for the second importer.
$this
->
addMappings
(
'term_import2'
,
array
(
0
=>
array
(
'source'
=>
'guid'
,
'target'
=>
'guid'
,
'unique'
=>
TRUE
,
),
1
=>
array
(
'source'
=>
'name'
,
'target'
=>
'name'
,
),
2
=>
array
(
'source'
=>
'parent'
,
'target'
=>
'parent'
,
),
)
);
$values
=
array
(
1
=>
'Europe'
,
2
=>
'Belgium'
,
);
// Import file using the first importer.
$this
->
importFile
(
'term_import'
,
$this
->
absolutePath
()
.
'/tests/feeds/terms.csv'
);
$this
->
assertText
(
'Created 2 terms.'
);
// Assert that two terms were created in the first vocabulary.
$terms
=
entity_load
(
'taxonomy_term'
,
array_keys
(
$values
));
foreach
(
$terms
as
$tid
=>
$term
)
{
$this
->
assertEqual
(
$values
[
$tid
],
$term
->
name
);
$this
->
assertEqual
(
$vocabulary1
,
$term
->
vocabulary_machine_name
);
}
// Assert that the second term's parent is the first term.
$parents
=
taxonomy_get_parents
(
$terms
[
2
]
->
tid
);
$message
=
format_string
(
'The term @term is correctly linked to its parent.'
,
array
(
'@term'
=>
$terms
[
2
]
->
name
));
if
(
!
empty
(
$parents
))
{
$parent
=
current
(
$parents
);
$this
->
assertEqual
(
1
,
$parent
->
tid
,
$message
);
}
else
{
$this
->
fail
(
$message
);
}
$values
=
array
(
3
=>
'Europe'
,
4
=>
'Belgium'
,
);
// Now import the file using the second importer.
$this
->
importFile
(
'term_import2'
,
$this
->
absolutePath
()
.
'/tests/feeds/terms.csv'
);
$this
->
assertText
(
'Created 2 terms.'
);
// Assert that two terms were created in the second vocabulary.
$terms
=
entity_load
(
'taxonomy_term'
,
array_keys
(
$values
));
foreach
(
$terms
as
$tid
=>
$term
)
{
$this
->
assertEqual
(
$values
[
$tid
],
$term
->
name
);
$this
->
assertEqual
(
$vocabulary2
,
$term
->
vocabulary_machine_name
);
}
// Assert that the second term's parent is the first term.
$parents
=
taxonomy_get_parents
(
$terms
[
4
]
->
tid
);
$message
=
format_string
(
'The term @term is correctly linked to its parent.'
,
array
(
'@term'
=>
$terms
[
4
]
->
name
));
if
(
!
empty
(
$parents
))
{
$parent
=
current
(
$parents
);
$this
->
assertEqual
(
3
,
$parent
->
tid
,
$message
);
}
else
{
$this
->
fail
(
$message
);
}
}
}
}
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