Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined array key "folder" #3

Closed
robinbeatty opened this issue Nov 14, 2023 · 15 comments
Closed

Undefined array key "folder" #3

robinbeatty opened this issue Nov 14, 2023 · 15 comments
Labels
enhancement New feature or request

Comments

@robinbeatty
Copy link

Hey, since upgrade to 1.2.1 assets won't index via php craft index-assets <volume name> and throws exception 'Undefined Array Key "folder"' at CloudinaryFs.php:72

Pretty sure this was fine in 1.2.0. Could you take a look?
Many thanks!

@robinbeatty
Copy link
Author

My bad – this is a problem with my Cloudinary config – not the plugin (tested with alternative cloudinary account and indexing works fine).

FYI the difference is something to do with the account's tier... might be good to detect the response to and render something useful to the user for this case?

@thomasvantuycom
Copy link
Owner

Hi @robinbeatty,

Could you inform me about the tiers associated with these various accounts and tell me if there was additional information available in the error stack trace?

@robinbeatty
Copy link
Author

Still tracking this down – your plugin seems to behave differently between different accounts on Cloudinary. Here is the trace:

`robinbeatty@Robins-Mac-Studio craft % ddev php craft index-assets cloudinary

Indexing assets in Cloudinary ...
Exception 'craft\errors\FsException' with message 'Undefined array key "folder"'

in /var/www/html/vendor/thomasvantuycom/craft-cloudinary/src/fs/CloudinaryFs.php:72

Caused by: PHP Warning 'yii\base\ErrorException' with message 'Undefined array key "folder"'

in /var/www/html/vendor/thomasvantuycom/craft-cloudinary/src/fs/CloudinaryFs.php:65

Stack trace:
#0 /var/www/html/vendor/sentry/sentry/src/ErrorHandler.php(342): yii\base\ErrorHandler->handleError(2, 'Undefined array...', '/var/www/html/v...', 65, Array)
#1 /var/www/html/vendor/thomasvantuycom/craft-cloudinary/src/fs/CloudinaryFs.php(65): Sentry\ErrorHandler->handleError(2, 'Undefined array...', '/var/www/html/v...', 65)
#2 /var/www/html/vendor/craftcms/cms/src/services/AssetIndexer.php(71): thomasvantuycom\craftcloudinary\fs\CloudinaryFs->getFileList('', true)
#3 /var/www/html/vendor/craftcms/cms/src/console/controllers/IndexAssetsController.php(162): craft\services\AssetIndexer->getIndexListOnVolume(Object(craft\models\Volume), '')
#4 /var/www/html/vendor/craftcms/cms/src/console/controllers/IndexAssetsController.php(113): craft\console\controllers\IndexAssetsController->_indexAssets(Array, '', 0)
#5 [internal function]: craft\console\controllers\IndexAssetsController->actionOne('cloudinary', 0)
#6 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#7 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#8 /var/www/html/vendor/yiisoft/yii2/console/Controller.php(180): yii\base\Controller->runAction('', Array)
#9 /var/www/html/vendor/craftcms/cms/src/console/ControllerTrait.php(90): yii\console\Controller->runAction('', Array)
#10 /var/www/html/vendor/craftcms/cms/src/console/Controller.php(217): craft\console\Controller->traitRunAction('', Array)
#11 /var/www/html/vendor/yiisoft/yii2/base/Module.php(552): craft\console\Controller->runAction('', Array)
#12 /var/www/html/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('index-assets', Array)
#13 /var/www/html/vendor/craftcms/cms/src/console/Application.php(91): yii\console\Application->runAction('index-assets', Array)
#14 /var/www/html/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('index-assets', Array)
#15 /var/www/html/vendor/craftcms/cms/src/console/Application.php(122): yii\console\Application->handleRequest(Object(craft\console\Request))
#16 /var/www/html/vendor/yiisoft/yii2/base/Application.php(384): craft\console\Application->handleRequest(Object(craft\console\Request))
#17 /var/www/html/craft(13): yii\base\Application->run()
#18 {main}`

@thomasvantuycom
Copy link
Owner

I'm curious whether the issue is related to dynamic folder mode. Can you please verify whether the problem is resolved by updating line 65 in src/fs/CloudinaryFs.php as follows?

'dirname' => $asset['asset_folder'] ?? $asset['folder'],

@robinbeatty
Copy link
Author

Yes that solves it :) Fantastic. In the meantime I had been comparing the settings of each account and indeed 'Dynamic Folders' is the only setting that's different.

@thomasvantuycom
Copy link
Owner

Alright, great. Don't hesitate to keep sharing bug reports. Despite the care taken, it's likely that more issues will appear with the plugin.

@robinbeatty
Copy link
Author

robinbeatty commented Nov 14, 2023

Ok thanks. ... think there must be another thing regarding this to update in the plugin. Yes the assets will index having updated to $asset['asset_folder'] ?? $asset['folder'] but in the get request for the Cloudinary transform is now returning 404. Does something need configuring there too?

example get url https://res.cloudinary.com/de0sihadb/image/upload/c_fill,g_center,h_68,q_auto,w_45/v1/Accommodation/Alyeska%20Resort/Seafood_at_Seven_Glaciers_tt8uuj.jpg?_a=BAAAROBs&v=1699968448

@thomasvantuycom
Copy link
Owner

Is the folder where the asset is stored different from the path segment in the delivery url (Accommodation/Alyeska%20Resort), in Craft or in the Cloudinary media library dashboard?

@robinbeatty
Copy link
Author

Ok, think this is being caused by assets that were previously deleted from cloudinary linging in a cache. After clearing Craft asset index caches, deleting the filesystem and volume and re-adding them I can now index the assets – strangely the assets that get indexed (as displayed in the console feedback) are those of the deleted cloudinary assets, but when I view /admin/assets list view I only see the correct assets as I would expect to see, and the image transform urls are correct, rendering the correct thumbnail. Not sure whether this is a stale cache issue on Cloudinary or Craft. The only unexpected behaviour here is the asset indexing, which appears to index more assets than are present in the cloudinary library.

@robinbeatty
Copy link
Author

robinbeatty commented Nov 14, 2023

Sorry, no actually – this is only now indexing files at 'root level' in Cloudinary. If there are subfolders in Cloudinary, the folders arrive as Craft asset folders, but they do not contain any images.

You're welcome to grab a copy of my db and cloudinary account access if it would help track this down – I'm guessing an issue with how assets are mapped to the folders?

@robinbeatty
Copy link
Author

Just to confirm that, having heard back from Cloudinary support, Dynamic Folders is enabled for this account, whereas the other account it's not enabled.

@thomasvantuycom
Copy link
Owner

Having access to your setup and Cloudinary account would be really helpful, since I don't have an account with dynamic folders. I can have a look at it tomorrow.

thomasvantuycom added a commit that referenced this issue Nov 19, 2023
@thomasvantuycom
Copy link
Owner

The issue has been addressed and incorporated into version 1.3.0, which is now available. As dynamic folders mode is a recent addition to the Cloudinary API, I'm labeling this as an enhancement.

@thomasvantuycom thomasvantuycom added the enhancement New feature or request label Nov 19, 2023
@robinbeatty
Copy link
Author

Thanks for the update. All works as expected – There's one thing I noticed that would be useful – when assets get deleted from the remote source they correctly get removed when craft re-indexes the volume. However, if they were in a subfolder, the subfolders in craft remain (as empty folders). Is there a way of automatically deleting the folders in craft if they don't exist in cloudinary?

@thomasvantuycom
Copy link
Owner

thomasvantuycom commented Nov 19, 2023

I believe that's standard Craft behaviour, and that that's why the "List empty folders" option exists in the asset indexing utility.

Screenshot 2023-11-19 at 21-55-25 Asset Indexes - Craft CMS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants