Skip to content
This repository was archived by the owner on Mar 24, 2024. It is now read-only.

Commit 76dd135

Browse files
author
Lorenz Bausch
committed
delete entries older than specific date
1 parent 4108645 commit 76dd135

File tree

12 files changed

+92
-8
lines changed

12 files changed

+92
-8
lines changed

app/Http/Controllers/GreylistController.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Http\Request;
66
use Carbon\Carbon;
7+
use Assets;
78
use SQLgreyGUI\Repositories\GreylistRepositoryInterface as Greylist;
89

910
class GreylistController extends Controller
@@ -35,6 +36,9 @@ public function __construct(Greylist $repo)
3536
*/
3637
public function index()
3738
{
39+
40+
Assets::add('datetimepicker');
41+
3842
$carbon = Carbon::now();
3943
$timestamp = $carbon->getTimestamp();
4044

@@ -74,7 +78,30 @@ public function delete()
7478
}
7579

7680
return redirect(action('GreylistController@index'))
77-
->with('success', 'deleted the following entries:<ul>' . implode(PHP_EOL, $message) . '</ul>');
81+
->withSuccess('deleted the following entries:<ul>' . implode(PHP_EOL, $message) . '</ul>');
82+
}
83+
84+
/**
85+
* delete by date
86+
*
87+
* @param Request $req
88+
* @return Response
89+
*/
90+
public function deleteByDate(Request $req)
91+
{
92+
$date = $req->input('delete_by_date');
93+
94+
if (!$date) {
95+
return redirect(action('GreylistController@index'))
96+
->withError('invalid date');
97+
}
98+
99+
$carbon = Carbon::createFromFormat('Y-m-d H:i', $date);
100+
101+
$num = $this->repo->destroyOlderThan($carbon);
102+
103+
return redirect(action('GreylistController@index'))
104+
->withSuccess('deleted entries: ' . $num);
78105
}
79106

80107
/**

app/Http/routes.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
post('greylist/live', 'GreylistController@live');
1111
post('greylist/delete', 'GreylistController@delete');
1212
post('greylist/move', 'GreylistController@move');
13+
post('greylist/deletebydate', 'GreylistController@deleteByDate');
1314

1415
// Whitelist
1516
get('whitelist/emails', 'WhitelistController@showEmails');

app/Repositories/GreylistRepositoryEloquent.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,10 @@ public function destroy(Greylist $greylist)
7373
->delete();
7474
}
7575

76+
public function destroyOlderThan(Carbon $date)
77+
{
78+
return Greylist::where('first_seen', '<=', $date->format('Y-m-d H:i:s'))
79+
->delete();
80+
}
81+
7682
}

app/Repositories/GreylistRepositoryInterface.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace SQLgreyGUI\Repositories;
44

5+
use Carbon\Carbon;
56
use SQLgreyGUI\Models\Greylist;
67

78
interface GreylistRepositoryInterface extends BaseRepositoryInterface
@@ -30,4 +31,12 @@ public function findBetween($start, $end = null);
3031
* @return bool
3132
*/
3233
public function destroy(Greylist $greylist);
34+
35+
/**
36+
* destroy entries older than given date
37+
*
38+
* @param Carbon $date
39+
* @return int
40+
*/
41+
public function destroyOlderThan(Carbon $date);
3342
}

app/macros.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,18 @@
33
use Collective\Html\HtmlBuilder as Html;
44

55
Html::macro('alert', function($type = 'info', $message) {
6-
if (!in_array($type, array('success', 'info', 'warning', 'danger'))) {
6+
$types = [
7+
'success' => 'success',
8+
'info' => 'info',
9+
'warning' => 'warning',
10+
'error' => 'danger'
11+
];
12+
13+
if (!isset($types[$type])) {
714
return false;
815
}
916

10-
return View::make('macros.alert-' . $type)
17+
return View::make('macros.alert-' . $types[$type])
1118
->with('message', $message);
1219
});
1320

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"laravelcollective/html": "~5.0",
1212
"components/jquery": "dev-master",
1313
"twbs/bootstrap": "3.3.*@dev",
14+
"eonasdan/bootstrap-datetimepicker": "dev-master",
1415
"fortawesome/font-awesome": "4.3.0",
1516
"afarkas/html5shiv": "dev-master",
1617
"rogeriopradoj/respond": "1.4.2",
@@ -45,7 +46,8 @@
4546
"php artisan optimize",
4647
"php artisan route:clear",
4748
"php artisan config:cache",
48-
"php artisan asset:flush --force"
49+
"php artisan asset:flush --force",
50+
"php artisan twig:clean"
4951
],
5052
"post-create-project-cmd": [
5153
"php -r \"copy('.env.example', '.env');\"",

config/assets.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,14 @@
132132
'dataTables.responsive.css',
133133
],
134134

135+
'datetimepicker' => [
136+
'jquery',
137+
'moment.js',
138+
'bootstrap',
139+
'bootstrap-datetimepicker.js',
140+
'bootstrap-datetimepicker.css',
141+
],
142+
135143
'font-awesome' => [
136144
'font-awesome.css',
137145
],
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../vendor/eonasdan/bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.css
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../vendor/eonasdan/bootstrap-datetimepicker/src/js/bootstrap-datetimepicker.js

public/assets/js/moment.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../vendor/moment/moment/moment.js

0 commit comments

Comments
 (0)