diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index 6a24f73ba..833bbe9f3 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -19,9 +19,9 @@ jobs: strategy: fail-fast: false matrix: - php: [8.0] - laravel: ["8.*"] - laravel-require: [8.0] + php: [8.2] + laravel: ["11.*"] + laravel-require: [11.0] name: "PHP ${{ matrix.php }} / Laravel ${{ matrix.laravel }}" @@ -36,7 +36,7 @@ jobs: extensions: mbstring, pdo_sqlite, fileinfo, gd, php_pgsql coverage: none - # Install legacy factories for Laravel 8/9 + # Install legacy factories for Laravel 11 - name: Install legacy factories for Laravel run: composer create-project laravel/laravel:^${{matrix.laravel-require}} laravel @@ -59,7 +59,7 @@ jobs: # Badaso Core Test PHPStan - name: Badaso core test PHPStan - run: cd laravel && + run: cd laravel && ./vendor/bin/phpstan analyse -c vendor/badaso/core/phpstan.neon.dist diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 897d747d3..ab3f533ef 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -38,15 +38,15 @@ jobs: strategy: fail-fast: false matrix: - php: [8.0, 8.1] - laravel: ["8.*", "9.*"] - laravel-require: [8.0] + php: [8.2] + laravel: ["11.*"] + laravel-require: [11.0] mysql-version: [8.0] coverage: [none] include: - - php: 8.1 - laravel: 9.* - laravel-require: 8.0 + - php: 8.2 + laravel: 11.* + laravel-require: 11.0 mysql-version: 8.0 coverage: xdebug @@ -70,7 +70,7 @@ jobs: extensions: mbstring, pdo_sqlite, fileinfo, gd, php_pgsql, json, openssl, php_pcov coverage: xdebug - # Install legacy factories for Laravel 8/9 + # Install legacy factories for Laravel 11 - name: Install legacy factories for Laravel run: composer create-project laravel/laravel:^${{matrix.laravel-require}} laravel @@ -130,8 +130,8 @@ jobs: sed -i 's/DB_PASSWORD=/DB_PASSWORD=postgres/g' .env && sed -i 's/DB_HOST=127.0.0.1/DB_HOST=localhost/g' .env && sed -i 's/DB_USERNAME=root/DB_USERNAME=postgres/g' .env && - sed -i 's/DB_PORT=3306/DB_PORT=5432/g' .env - + sed -i 's/DB_PORT=3306/DB_PORT=5432/g' .env + # Pgsql | Laravel setup - name: Pgsql | Laravel setup diff --git a/.gitpod.yml b/.gitpod.yml index f11c923a0..e80cb6bba 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -2,7 +2,7 @@ image: file: .gitpod.Dockerfile tasks: - name: Starting Project - init: composer create-project laravel/laravel:^8.0 laravel && + init: composer create-project laravel/laravel:^11.0 laravel && mkdir -p laravel/packages/badaso/core && mv {,.}* laravel/packages/badaso/core 2>/dev/null; true && cd laravel && diff --git a/.gitpod/composer.json b/.gitpod/composer.json index ec19e502b..d24517480 100644 --- a/.gitpod/composer.json +++ b/.gitpod/composer.json @@ -1,86 +1,84 @@ { - "name": "laravel/laravel", - "type": "project", - "description": "The Laravel Framework.", - "keywords": [ - "framework", - "laravel" + "name": "laravel/laravel", + "type": "project", + "description": "The Laravel Framework.", + "keywords": [ + "framework", + "laravel" + ], + "license": "MIT", + "require": { + "php": "^8.2", + "laravel/framework": "^11.0", + "laravel/tinker": "^2.9", + "laravel-doctrine/orm": "2.1", + "psr/http-message": "1.1", + "arcanedev/log-viewer": "^11.0", + "darkaonline/l5-swagger": "^8.6", + "phpstan/phpstan": "^1.11", + "spatie/laravel-backup": "^8.8", + "unisharp/laravel-filemanager": "^2.9", + "spatie/laravel-activitylog": "^4.8", + "php-open-source-saver/jwt-auth": "^2.3", + "google/apiclient": "^2.16", + "spatie/flysystem-dropbox": "^3.0", + "masbug/flysystem-google-drive-ext": "^2.3", + "laravel/octane": "^2.3", + "laravel/sanctum": "^4.0", + "laravel/ui": "^4.5", + "webpatser/laravel-uuid": "^4.0", + "predis/predis": "^2.2", + "league/flysystem-aws-s3-v3": "^3.28", + "league/flysystem": "^3.28", + "doctrine/dbal": "^3.8" + }, + "require-dev": { + "fakerphp/faker": "^1.23", + "laravel/pint": "^1.13", + "laravel/sail": "^1.26", + "mockery/mockery": "^1.6", + "nunomaduro/collision": "^8.0", + "phpunit/phpunit": "^11.0.1", + "spatie/laravel-ignition": "^2.4" + }, + "autoload": { + "psr-4": { + "App\\": "app/", + "Database\\Factories\\": "database/factories/", + "Database\\Seeders\\": "database/seeders/", + "Uasoft\\Badaso\\": "packages/badaso/core/src/" + } + }, + "autoload-dev": { + "psr-4": { + "Tests\\": "tests/" + } + }, + "scripts": { + "post-autoload-dump": [ + "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump", + "@php artisan package:discover --ansi" ], - "license": "MIT", - "require": { - "php": "^7.3|^8.0", - "fruitcake/laravel-cors": "^2.0", - "laravel/framework": "^8.75", - "masbug/flysystem-google-drive-ext": "*", - "google/apiclient": "^2.12", - "arcanedev/log-viewer": "^8.1|^9.0", - "darkaonline/l5-swagger": "^8.0|^8.3", - "doctrine/dbal": "^2.5", - "guzzlehttp/guzzle": "^7.2", - "larapack/doctrine-support": "^0.1.9", - "laravel/octane": "^1.2", - "laravel/sanctum": "^2.14.1", - "laravel/tinker": "^2.7", - "laravel/ui": "^3.4", - "league/flysystem": "~1.1|~2.0|~3.0", - "league/flysystem-aws-s3-v3": "^1.0.28|^3.0", - "php-open-source-saver/jwt-auth": "^1.4", - "phpstan/phpstan": "^1.4", - "predis/predis": "^1.1", - "symfony/var-exporter": "^5.2.0|^6.0", - "spatie/flysystem-dropbox": "^1.2.2|^2.0", - "spatie/laravel-activitylog": "^3.17|^4.4", - "spatie/laravel-backup": "^6.16|^8.1.0", - "unisharp/laravel-filemanager": "^2.4", - "webpatser/laravel-uuid": "^4.0", - "zircote/swagger-php": "^3.2" - }, - "require-dev": { - "facade/ignition": "^2.5", - "fakerphp/faker": "^1.9.1", - "laravel/sail": "^1.0.1", - "mockery/mockery": "^1.4.4", - "nunomaduro/collision": "^5.10", - "phpunit/phpunit": "^9.5.10" - }, - "autoload": { - "psr-4": { - "App\\": "app/", - "Database\\Factories\\": "database/factories/", - "Database\\Seeders\\": "database/seeders/", - "Uasoft\\Badaso\\": "packages/badaso/core/src/" - } - }, - "autoload-dev": { - "psr-4": { - "Tests\\": "tests/" - } - }, - "scripts": { - "post-autoload-dump": [ - "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump", - "@php artisan package:discover --ansi" - ], - "post-update-cmd": [ - "@php artisan vendor:publish --tag=laravel-assets --ansi --force" - ], - "post-root-package-install": [ - "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"" - ], - "post-create-project-cmd": [ - "@php artisan key:generate --ansi" - ] - }, - "extra": { - "laravel": { - "dont-discover": [] - } - }, - "config": { - "optimize-autoloader": true, - "preferred-install": "dist", - "sort-packages": true - }, - "minimum-stability": "dev", - "prefer-stable": true + "post-update-cmd": [ + "@php artisan vendor:publish --tag=laravel-assets --ansi --force" + ], + "post-root-package-install": [ + "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"" + ], + "post-create-project-cmd": [ + "@php artisan key:generate --ansi" + ] + }, + "extra": { + "laravel": { + "dont-discover": [] + } + }, + "config": { + "optimize-autoloader": true, + "preferred-install": "dist", + "sort-packages": true + }, + "minimum-stability": "dev", + "prefer-stable": true } diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f335c6df9..2b1b32bf9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -45,7 +45,7 @@ Steps for registering and getting a license on Badaso Dashboard can be found on After getting the license, you can proceed to Badaso installation. -1, Clone badaso into Laravel project. Sample: +1. Clone badaso into Laravel project. Sample: - Root Laravel Project - /packages // new folder - /badaso // new folder @@ -56,26 +56,16 @@ cd into badaso directory, then run git clone https://github.com/uasoft-indonesia/badaso.git ``` -2. Add the following Badaso provider and JWT provider to ```/config/app.php```. +2. Add the following Badaso provider ```/bootstrap/providers.php```. ``` -'providers' => [ +'return' => [ ..., - Uasoft\Badaso\Providers\BadasoServiceProvider::class, - PHPOpenSourceSaver\JWTAuth\Providers\LaravelServiceProvider::class, + "Uasoft\\Badaso\\Providers\\BadasoServiceProvider" ] ``` -3. Add the following aliases to ```config/app.php```. -``` -'aliases' => [ - ..., - 'JWTAuth' => PHPOpenSourceSaver\JWTAuth\Facades\JWTAuth::class, - 'JWTFactory' => PHPOpenSourceSaver\JWTAuth\Facades\JWTFactory::class, -] -``` - -4. Add badaso providers to autoload +3. Add badaso providers to autoload ``` "autoload": { @@ -87,21 +77,21 @@ git clone https://github.com/uasoft-indonesia/badaso.git } ``` -5. Copy required library from ```packages/badaso/core/composer.json``` to ```/composer.json``` then ```composer install``` +4. Copy required library from ```packages/badaso/core/composer.json``` to ```/composer.json``` then ```composer install``` -6. Run the following commands to update dependencies in package.json and webpack. +5. Run the following commands to update dependencies in package.json and webpack. ``` php artisan badaso:setup ``` -7. Run the following commands in sequence. +6. Run the following commands in sequence. ``` composer dump-autoload php artisan migrate php artisan db:seed --class=BadasoSeeder ``` -8. Open the ```env``` file then add the following lines. +7. Open the ```env``` file then add the following lines. ``` #Set a key as secret key for generating JWT token JWT_SECRET= @@ -131,7 +121,7 @@ MIX_LOG_VIEWER_ROUTE="log-viewer" MIX_ADMIN_PANEL_ROUTE_PREFIX, MIX_API_ROUTE_PREFIX & MIX_LOG_VIEWER_ROUTE should be different ::: -9. Add the following Badaso guard and auth provider in ```config/auth.php```. Make sure to use Badaso guard as auth default in ```config/auth.php```. +8. Add the following Badaso guard and auth provider in ```config/auth.php```. Make sure to use Badaso guard as auth default in ```config/auth.php```. ```php diff --git a/composer.json b/composer.json index 1513adcf7..f36eaf098 100644 --- a/composer.json +++ b/composer.json @@ -24,30 +24,25 @@ }, "type": "library", "require": { + "laravel-doctrine/orm": "2.1", "psr/http-message": "1.1", - "arcanedev/log-viewer": "8.1.0", - "larapack/doctrine-support": "0.1.9", - "darkaonline/l5-swagger": "8.5", - "symfony/var-exporter": "5.4.21", - "phpstan/phpstan": "1.10.15", - "spatie/laravel-backup": "7.8", - "unisharp/laravel-filemanager": "2.6", - "spatie/laravel-activitylog": "4.7.1", - "php-open-source-saver/jwt-auth": "2.1.0", - "google/apiclient": "2.13.2", - "spatie/flysystem-dropbox": "1.2.3", - "masbug/flysystem-google-drive-ext": "1.3.2", - "laravel/octane": "1.5.5", - "laravel/sanctum": "2.15.1", - "laravel/tinker": "2.8.1", - "laravel/ui": "3.4.6", - "webpatser/laravel-uuid": "4.0.1", - "predis/predis": "2.1.2", - "guzzlehttp/guzzle": "7.5.1", - "zircote/swagger-php": "4.7.10", - "doctrine/dbal": "2.13.9", - "league/flysystem-aws-s3-v3": "1.0.29", - "league/flysystem": "1.1.10" + "arcanedev/log-viewer": "^11.0", + "darkaonline/l5-swagger": "^8.6", + "phpstan/phpstan": "^1.11", + "spatie/laravel-backup": "^8.8", + "unisharp/laravel-filemanager": "^2.9", + "spatie/laravel-activitylog": "^4.8", + "php-open-source-saver/jwt-auth": "^2.3", + "google/apiclient": "^2.16", + "spatie/flysystem-dropbox": "^3.0", + "masbug/flysystem-google-drive-ext": "^2.3", + "laravel/octane": "^2.3", + "laravel/sanctum": "^4.0", + "laravel/ui": "^4.5", + "webpatser/laravel-uuid": "^4.0", + "predis/predis": "^2.2", + "league/flysystem-aws-s3-v3": "^3.28", + "league/flysystem": "^3.28" }, "require-dev": { "phpunit/phpunit": "^9.5", diff --git a/src/Config/badaso-hidden-tables.php b/src/Config/badaso-hidden-tables.php index 43ba1403d..0768694c7 100644 --- a/src/Config/badaso-hidden-tables.php +++ b/src/Config/badaso-hidden-tables.php @@ -26,4 +26,10 @@ 'personal_access_tokens', 'users', 'password_resets', + 'cache', + 'cache_locks', + 'jobs', + 'job_batches', + 'password_reset_tokens', + 'sessions', ]; diff --git a/src/Controllers/BadasoCRUDController.php b/src/Controllers/BadasoCRUDController.php index f7bd9250f..0453684e8 100644 --- a/src/Controllers/BadasoCRUDController.php +++ b/src/Controllers/BadasoCRUDController.php @@ -47,7 +47,6 @@ public function browse(Request $request) $protected_tables = Badaso::getProtectedTables(); $tables = SchemaManager::listTables(); - $tables_with_crud_data = []; foreach ($tables as $key => $value) { if (! in_array($key, $protected_tables)) { @@ -433,6 +432,7 @@ function ($attribute, $value, $fail) use ($request) { return ApiResponse::success($new_data_type); } catch (Exception $e) { + // dd($e); DB::rollBack(); return ApiResponse::failed($e); diff --git a/src/Controllers/BadasoDatabaseController.php b/src/Controllers/BadasoDatabaseController.php index ee1d12ef3..6cbff66c2 100644 --- a/src/Controllers/BadasoDatabaseController.php +++ b/src/Controllers/BadasoDatabaseController.php @@ -109,7 +109,6 @@ function ($attribute, $value, $fail) { Rule::notIn(Badaso::getProtectedTables()), ], ]); - $columns = SchemaManager::describeTable($request->table)->toArray(); $columnsFK = SchemaManager::getDoctrineForeignKeys($request->table); $fKConstraints = []; diff --git a/src/Controllers/BadasoTableController.php b/src/Controllers/BadasoTableController.php index 52863f246..374a25f49 100644 --- a/src/Controllers/BadasoTableController.php +++ b/src/Controllers/BadasoTableController.php @@ -46,7 +46,6 @@ public function read(Request $request) $request->validate([ 'table' => 'required', ]); - $table = $request->table; $table_fields = SchemaManager::describeTable($table); $fields = []; diff --git a/src/Database/Schema/SchemaManager.php b/src/Database/Schema/SchemaManager.php index bc30798f7..3f92dd25e 100644 --- a/src/Database/Schema/SchemaManager.php +++ b/src/Database/Schema/SchemaManager.php @@ -2,9 +2,11 @@ namespace Uasoft\Badaso\Database\Schema; +use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Schema\SchemaException; use Doctrine\DBAL\Schema\Table as DoctrineTable; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Schema; use Uasoft\Badaso\Database\Types\Type; abstract class SchemaManager @@ -18,7 +20,7 @@ public static function __callStatic($method, $args) public static function manager() { - return DB::connection()->getDoctrineSchemaManager(); + return DB::connection()->select('SELECT schema_name FROM information_schema.schemata'); } public static function getDatabaseConnection() @@ -37,10 +39,12 @@ public static function tableExists($table) public static function listTables() { + $sm = Schema::getTables(); + $tables = []; - foreach (static::manager()->listTableNames() as $table_name) { - $tables[$table_name] = static::listTableDetails($table_name); + foreach ($sm as $key => $table_name) { + $tables[$table_name['name']] = $table_name['name']; } return $tables; @@ -52,16 +56,43 @@ public static function listTables() */ public static function listTableDetails($table_name) { - $columns = static::manager()->listTableColumns($table_name); + $sm = static::registerConnection()->createSchemaManager(); + $columns = $sm->listTableColumns($table_name); $foreign_keys = []; - if (static::manager()->getDatabasePlatform()->supportsForeignKeyConstraints()) { - $foreign_keys = static::manager()->listTableForeignKeys($table_name); + $foreign_keys = $sm->listTableForeignKeys($table_name); + + $indexes = $sm->listTableIndexes($table_name); + + return new Table($table_name, $columns, $indexes, [], $foreign_keys, []); + } + + public static function registerConnection() + { + $databaseConfig = config('database.connections.'.config('database.default')); + $driver_name = DB::getDriverName(); + + if ($driver_name == 'mysql' || $driver_name == 'pgsql') { + $connectionParams = [ + 'dbname' => $databaseConfig['database'], + 'user' => $databaseConfig['username'], + 'password' => $databaseConfig['password'], + 'host' => $databaseConfig['host'], + 'driver' => 'pdo_'.$driver_name, + 'port' => $databaseConfig['port'], + ]; + } + + if ($driver_name == 'sqlite') { + $connectionParams = [ + 'path' => $databaseConfig['database'], + 'driver' => 'pdo_'.$driver_name, + ]; } - $indexes = static::manager()->listTableIndexes($table_name); + $doctrine_connection = DriverManager::getConnection($connectionParams); - return new Table($table_name, $columns, $indexes, $foreign_keys, false, []); + return $doctrine_connection; } /** @@ -141,6 +172,8 @@ public static function getDoctrineColumn($table, $column) public static function getDoctrineForeignKeys($table) { - return static::manager()->listTableForeignKeys($table); + $sm = static::registerConnection()->createSchemaManager(); + + return $sm->listTableForeignKeys($table); } } diff --git a/src/Database/Types/Common/VarCharType.php b/src/Database/Types/Common/VarCharType.php index 235314abf..a7f1a97f3 100644 --- a/src/Database/Types/Common/VarCharType.php +++ b/src/Database/Types/Common/VarCharType.php @@ -6,10 +6,10 @@ class VarCharType extends DoctrineStringType { - const NAME = 'varchar'; + const NAME = 'string'; public function getName() { - return static::NAME; + return 'varchar'; } } diff --git a/src/Database/Types/Type.php b/src/Database/Types/Type.php index f6c64c6e4..41a05be54 100644 --- a/src/Database/Types/Type.php +++ b/src/Database/Types/Type.php @@ -4,6 +4,7 @@ use Doctrine\DBAL\Platforms\AbstractPlatform as DoctrineAbstractPlatform; use Doctrine\DBAL\Types\Type as DoctrineType; +use Illuminate\Support\Facades\DB; use Uasoft\Badaso\Database\Platforms\Platform; use Uasoft\Badaso\Database\Schema\SchemaManager; @@ -48,10 +49,12 @@ public static function getPlatformTypes() static::registerCustomPlatformTypes(); } - $platform = SchemaManager::getDatabasePlatform(); + $doctrine_connection = SchemaManager::registerConnection(); + $platform = $doctrine_connection->getDatabasePlatform(); + $platform_name = DB::getDriverName(); static::$platform_types = Platform::getPlatformTypes( - $platform->getName(), + $platform_name, static::getPlatformTypeMapping($platform) ); @@ -81,7 +84,9 @@ public static function registerCustomPlatformTypes($force = false) return; } - $platform = SchemaManager::getDatabasePlatform(); + $doctrine_connection = SchemaManager::registerConnection(); + $platform = $doctrine_connection->getDatabasePlatform(); + // $platform_name = ucfirst(DB::getDriverName()); $platform_name = ucfirst($platform->getName()); $custom_types = array_merge( diff --git a/src/Helpers/DataTypeToComponent.php b/src/Helpers/DataTypeToComponent.php index f59161e42..ca982623e 100644 --- a/src/Helpers/DataTypeToComponent.php +++ b/src/Helpers/DataTypeToComponent.php @@ -8,6 +8,7 @@ class DataTypeToComponent protected static $type_list = [ 'CHAR' => 'text', 'VARCHAR' => 'text', + 'STRING' => 'text', 'BINARY' => 'text', 'VARBINARY' => 'text', 'TINYBLOB' => 'text', diff --git a/src/Providers/BadasoServiceProvider.php b/src/Providers/BadasoServiceProvider.php index b6364829e..582ffda29 100644 --- a/src/Providers/BadasoServiceProvider.php +++ b/src/Providers/BadasoServiceProvider.php @@ -6,7 +6,7 @@ use Illuminate\Foundation\AliasLoader; use Illuminate\Support\ServiceProvider; use L5Swagger\L5SwaggerServiceProvider; -use Larapack\DoctrineSupport\DoctrineSupportServiceProvider; +use LaravelDoctrine\ORM\DoctrineServiceProvider; use Uasoft\Badaso\Badaso; use Uasoft\Badaso\Commands\AdminCommand; use Uasoft\Badaso\Commands\BackupCommand; @@ -99,7 +99,7 @@ public function boot() public function register() { $this->app->register(OrchestratorEventServiceProvider::class); - $this->app->register(DoctrineSupportServiceProvider::class); + $this->app->register(DoctrineServiceProvider::class); $this->app->register(DropboxServiceProvider::class); $this->app->register(GoogleDriveServiceProvider::class); $this->app->register(LogViewerServiceProvider::class); diff --git a/src/resources/js/layout/admin/footer/Footer.vue b/src/resources/js/layout/admin/footer/Footer.vue index fa17208de..092426194 100644 --- a/src/resources/js/layout/admin/footer/Footer.vue +++ b/src/resources/js/layout/admin/footer/Footer.vue @@ -2,7 +2,7 @@