Open a-am opened 8 years ago
I have the same problem, categories and related entries are not connected. Any idea?
Assets (based on the filename) don't connect neither.
@boboldehampsink in your mind when might you schedule this fix? Thank you for your time.
I have not been able to reproduce this yet. The quickest way to get the fix in is to submit a PR, or wait until I find the time and the bug.
@boboldehampsink I'm also having this issue. I have a channel of chemicals (ingredients), and a category of classification groups (family). The chemical channel imports entries but fails to assign the proper category.
CSV attached. ingred-1.csv.zip
@boboldehampsink Hi Bob, When I use your Export plugin, categories are comma seperated in the export CSV, but when I import that file again, the categories keep empty. Is this a bug?
Title,Slug,Parent,Ancestors,Author,"Post Date","Expiry Date",Enabled,Status,Body,Assets,Cat,Tags
"Product 1",product-1,,,martijn,2016-06-29,,Yes,live,"<p>Dit is het eerste product</p>","Pic 054 Clean 790, Pic 056 Clean 790, Pic 058 Clean 790, Pic 062 Clean 790, Pic 079 Clean 790","Appels, Bananen",
@boboldehampsink Hi there. I also can't seem to get categories to populate when importing entries. Is this feature supported?
This may not be your issue, but I always forget that (at least) two things need to be in place before importing a related category will work:
Hope that helps.
@gmhenderson are you talking about importing entries with a column which should relate categories? Or are you referring to importing only categories?
The former: Importing entries with a column which should relate a category.
@gmhenderson Awesome, that seemed to work! Thank you!
@gmhenderson FYI, looks like you can use the category Title as well as the slug. I don't know if that's new since you've used it or not, but both worked successfully for me.
Is this a bug or not? Does one have to use a slug or titles or can either work? Having no luck at all importing an entry with categories. Super simple CSV. See here:
This issue is about relating categories, not importing categories. You will find the answer to your question in the FAQ tho.
"importing an entry with related categories" is that not clear? What answer? Having URLs ticked? It is. There is no heirarchy. top level.
Thanks. That issue is still under investigation.
Thanks. But we're seeing conflicting discussion all over the place. You can't reproduce it. It's a bug. It's not a bug. @wjthomas9 got it to work. It's still under investigation. You can't reproduce. @gmhenderson got it to work. Refer to the FAQ. And on and on.
We need to know whether this will work or not, so we can decide if this plug-in is a solution or not.
The matter is simple: Can this plug-in import entries with related categories? Yes or no.
Wish it were that simple. I've not been able to reproduce, works perfectly fine on my end. Use this in multiple sites, never had a problem with it. Still, in some scenarios it doesn't work. If someone is able to set me up a reproduction site I could investigate better.
It's the modifyImportRow hook. If one uses that sample code in the Read Me, related categories will not import.
So we will have to run at least two imports, one with our Import Helper that uses the hook enabled (for tables, booleans, dates, etc.), and one without, in order to append the related categories.
Unless someone can provide better example code to exclude an entry category field, but I can't think of how right now.
Ah, you may be on to something. Can anyone else in this thread confirm they use this hook?
I can confirm I need to unset any fields I expect to be automatically related (entries, categories, etc) in my modifyImportRow
hook in the $content
array before calling $element->setContentFromPost()
.
I've been struggling with this problem for a few hrs now, and out of desperation I tried switching the language in Craft from norwegian to english. Suddenly importing entries with related categories started working.
Could it be that simple? To those who are having this issue: Have you also set Craft to a language other than English?
@boboldehampsink & @smockensturm I just tried the method that @adamfairholm suggested and that worked without needing to enable and disable the import helper plugin.
// Unset related entries fields
unset($content['entriesField1']);
unset($content['entriesField2']);
...
// Set modified content
$element->setContentFromPost($content);
First off..thank you @boboldehampsink for this fantastic plugin! You have saved me many hours of manual labor.
I've been experiencing the same issue where I'm performing an import of entries and their associated categories are not being connected. For me, I was able to narrow it down to two issues, one that might be a bug.
My first issue related to what @gmhenderson called out in that categories need to have individual URLs associated with them. Once I did this, the import started working on some of the categories but not others.
The second issue that I noticed with categories that would not associate: they all had some non-alphanumeric character in the title. Ultimately, I found that category titles must match the slug (sans dash) to import and associate entries on category titles...not sure why though.
TLDR
I removed the non-alpha character (ie. / . '), tried to do a replace data
but it didn't work. I then cleared out all the entries and re-imported. Still didn't work. It wasn't until I imported all the categories with clean data that I discovered what was happening. What I found is that even though I was using category titles to key off of, they still needed to match the slug! As long as my category title matches what a default slug would look like generated from Craft I have no issue importing using category titles.
I don't have any cycles now to review the codebase but hopefully this will help somebody else out and possibly provide some direction for where to look for a fix.
Hey @boboldehampsink, Thanks for the plugin. Nice work.
While using the modifyImportRow hook I wasn't able to get categories or images to import correctly, like some of the others above.
I was able to solve the issue by creating a function that manually found the category and asset ids and returned a comma separated list of the found ids.
The categories worked like a dream, but the images were still having issues. Craft's asset field type was expecting an array of values, and wrapping the comma separated list in an array didn't solve the issue.
I changed this line in craft/app/fieldtypes/AssetsFieldType.php
$fileIds = array_merge($value, $fileIds);
To:
$fileIds = array_merge((array)$value, $fileIds);
And the images started importing correctly. This is definitely a hacky fix, that I'll probably revert after running my import, but maybe it gives a little be better direction about where the issue lies.
@mitch-rickman I'm trying to achieve the same. Can you share what you did for the categories? Thanks in advance.
@masiorama, for the categories I used the element criteria model (https://craftcms.com/docs/templating/elementcriteriamodel) to search for a custom field associated with each category, this may not work for your particular situation though.
If you can translate the categories to thir ids for the CSV I would recommend that, because I don't think I could get it to work consistently otherwise.
In the end this solution was too slow and caused issues with the import. I had 25,000 items to import and found that it was easier to write a custom import script using new EntryModel and using a pre-prepard CSV that had the category and asset ids already converted so the script could run without any extra lookups. No discredit to this plugin though, just had way too much data on my end
@mitch-rickman thank you very much for your hints. I managed to make it work for my categories as you described. Fortunately my set of data is significantly smaller than yours.
I was having dramas importing multiple field types, I found that using modifyImportRow
was incorrectly mutating data on ->setContentFromPost()
. I have an entry with an Entry relation, Category relation and 2 asset relations, all were working from scratch without the hook except for the Category relation. When implementing the hook, all relations were mutated.
To fix I had to run criteria lookups for all relations, see below for complete working code.
public function modifyImportRow($element, $map, $data) {
// Map data to fields
$fields = array_combine($map, $data);
// Initialize content array
$content = array();
// Arrange your content in a way that makes sense for your plugin
foreach ($fields as $handle => $value) {
switch ($handle) {
case 'hLDevelopement':
$criteria = craft()->elements->getCriteria(ElementType::Entry);
$criteria->slug = $value;
$value = array($criteria->first()->id);
break;
case 'hLBuilder':
$criteria = craft()->elements->getCriteria(ElementType::Category);
$criteria->title = $value;
$value = array($criteria->first()->id);
break;
case 'hLFacadeImage':
$criteria = craft()->elements->getCriteria(ElementType::Asset);
$criteria->title = $value;
$value = array($criteria->first()->id);
break;
case 'hLBrochure':
$criteria = craft()->elements->getCriteria(ElementType::Asset);
$criteria->title = $value;
$value = array($criteria->first()->id);
break;
default:
break;
}
$content[$handle] = $value;
}
// Set modified content
$element->setContentFromPost($content);
}
Note that I have set this up for single relations, however the same principles could easily be addapted to iterate values and push to the $value
array.
When I run the import all the entries get imported however none of the "Series" or "Speaker" get connected. Series are categories and the Speakers are entries. All Series and Speakers are present in there group and channels. I have verified the CSV file is valid. I have included a small piece of the larger csv file. 56df6a7c637376399400001a.csv.zip