Skip to content

Commit f1bd758

Browse files
authored
Merge pull request #25 from zigzagdev/feature/20_newsBatch
batchJobs
2 parents e6f4d46 + aa8e49b commit f1bd758

File tree

9 files changed

+61
-13
lines changed

9 files changed

+61
-13
lines changed

app/Console/Commands/ReadNews.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use App\Models\Api\News;
6+
use Illuminate\Console\Command;
7+
8+
class ReadNews extends Command
9+
{
10+
/**
11+
* The name and signature of the console command.
12+
*
13+
* @var string
14+
*/
15+
protected $signature = 'command:name';
16+
17+
/**
18+
* The console command description.
19+
*
20+
* @var string
21+
*/
22+
protected $description = 'Command description';
23+
24+
/**
25+
* Create a new command instance.
26+
*
27+
* @return void
28+
*/
29+
public function __construct()
30+
{
31+
parent::__construct();
32+
}
33+
34+
/**
35+
* Execute the console command.
36+
*
37+
* @return int
38+
*
39+
*/
40+
public function handle()
41+
{
42+
$from = date('Y-m-01');
43+
$to = date('Y-m-t');
44+
echo News::whereBetween('created_at', [$from, $to])->get()->count();
45+
}
46+
}

app/Console/Kernel.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
namespace App\Console;
44

5+
use App\Console\Commands\ReadNews;
56
use Illuminate\Console\Scheduling\Schedule;
67
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
8+
use App\Console\Commands\InformationSend;
79

810
class Kernel extends ConsoleKernel
911
{
@@ -13,9 +15,14 @@ class Kernel extends ConsoleKernel
1315
* @param \Illuminate\Console\Scheduling\Schedule $schedule
1416
* @return void
1517
*/
18+
19+
protected $commands = [
20+
ReadNews::class
21+
];
22+
1623
protected function schedule(Schedule $schedule)
1724
{
18-
// $schedule->command('inspire')->hourly();
25+
$schedule->command('command:name')->monthly()->at('10:00');
1926
}
2027

2128
/**

app/Http/Controllers/Api/AdminColumnChangeController.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,15 @@
1010
use App\Http\Resources\Api\ErrorResource;
1111
use App\Http\Resources\Api\SuccessResource;
1212
use App\Models\Api\Admin;
13-
use Illuminate\Http\Request;
1413
use Illuminate\Support\Facades\DB;
1514
use Illuminate\Support\Facades\Hash;
16-
use Illuminate\Testing\Fluent\Concerns\Has;
1715
use PharIo\Manifest\Email;
1816
use Symfony\Component\HttpFoundation\Response;
1917

2018
class AdminColumnChangeController extends Controller
2119
{
2220
public function adminEmailChange(EmailRequest $request)
2321
{
24-
// emailChangeFunction
2522
try {
2623
DB::beginTransaction();
2724
$adminId = $request->admin_id;

app/Http/Controllers/Api/ArticleController.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@
1515
use App\Models\Api\Article;
1616
use App\Models\Api\Comment;
1717
use App\Models\Api\MountainRating;
18-
use App\Models\Api\News;
1918
use Illuminate\Support\Facades\DB;
2019
use Illuminate\Support\Facades\Mail;
2120
use Symfony\Component\HttpFoundation\Response;
22-
use App\Consts\Api\Prefecture;
2321
use Illuminate\Http\Request;
2422
use Carbon\Carbon;
2523
use App\Mail\Api\ArticleCreateMail;
@@ -31,6 +29,7 @@ class ArticleController extends Controller
3129
public function articleWrite(ArticleRequest $request)
3230
{
3331
try {
32+
DB::beginTransaction();
3433
$adminId = $request->adminId;
3534

3635
// Whether admin is existed or not .
@@ -59,7 +58,7 @@ public function articleWrite(ArticleRequest $request)
5958
'mountain_name' => $request->input('mountainName'),
6059
'prefecture' => $request->input('prefecture'),
6160
]);
62-
61+
DB::commit();
6362
Mail::to($admin->address)->send(new ArticleCreateMail($admin, $newArticle));
6463
return new RegisterArticleResource($request);
6564
} catch (\Exception $e) {
@@ -127,12 +126,12 @@ public function articleDelete(Request $request)
127126
return new ErrorResource($request, Response::HTTP_BAD_REQUEST);
128127
}
129128
$address = $findArticle->address;
130-
DB::commit();
131129
Article::where([
132130
'adminId' => $adminId,
133131
'id' => $findArticle->id
134132
])->delete();
135133

134+
DB::commit();
136135
Mail::to($address)->send(new ArticleDeleteNotificationMail());
137136
return new SuccessResource($request);
138137
} catch (\Exception $e) {

app/Http/Controllers/Api/CommentController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ public function changeComment(CommentRequest $request) {
6767
'article_id' => $articleId,
6868
]);
6969

70-
DB::commit();
7170
$mailUserInform = Article::compilingComments($articleId);
71+
DB::commit();
7272
Mail::to($mailUserInform->address)->send(new CommentNoticeChange($mailUserInform));
7373
return new CommentUpdateResource($request);
7474
} catch (\Exception $e) {
@@ -93,7 +93,6 @@ public function deleteComment(Request $request)
9393
}
9494
Comment::find($commentId)->delete();
9595
DB::commit();
96-
9796
return new CommentDeleteResource($request);
9897
} catch (\Exception $e) {
9998
DB::rollBack();

app/Http/Controllers/Api/DisplayController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ public function ratingDisplay(Request $request)
7878
}
7979
return new RatingDisplayCollection($avg);
8080
} catch (\Exception $e) {
81-
DB::rollBack();
8281
$request->merge(['statusMessage' => sprintf(CommonConst::FETCH_FAILED, '検索内容')]);
8382
return new ErrorResource($request, Response::HTTP_BAD_REQUEST);
8483
}

app/Http/Controllers/Api/LoginController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public function login(LoginRequest $request)
3535

3636
//トークン生成
3737
$token = TokenMakeService::createToken($loginUser->id);
38-
DB::commit();
3938
$request->merge(['adminToken' => $token, 'adminId' => $loginUser->id]);
39+
DB::commit();
4040
return new AdminLoginResource($request);
4141
} catch (\Exception $e) {
4242
DB::rollBack();

app/Http/Controllers/Api/LogoutController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class LogoutController extends Controller
1717
public function logout(Request $request)
1818
{
1919
try {
20+
DB::beginTransaction();
2021
$expirationValid = AdminToken::where('admin_id', $request->adminId)->orderBy('created_at', 'desc')->first();
2122
if ($expirationValid->expired_at <= Carbon::now()) {
2223
$request->merge(['statusMessage' => sprintf(CommonConst::FAILED, 'ログアウト')]);
@@ -26,6 +27,7 @@ public function logout(Request $request)
2627
->where('expired_at', '>', Carbon::now())->update([
2728
'expired_at' => Carbon::now()
2829
]);
30+
DB::commit();
2931
return new SuccessResource($request);
3032
} catch (\Exception $e) {
3133
DB::rollBack();

app/Http/Controllers/Api/NewsMakingController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ public function newsReWrite(Request $request)
7171
'expiration' => Carbon::now()->addMonths(3),
7272
]);
7373
DB::commit();
74-
7574
Mail::to($findNews->address)->send(new NewsUpdateMail($findNews));
7675
return new NewsResource($request);
7776
} catch (\Exception $e) {

0 commit comments

Comments
 (0)