diff --git a/app/Http/Controllers/API/Settings/RoleController.php b/app/Http/Controllers/API/Settings/RoleController.php index 73d1a390..5b364037 100644 --- a/app/Http/Controllers/API/Settings/RoleController.php +++ b/app/Http/Controllers/API/Settings/RoleController.php @@ -13,6 +13,7 @@ use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Http\Response; +use League\Csv\Writer; use Symfony\Component\HttpFoundation\StreamedResponse; /** @@ -608,6 +609,7 @@ public function exportDetailedListAsCsv() $headers = [ 'Content-type' => 'text/csv', 'Content-Disposition' => 'attachment; filename='.$fileName, + 'Content-Transfer-Encoding' => 'utf-8', 'Pragma' => 'no-cache', 'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0', 'Expires' => '0', @@ -620,20 +622,26 @@ public function exportDetailedListAsCsv() 'İzin Değeri', ]; - $callback = function () use ($data, $columns) { - $file = fopen('php://output', 'w'); - fputcsv($file, $columns); + $writer = Writer::createFromPath("php://temp", "r+"); + $writer->insertOne($columns); - foreach ($data as $row) { - fputcsv($file, [ - $columns[0] => $row['username'], - $columns[1] => $row['role_name'], - $columns[2] => $row['perm_type'], - $columns[3] => $row['perm_value'], - ]); - } + foreach ($data as $row) { + $writer->insertOne([ + $row['username'], + $row['role_name'], + $row['perm_type'], + $row['perm_value'], + ]); + } - fclose($file); + $flushThreshold = 1000; + $callback = function () use ($writer, $flushThreshold) { + foreach ($writer->chunk(1024) as $offset => $chunk) { + echo $chunk; + if ($offset % $flushThreshold === 0) { + flush(); + } + } }; return response()->stream($callback, 200, $headers); diff --git a/composer.json b/composer.json index e95cb6b9..41857207 100644 --- a/composer.json +++ b/composer.json @@ -24,6 +24,7 @@ "laravel/helpers": "^1.5", "laravel/tinker": "^2.7", "laravel/ui": "^4.0", + "league/csv": "^9.0", "limanmys/php-smb": "^3.5", "mervick/aes-everywhere": "^1.1", "mews/captcha": "^3.2", diff --git a/composer.lock b/composer.lock index be8e28fb..555e9d52 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "de6498709f134193e5eff9a6041d67dc", + "content-hash": "3940358ee35260eb0d0a4c10b742aa55", "packages": [ { "name": "ankitpokhrel/tus-php", @@ -2938,6 +2938,95 @@ ], "time": "2022-12-11T20:36:23+00:00" }, + { + "name": "league/csv", + "version": "9.14.0", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/csv.git", + "reference": "34bf0df7340b60824b9449b5c526fcc3325070d5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/csv/zipball/34bf0df7340b60824b9449b5c526fcc3325070d5", + "reference": "34bf0df7340b60824b9449b5c526fcc3325070d5", + "shasum": "" + }, + "require": { + "ext-filter": "*", + "ext-json": "*", + "ext-mbstring": "*", + "php": "^8.1.2" + }, + "require-dev": { + "doctrine/collections": "^2.1.4", + "ext-dom": "*", + "ext-xdebug": "*", + "friendsofphp/php-cs-fixer": "^v3.22.0", + "phpbench/phpbench": "^1.2.15", + "phpstan/phpstan": "^1.10.50", + "phpstan/phpstan-deprecation-rules": "^1.1.4", + "phpstan/phpstan-phpunit": "^1.3.15", + "phpstan/phpstan-strict-rules": "^1.5.2", + "phpunit/phpunit": "^10.5.3", + "symfony/var-dumper": "^6.4.0" + }, + "suggest": { + "ext-dom": "Required to use the XMLConverter and the HTMLConverter classes", + "ext-iconv": "Needed to ease transcoding CSV using iconv stream filters" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "9.x-dev" + } + }, + "autoload": { + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "League\\Csv\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ignace Nyamagana Butera", + "email": "nyamsprod@gmail.com", + "homepage": "https://github.com/nyamsprod/", + "role": "Developer" + } + ], + "description": "CSV data manipulation made easy in PHP", + "homepage": "https://csv.thephpleague.com", + "keywords": [ + "convert", + "csv", + "export", + "filter", + "import", + "read", + "transform", + "write" + ], + "support": { + "docs": "https://csv.thephpleague.com", + "issues": "https://github.com/thephpleague/csv/issues", + "rss": "https://github.com/thephpleague/csv/releases.atom", + "source": "https://github.com/thephpleague/csv" + }, + "funding": [ + { + "url": "https://github.com/sponsors/nyamsprod", + "type": "github" + } + ], + "time": "2023-12-29T07:34:53+00:00" + }, { "name": "league/flysystem", "version": "3.17.0",