Skip to content
This repository has been archived by the owner. It is now read-only.

fixes for #3 #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

fixes for #3 #4

wants to merge 3 commits into from

Conversation

caseyfaber
Copy link

@caseyfaber caseyfaber commented Feb 27, 2019

fixes singletons not exporting or importing
fixes collection links not restoring
#3

@@ -668,9 +668,9 @@ protected function restoreEntries($zip, $zipHandle, $fullRestore) {
if (!isset($entry[$field['name']])) {
continue;
}
foreach ($entry[$field['name']] as $idx => $value) {
foreach ($entry as $idx => $value) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Believe that is not exactly what we need, as we should iterate over a collection link field (the collection field can be multiple) and not the full entry fields.
Think below should be more appropriate and fixes the issue:

        // Handle collection link fields by updating the referencing ids.
        foreach ($collection['fields'] as $field) {
          switch ($field['type']) {
            case 'multiplecollectionlink':
            case 'collectionlink':
              foreach ($entries as $entry) {
                if (!isset($entry[$field['name']]) || !is_array($entry[$field['name']])) {
                  continue;
                }
                foreach ($entry[$field['name']] as $idx => $value) {
                  if (isset($value['_id']) && isset($idsMapping[$value['_id']])) {
                    $entry[$field['name']][$idx]['_id'] = $idsMapping[$value['_id']];
                  }
                }
              }
              break;
          }
        }
        $this->module('collections')->save($collection['name'], [$entry]);

Note that also moved the save out of the loop (that was a bad mistake I did before)

@ericsolberg
Copy link

Any chance this fix is going to get merged?

@pauloamgomes
Copy link
Owner

Thanks @ericsolberg , yes, as I found some free time to do what requested.. the PR needs an update.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants