22
33namespace Pterodactyl \Services \Eggs \Sharing ;
44
5+ use Pterodactyl \Models \Egg ;
56use Illuminate \Http \UploadedFile ;
67use Illuminate \Database \ConnectionInterface ;
78use Pterodactyl \Contracts \Repository \EggRepositoryInterface ;
@@ -46,15 +47,15 @@ public function __construct(
4647 /**
4748 * Update an existing Egg using an uploaded JSON file.
4849 *
49- * @param int $egg
50+ * @param \Pterodactyl\Models\Egg $egg
5051 * @param \Illuminate\Http\UploadedFile $file
5152 *
5253 * @throws \Pterodactyl\Exceptions\Model\DataValidationException
5354 * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
5455 * @throws \Pterodactyl\Exceptions\Service\Egg\BadJsonFormatException
5556 * @throws \Pterodactyl\Exceptions\Service\InvalidFileUploadException
5657 */
57- public function handle (int $ egg , UploadedFile $ file )
58+ public function handle (Egg $ egg , UploadedFile $ file )
5859 {
5960 if ($ file ->getError () !== UPLOAD_ERR_OK || ! $ file ->isFile ()) {
6061 throw new InvalidFileUploadException (
@@ -81,7 +82,7 @@ public function handle(int $egg, UploadedFile $file)
8182 }
8283
8384 $ this ->connection ->beginTransaction ();
84- $ this ->repository ->update ($ egg , [
85+ $ this ->repository ->update ($ egg-> id , [
8586 'author ' => object_get ($ parsed , 'author ' ),
8687 'name ' => object_get ($ parsed , 'name ' ),
8788 'description ' => object_get ($ parsed , 'description ' ),
@@ -99,19 +100,19 @@ public function handle(int $egg, UploadedFile $file)
99100 // Update Existing Variables
100101 collect ($ parsed ->variables )->each (function ($ variable ) use ($ egg ) {
101102 $ this ->variableRepository ->withoutFreshModel ()->updateOrCreate ([
102- 'egg_id ' => $ egg ,
103+ 'egg_id ' => $ egg-> id ,
103104 'env_variable ' => $ variable ->env_variable ,
104105 ], collect ($ variable )->except (['egg_id ' , 'env_variable ' ])->toArray ());
105106 });
106107
107108 $ imported = collect ($ parsed ->variables )->pluck ('env_variable ' )->toArray ();
108- $ existing = $ this ->variableRepository ->setColumns (['id ' , 'env_variable ' ])->findWhere ([['egg_id ' , '= ' , $ egg ]]);
109+ $ existing = $ this ->variableRepository ->setColumns (['id ' , 'env_variable ' ])->findWhere ([['egg_id ' , '= ' , $ egg-> id ]]);
109110
110111 // Delete variables not present in the import.
111112 collect ($ existing )->each (function ($ variable ) use ($ egg , $ imported ) {
112113 if (! in_array ($ variable ->env_variable , $ imported )) {
113114 $ this ->variableRepository ->deleteWhere ([
114- ['egg_id ' , '= ' , $ egg ],
115+ ['egg_id ' , '= ' , $ egg-> id ],
115116 ['env_variable ' , '= ' , $ variable ->env_variable ],
116117 ]);
117118 }
0 commit comments