craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.28k stars 635 forks source link

Craft 3.7.35 asset saving error in plugin due to temp file changes #10668

Closed alanski66 closed 2 years ago

alanski66 commented 2 years ago

Description

I have a plugin that works across multiple sites and servers. It uses Imagick to create and save an images from PDF file.

I was setting temp path : $tmpImagePath = sys_get_temp_dir() . '/';

But due to the warning tried moving up into the storage temp Sets $tmpImagePath = getenv('CRAFTENV_BASE_PATH').'storage/runtime/temp/';

I get the same error. I tested on pre Craft CMS 3.7.35 on local dev and staging and production servers and it works fine. As soon as I upgrade to 3.7.35 i get errors on saving assets. (supposed to launch site today this is an unexpected show stopper)

Steps to reproduce

  1. Save an asset in a plugin
  2. Get error below

`craft\errors\FileException: There was an error relocating the file. in /Users/moimac/sites/web/vendor/craftcms/cms/src/elements/Asset.php:2235 Stack trace:

0 /Users/moimac/sites/web/vendor/craftcms/cms/src/elements/Asset.php(2000): craft\elements\Asset->_relocateFile()

1 /Users/moimac/sites/web/vendor/craftcms/cms/src/services/Elements.php(2701): craft\elements\Asset->afterSave(false)

2 /Users/moimac/sites/web/vendor/craftcms/cms/src/services/Elements.php(784): craft\services\Elements->_saveElementInternal(Object(craft\elements\Asset), true, false, true)

3 /Users/moimac/sites/web/vendor/craftcms/cms/src/services/Assets.php(212): craft\services\Elements->saveElement(Object(craft\elements\Asset))

4 /Users/moimac/sites/web/vendor/craftcms/cms/src/fields/Assets.php(584): craft\services\Assets->moveAsset(Object(craft\elements\Asset), Object(craft\models\VolumeFolder))

5 /Users/moimac/sites/web/vendor/craftcms/cms/src/base/Element.php(4142): craft\fields\Assets->afterElementSave(Object(craft\elements\Entry), false)

6 /Users/moimac/sites/web/vendor/craftcms/cms/src/elements/Entry.php(1680): craft\base\Element->afterSave(false)

7 /Users/moimac/sites/web/vendor/craftcms/cms/src/services/Elements.php(2701): craft\elements\Entry->afterSave(false)

8 /Users/moimac/sites/web/vendor/craftcms/cms/src/services/Elements.php(784): craft\services\Elements->_saveElementInternal(Object(craft\elements\Entry), true, false, true)

9 /Users/moimac/sites/web/vendor/craftcms/cms/src/controllers/EntryRevisionsController.php(506): craft\services\Elements->saveElement(Object(craft\elements\Entry))

10 [internal function]: craft\controllers\EntryRevisionsController->actionPublishDraft()

11 /Users/moimac/sites/web/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)

12 /Users/moimac/sites/web/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)

13 /Users/moimac/sites/web/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('publish-draft', Array)

14 /Users/moimac/sites/web/vendor/craftcms/cms/src/web/Application.php(293): yii\base\Module->runAction('entry-revisions...', Array)

15 /Users/moimac/sites/web/vendor/craftcms/cms/src/web/Application.php(602): craft\web\Application->runAction('entry-revisions...', Array)

16 /Users/moimac/sites/web/vendor/craftcms/cms/src/web/Application.php(272): craft\web\Application->_processActionRequest(Object(craft\web\Request))

17 /Users/moimac/sites/web/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))

18 /Users/moimac/sites/web/public_html/index.php(21): yii\base\Application->run()

19 /Users/moimac/.composer/vendor/laravel/valet/server.php(235): require('/Users/alanspar...')

20 {main}`

Additional info

Antimated commented 2 years ago

I have the same "There was an error relocating the file" error without the use of any plugins. Just a native assets field...

alanski66 commented 2 years ago

I think Craft is doing some permission check on asset upload temp directories and failing to verify .... got very unhappy faces on clients

Antimated commented 2 years ago

@joomkit maybe for the meanwhile just change your craft version to 3.7.34 in your composer.json and do a composer update.

EDIT: just had to deploy a website to production too and had to do the same thing, luckily I caught the error in advance.

andris-sevcenko commented 2 years ago

Is there any more information you can provide about what you're doing when you're hitting this? Is this a file move or upload? If it's between folders/volumes - anything, really, that you think might be relevant.

Currently I'm having trouble reproducing this.

andris-sevcenko commented 2 years ago

Okay, found the problem - sorry for that! Just pushed a fix that will be a part of the next release.

To get the fix early, change your craftcms/cms requirement in composer.json to:

"require": {
  "craftcms/cms": "dev-develop#f5f440942e54093500ffb418bd0557ae3c704d78",
  "...": "..."
}

Then run composer update.

alanski66 commented 2 years ago

@joomkit maybe for the meanwhile just change your craft version to 3.7.34 in your composer.json and do a composer update.

EDIT: just had to deploy a website to production too and had to do the same thing, luckily I caught the error in advance.

Thanks downgrade fixed temporarily.

Lightning response from @andris-sevcenko ! thx man

brandonkelly commented 2 years ago

Craft 3.7.36 is out now with that fix. Thanks all!