boboldehampsink / import

DEPRECATED - Import plugin for Craft CMS
MIT License
177 stars 28 forks source link

PHP Error on Import #133

Closed artmem closed 7 years ago

artmem commented 8 years ago

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 commented 8 years ago

Confirmed, looking into it.

boboldehampsink commented 8 years ago

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 commented 8 years ago

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

boboldehampsink commented 8 years ago

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

lindseydiloreto commented 8 years ago

Can confirm.

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

boboldehampsink commented 8 years ago

Would you agree this is a Craft issue?

lindseydiloreto commented 8 years ago

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

boboldehampsink commented 8 years ago

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 commented 8 years ago

Lol, sounds good to me. Thanks!

artmem commented 7 years ago

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 commented 7 years ago

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

boboldehampsink commented 7 years ago

Fixed in 2.6.2940