modmore / importX

Addon for MODX Revolution which will take your CSV Formatted files (or raw paste) and transforms it into resources. Funded by Working Party (digital agency based in Sydney, @workingparty)
http://www.markhamstra.com/
23 stars 17 forks source link

Keep Existing Values on Update #64

Open doctorallen opened 8 years ago

doctorallen commented 8 years ago

I'm using the latest version of importX, and when updating resources, it seems to remove all values that I don't pass in the CSV. I want to update field values, and keep any existing resource and template variables that I have not been passed the same.

I'm digging through the code trying to figure out where I can get this to work, but if someone has experience with doing this, or has done it before, that might save me some time.

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/32153194-keep-existing-values-on-update?utm_campaign=plugin&utm_content=tracker%2F1511225&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F1511225&utm_medium=issues&utm_source=github).
CouponCodeSwap commented 8 years ago

I'm experiencing the same issue. Because TV values are not in the same table, it makes it difficult to do an update import because all TV values not included in CSV file get deleted.

doctorallen commented 8 years ago

I've dug into it a bit, and I think that it's part of the MODX resource/update processor. I'm trying to figure out it's possible to prevent the replacement of all of these values using some option but so far I haven't found anything.

doctorallen commented 8 years ago

Yeah, it definitely is the MODX resource/update processor. It queries all of the modx templateVariables, and either sets their new value to the value passed to the processor, or the default value, when in reality it should be looping over the passed TVs.

What I did was added a new processor that extends the existing processor and overrides the saveTemplateVariables function. Here is the code for the new processor. I put this in /core/model/mox/processors/resource/. I then set the importx.processor setting to updatenooverride. You still have to pass the alias, parent, and published settings in the CSV, because apparently those get overridden anyway and I didn't care to try and fix that as well.

Here is the example CSV I used:

id;alias;parent;published;tv1
2;test-alias;18;1;value1
Mark-H commented 8 years ago

I'm reopening this as it is something I'd like to keep in mind for importx v2. :)