edms2023/app/Test.php

201 lines
7.0 KiB
PHP
Raw Permalink Normal View History

2023-09-14 20:59:46 +00:00
<?php
namespace App;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
// use Illuminate\Database\Migrations\Migration;
use App\Permission;
use DB;
class Test
{
public function handle()
{
$this->callMigrationsForFile();
$this->addPermissions();
}
public function oldToDo()
{
echo "Begin: ============= call Update Reg Number =================\n";
// $this->updateRegNumber();
echo "End: ========================================================\n";
echo "Begin: ============= call RegNumber Migration =================\n";
// $this->dbChanges();
$this->addAPIPermission();
echo "End: ========================================================\n";
// $this->dbOptimization();
}
private function addPermissions()
{
Permission::create(['name'=>'advanced dashboard', 'description'=>'umumy hatlaryn hasabaty we sanawlary, dashboard']);
}
private function callMigrationsForFile()
{
Schema::dropIfExists('shared_files');
Schema::dropIfExists('directories');
Schema::dropIfExists('my_files');
DB::table('migrations')->whereRaw('migration regexp("my_files") or migration regexp("shared_files")')->delete();
\Artisan::call('migrate', [
'--path' => 'database/migrations/2022_03_08_073216_create_my_files_table.php',
]);
\Artisan::call('migrate', [
'--path' => 'database/migrations/2022_03_08_081633_create_shared_files_table.php',
]);
}
private function dbOptimization()
{
DB::table('workflow_documents')->where('delivery_type_id', 0)->update(['delivery_type_id' => 2]);
Schema::table('users', function(Blueprint $table){
$table->index('department_id');
});
Schema::table('reg_numbers', function(Blueprint $table){
$table->foreign('user_id')->references('id')->on('users');
});
Schema::table('comments', function(Blueprint $table){
$table->foreign('workflow_document_id')->references('id')->on('workflow_documents');
$table->foreign('user_id')->references('id')->on('users');
});
Schema::table('workflow_documents', function(Blueprint $table){
$table->foreign('priority_id')->references('id')->on('priorities');
$table->foreign('delivery_type_id')->references('id')->on('delivery_types');
$table->foreign('document_type_id')->references('id')->on('document_types');
$table->foreign('creator_id')->references('id')->on('users');
$table->index('workflow_type_id');
});
Schema::table('workflow_document_files', function(Blueprint $table){
$table->index('workflow_document_id');
$table->foreign('uploaded_by')->references('id')->on('users');
});
Schema::table('workflow_document_senders', function(Blueprint $table){
$table->foreign('workflow_document_id')->references('id')->on('workflow_documents');
$table->foreign('contact_id')->references('id')->on('contacts');
});
Schema::table('workflow_document_users', function(Blueprint $table){
$table->foreign('workflow_document_id')->references('id')->on('workflow_documents');
$table->index('process_id');
});
Schema::table('workflow_document_process', function(Blueprint $table){
$table->foreign('workflow_document_id')->references('id')->on('workflow_documents');
$table->foreign('user_id')->references('id')->on('users');
$table->foreign('assign_by')->references('id')->on('users');
});
}
private function dbChangesPromotionxx()
{
if(!Schema::hasColumn('workflow_document_users', 'promotion_user'))
{
Schema::table('workflow_document_users', function(Blueprint $table){
$table->unsignedInteger('promotion_user')->default(null)->after('promotion_id');
});
}
}
private function updateRegNumber()
{
$wds = WorkflowDocument::all();
foreach($wds as $wd)
{
$wd->registration_number = preg_replace('/REG-/', '', $wd->registration_number);
$wd->save();
}
}
private function callMigrations()
{
Schema::dropIfExists('notifications');
Schema::dropIfExists('user_notifications');
Schema::dropIfExists('reset_document_numbers');
\Artisan::call('migrate', [
'--path' => 'database/migrations/2021_03_22_151904_create_comments_table.php',
'--path' => 'database/migrations/2021_04_03_095730_create_reg_numbers_table.php',
'--path' => 'database/migrations/2021_04_03_120440_create_reg_number_seq_table.php',
'--path' => 'database/migrations/2021_04_09_121638_create_notifications_table.php'
]);
}
private function dbChanges()
{
if(!Schema::hasColumn('settings', 'temporary_registration_number_prefix'))
{
Schema::table('settings', function(Blueprint $table){
$table->string('temporary_registration_number_prefix')->default('TMP')->after('internal_registration_number_prefix');
});
}
DB::statement('alter table workflow_document_process modify assign_date datetime');
DB::table('reg_number_seq')->insert(['seq_inc'=>0, 'seq_out'=>0, 'seq_int'=>0, 'seq_tmp'=>0]);
if(!Schema::hasColumn('document_types', 'incoming'))
{
Schema::table('document_types', function(Blueprint $table){
$table->boolean('incoming')->default(1);
});
}
if(!Schema::hasColumn('document_types', 'outgoing'))
{
Schema::table('document_types', function(Blueprint $table){
$table->boolean('outgoing')->default(1);
});
}
if(!Schema::hasColumn('document_types', 'internal'))
{
Schema::table('document_types', function(Blueprint $table){
$table->boolean('internal')->default(1);
});
}
DB::table('document_types')->update([
'incoming' => 1,
'outgoing' => 1,
'internal' => 1,
]);
}
private function addAPIPermission()
{
Permission::create([
'id' => 12,
'name' => 'view API Documents',
'description' => 'view api documents'
]);
Permission::create([
'id' => 13,
'name' => 'send API Documents',
'description' => 'send api documents'
]);
}
public function addColumnsToSharedFiles()
{
Schema::table('shared_files', function(Blueprint $table){
$table->unsignedInteger('parent_id')->default(0)->after('permission');
$table->unsignedInteger('shared_by')->after('by_admin');
$table->text('path_to_root')->nullable();
$table->boolean('show_home')->default(1);
});
}
}