Skip to content

Commit

Permalink
Merge pull request #218 from uasoft-indonesia/bugfix/badasohidden
Browse files Browse the repository at this point in the history
update setup
  • Loading branch information
rizkiheryandi authored Aug 8, 2024
2 parents a88e42c + 965fce7 commit cb53082
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/Commands/BadasoPostSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
use Symfony\Component\VarExporter\VarExporter;
use Uasoft\Badaso\Module\Post\Facades\BadasoPostModule;

class BadasoPostSetup extends Command
Expand Down Expand Up @@ -126,14 +125,35 @@ protected function addPostTablesToHiddenTables()
$config_path = config_path('badaso-hidden-tables.php');
$config_hidden_tables = require $config_path;
$tables = BadasoPostModule::getProtectedTables();
$except_tables = ['migrations', 'activity_log', 'failed_jobs', 'personal_access_tokens', 'users', 'password_resets'];

$filter_hidden_tables = array_diff($config_hidden_tables, $except_tables);
$filter_hidden_table = [];
foreach ($filter_hidden_tables as $value) {
$filter_hidden_table[] = str_replace(ENV('BADASO_TABLE_PREFIX'), '', $value);
}

foreach ($tables as $key => $value) {
if (! in_array($value, $config_hidden_tables)) {
array_push($config_hidden_tables, $value);
if (! in_array($value, $filter_hidden_table)) {
array_push($filter_hidden_table, $value);
}
}

$exported_config = VarExporter::export($config_hidden_tables);
$prefixed_hidden_table = array_map(function ($item) {
return
"env('BADASO_TABLE_PREFIX', 'badaso_').'{$item}'";
}, $filter_hidden_table);

$default_table = array_map(function ($item) {
return
"'{$item}'";
}, $except_tables);

$exported_config = implode(",\n ", $prefixed_hidden_table);
$except_table = implode(",\n ", $default_table);

$exported_config = "[\n // badaso default table\n {$exported_config},\n\n// laravel default table\n {$except_table},\n]";

$exported_config = <<<PHP
<?php
return {$exported_config} ;
Expand Down

0 comments on commit cb53082

Please sign in to comment.