mirror of
https://bitbucket.org/studiotem/jandl-taskmanager-app.git
synced 2026-10-21 14:29:34 +00:00
no message
This commit is contained in:
1 parent
b076052f4b
commit
8affdbe955
9 files changed
+257
-12
No files matched your search
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user