no message

This commit is contained in:
StudioTem committed 2023-03-10 10:02:25 +01:00
1 parent b076052f4b
commit 8affdbe955
9 files changed
+257 -12

No files matched your search

+3 -2
View File
@@ -29,7 +29,8 @@ class Api
private static function doRequest($command)
{
$response = Http::withOptions([
$response = Http::timeout(60)
->withOptions([
'debug' => true,
'verify' => false,
])->withBasicAuth(self::$username, self::$password)
@@ -52,6 +53,6 @@ class Api
public static function getProjects()
{
return self::doRequest('TM_GET_CLIENTS')['projects'];
return self::doRequest('TM_GET_PROJECTS')['projects'];
}
}
+42 -6
View File
@@ -35,8 +35,8 @@ class KaratService
})->map(function ($item) {
$arrayToInsert = $item->toArray();
$arrayToInsert['created_at'] = Carbon::now();
$arrayToInsert['updated_at'] = Carbon::now();
$arrayToInsert['created_at'] = Carbon::now()->toDateTimeString();
$arrayToInsert['updated_at'] = Carbon::now()->toDateTimeString();
return $arrayToInsert;
});
@@ -71,8 +71,8 @@ class KaratService
})->map(function ($item) {
$arrayToInsert = $item->toArray();
$arrayToInsert['created_at'] = Carbon::now();
$arrayToInsert['updated_at'] = Carbon::now();
$arrayToInsert['created_at'] = Carbon::now()->toDateTimeString();
$arrayToInsert['updated_at'] = Carbon::now()->toDateTimeString();
return $arrayToInsert;
});
@@ -82,19 +82,55 @@ class KaratService
private function removeClientsThatAreNotInKaratAnymore( Collection $karatClients, Collection $dbClients )
{
dd('finish me');
$codesInDbThatAreNotInKaratAnymore = $dbClients->pluck('code' )->diff( $karatClients->pluck('code'));
\App\Models\Client::whereIn('code', $codesInDbThatAreNotInKaratAnymore)->delete();
}
public function syncProjects()
{
$karatProjects = Project::all();
$array = [];
foreach ( $karatProjects as $project ) {
$array[$project->code][] = $project->code;
}
foreach ( $array as $key => $item ) {
if ( count($item) > 1 ) echo ($key) . PHP_EOL;
}
dd('here');
$dbProjects = \App\Models\Project::all();
$this->insertProjectsFromKarat($karatProjects, $dbProjects);
$this->insertProjectsFromKarat($karatProjects->take(200), $dbProjects);
dd('here');
$this->removeProjectsThatAreNotInKaratAnymore($karatProjects, $dbProjects);
}
private function insertProjectsFromKarat( Collection $karatProjects, Collection $dbProjects )
{
$projectsToSkip = $dbProjects->pluck('code' )->intersect( $karatProjects->pluck('code'));
$karatProjectsToInsert = $karatProjects->reject(function ($item) use ($projectsToSkip) {
return $projectsToSkip->contains($item->code);
})->map(function ($item) {
$arrayToInsert = $item->toArray();
$dbClient = \App\Models\Client::where('code', $item->client_id)->first();
$arrayToInsert['created_at'] = Carbon::now()->toDateTimeString();
$arrayToInsert['updated_at'] = Carbon::now()->toDateTimeString();
$arrayToInsert['client_id'] = ($dbClient) ? $dbClient->id : null;
// $arrayToInsert['client_id'] = 12;
return $arrayToInsert;
});
\App\Models\Project::insert($karatProjectsToInsert->toArray());
}
}
+4 -4
View File
@@ -5,12 +5,12 @@ namespace App\Services\Karat;
class Project extends Api {
public $code;
public $name;
public $client;
public $client_id;
public function __construct($code, $name, $client) {
public function __construct($code, $name, $client_id) {
$this->code = $code;
$this->name = $name;
$this->client = $client;
$this->client_id = $client_id;
}
public static function all() {
@@ -25,7 +25,7 @@ class Project extends Api {
return [
'code' => $this->code,
'name' => $this->name,
'client' => $this->client,
'client_id' => $this->client_id,
];
}