Skip to content
This repository has been archived by the owner on Apr 5, 2018. It is now read-only.

PHP Error on Import #133

Closed
artmem opened this issue Aug 26, 2016 · 12 comments
Closed

PHP Error on Import #133

artmem opened this issue Aug 26, 2016 · 12 comments
Labels

Comments

@artmem
Copy link

artmem commented Aug 26, 2016

I'm getting a php error after setting up my import and clicking next. It doesn't matter what type I choose, I get the same error:

PHP warning

Invalid argument supplied for foreach()

/craft/app/assetsourcetypes/LocalAssetSourceType.php(371)

359     /**
360      * @inheritDoc BaseAssetSourceType::getNameReplacementInFolder()
361      *
362      * @param AssetFolderModel $folder
363      * @param string           $fileName
364      *
365      * @return string
366      */
367     protected function getNameReplacementInFolder(AssetFolderModel $folder, $fileName)
368     {
369         $fileList = IOHelper::getFolderContents($this->getSourceFileSystemPath().$folder->path, false);
370 
371         foreach ($fileList as &$file)
372         {
373             $file = IOHelper::getFileName($file);
374         }
375 
376         return AssetsHelper::getFilenameReplacement($fileList, $fileName);
377     }
378 
379     /**
380      * @inheritDoc BaseSavableComponentType::defineSettings()
381      *
382      * @return array
383      */
Stack Trace
#0  
–  /craft/app/etc/web/WebApp.php(685): CApplication->handleError(2, "Invalid argument supplied for foreach()", "/craft/app/assetsourcetypes/LocalAssetSourc...", 371)
680         if (version_compare(PHP_VERSION, '7', '>=') && $code === 2 && strpos($message, 'should be compatible with') !== false)
681         {
682             return;
683         }
684 
685         parent::handleError($code, $message, $file, $line);
686     }
687 
688     // Private Methods
689     // =========================================================================
690 
#1  
–  /craft/app/assetsourcetypes/LocalAssetSourceType.php(371): Craft\WebApp->handleError(2, "Invalid argument supplied for foreach()", "/craft/app/assetsourcetypes/LocalAssetSourc...", 371, ...)
366      */
367     protected function getNameReplacementInFolder(AssetFolderModel $folder, $fileName)
368     {
369         $fileList = IOHelper::getFolderContents($this->getSourceFileSystemPath().$folder->path, false);
370 
371         foreach ($fileList as &$file)
372         {
373             $file = IOHelper::getFileName($file);
374         }
375 
376         return AssetsHelper::getFilenameReplacement($fileList, $fileName);
#2  
–  /craft/app/assetsourcetypes/BaseAssetSourceType.php(227): Craft\LocalAssetSourceType->getNameReplacementInFolder(Craft\AssetFolderModel, "wpcsv-export-20160826015827.csv")
222                 $filename = "image_".$date->format('Ymd_His').".".IOHelper::getExtension($filename);
223             }
224 
225             if ($preventConflicts)
226             {
227                 $newFileName = $this->getNameReplacementInFolder($folder, $filename);
228                 $response = $this->insertFileInFolder($folder, $localFilePath, $newFileName);
229             }
230             else
231             {
232                 $response = $this->insertFileInFolder($folder, $localFilePath, $filename);
#3  
+  /craft/plugins/import/controllers/ImportController.php(64): Craft\BaseAssetSourceType->insertFileByPath("/craft/storage/runtime/temp/assets57bfaa36d...", Craft\AssetFolderModel, "wpcsv-export-20160826015827.csv", true)
#4  
+  /craft/app/framework/web/actions/CInlineAction.php(49): Craft\ImportController->actionUpload()
#5  
+  /craft/app/framework/web/CController.php(308): CInlineAction->runWithParams(array("p" => "admin/import"))
#6  
+  /craft/app/framework/web/CController.php(286): CController->runAction(CInlineAction)
#7  
+  /craft/app/framework/web/CController.php(265): CController->runActionWithFilters(CInlineAction, array())
#8  
+  /craft/app/framework/web/CWebApplication.php(282): CController->run("upload")
#9  
+  /craft/app/etc/web/WebApp.php(815): CWebApplication->runController("import/upload")
#10 
+  /craft/app/etc/web/WebApp.php(285): Craft\WebApp->_processActionRequest()
#11 
+  /craft/app/framework/base/CApplication.php(185): Craft\WebApp->processRequest()
#12 
+  /craft/app/index.php(62): CApplication->run()
#13 
+  /index.php(19): require_once("/craft/app/index.php")
2016-08-26 02:32:22 Apache / Craft 2.6.2916
@boboldehampsink
Copy link
Owner

Confirmed, looking into it.

@boboldehampsink
Copy link
Owner

boboldehampsink commented Sep 14, 2016

This is because the target folder doesn't physically exist. Actually, this is a Craft bug - IOHelper::getFolderContents returns false, but this function assumes its always an array. @takobell @brandonkelly.

@lindseydiloreto
Copy link

+1 I'm experiencing the exact same error as OP.

@boboldehampsink
Copy link
Owner

Can you confirm this is because the target folder doesn't physically exist?

@lindseydiloreto
Copy link

Can confirm.

The selected Asset Source did not point to a valid folder. Creating the folder resolved the issue.

@boboldehampsink
Copy link
Owner

Would you agree this is a Craft issue?

@lindseydiloreto
Copy link

Dunno... I didn't dig deep enough to see the root of the problem.

@boboldehampsink
Copy link
Owner

Hah ok. To me the stacktrace makes this clear ;-) I will inform the Craft team. Dunno if @takobell or @brandonkelly likes me tagging them here...

@lindseydiloreto
Copy link

Lol, sounds good to me. Thanks!

@artmem
Copy link
Author

artmem commented Sep 15, 2016

In my case, the there was a typo in my asset folder path setting, and since it was a fresh install, I didn't check it before running import. Fixing the path resolved the issue. Seems like Craft should throw an error rather than fail.

@angrybrad
Copy link

Yeah, Craft issue. Should have this one sorted by the next release.

@boboldehampsink
Copy link
Owner

Fixed in 2.6.2940

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

No branches or pull requests

4 participants