Files
dockerfluxodecaixapro/modules/notes/database/migrations/001_insert_notes_module.php
T
2026-09-01 10:46:29 -03:00

113 lines
3.6 KiB
PHP
Executable File

<?php
/**
* SysCMS - Content Management System
*
* Copyright (c) 2026 Marco Costa
* All rights reserved.
*
* Author: Marco Costa
* Email: contato@syspanel.com.br
* Project: SysCMS
*
* This software is licensed, not sold.
* Permission is granted to use this software
* subject to the terms of the SysCMS Commercial License.
*
* Redistribution, sublicensing, resale, or
* disclosure of this software, in whole or in part,
* is strictly prohibited without prior written permission.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
*/
use Illuminate\Database\Capsule\Manager as Capsule;
/**
* Migration: Insert Notes Module
*/
class InsertNotesModule
{
/**
* Run the migrations.
*
* @return void
*/
public function up(): void
{
$moduleName = 'notes';
$moduleData = [
'modules_name' => $moduleName,
'modules_display_name' => 'Notes',
'modules_description' => 'Módulo de notas e links para o usuário.',
'modules_version' => '1.0.0',
'modules_author' => 'SysCMS Team',
'modules_ative' => 1,
'modules_public' => 0,
'modules_blocked' => 0,
'modules_dependencies' => json_encode(['users']),
'modules_permissions' => json_encode([
"notes.view",
"notes.create",
"notes.edit",
"notes.delete"
]),
'modules_settings' => json_encode([
"menu" => [
"dashboard" => [
"icon" => "bi bi-sticky",
"label" => "Notes",
"route" => "admin/notes",
"order" => 60,
"permission" => "notes.view"
]
]
]),
'modules_path' => 'modules/notes',
'modules_namespace' => 'Modules\\Notes',
'modules_icon' => 'bi bi-sticky',
'menu_side_bar' => 1,
'menu_nav_bar' => 0,
'modules_order' => 60,
'modules_install_date' => date('Y-m-d H:i:s'),
'modules_update_date' => date('Y-m-d H:i:s')
];
$existingModule = Capsule::table('modules')->where('modules_name', $moduleName)->first();
if (!$existingModule) {
$moduleId = Capsule::table('modules')->insertGetId($moduleData);
// Associate with all existing companies
if (Capsule::schema()->hasTable('bus')) {
$companies = Capsule::table('bus')->get();
foreach ($companies as $company) {
Capsule::table('bus_modules')->insert([
'bus_modules_bus_id' => $company->bus_id,
'bus_modules_module_id' => $moduleId,
'bus_modules_is_enabled' => 1,
'bus_modules_show_public_nav' => 0,
'bus_modules_show_dashboard_nav' => 1,
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s')
]);
}
}
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down(): void
{
$module = Capsule::table('modules')->where('modules_name', 'notes')->first();
if ($module) {
Capsule::table('bus_modules')->where('bus_modules_module_id', $module->modules_id)->delete();
Capsule::table('modules')->where('modules_id', $module->modules_id)->delete();
}
}
}