I'm importing an existing ExpressionEngine site's content into Craft, using content exported in XML on the EE site, and stepping through each entry.
This includes hooking up Assets files, where the Assets field/upload location is pointing to the same S3 bucket that Channel Files was on the EE site.
In my first load of these entries, I was able to successfully map the Assets fields using the following code:
$assets = craft()->elements->getCriteria(ElementType::Asset); $assets->filename = $referenceFile->filename; $assets->limit = 1; foreach ($assets as $assetMatched) $assetId = $assetMatched->id; $assetsToSave = $assetId; if ($saveAssets) $entryToSave->getContent()->referenceItemFiles = $assetsToSave;
On a re-run of the import, where I check for a match on the imported entry at each pass, I began receiving an FK error on the Assets field, but I want to set that aside for now. I reverted my database and ran the 1st time import again. I'm now seeing the following error:
S3::copyObject(reference-materials, 1610-10-01-001-0000015-supertrust_final_prospectus_may_29_1992--pp_33-end.pdf, reference-materials, 1610-10-01-001-0000015-supertrust_final_prospectus_may_29_1992-pp_33-end_1.pdf): [NoSuchKey] The specified key does not exist.
Based on a) the
copyObject text and b) the
_1 in the second filename, I'm now concerned. My question:
What's being done here when I save a new or existing entry in plugin code that includes an Assets field?
Is Craft trying to copy files? I'm now seeing a bunch of files in my S3 bucket with today's date as timestamp, and I'm not seeing corresponding activity on the live site using the same bucket, so it seems that Craft is not just creating relations for those files, but is actually touching the files, too. This is not what I would expect.
What should I expect to happen when I map asset IDs to an Assets field based on files that already exist? I had Craft index the S3 bucket via the admin prior to running this code, so that the database has records of those files.
Update: It looks like Craft has renamed files in the existing bucket, causing them to break on the other site. Specifically, it looks like Craft has replaced
-- in the filenames with