Skip to content

Commit

Permalink
add clear command (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
sidigi committed May 14, 2019
1 parent d1ccd7b commit 7c5687d
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
66 changes: 66 additions & 0 deletions app/Console/Commands/CLearDataApplicationCommand.php
@@ -0,0 +1,66 @@
<?php

namespace App\Console\Commands;

use App\Models\Content\Content;
use App\Models\Tweet\Tweet;
use App\UseCases\ContentService;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;

class CLearDataApplicationCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:clear';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Clear all data application';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->clearTweets();
$this->clearContent();
}

protected function clearTweets(): void
{
DB::table('tweets')->truncate();

$this->info('Tweets deleted');
}

protected function clearContent(): void
{
/** @var ContentService $contentService */
$contentService = app()->make(ContentService::class);

Content::all()->each(static function (Content $item) use ($contentService){
$contentService->delete($item->id);
});

$this->info('Content deleted');
}
}
2 changes: 1 addition & 1 deletion app/UseCases/ContentService.php
Expand Up @@ -14,7 +14,7 @@ class ContentService
{
public function createVideo(string $url, Meta $meta): void
{
DB::transaction(function () use ($url, $meta){
DB::transaction(static function () use ($url, $meta){
/** @var Video $video */
$video = Video::add($url);

Expand Down

0 comments on commit 7c5687d

Please sign in to comment.