Skip to content

Commit

Permalink
feat: datestamp filename of exported SQL file. (#5136)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrhm authored May 23, 2021
1 parent 6378bc1 commit a658fcf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion app/Http/Controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Http\Request;
use App\Helpers\LocaleHelper;
use App\Helpers\AccountHelper;
use Illuminate\Support\Carbon;
use App\Helpers\TimezoneHelper;
use App\Models\Contact\Contact;
use App\Jobs\ExportAccountAsSQL;
Expand Down Expand Up @@ -203,8 +204,10 @@ public function exportToSql()

$adapter = disk_adapter(ExportAccountAsSQL::STORAGE);

$exportdate = Carbon::now(DateHelper::getTimezone())->format('Y-m-d');

return response()
->download($adapter->getPathPrefix().$path, 'monica.sql')
->download($adapter->getPathPrefix().$path, "monica-export.$exportdate.sql")
->deleteFileAfterSend(true);
}

Expand Down
5 changes: 4 additions & 1 deletion tests/Feature/SettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Tests\Feature;

use Tests\FeatureTestCase;
use Illuminate\Support\Carbon;
use App\Models\Contact\Contact;
use LaravelWebauthn\Models\WebauthnKey;
use Illuminate\Foundation\Testing\DatabaseTransactions;
Expand Down Expand Up @@ -48,10 +49,12 @@ public function test_user_can_export_account()

$response->assertSee(trans('settings.export_title'));

Carbon::setTestNow(Carbon::create(2021, 11, 25, 7, 0, 0));

$response = $this->get(route('settings.sql'));

$response->assertStatus(200);
$this->assertTrue($response->headers->get('content-disposition') == 'attachment; filename=monica.sql');
$this->assertTrue($response->headers->get('content-disposition') == 'attachment; filename=monica-export.2021-11-25.sql');
}

public function test_user_can_delete_account()
Expand Down

0 comments on commit a658fcf

Please sign in to comment.