timkelty / craftcms-site-sync

Sync content to locales on element save.
MIT License
40 stars 9 forks source link

Assets not syncing. #12

Closed BrandonJamesBorders closed 6 years ago

BrandonJamesBorders commented 7 years ago

Not sure if this is a bug or simply not a feature, but Assets don't sync. Is there a solution for this?

Thanks!

timkelty commented 6 years ago

Hmm. Bummer, I would think it would. I'll put it on my list to check out.

Out of curiosity - do other element fields (Entries, Users, etc) sync, or is it specifically Assets?

BrandonJamesBorders commented 6 years ago

Yup, every other field I've tested is syncing correctly.

I'm hoping to dive into it more this week as well and will be sure to share any findings.

BrandonJamesBorders commented 6 years ago

@timkelty I've come up with a solution but would appreciate your feedback before I implement it into a live site.

In the LocaleSyncService.php file I added the following code to the updateElement function between line 125 and 126.


if ($field instanceof Fieldmodel) {
     if($field->type == 'Assets') {
          craft()->relations->saveRelations($field, $element, $this->_element->content->$fieldHandle);
     }
}

I came to this conclusion as the craft saveContent function does not handle relationships (as far as I can tell).

Of what you know about craft, do you see any pitfalls about implementing this code?

Thanks!

timkelty commented 6 years ago

Taking a look this morning, thanks for your patience.

timkelty commented 6 years ago

The problem with your solution the $matches comparison, as at that point you'd be comparing two BaseElementModel instances.

I just pushed a new version 1.5.0, which adds support to sync ALL elements fields (Entries, Categories, Assets). Give it a shot, it should work for you.

BrandonJamesBorders commented 6 years ago

@timkelty that update has worked. Thanks for the improvement!

Still getting a notice in the admin that the plugin has an update.

timkelty commented 6 years ago

@BrandonJamesBorders ah, shoot.

Upgrade to 1.5.1 and that should be taken care of.