Publisher does not support the Fluid field type. Please do not contact asking when support will be available.

If you purchased an add-on from expressionengine.com, be sure to visit boldminded.com/claim to add the license to your account here on boldminded.com.

Ticket: Can’t import categories with numeric value

Status Resolved
Add-on / Version DataGrab 4.2.2
Severity
EE Version 7.2.9

Gauthier De Paoli

May 09, 2023

When trying to import categories with numeric value (like 518, 001, 900, etc.) the datagrab_models threats these values as “cat_id” and not category values.

The magic occurs in datagrab_model.php:1806 in function findAndCreateCategories();

Repeatedly, it is written // Assume numeric categories are cat_id’s

Would it be possible to fix that ? Is it a

A possible solution would be to change the “is_numeric” function comparaison by a stricted one is_int() since is_numeric(‘001’) === TRUE but is_int(‘001’) === FALSE

 

#1

BoldMinded (Brian)

Can you share an example of what your import file looks like?

#2

Gauthier De Paoli

Please find an exemple here : https://pastebin.com/8kNjiqpL

It’s the content of a .csv file

#3

BoldMinded (Brian)

So after thinking about this a bit more I’m not sure what the solution is. Using is_int() assumes that the value is an actual integer, and coming from an XML or JSON file where someone might have it quoted means is_int() will fail, which is why it’s using is_numeric(). Even in your example the numbers are quoted, so I’m assuming is_int() is going to fail. If I make a change like this it could likely break a lot of people’s imports.

#4

BoldMinded (Brian)

I just double checked old builds of DataGrab, prior to me owning it, and it’s been this way for a long time. I hesitate to make this sort of change.

#5

Gauthier De Paoli

Hey Brian,

You’re right. Every value coming from the CSV/XML file will always be a string so is_int() will always return false.

A non-breaking change would be to add a configuration option for each category configuration row => Allow cell value to be a category_id (default: yes)

The condition :

if ($this->settings['config']['allow_numeric_value_to_be_category_id'] && is_numeric($cat)) {
    $entry_categories[] = $cat;
} else {
    ...
}
#6

BoldMinded (Brian)

Gauthier, the next comment will have a link to a new build, but it’s a beta version of v5 that isn’t public yet. Version 4 is in code freeze and not getting anymore additions or bug fixes. You can read the docs at https://docs.boldminded.com/datagrab/docs/version-5.0

#7

BoldMinded (Brian)

Comment has been marked private.

#8

Gauthier De Paoli

Comment has been marked private.

Login to reply