Browse Source

Fix the Info Identities saving with an upsert

Update the dependencies
pull/1228/head
Timothée Jaussoin 2 years ago
parent
commit
bf5d247ea0
  1. 18
      app/Identity.php
  2. 10
      app/Info.php
  3. 61
      composer.lock

18
app/Identity.php

@ -6,7 +6,7 @@ use Movim\Model;
class Identity extends Model class Identity extends Model
{ {
protected $primaryKey = ['info_id', 'category', 'type'];
public $primaryKey = ['info_id', 'category', 'type'];
public $incrementing = false; public $incrementing = false;
public function info() public function info()
@ -14,14 +14,16 @@ class Identity extends Model
return $this->belongsTo('App\Info'); return $this->belongsTo('App\Info');
} }
public function save(array $options = [])
public static function saveMany($identities)
{ {
try {
parent::save($options);
} catch (\Exception $e) {
/**
* Existing info are saved in the DB
*/
if ($identities->isNotEmpty()) {
Identity::upsert($identities->map(function (Identity $identity) {
return [
'info_id' => $identity->info_id,
'category' => $identity->category,
'type' => $identity->type,
];
})->all(), $identities->first()->primaryKey);
} }
} }
} }

10
app/Info.php

@ -26,11 +26,13 @@ class Info extends Model
unset($this->identities); unset($this->identities);
parent::save($options); parent::save($options);
if ($this->freshIdentities) {
$this->identities()->delete();
$this->identities()->saveMany($this->freshIdentities);
}
if ($this->freshIdentities && $this->freshIdentities->isNotEmpty()) {
$this->freshIdentities->each(function ($row) {
$row->info_id = $this->id;
});
Identity::saveMany($this->freshIdentities);
}
} catch (\Exception $e) { } catch (\Exception $e) {
/** /**
* Existing info are saved in the DB * Existing info are saved in the DB

61
composer.lock

@ -1793,7 +1793,7 @@
}, },
{ {
"name": "illuminate/bus", "name": "illuminate/bus",
"version": "v10.14.1",
"version": "v10.15.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/illuminate/bus.git", "url": "https://github.com/illuminate/bus.git",
@ -1846,16 +1846,16 @@
}, },
{ {
"name": "illuminate/collections", "name": "illuminate/collections",
"version": "v10.14.1",
"version": "v10.15.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/illuminate/collections.git", "url": "https://github.com/illuminate/collections.git",
"reference": "7fdccaabe533b7d86e59d278901aac075aae0abc"
"reference": "fba281693edb2caf429c872d59770a28a4e01595"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/illuminate/collections/zipball/7fdccaabe533b7d86e59d278901aac075aae0abc",
"reference": "7fdccaabe533b7d86e59d278901aac075aae0abc",
"url": "https://api.github.com/repos/illuminate/collections/zipball/fba281693edb2caf429c872d59770a28a4e01595",
"reference": "fba281693edb2caf429c872d59770a28a4e01595",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1897,11 +1897,11 @@
"issues": "https://github.com/laravel/framework/issues", "issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework" "source": "https://github.com/laravel/framework"
}, },
"time": "2023-06-23T21:58:46+00:00"
"time": "2023-07-08T21:20:28+00:00"
}, },
{ {
"name": "illuminate/conditionable", "name": "illuminate/conditionable",
"version": "v10.14.1",
"version": "v10.15.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/illuminate/conditionable.git", "url": "https://github.com/illuminate/conditionable.git",
@ -1947,7 +1947,7 @@
}, },
{ {
"name": "illuminate/container", "name": "illuminate/container",
"version": "v10.14.1",
"version": "v10.15.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/illuminate/container.git", "url": "https://github.com/illuminate/container.git",
@ -1998,7 +1998,7 @@
}, },
{ {
"name": "illuminate/contracts", "name": "illuminate/contracts",
"version": "v10.14.1",
"version": "v10.15.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/illuminate/contracts.git", "url": "https://github.com/illuminate/contracts.git",
@ -2046,16 +2046,16 @@
}, },
{ {
"name": "illuminate/database", "name": "illuminate/database",
"version": "v10.14.1",
"version": "v10.15.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/illuminate/database.git", "url": "https://github.com/illuminate/database.git",
"reference": "0bdd76ef2d761786b33cb968d29b985721c70260"
"reference": "f40768ccf945a494c005000f348a13e8828a2621"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/illuminate/database/zipball/0bdd76ef2d761786b33cb968d29b985721c70260",
"reference": "0bdd76ef2d761786b33cb968d29b985721c70260",
"url": "https://api.github.com/repos/illuminate/database/zipball/f40768ccf945a494c005000f348a13e8828a2621",
"reference": "f40768ccf945a494c005000f348a13e8828a2621",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2111,11 +2111,11 @@
"issues": "https://github.com/laravel/framework/issues", "issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework" "source": "https://github.com/laravel/framework"
}, },
"time": "2023-06-25T14:36:40+00:00"
"time": "2023-07-08T21:13:43+00:00"
}, },
{ {
"name": "illuminate/events", "name": "illuminate/events",
"version": "v10.14.1",
"version": "v10.15.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/illuminate/events.git", "url": "https://github.com/illuminate/events.git",
@ -2170,7 +2170,7 @@
}, },
{ {
"name": "illuminate/macroable", "name": "illuminate/macroable",
"version": "v10.14.1",
"version": "v10.15.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/illuminate/macroable.git", "url": "https://github.com/illuminate/macroable.git",
@ -2216,7 +2216,7 @@
}, },
{ {
"name": "illuminate/pipeline", "name": "illuminate/pipeline",
"version": "v10.14.1",
"version": "v10.15.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/illuminate/pipeline.git", "url": "https://github.com/illuminate/pipeline.git",
@ -2264,16 +2264,16 @@
}, },
{ {
"name": "illuminate/support", "name": "illuminate/support",
"version": "v10.14.1",
"version": "v10.15.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/illuminate/support.git", "url": "https://github.com/illuminate/support.git",
"reference": "b1374932ec9a90bc223f9c5a12beba4cf909f4f4"
"reference": "aa6c012527c05d1c2f11df0b84d9ba8742d2b88f"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/illuminate/support/zipball/b1374932ec9a90bc223f9c5a12beba4cf909f4f4",
"reference": "b1374932ec9a90bc223f9c5a12beba4cf909f4f4",
"url": "https://api.github.com/repos/illuminate/support/zipball/aa6c012527c05d1c2f11df0b84d9ba8742d2b88f",
"reference": "aa6c012527c05d1c2f11df0b84d9ba8742d2b88f",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2331,7 +2331,7 @@
"issues": "https://github.com/laravel/framework/issues", "issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework" "source": "https://github.com/laravel/framework"
}, },
"time": "2023-06-27T18:33:36+00:00"
"time": "2023-07-09T12:11:55+00:00"
}, },
{ {
"name": "league/commonmark", "name": "league/commonmark",
@ -4363,23 +4363,24 @@
}, },
{ {
"name": "react/promise", "name": "react/promise",
"version": "v2.10.0",
"version": "v3.0.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/reactphp/promise.git", "url": "https://github.com/reactphp/promise.git",
"reference": "f913fb8cceba1e6644b7b90c4bfb678ed8a3ef38"
"reference": "c86753c76fd3be465d93b308f18d189f01a22be4"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/reactphp/promise/zipball/f913fb8cceba1e6644b7b90c4bfb678ed8a3ef38",
"reference": "f913fb8cceba1e6644b7b90c4bfb678ed8a3ef38",
"url": "https://api.github.com/repos/reactphp/promise/zipball/c86753c76fd3be465d93b308f18d189f01a22be4",
"reference": "c86753c76fd3be465d93b308f18d189f01a22be4",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=5.4.0"
"php": ">=7.1.0"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^9.5 || ^5.7 || ^4.8.36"
"phpstan/phpstan": "1.10.20 || 1.4.10",
"phpunit/phpunit": "^9.5 || ^7.5"
}, },
"type": "library", "type": "library",
"autoload": { "autoload": {
@ -4423,7 +4424,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/reactphp/promise/issues", "issues": "https://github.com/reactphp/promise/issues",
"source": "https://github.com/reactphp/promise/tree/v2.10.0"
"source": "https://github.com/reactphp/promise/tree/v3.0.0"
}, },
"funding": [ "funding": [
{ {
@ -4431,7 +4432,7 @@
"type": "open_collective" "type": "open_collective"
} }
], ],
"time": "2023-05-02T15:15:43+00:00"
"time": "2023-07-11T16:12:49+00:00"
}, },
{ {
"name": "react/promise-timer", "name": "react/promise-timer",

Loading…
Cancel
Save