<?php

/**

 * Download Error Report for Failed Imports

 */



define('MIGRATION_ACCESS', true);

require_once '../config.php';



$jobId = $_GET['job'] ?? '';

$logFile = __DIR__ . "/../logs/failed_{$jobId}.log";



if (!file_exists($logFile)) {

    die('No error log found');

}



header('Content-Type: text/csv');

header('Content-Disposition: attachment; filename="import_errors_' . $jobId . '.csv"');



$handle = fopen($logFile, 'r');

while ($line = fgets($handle)) {

    echo $line;

}

fclose($handle);

?>