Skip to content

Commit 2683971

Browse files
committed
[mis]a lot
1 parent 09ee1a9 commit 2683971

File tree

382 files changed

+49244
-944
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

382 files changed

+49244
-944
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ yarn-error.log
2222
/.nova
2323
/.vscode
2424
/.zed
25+
/.kanbn
26+
lang/php_*.json
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use Illuminate\Console\Command;
6+
use App\Models\CommandLog;
7+
use App\Traits\LogsScheduledCommands;
8+
use Carbon\Carbon;
9+
10+
class CleanCommandLogs extends Command
11+
{
12+
use LogsScheduledCommands;
13+
14+
protected $signature = 'grgsdev:logs-command-clean';
15+
protected $description = 'Clean up old command logs';
16+
17+
public function handle()
18+
{
19+
// Obtém o número de dias da configuração
20+
21+
if (!config('app.keep_command_logs_for')) {
22+
$days = 7;
23+
} else {
24+
$days = config('app.keep_command_logs_for', 7);
25+
}
26+
27+
$thresholdDate = Carbon::now()->subDays($days);
28+
29+
try {
30+
$deletedCount = CommandLog::where('executed_at', '<', $thresholdDate)->delete();
31+
$outputMessage = "{$deletedCount} registros antigos de logs foram excluídos. Registros mais antigos que {$days} dias foram excluídos.";
32+
33+
$this->logCommandExecution($outputMessage, true);
34+
$this->info($outputMessage);
35+
} catch (\Exception $e) {
36+
// Registro de falha no log
37+
$this->logCommandExecution($e->getMessage(), false);
38+
$this->error("Falha ao limpar logs de comandos antigos: {$e->getMessage()}");
39+
}
40+
}
41+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use Carbon\Carbon;
6+
use Illuminate\Console\Command;
7+
use Illuminate\Support\Facades\DB;
8+
use App\Traits\LogsScheduledCommands;
9+
10+
class CleanDeletedRecordsBackup extends Command
11+
{
12+
use LogsScheduledCommands;
13+
protected $signature = 'grgsdev:deleted-backup-clean'; // Nome do comando
14+
protected $description = 'Clean up old deleted records backups';
15+
16+
public function handle()
17+
{
18+
// Verifica se a configuração 'keep_deleted_backup' está ativa
19+
if (!config('app.keep_deleted_backup')) {
20+
$this->logCommandExecution("Backup de registros excluídos está desativado. Nenhuma ação necessária.", true);
21+
$this->info('Backup de registros excluídos está desativado. Nenhuma ação necessária.');
22+
return;
23+
}
24+
25+
// Obtém o número de dias configurados
26+
$days = config('app.keep_deleted_backup_for');
27+
$thresholdDate = Carbon::now()->subDays($days); // Data limite
28+
29+
try {
30+
$deletedCount = DB::table('deleted_records')
31+
->where('deleted_at', '<', $thresholdDate)
32+
->delete();
33+
$this->logCommandExecution("{$deletedCount} Backups antigos removidos com sucesso. Registros mais antigos que {$days} dias foram excluídos.", true);
34+
$this->info("{$deletedCount} Backups antigos removidos com sucesso. Registros mais antigos que {$days} dias foram excluídos.");
35+
} catch (\Exception $e) {
36+
// Registro de falha no log
37+
$this->logCommandExecution($e->getMessage(), false);
38+
$this->error("Falha ao limpar backups antigos: {$e->getMessage()}");
39+
}
40+
41+
42+
// Realiza a limpeza de backups antigos
43+
}
44+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
namespace App\Console\Commands\GrgsDev;
4+
5+
use Illuminate\Console\Command;
6+
use Illuminate\Support\Facades\File;
7+
8+
class AppendAttributes extends Command
9+
{
10+
protected $signature = 'grgsdev:append-attributes';
11+
protected $description = 'Append translated attributes to the attributes key in validation.php for each locale';
12+
13+
public function handle()
14+
{
15+
// Caminho do arquivo de traduções gerado pelo comando TranslateAttributes
16+
$inputFilePath = base_path('documentation/translations/appTranslatedAttributes.php');
17+
18+
// Verificar se o arquivo existe
19+
if (!File::exists($inputFilePath)) {
20+
$this->error("O arquivo appTranslatedAttributes.php não foi encontrado.");
21+
return Command::FAILURE;
22+
}
23+
24+
// Incluir o arquivo de traduções
25+
$translatedAttributes = include $inputFilePath;
26+
27+
// Verifica se o array de traduções é válido
28+
if (!is_array($translatedAttributes)) {
29+
$this->error("O arquivo appTranslatedAttributes.php não contém um array válido.");
30+
return Command::FAILURE;
31+
}
32+
33+
// Loop através de cada idioma (locale) e suas traduções
34+
foreach ($translatedAttributes as $locale => $attributes) {
35+
// Caminho do arquivo validation.php para o idioma atual
36+
$validationFilePath = base_path("lang/{$locale}/validation.php");
37+
38+
// Verificar se o arquivo validation.php existe
39+
if (!File::exists($validationFilePath)) {
40+
$this->error("O arquivo validation.php para o idioma '{$locale}' não foi encontrado.");
41+
continue;
42+
}
43+
44+
// Incluir o conteúdo de validation.php
45+
$validationArray = include $validationFilePath;
46+
47+
// Verificar se a chave 'attributes' existe, se não, pula o idioma
48+
if (!isset($validationArray['attributes'])) {
49+
$this->error("A chave 'attributes' não foi encontrada no arquivo validation.php para o idioma '{$locale}'.");
50+
continue;
51+
}
52+
53+
// Pegar os atributos existentes em 'attributes'
54+
$existingAttributes = $validationArray['attributes'];
55+
56+
// Adicionar as chaves novas (que não existem em attributes) ao array existente
57+
foreach ($attributes as $key => $value) {
58+
if (!array_key_exists($key, $existingAttributes)) {
59+
$existingAttributes[$key] = $value;
60+
}
61+
}
62+
63+
// Ordenar o array 'attributes' em ordem alfabética
64+
ksort($existingAttributes);
65+
66+
// Atualizar apenas a chave 'attributes' no array de validation.php
67+
$validationArray['attributes'] = $existingAttributes;
68+
69+
// Lê o conteúdo original do arquivo validation.php para não modificar sua estrutura
70+
$originalContent = File::get($validationFilePath);
71+
72+
// Atualiza somente a chave 'attributes' no arquivo
73+
$updatedAttributesExport = var_export($existingAttributes, true);
74+
$updatedContent = preg_replace(
75+
'/\'attributes\'\s*=>\s*\[[^\]]*\]/s',
76+
"'attributes' => {$updatedAttributesExport}",
77+
$originalContent
78+
);
79+
80+
// Escreve o conteúdo atualizado no arquivo, mantendo o restante da estrutura
81+
File::put($validationFilePath, $updatedContent);
82+
83+
$this->info("Atributos atualizados para o idioma '{$locale}' em lang/{$locale}/validation.php");
84+
}
85+
86+
return Command::SUCCESS;
87+
}
88+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
namespace App\Console\Commands\GrgsDev;
4+
5+
use Illuminate\Console\Command;
6+
use Illuminate\Support\Facades\File;
7+
use RecursiveDirectoryIterator;
8+
use RecursiveIteratorIterator;
9+
use RegexIterator;
10+
11+
class ExtractAttributes extends Command
12+
{
13+
protected $signature = 'grgsdev:attributes';
14+
protected $description = 'Extract attribute keys from rules() method in Request classes';
15+
16+
public function handle()
17+
{
18+
// Diretório de onde iremos buscar os arquivos PHP
19+
$directory = app_path('Http/Requests');
20+
21+
// Verificar se o diretório existe
22+
if (!File::isDirectory($directory)) {
23+
$this->error("O diretório 'app/Http/Requests' não foi encontrado.");
24+
return Command::FAILURE;
25+
}
26+
27+
// Função para ler todos os arquivos .php recursivamente
28+
$phpFiles = $this->getPhpFiles($directory);
29+
30+
$attributes = [];
31+
32+
// Percorrer todos os arquivos encontrados
33+
foreach ($phpFiles as $file) {
34+
$content = File::get($file);
35+
36+
// Usar regex para encontrar o método rules()
37+
if (preg_match('/public function rules\(\)\s*\{(.*?)\}/s', $content, $matches)) {
38+
$rulesContent = $matches[1];
39+
40+
// Encontrar as chaves dentro do array de rules()
41+
if (preg_match_all('/\'([^\']+)\'\s*=>/', $rulesContent, $ruleMatches)) {
42+
$keys = $ruleMatches[1];
43+
$attributes = array_merge($attributes, $keys);
44+
}
45+
}
46+
}
47+
48+
// Remover duplicatas e ordenar o array
49+
$attributes = array_unique($attributes);
50+
sort($attributes);
51+
52+
// Gerar o arquivo de saída no formato esperado
53+
$output = "<?php\n\nreturn [\n";
54+
foreach ($attributes as $attribute) {
55+
$output .= " '$attribute',\n";
56+
}
57+
$output .= "];\n";
58+
59+
// Salvar o arquivo appAttributes.php no diretório app_path('documentation/translations')
60+
$outputFilePath = base_path('documentation/translations/appAttributes.php');
61+
62+
// Criar o diretório se não existir
63+
if (!File::isDirectory(base_path('documentation/translations'))) {
64+
File::makeDirectory(base_path('documentation/translations'), 0755, true);
65+
}
66+
67+
// Escrever o arquivo com os atributos extraídos
68+
File::put($outputFilePath, $output);
69+
70+
$this->info("Atributos extraídos com sucesso em " . base_path('documentation/translations/appAttributes.php'));
71+
72+
return Command::SUCCESS;
73+
}
74+
75+
// Função para obter todos os arquivos .php recursivamente
76+
protected function getPhpFiles($directory)
77+
{
78+
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory));
79+
$regexIterator = new RegexIterator($iterator, '/^.+\.php$/i', RegexIterator::GET_MATCH);
80+
81+
$files = [];
82+
foreach ($regexIterator as $file) {
83+
$files[] = $file[0];
84+
}
85+
86+
return $files;
87+
}
88+
}

0 commit comments

Comments
 (0)