Skip to content

Commit b6b2e63

Browse files
feat(rewrite): Added endpoint for returning article to non published stag
1 parent 5a1d577 commit b6b2e63

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/SWP/Bundle/ContentBundle/Controller/ArticleController.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,6 @@ public function getAction($id): SingleResourceResponseInterface {
123123
public function getByCodeAction(Request $request): SingleResourceResponseInterface {
124124
// Extract parameters from the request
125125
$code = $request->query->get('code', '');
126-
//$tenantCode = $request->query->get('tenant_code', '');
127-
128-
//var_dump($code, $tenantCode);
129126

130127
$article = $this->entityManager->createQuery('SELECT a.id FROM SWP\Bundle\ContentBundle\Model\Article a where a.code = :code')
131128
->setParameter('code', $code)
@@ -137,6 +134,23 @@ public function getByCodeAction(Request $request): SingleResourceResponseInterfa
137134
throw new NotFoundHttpException('Article was not found');
138135
}
139136

137+
$article->setStatus('new');
138+
$article->setRouteId(null);
139+
$article->setPublishedAt(null);
140+
$article->setIsPublishable(false);
141+
$this->entityManager->flush();
142+
143+
// Find the swp_package associated with the article
144+
$swpPackage = $article->getPackage();
145+
146+
if (null !== $swpPackage) {
147+
// Update the swp_package fields
148+
$swpPackage->setStatus('new');
149+
$swpPackage->setServices([]);
150+
$swpPackage->setFirstPublishedAt(null);
151+
$this->entityManager->flush();
152+
}
153+
140154
return new SingleResourceResponse($article);
141155
}
142156

0 commit comments

Comments
 (0)