Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

cattr-app/server-application

87 stars
1 code files
View cattr-app/server-application on GitHub

app/Console/Commands/ResetCommand.php

Open in GitHub
use Exception;
use Illuminate\Console\Command;
use DB;
use Illuminate\Database\Console\Seeds\SeedCommand;
use Nwidart\Modules\Commands\SeedCommand as ModuleSeedCommand;
use Settings;
use Storage;
use Symfony\Component\Console\Attribute\AsCommand;
 
#[AsCommand(name: 'cattr:reset')]
class ResetCommand extends Command
{
protected $signature = 'cattr:reset {--s|seed} {--f|force} {--i|images}';
 
protected $description = 'Cattr flush database';
 
protected array $protectedTables = ['migrations', 'jobs', 'failed_jobs'];
 
public function handle(): int
{
if (!$this->option('force') && !$this->confirm('Are you sure want to drop data for your Cattr instance?')) {
return 0;
}
 
DB::statement('SET FOREIGN_KEY_CHECKS=0;');
 
$tables = DB::connection()->getDoctrineSchemaManager()->listTableNames();
foreach ($tables as $table) {
if (!in_array($table, $this->protectedTables, true)) {
DB::table($table)->truncate();
}
}
 
DB::statement('SET FOREIGN_KEY_CHECKS=1;');
 
if ($this->option('images')) {
Storage::deleteDirectory('uploads/screenshots');
}
 
$this->call(SeedCommand::class, [
'--class' => 'InitialSeeder',
'--force' => true
]);
 
if ($this->option('seed')) {
$this->call(SeedCommand::class, [
'--force' => true
]);
$this->call(ModuleSeedCommand::class, [
'--force' => true
]);
}
 
return 0;
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.