Skip to content

Commit e98b5a1

Browse files
committed
fix: sponsored projects parent project setup
Change-Id: I206e64e0a69ad850f0ee17c43b99c8fe4ccc066f
1 parent 09e71ce commit e98b5a1

2 files changed

Lines changed: 21 additions & 10 deletions

File tree

app/Http/Controllers/Apis/Protected/Main/OAuth2SponsoredProjectApiController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ function getUpdateValidationRules(array $payload): array
140140
*/
141141
protected function updateEntity($id, array $payload): IEntity
142142
{
143-
return $this->service->update($id, HTMLCleaner::cleanData($payload, ['description']));
143+
return $this->service->update(intval($id), HTMLCleaner::cleanData($payload, ['description']));
144144
}
145145

146146
/**

app/Services/Model/Imp/SponsoredProjectService.php

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public function add(array $payload): SponsoredProject
118118
public function update(int $project_id, array $payload): SponsoredProject
119119
{
120120
return $this->tx_service->transaction(function() use ($project_id, $payload){
121+
121122
if(isset($payload['name'])) {
122123
$name = trim($payload['name']);
123124
$formerProject = $this->repository->getByName($name);
@@ -128,20 +129,30 @@ public function update(int $project_id, array $payload): SponsoredProject
128129

129130
$sponsoredProject = $this->repository->getById($project_id);
130131

131-
if(is_null($sponsoredProject) || !$sponsoredProject instanceof SponsoredProject)
132+
if(!$sponsoredProject instanceof SponsoredProject)
132133
throw new EntityNotFoundException(sprintf("sponsored project %s not found.", $project_id));
133134

134135
SponsoredProjectFactory::populate($sponsoredProject, $payload);
135136

136-
if(array_key_exists('parent_project_id', $payload) && is_null($payload['parent_project_id'])) {
137-
$sponsoredProject->clearParentProject();
138-
} else if(isset($payload['parent_project_id'])) {
139-
$parentProject = $this->repository->getById(intval($payload['parent_project_id']));
140-
141-
if(is_null($parentProject) || !$parentProject instanceof SponsoredProject)
142-
throw new EntityNotFoundException(sprintf("sponsored project parent %s not found.", $project_id));
137+
if(isset($payload['parent_project_id'])) {
143138

144-
$sponsoredProject->setParentProject($parentProject);
139+
$parent_project_id = intval($payload['parent_project_id']);
140+
$sponsoredProject->clearParentProject();
141+
if($parent_project_id > 0) {
142+
$parentProject = $this->repository->getById(intval($payload['parent_project_id']));
143+
144+
if (!$parentProject instanceof SponsoredProject)
145+
throw new EntityNotFoundException
146+
(
147+
sprintf
148+
(
149+
"sponsored project parent %s not found.",
150+
$parent_project_id
151+
)
152+
);
153+
154+
$sponsoredProject->setParentProject($parentProject);
155+
}
145156
}
146157

147158
return $sponsoredProject;

0 commit comments

Comments
 (0)