38
common/Core/Commands/GenerateChecksums.php
Executable file
38
common/Core/Commands/GenerateChecksums.php
Executable file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Common\Core\Commands;
|
||||
|
||||
use File;
|
||||
use Illuminate\Console\Command;
|
||||
use Str;
|
||||
|
||||
class GenerateChecksums extends Command
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'checksums:generate';
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
$rootPath = base_path();
|
||||
$allFiles = File::allFiles($rootPath);
|
||||
$bar = $this->output->createProgressBar(count($allFiles));
|
||||
$bar->start();
|
||||
|
||||
$checksums = [];
|
||||
foreach ($allFiles as $file) {
|
||||
if (Str::startsWith($file->getFilename(), '.')) {
|
||||
continue;
|
||||
}
|
||||
$relativePath = str_replace($rootPath, '', $file->getPathname());
|
||||
$checksums[$relativePath] = md5_file($file);
|
||||
$bar->advance();
|
||||
}
|
||||
file_put_contents("$rootPath/checksums.json", json_encode($checksums));
|
||||
|
||||
$bar->finish();
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
20
common/Core/Commands/GenerateSitemap.php
Executable file
20
common/Core/Commands/GenerateSitemap.php
Executable file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Common\Core\Commands;
|
||||
|
||||
use Common\Admin\Sitemap\BaseSitemapGenerator;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class GenerateSitemap extends Command
|
||||
{
|
||||
protected $signature = 'sitemap:generate';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$sitemap = class_exists('App\Services\SitemapGenerator')
|
||||
? app('App\Services\SitemapGenerator')
|
||||
: app(BaseSitemapGenerator::class);
|
||||
$sitemap->generate();
|
||||
$this->info('Sitemap generated successfully');
|
||||
}
|
||||
}
|
||||
37
common/Core/Commands/SeedCommand.php
Executable file
37
common/Core/Commands/SeedCommand.php
Executable file
@@ -0,0 +1,37 @@
|
||||
<?php namespace Common\Core\Commands;
|
||||
|
||||
use File;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Str;
|
||||
|
||||
class SeedCommand extends Command
|
||||
{
|
||||
protected $signature = 'common:seed';
|
||||
|
||||
protected $description = 'Execute all common package seeders.';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$paths = collect(File::files(__DIR__ . '/../../Database/Seeds'));
|
||||
|
||||
$paths->filter(function($path) {
|
||||
return Str::endsWith($path, '.php');
|
||||
})->each(function($path) {
|
||||
Model::unguarded(function () use ($path) {
|
||||
$namespace = 'Common\Database\Seeds\\'.basename($path, '.php');
|
||||
$this->getSeeder($namespace)->__invoke();
|
||||
});
|
||||
});
|
||||
|
||||
$this->info('Seeded database successfully.');
|
||||
}
|
||||
|
||||
protected function getSeeder(string $namespace): Seeder
|
||||
{
|
||||
$class = $this->laravel->make($namespace);
|
||||
|
||||
return $class->setContainer($this->laravel)->setCommand($this);
|
||||
}
|
||||
}
|
||||
45
common/Core/Commands/UpdateSimplePaginateTables.php
Executable file
45
common/Core/Commands/UpdateSimplePaginateTables.php
Executable file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Common\Core\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class UpdateSimplePaginateTables extends Command
|
||||
{
|
||||
protected $signature = 'pagination:optimize';
|
||||
protected $description = 'Optimize pagination for large tables.';
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
$max = 150000;
|
||||
|
||||
$tables = [];
|
||||
|
||||
collect(DB::select('SHOW TABLES'))
|
||||
->map(function ($val) {
|
||||
foreach ($val as $key => $tbl) {
|
||||
return $tbl;
|
||||
}
|
||||
})
|
||||
->each(function ($table) use ($max, &$tables) {
|
||||
if (DB::table($table)->count() > $max) {
|
||||
$tables[] = $table;
|
||||
}
|
||||
});
|
||||
|
||||
settings()->save([
|
||||
'simple_pagination_tables' => implode(',', $tables),
|
||||
]);
|
||||
|
||||
$this->info(
|
||||
sprintf(
|
||||
'Tables with more than %d rows: %s',
|
||||
$max,
|
||||
implode(', ', $tables),
|
||||
),
|
||||
);
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user