Trouble with the import_asset_csv_to_matrix.php not importing anything


(Nic Hubbard) #1

I am trying to get the import_asset_csv_to_matrix.php script to import about 1000 assets. I have a carefully created data-import.csv file, parent ID, Schema ID, metadata-associations.csv and asset-associations.csv files.

php /home/websites/squiz_matrix/scripts/import/import_asset_csv_to_matrix.php /home/websites/squiz_matrix/ news_item data-import.csv 9209 9210 metadata-associations.csv asset-associations.csv

When I run the script I get the following:

- All done
Assets added    : 0
Assets modified : 0
Assets deleted  : 0

I can never get it to import anything. 

 

It looks like on line 163 that the while loop only runs once which is really strange.

 

Is there a way to check errors for this script, or figure out why it isn't importing anything?

 

Any help would be great!


(Marcus Fong) #2

You didn’t use the Macintosh version of Microsoft Excel to create your CSV file by any chance, did you?

I remember we’ve had problems with that before, because for some reason Excel on MacOS X would save its CSV files using the old MacOS Classic linebreak (CR) instead of the MacOS X / UNIX linebreak (LF). So Matrix ends up seeing the file as one gigantic line of unparseable junk, with… sometimes interesting results.


(Nic Hubbard) #3

You didn't use the Macintosh version of Microsoft Excel to create your CSV file by any chance, did you?

 

I actually did! Saved them as Windows CSV Files and it is working now. Thanks for pointing that out!

 

One other question. Can I use the script to set the created date? I was trying to map the created date attribute to created_date in Matrix, but that isn't working.


(Marcus Fong) #4

Hmm... the script calls setAttrValue() to update the mapped attributes:

 

$asset->setAttrValue($attribute_name, $asset_spec[$supplied_name]);

 

I think the problem you're having is that created_date corresponds to the "created" column in the sq_ast table itself, as opposed to being an attribute stored in the sq_ast_attr_values table. It looks to me like the created, published and updated dates are updated via the asset's setDate() function, not its setAttrValue() function, and I don't see any references to setDate() in import_asset_csv_to_matrix.php.


(Nic Hubbard) #5

Are there other ways to bulk update the Created Date?


(Marcus Fong) #6

Unfortunately, the only places in the code I can see the "setDate" function being called are either as part of workflow processes, or from the asset's Settings screen.  :(

 

You have Squizmap access, don't you, Nic? It might be worth logging an enhancement request...


(Nic Hubbard) #7

You have Squizmap access, don't you, Nic? It might be worth logging an enhancement request...

 

Yes: https://squizmap.squiz.net/matrix/8883


(Nic Hubbard) #8

Unfortunately, the only places in the code I can see the "setDate" function being called are either as part of workflow processes, or from the asset's Settings screen.  :(

 

It does look like there is a Trigger action to set the date on an asset. So, when I import I could set the date as metadata, then use the After Asset Created action to set the Created Date from the metadata value.


(Marcus Fong) #9

Oh, I see now... the trigger action does set the date, but it does so via a direct DB update rather than via the setDate() function.

 

So that should work too. The only thing I'd be a bit cautious about is the potential performance penalty from doing a large import with triggers firing...


(Nic Hubbard) #10

So that should work too. The only thing I'd be a bit cautious about is the potential performance penalty from doing a large import with triggers firing...

 

Good call. Would it be better to batch that trigger later? Any performance issues there?


(Marcus Fong) #11

I'm not sure, to be honest. I've never actually had to use batch triggers before, as most things can be handled more efficiently with the command-line scripts if you have access to them.