public function fire()
{
$this->info("エクスポートを開始します... \n");
// 空フォルダを作成
$export_path = storage_path() . '/export/';
$this->makeExportDir($export_path);
// 記事ID一覧の取得
$items = $this->itemService->getAll();
if (empty($items)) {
$this->info("エクスポート対象の記事が見つかりませんでした。\n" . "エクスポートをを終了します。\n");
return;
}
// 100件区切りでデータエクスポート
$chunk = 100;
for ($i = 0; $i <= count($items); $i += $chunk) {
$target_items = array_slice($items, $i, 100);
$this->exportData($export_path, $target_items);
echo count($target_items) + $i . '/' . count($items) . "\n";
usleep(500000);
}
$this->info("\n\nファイルが storage/export にあるか確認してください。 \n");
$this->info("\n\nエクスポートを終了しました。\n");
}