mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
New export functionality.
This commit is contained in:
66
app/Repositories/ExportJob/ExportJobRepository.php
Normal file
66
app/Repositories/ExportJob/ExportJobRepository.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* ExportJobRepository.php
|
||||
* Copyright (C) 2016 Sander Dorigo
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Repositories\ExportJob;
|
||||
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Models\ExportJob;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* Class ExportJobRepository
|
||||
*
|
||||
* @package FireflyIII\Repositories\ExportJob
|
||||
*/
|
||||
class ExportJobRepository implements ExportJobRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function cleanup()
|
||||
{
|
||||
$dayAgo = Carbon::create()->subDay();
|
||||
ExportJob::where('created_at', '<', $dayAgo->format('Y-m-d H:i:s'))
|
||||
->where('status', 'never_started')
|
||||
// TODO also delete others.
|
||||
->delete();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ExportJob
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$exportJob = new ExportJob;
|
||||
$exportJob->user()->associate(Auth::user());
|
||||
/*
|
||||
* In theory this random string could give db error.
|
||||
*/
|
||||
$exportJob->key = Str::random(12);
|
||||
$exportJob->status = 'export_status_never_started';
|
||||
$exportJob->save();
|
||||
|
||||
return $exportJob;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $key
|
||||
*
|
||||
* @return ExportJob|null
|
||||
*/
|
||||
public function findByKey($key)
|
||||
{
|
||||
return Auth::user()->exportJobs()->where('key', $key)->first();
|
||||
}
|
||||
|
||||
}
|
38
app/Repositories/ExportJob/ExportJobRepositoryInterface.php
Normal file
38
app/Repositories/ExportJob/ExportJobRepositoryInterface.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* ExportJobRepositoryInterface.php
|
||||
* Copyright (C) 2016 Sander Dorigo
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Repositories\ExportJob;
|
||||
|
||||
use FireflyIII\Models\ExportJob;
|
||||
|
||||
/**
|
||||
* Interface ExportJobRepositoryInterface
|
||||
*
|
||||
* @package FireflyIII\Repositories\ExportJob
|
||||
*/
|
||||
interface ExportJobRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function cleanup();
|
||||
|
||||
/**
|
||||
* @return ExportJob
|
||||
*/
|
||||
public function create();
|
||||
|
||||
/**
|
||||
* @param $key
|
||||
*
|
||||
* @return ExportJob|null
|
||||
*/
|
||||
public function findByKey($key);
|
||||
|
||||
}
|
Reference in New Issue
Block a user