diff --git a/php_code/app/Console/Commands/PopulateTableFromSql.php b/php_code/app/Console/Commands/PopulateTableFromSql.php new file mode 100644 index 00000000..d278a445 --- /dev/null +++ b/php_code/app/Console/Commands/PopulateTableFromSql.php @@ -0,0 +1,46 @@ +argument('file'); + $path = base_path($file); + //$path = File::path($file); + + if (!File::exists($path)) { + $this->error("SQL file not found: {$path}"); + return self::FAILURE; + } + + $sql = File::get($path); + + + + + $connection = $this->option('connection') ?: config('database.default'); + $pdo = DB::connection($connection)->getPdo(); + + // Naive split; works for many simple SQL files. For complex dumps, + // consider using a DB-specific import (Option B). + $statements = array_filter(array_map('trim', preg_split('/;\s*[\r\n]+/', $sql))); + + foreach ($statements as $stmt) { + if ($stmt !== '') { + $pdo->exec($stmt); + } + } + + $this->info('SQL import complete.'); + return self::SUCCESS; + } +} diff --git a/php_code/database/user_group.sql b/php_code/database/user_group.sql new file mode 100644 index 00000000..6f590f15 --- /dev/null +++ b/php_code/database/user_group.sql @@ -0,0 +1,18 @@ +insert into `user_group_matrices` (`admin_gui`, `created_at`, `drawing_tools`, `id`, `name`, `permit_tools_backend`, `update_permits`, `updated_at`, `view_drawing_tools`) values (1, NULL, 1, 1, 'LUSPA National', 1, 0, NULL, 1); +insert into `user_group_matrices` (`admin_gui`, `created_at`, `drawing_tools`, `id`, `name`, `permit_tools_backend`, `update_permits`, `updated_at`, `view_drawing_tools`) values (1, NULL, 1, 2, 'LUSPA Regional', 1, 0, NULL, 1); +insert into `user_group_matrices` (`admin_gui`, `created_at`, `drawing_tools`, `id`, `name`, `permit_tools_backend`, `update_permits`, `updated_at`, `view_drawing_tools`) values (0, NULL, 0, 3, 'District Chief Executive', 1, 0, NULL, 1); +insert into `user_group_matrices` (`admin_gui`, `created_at`, `drawing_tools`, `id`, `name`, `permit_tools_backend`, `update_permits`, `updated_at`, `view_drawing_tools`) values (0, NULL, 0, 4, 'District Coordinating Director', 0, 0, NULL, 1); +insert into `user_group_matrices` (`admin_gui`, `created_at`, `drawing_tools`, `id`, `name`, `permit_tools_backend`, `update_permits`, `updated_at`, `view_drawing_tools`) values (1, NULL, 0, 5, 'District MIS', 1, 0, NULL, 1); +insert into `user_group_matrices` (`admin_gui`, `created_at`, `drawing_tools`, `id`, `name`, `permit_tools_backend`, `update_permits`, `updated_at`, `view_drawing_tools`) values (1, NULL, 1, 6, 'Head of Physical Planning Department', 1, 1, NULL, 1); +insert into `user_group_matrices` (`admin_gui`, `created_at`, `drawing_tools`, `id`, `name`, `permit_tools_backend`, `update_permits`, `updated_at`, `view_drawing_tools`) values (0, NULL, 1, 7, 'Development Planning Officer', 1, 0, NULL, 1); +insert into `user_group_matrices` (`admin_gui`, `created_at`, `drawing_tools`, `id`, `name`, `permit_tools_backend`, `update_permits`, `updated_at`, `view_drawing_tools`) values (0, NULL, 1, 8, 'Head of Works Department', 1, 0, NULL, 1); +insert into `user_group_matrices` (`admin_gui`, `created_at`, `drawing_tools`, `id`, `name`, `permit_tools_backend`, `update_permits`, `updated_at`, `view_drawing_tools`) values (0, NULL, 1, 9, 'Head of the Roads Unit or Urban Roads Department', 1, 0, NULL, 1); +insert into `user_group_matrices` (`admin_gui`, `created_at`, `drawing_tools`, `id`, `name`, `permit_tools_backend`, `update_permits`, `updated_at`, `view_drawing_tools`) values (0, NULL, 1, 10, 'District Fire Officer', 1, 0, NULL, 1); +insert into `user_group_matrices` (`admin_gui`, `created_at`, `drawing_tools`, `id`, `name`, `permit_tools_backend`, `update_permits`, `updated_at`, `view_drawing_tools`) values (0, NULL, 0, 11, 'District Disaster Prevention Department', 1, 0, NULL, 1); +insert into `user_group_matrices` (`admin_gui`, `created_at`, `drawing_tools`, `id`, `name`, `permit_tools_backend`, `update_permits`, `updated_at`, `view_drawing_tools`) values (0, NULL, 0, 12, 'Head of District Health Department', 1, 0, NULL, 1); +insert into `user_group_matrices` (`admin_gui`, `created_at`, `drawing_tools`, `id`, `name`, `permit_tools_backend`, `update_permits`, `updated_at`, `view_drawing_tools`) values (0, NULL, 0, 13, 'Representative of the Lands Commission', 1, 0, NULL, 1); +insert into `user_group_matrices` (`admin_gui`, `created_at`, `drawing_tools`, `id`, `name`, `permit_tools_backend`, `update_permits`, `updated_at`, `view_drawing_tools`) values (0, NULL, 0, 14, 'Representative of the Environmental Protection Agency', 1, 0, NULL, 1); +insert into `user_group_matrices` (`admin_gui`, `created_at`, `drawing_tools`, `id`, `name`, `permit_tools_backend`, `update_permits`, `updated_at`, `view_drawing_tools`) values (0, NULL, 0, 15, 'Rep from Traditional Council', 1, 0, NULL, 1); +insert into `user_group_matrices` (`admin_gui`, `created_at`, `drawing_tools`, `id`, `name`, `permit_tools_backend`, `update_permits`, `updated_at`, `view_drawing_tools`) values (0, NULL, 0, 16, 'Chairman of the Works Sub Committee', 1, 0, NULL, 1); +insert into `user_group_matrices` (`admin_gui`, `created_at`, `drawing_tools`, `id`, `name`, `permit_tools_backend`, `update_permits`, `updated_at`, `view_drawing_tools`) values (0, NULL, 0, 17, 'Chairman of Development Sub Planning Committee', 1, 0, NULL, 1); +insert into `user_group_matrices` (`admin_gui`, `created_at`, `drawing_tools`, `id`, `name`, `permit_tools_backend`, `update_permits`, `updated_at`, `view_drawing_tools`) values (0, NULL, 0, 18, '2 Nominated Elected Assembly Members', 1, 0, NULL, 1); diff --git a/php_code/info.md b/php_code/info.md index 69a5289f..4851e714 100644 --- a/php_code/info.md +++ b/php_code/info.md @@ -77,3 +77,5 @@ add_header Content-Security-Policy "frame-ancestors 'self' https://lupmis.houseb } php artisan make:model UserGroupMatrix -m + +php artisan sql:populate database/user_group.sql