1

I'm trying to import entries with an Asset inside a subfolder. Since I don't know what the new Craft subfolder ID will be for each Asset I tried to use the folderPath property from Craft's Asset element class:

[
{
    "@model": "barrelstrength\\sproutimport\\importers\\elements\\Entry",
    "attributes": {
        "sectionId": 2,
        "typeId": 2,
        "authorId": 1,
        "slug": "my-sample-document",
        "postDate": "2017-11-09 13:06:00",
        "expiryDate": null,
        "enabled": true
    },
    "content": {
        "title": "My Sample Document",
        "fields": {
            "description": "<p>Nulla sit amet est. In hac habitasse platea dictumst. Pellentesque ut neque.</p>"
        },
        "related": {
            "documentFile": {
                "@model": "barrelstrength\\sproutimport\\importers\\elements\\Asset",
                "params": {
                    "filename": ["my-sample-document.pdf"],
                    "volumeId": 9,
                    "folderPath": "documents/pdfs/"
                }
            }
        }
    }
}
]

However the import fails with this error:

[error][sprout-import] Setting unknown property: craft\elements\db\AssetQuery::folderPath

I don't get an error when I use the folderId property. Can I only use properties that correspond with database columns? Is there any way to do this if I don't know the subfolder ID for every asset I'm importing?

  • Craft 3.0.26.1
  • Sprout Import 1.0.0-beta.14

1 Answer 1

1

folderPath is not supported when relating an asset to an Entry but there is a workaround. In your generation script you can call the code below to get the folderId with the given path:

$folderId = \craft\records\VolumeFolder::find()
->where(['path' => 'documents/pdfs/'])
->scalar();
4
  • Where is my "generation script"?
    – kmgdev
    Commented Oct 16, 2018 at 17:48
  • @kgrote that is the script you created for the import json data format. Commented Oct 17, 2018 at 13:31
  • I didn't create a script. I just exported data in JSON format from ExpressionEngine and imported it to Sprout Import.
    – kmgdev
    Commented Oct 17, 2018 at 18:46
  • Where in the docs does it talk about how to use an import script?
    – kmgdev
    Commented Oct 18, 2018 at 21:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.