๊ฐ์ ธ ์ค๊ธฐ ๊ฐ์ฒด ํด๋์ค๋ฅผ ๋ง๋ค๊ณ ToCollection์ ๋ฌธ์ ๋ฅผ ์ง์ ํ์ต๋๋ค. Excel :: import๋ฅผ ์ํ ํ ๋ ์๋ Actual Behavior
ํ์๋ ์ค๋ฅ๊ฐ ํ์๋ฉ๋๋ค.
ํธ๋์ญ์ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ์ฌ์ฉํ์ง ๋ง์ญ์์ค. MongoDB๋ฅผ ์ฌ์ฉํฉ๋๋ค.
๊ทธ ์ธ์๋ ๋ชจ๋ธ ์ํฌํธ๊ฐ ์ง์ ๋์ง ์์์ผ๋ฉฐ ํจํค์ง๋ ๊ฐ๋ฐ์๊ฐ ์ด๋ฒคํธ๋ฅผ ํตํด ์ฒ๋ฆฌํด์ผํ๋ ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ค๋น๋ฅผ ์ํํ์ง ์์์ผํฉ๋๋ค.
์์๋๋ ๋์ :
์ปฌ๋ ์ ํ์ dd.
์ค์ ํ๋ :
1) Tests\Unit\Services\Websites\WebsiteCredentialsImportServiceTest::testImportTabDelimited
Error: Call to a member function beginTransaction() on null
/var/www/vhosts/website.local/vendor/laravel/framework/src/Illuminate/Database/Concerns/ManagesTransactions.php:109
/var/www/vhosts/website.local/vendor/laravel/framework/src/Illuminate/Database/Concerns/ManagesTransactions.php:93
/var/www/vhosts/website.local/vendor/laravel/framework/src/Illuminate/Database/Concerns/ManagesTransactions.php:23
/var/www/vhosts/website.local/vendor/laravel/framework/src/Illuminate/Database/DatabaseManager.php:327
/var/www/vhosts/website.local/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:223
/var/www/vhosts/website.local/vendor/maatwebsite/excel/src/Reader.php:96
/var/www/vhosts/website.local/vendor/maatwebsite/excel/src/Excel.php:120
/var/www/vhosts/website.local/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:223
/var/www/vhosts/website.local/app/Services/Websites/WebsiteCredentialsImportService.php:198
/var/www/vhosts/website.local/app/Services/Websites/WebsiteCredentialsImportService.php:182
/var/www/vhosts/website.local/app/Services/Websites/WebsiteCredentialsImportService.php:122
/var/www/vhosts/website.local/tests/Unit/Services/Websites/WebsiteCredentialsImportServiceTest.php:25
<?php
namespace App\Imports\Websites;
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\ToCollection;
/**
* Class WebsiteCredentialsImport
*
* <strong i="29">@package</strong> App\Imports\Websites
*/
class WebsiteCredentialsImport implements ToCollection
{
public function collection(Collection $rows)
{
dd(['COLLECTION' => $rows]);
}
}
$collection = Excel::import(
new WebsiteCredentialsImport,
$this->file_name,
null,
$this->reader_type
);
์ ํจ์ฑ ๊ฒ์ฌ ๋ฐ ๋ฐฐ์น ์ฝ์ ์ ์ํด ๋ฐ์ดํฐ๋ฒ ์ด์ค ํธ๋์ญ์ ์ ์ฌ์ฉํฉ๋๋ค. Eloquent / Laravel-DB ์ฌ์ฉ์์๊ฒ ๋งค์ฐ ์ค์ํฉ๋๋ค. .eg Mongo๋ฅผ ์ฌ์ฉํ๋ ์ฌ์ฉ์๋ฅผ ์ํด ๋นํ์ฑํํ๋ ๊ตฌ์ฑ ์ต์ ์ ์ ๊ณตํ๋ PR์ ๋ณํฉํ๊ฒ๋์ด ๊ธฐ์ฉ๋๋ค.
๋ค์ ๋ฒ์ ์๋ Laravel-DB ํธ๋์ญ์ ์ ๋นํ์ฑํํ๋ ์ค์ ๊ณผ ์ฌ์ฉ์ ์ง์ ํธ๋์ญ์ ์ฒ๋ฆฌ๊ธฐ๋ฅผ ์ถ๊ฐํ๋ ๋ฐฉ๋ฒ์ด ์์ต๋๋ค.
์๋ ํ์ธ์ !
๋๋ ๋งค์ฐ ์ ํํ ์ํฉ์ ์์ต๋๋ค. ์ฝ์ ๋ฐ์ดํฐ๋ฅผ ์ ์ฅํ ํ์๊ฐ ์์ผ๋ฉฐ Mongo๋ฅผ ์ฌ์ฉํ๊ณ ์์ต๋๋ค.
๊ฑฐ๋๋ฅผ ๋นํ์ฑํํ๋ ์ฝ๋๋ฅผ ์๋ ค์ฃผ์๊ฒ ์ต๋๊น?
์๋ ํ์ธ์ !
๋๋ ๋งค์ฐ ์ ํํ ์ํฉ์ ์์ต๋๋ค. ์ฝ์ ๋ฐ์ดํฐ๋ฅผ ์ ์ฅํ ํ์๊ฐ ์์ผ๋ฉฐ Mongo๋ฅผ ์ฌ์ฉํ๊ณ ์์ต๋๋ค.
๊ฑฐ๋๋ฅผ ๋นํ์ฑํํ๋ ์ฝ๋๋ฅผ ์๋ ค์ฃผ์๊ฒ ์ต๋๊น?
https://github.com/Maatwebsite/Laravel-Excel/commit/13374dab1592f00f715fa0e02541ecb52217655b#diff -19c82312ec0dbaba6a8c595db14fa56f
๊ด๋ จ ๋ฌธ์ ์น์ : https://docs.laravel-excel.com/3.1/imports/validation.html#disable -transactions
์๋
ํ์ธ์, ์ ๋ ๊ฐ์ ์ํฉ์ ์์ต๋๋ค. Excel ํ์ผ์ ์ฝ์ด์ผํ๊ณ mongodb์ ์ ์ฅํด์ผํฉ๋๋ค.
์์ ์ฌํญ์ ์ฝ์์ผ๋ฉฐ ํ์ฌ ์ค๋ฅ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
"[MaatwebsiteExcel \ Transactions \ TransactionManager]์ ๋ํ NULL ๋๋ผ์ด๋ฒ๋ฅผ ํ์ธํ ์ ์์ต๋๋ค."
๊ทธ๊ฒ์ ํด๊ฒฐํ๋ ๋ฐฉ๋ฒ์ ์๊ณ ์์ต๋๊น?
ํ๋ฅญํ ํจํค์ง์ ๊ฐ์ฌ๋๋ฆฝ๋๋ค.
ํธ์ง : ์ปฌ๋ ์ ์ ๊ฐ์ ธ ์ค๊ธฐ๋ฅผ ์ฌ์ฉ ํ๋๋ฐ ์๋ํ์ง๋ง ์ฌ์ ํ ๊ฐ์ ธ ์ค๊ธฐ toModel์ด ์ค๋จ๋๋ ์ด์ ๋ฅผ ์์ง ๋ชปํฉ๋๋ค.
Collection์ ํธ๋์ญ์ ์ ์ฌ์ฉํ์ง ์๊ธฐ ๋๋ฌธ์ ๋๋ค. ๊ฑฐ๋๋ฅผ ๋นํ์ฑํํ๋ ๋ฐฉ๋ฒ์ ์ค๋ช ํ๋ ์ด์ ์๊ฒฌ์ ์ฐธ์กฐํ์ญ์์ค.
Collection์ ํธ๋์ญ์ ์ ์ฌ์ฉํ์ง ์๊ธฐ ๋๋ฌธ์ ๋๋ค. ๊ฑฐ๋๋ฅผ ๋นํ์ฑํํ๋ ๋ฐฉ๋ฒ์ ์ค๋ช ํ๋ ์ด์ ์๊ฒฌ์ ์ฐธ์กฐํ์ญ์์ค.
์๋
ํ์ธ์, ๋น ๋ฅธ ๋ต์ฅ์ ๋ณด๋ด ์ฃผ์
์ ๊ฐ์ฌํฉ๋๋ค.
๊ทํ์ ์๊ฒฌ์ ์ฝ์์ผ๋ฏ๋ก "[MaatwebsiteExcel \ Transactions \ TransactionManager]์ ๋ํ NULL ๋๋ผ์ด๋ฒ๋ฅผ ํ์ธํ ์ ์์ต๋๋ค."๋ผ๋ ๋ฉ์์ง๋ฅผ ๋ฐ์์ต๋๋ค. ์ค๋ฅ.
๊ทธ๋์ ์ ๋ ์ปฌ๋ ์
์ผ๋ก ์ ํํ์ต๋๋ค
๋น์ ์ ์๋ง ๋น์ ์ ์ค์ ์ ๋ญ๊ฐ ์๋ชป ์
๋ ฅํ๊ณ ์์ ๊ฒ์
๋๋ค. NULL
์ (๋) ์ ํจํ ๋๋ผ์ด๋ฒ์ฒ๋ผ ๋ค๋ฆฌ์ง ์์ต๋๋ค. 'null'
(๋ฌธ์์ด์์ฃผ์)์
๋๋ค.
๋๋ ๋ํ ๊ฐ์ ์ํฉ์ ์ฒํด์๋ค. https://docs.laravel-excel.com/3.1/imports/validation.html#disable -transactions์์ ํด๊ฒฐ์ฑ
์ ์ป์์ต๋๋ค.
ํ์ง๋ง Custom transaction handlers
๋ง๋๋ ๋ฐฉ๋ฒ๊ณผ ์ฌ์ฉ ์์น๋ฅผ ๋ชจ๋ฅด๊ฒ ์ต๋๋ค.
๋๋ mongodb๊ฐ ์์ต๋๋ค. ์ด https://docs.laravel-excel.com/3.1/imports/validation.html#disable -transactions๊ฐ ๋๋ฅผ ์ํด ์๋ํฉ๋๋ค. ์ซ์ @myeong_
์๋ง๋ ์ฌ๋ฌ๋ถ์ # 2384์์ํ๋ ๊ฒ๊ณผ ๊ฐ์ ๋ฌธ์ ๋ฅผ ๊ฒช๊ณ ์์ ๊ฒ์ ๋๋ค.
๋ด ์๋ฃจ์ ์ด ๋์์ด ๋ ์ ์์ต๋๋ค.
php artisan config:clear
๋๋ก๋ ํนํ ํจํค์ง๋ฅผ ์ ๋ฐ์ดํธ ํ ๋ Laravel์ด ์บ์๋ฅผ ์ ๋ฆฌํ์ง ์๊ณ ํจํค์ง๊ฐ ๊ตฌ์ฑ ํ์ผ์ ์ฐพ์ง ๋ชปํ๋ ๊ฒฝ์ฐ๊ฐ ์์ต๋๋ค. ๋ฐ๋ผ์ ๋๋ผ์ด๋ฒ๋ ํญ์ NULL์ด๊ณ ์คํจํฉ๋๋ค.
์๋ง๋ ์ฌ๋ฌ๋ถ์ # 2384์์ํ๋ ๊ฒ๊ณผ ๊ฐ์ ๋ฌธ์ ๋ฅผ ๊ฒช๊ณ ์์ ๊ฒ์ ๋๋ค.
๋ด ์๋ฃจ์ ์ด ๋์์ด ๋ ์ ์์ต๋๋ค.
php artisan config:clear
๋๋ก๋ ํนํ ํจํค์ง๋ฅผ ์ ๋ฐ์ดํธ ํ ๋ Laravel์ด ์บ์๋ฅผ ์ ๋ฆฌํ์ง ์๊ณ ํจํค์ง๊ฐ ๊ตฌ์ฑ ํ์ผ์ ์ฐพ์ง ๋ชปํ๋ ๊ฒฝ์ฐ๊ฐ ์์ต๋๋ค. ๋ฐ๋ผ์ ๋๋ผ์ด๋ฒ๋ ํญ์ NULL์ด๊ณ ์คํจํฉ๋๋ค.
๋ฒ ์คํธ ๋ต๋ณ
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์๋ง๋ ์ฌ๋ฌ๋ถ์ # 2384์์ํ๋ ๊ฒ๊ณผ ๊ฐ์ ๋ฌธ์ ๋ฅผ ๊ฒช๊ณ ์์ ๊ฒ์ ๋๋ค.
๋ด ์๋ฃจ์ ์ด ๋์์ด ๋ ์ ์์ต๋๋ค.
php artisan config:clear
๋๋ก๋ ํนํ ํจํค์ง๋ฅผ ์ ๋ฐ์ดํธ ํ ๋ Laravel์ด ์บ์๋ฅผ ์ ๋ฆฌํ์ง ์๊ณ ํจํค์ง๊ฐ ๊ตฌ์ฑ ํ์ผ์ ์ฐพ์ง ๋ชปํ๋ ๊ฒฝ์ฐ๊ฐ ์์ต๋๋ค. ๋ฐ๋ผ์ ๋๋ผ์ด๋ฒ๋ ํญ์ NULL์ด๊ณ ์คํจํฉ๋๋ค.