Initial commit - CMS Gov Bapenda Garut dengan EditorJS

This commit is contained in:
2026-01-05 06:47:36 +07:00
commit bd649bd5f2
634 changed files with 215640 additions and 0 deletions

View File

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class CreateRolesTable extends Migration
{
public function up()
{
$this->forge->addField([
'id' => [
'type' => 'INT',
'constraint' => 11,
'unsigned' => true,
'auto_increment' => true,
],
'name' => [
'type' => 'VARCHAR',
'constraint' => 50,
],
]);
$this->forge->addKey('id', true);
$this->forge->addUniqueKey('name');
$this->forge->createTable('roles', true, ['ENGINE' => 'InnoDB']);
}
public function down()
{
$this->forge->dropTable('roles');
}
}

View File

@@ -0,0 +1,79 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class CreateUsersTable extends Migration
{
public function up()
{
$this->forge->addField([
'id' => [
'type' => 'INT',
'constraint' => 11,
'unsigned' => true,
'auto_increment' => true,
],
'role_id' => [
'type' => 'INT',
'constraint' => 11,
'unsigned' => true,
],
'username' => [
'type' => 'VARCHAR',
'constraint' => 100,
],
'email' => [
'type' => 'VARCHAR',
'constraint' => 255,
],
'phone_number' => [
'type' => 'VARCHAR',
'constraint' => 20,
'null' => true,
],
'password_hash' => [
'type' => 'VARCHAR',
'constraint' => 255,
],
'telegram_id' => [
'type' => 'BIGINT',
'constraint' => 20,
'null' => true,
],
'is_active' => [
'type' => 'TINYINT',
'constraint' => 1,
'default' => 1,
],
'last_login_at' => [
'type' => 'DATETIME',
'null' => true,
],
'created_at' => [
'type' => 'DATETIME',
'null' => true,
],
'updated_at' => [
'type' => 'DATETIME',
'null' => true,
],
]);
$this->forge->addKey('id', true);
$this->forge->addUniqueKey('username');
$this->forge->addUniqueKey('email');
$this->forge->addUniqueKey('phone_number');
$this->forge->addUniqueKey('telegram_id');
$this->forge->addKey('role_id');
$this->forge->addForeignKey('role_id', 'roles', 'id', 'CASCADE', 'CASCADE');
$this->forge->createTable('users', true, ['ENGINE' => 'InnoDB']);
}
public function down()
{
$this->forge->dropTable('users');
}
}

View File

@@ -0,0 +1,66 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class CreateNewsTable extends Migration
{
public function up()
{
$this->forge->addField([
'id' => [
'type' => 'INT',
'constraint' => 11,
'unsigned' => true,
'auto_increment' => true,
],
'title' => [
'type' => 'VARCHAR',
'constraint' => 255,
],
'slug' => [
'type' => 'VARCHAR',
'constraint' => 255,
],
'content' => [
'type' => 'LONGTEXT',
],
'status' => [
'type' => 'ENUM',
'constraint' => ['draft', 'published'],
'default' => 'draft',
],
'published_at' => [
'type' => 'DATETIME',
'null' => true,
],
'created_by' => [
'type' => 'INT',
'constraint' => 11,
'unsigned' => true,
],
'created_at' => [
'type' => 'DATETIME',
'null' => true,
],
'updated_at' => [
'type' => 'DATETIME',
'null' => true,
],
]);
$this->forge->addKey('id', true);
$this->forge->addUniqueKey('slug');
$this->forge->addKey('created_by');
$this->forge->addKey('status');
$this->forge->addForeignKey('created_by', 'users', 'id', 'CASCADE', 'CASCADE');
$this->forge->createTable('news', true, ['ENGINE' => 'InnoDB']);
}
public function down()
{
$this->forge->dropTable('news');
}
}

View File

@@ -0,0 +1,55 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class CreatePagesTable extends Migration
{
public function up()
{
$this->forge->addField([
'id' => [
'type' => 'INT',
'constraint' => 11,
'unsigned' => true,
'auto_increment' => true,
],
'title' => [
'type' => 'VARCHAR',
'constraint' => 255,
],
'slug' => [
'type' => 'VARCHAR',
'constraint' => 255,
],
'content' => [
'type' => 'LONGTEXT',
],
'status' => [
'type' => 'ENUM',
'constraint' => ['draft', 'published'],
'default' => 'draft',
],
'created_at' => [
'type' => 'DATETIME',
'null' => true,
],
'updated_at' => [
'type' => 'DATETIME',
'null' => true,
],
]);
$this->forge->addKey('id', true);
$this->forge->addUniqueKey('slug');
$this->forge->addKey('status');
$this->forge->createTable('pages', true, ['ENGINE' => 'InnoDB']);
}
public function down()
{
$this->forge->dropTable('pages');
}
}

View File

@@ -0,0 +1,55 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class CreateAuditLogsTable extends Migration
{
public function up()
{
$this->forge->addField([
'id' => [
'type' => 'INT',
'constraint' => 11,
'unsigned' => true,
'auto_increment' => true,
],
'user_id' => [
'type' => 'INT',
'constraint' => 11,
'unsigned' => true,
'null' => true,
],
'action' => [
'type' => 'VARCHAR',
'constraint' => 100,
],
'ip_address' => [
'type' => 'VARCHAR',
'constraint' => 45,
],
'user_agent' => [
'type' => 'TEXT',
'null' => true,
],
'created_at' => [
'type' => 'DATETIME',
'null' => true,
],
]);
$this->forge->addKey('id', true);
$this->forge->addKey('user_id');
$this->forge->addKey('action');
$this->forge->addKey('created_at');
$this->forge->addForeignKey('user_id', 'users', 'id', 'SET NULL', 'CASCADE');
$this->forge->createTable('audit_logs', true, ['ENGINE' => 'InnoDB']);
}
public function down()
{
$this->forge->dropTable('audit_logs');
}
}

View File

@@ -0,0 +1,51 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class CreateSettingsTable extends Migration
{
public function up()
{
$this->forge->addField([
'id' => [
'type' => 'INT',
'constraint' => 11,
'unsigned' => true,
'auto_increment' => true,
],
'key' => [
'type' => 'VARCHAR',
'constraint' => '100',
],
'value' => [
'type' => 'TEXT',
'null' => true,
],
'description' => [
'type' => 'VARCHAR',
'constraint' => '255',
'null' => true,
],
'created_at' => [
'type' => 'DATETIME',
'null' => true,
],
'updated_at' => [
'type' => 'DATETIME',
'null' => true,
],
]);
$this->forge->addKey('id', true);
$this->forge->addUniqueKey('key');
$this->forge->createTable('settings', true);
}
public function down()
{
$this->forge->dropTable('settings', true);
}
}

View File

@@ -0,0 +1,81 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
/**
* Migration untuk membuat tabel login_attempts
*
* Tabel ini digunakan untuk:
* - Mencatat semua percobaan login (berhasil dan gagal)
* - Monitoring aktivitas mencurigakan
* - Implementasi account lockout
* - Audit trail untuk keamanan
*/
class CreateLoginAttemptsTable extends Migration
{
public function up()
{
$this->forge->addField([
'id' => [
'type' => 'INT',
'constraint' => 11,
'unsigned' => true,
'auto_increment' => true,
],
'ip_address' => [
'type' => 'VARCHAR',
'constraint' => '45',
'comment' => 'IP address dari percobaan login',
],
'username' => [
'type' => 'VARCHAR',
'constraint' => '100',
'null' => true,
'comment' => 'Username yang dicoba (null jika user tidak ditemukan)',
],
'user_id' => [
'type' => 'INT',
'constraint' => 11,
'unsigned' => true,
'null' => true,
'comment' => 'ID user jika login berhasil',
],
'success' => [
'type' => 'TINYINT',
'constraint' => 1,
'default' => 0,
'comment' => '1 = berhasil, 0 = gagal',
],
'user_agent' => [
'type' => 'TEXT',
'null' => true,
'comment' => 'User agent browser',
],
'created_at' => [
'type' => 'DATETIME',
'null' => true,
],
]);
$this->forge->addKey('id', true);
$this->forge->addKey('ip_address');
$this->forge->addKey('username');
$this->forge->addKey('user_id');
$this->forge->addKey('created_at');
// Index composite untuk query cepat berdasarkan IP dan waktu
$this->forge->addKey(['ip_address', 'created_at']);
// Index composite untuk query berdasarkan username dan waktu
$this->forge->addKey(['username', 'created_at']);
$this->forge->createTable('login_attempts', true);
}
public function down()
{
$this->forge->dropTable('login_attempts', true);
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class UpdatePagesTableForEditorJs extends Migration
{
public function up()
{
$fields = [
'content_json' => [
'type' => 'LONGTEXT',
'null' => true,
'after' => 'content',
],
'content_html' => [
'type' => 'LONGTEXT',
'null' => true,
'after' => 'content_json',
],
'excerpt' => [
'type' => 'TEXT',
'null' => true,
'after' => 'content_html',
],
'featured_image' => [
'type' => 'VARCHAR',
'constraint' => 255,
'null' => true,
'after' => 'excerpt',
],
];
$this->forge->addColumn('pages', $fields);
}
public function down()
{
$this->forge->dropColumn('pages', ['content_json', 'content_html', 'excerpt', 'featured_image']);
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class UpdateNewsTableForEditorJs extends Migration
{
public function up()
{
$fields = [
'content_json' => [
'type' => 'LONGTEXT',
'null' => true,
'after' => 'content',
],
'content_html' => [
'type' => 'LONGTEXT',
'null' => true,
'after' => 'content_json',
],
'excerpt' => [
'type' => 'TEXT',
'null' => true,
'after' => 'content_html',
],
];
$this->forge->addColumn('news', $fields);
}
public function down()
{
$this->forge->dropColumn('news', ['content_json', 'content_html', 'excerpt']);
}
}

View File

View File

@@ -0,0 +1,85 @@
<?php
namespace App\Database\Seeds;
use CodeIgniter\Database\Seeder;
class AdminSeeder extends Seeder
{
public function run(): void
{
$db = \Config\Database::connect();
echo "Starting AdminSeeder...\n";
// Step 1: Check and create admin role if not exists
$roleBuilder = $db->table('roles');
$adminRole = $roleBuilder->where('name', 'admin')->get()->getRowArray();
if (!$adminRole) {
$roleData = [
'name' => 'admin',
];
$roleBuilder->insert($roleData);
$adminRoleId = $db->insertID();
echo "✓ Role 'admin' created successfully (ID: {$adminRoleId})\n";
} else {
$adminRoleId = $adminRole['id'];
echo "✓ Role 'admin' already exists (ID: {$adminRoleId})\n";
}
// Step 2: Check and create editor role if not exists (optional, but good practice)
$editorRole = $roleBuilder->where('name', 'editor')->get()->getRowArray();
if (!$editorRole) {
$roleData = [
'name' => 'editor',
];
$roleBuilder->insert($roleData);
echo "✓ Role 'editor' created successfully\n";
} else {
echo "✓ Role 'editor' already exists\n";
}
// Step 3: Check if admin user already exists
$userBuilder = $db->table('users');
$adminUser = $userBuilder->where('username', 'admin')->get()->getRowArray();
if (!$adminUser) {
// Create admin user
$userData = [
'role_id' => $adminRoleId,
'username' => 'admin',
'email' => 'admin@bapenda.local',
'phone_number' => '081234567890',
'password_hash' => password_hash('Admin@123', PASSWORD_DEFAULT),
'telegram_id' => null,
'is_active' => 1,
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'),
];
$userBuilder->insert($userData);
$userId = $db->insertID();
echo "✓ Admin user created successfully (ID: {$userId})\n";
echo " Username: admin\n";
echo " Email: admin@bapenda.local\n";
echo " Password: Admin@123\n";
} else {
// Update password to ensure it's correct (idempotent)
$passwordHash = password_hash('Admin@123', PASSWORD_DEFAULT);
$userBuilder->where('id', $adminUser['id'])->update([
'password_hash' => $passwordHash,
'role_id' => $adminRoleId,
'is_active' => 1,
'updated_at' => date('Y-m-d H:i:s'),
]);
echo "✓ Admin user already exists (ID: {$adminUser['id']})\n";
echo " Username: {$adminUser['username']}\n";
echo " Email: {$adminUser['email']}\n";
echo " Password: Admin@123 (updated)\n";
}
echo "\nAdminSeeder completed successfully!\n";
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace App\Database\Seeds;
use CodeIgniter\Database\Seeder;
class RolesSeeder extends Seeder
{
public function run()
{
//
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace App\Database\Seeds;
use CodeIgniter\Database\Seeder;
use App\Models\SettingsModel;
class SettingsSeeder extends Seeder
{
public function run()
{
$settingsModel = new SettingsModel();
echo "Starting SettingsSeeder...\n";
// Default settings
$defaultSettings = [
[
'key' => 'site_name',
'value' => 'Bapenda Garut',
'description' => 'Nama situs yang ditampilkan di sidebar dan judul halaman',
],
[
'key' => 'site_description',
'value' => 'Badan Pendapatan Daerah Kabupaten Garut',
'description' => 'Deskripsi singkat tentang situs',
],
];
foreach ($defaultSettings as $setting) {
$existing = $settingsModel->where('key', $setting['key'])->first();
if (!$existing) {
$settingsModel->insert($setting);
echo "✓ Setting '{$setting['key']}' created successfully\n";
} else {
echo "✓ Setting '{$setting['key']}' already exists\n";
}
}
echo "\nSettingsSeeder completed successfully!\n";
}
}