Skip to content

Commit 0636035

Browse files
committed
rework deployments
1 parent d49bb50 commit 0636035

File tree

1 file changed

+7
-26
lines changed

1 file changed

+7
-26
lines changed

glued/Controllers/IfController.php

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,13 @@ public function getServices(Request $request, Response $response, array $args =
8282
return $response->withJson($uniqueServices);
8383
}
8484

85-
86-
public function deployments_r1(Request $request, Response $response, array $args = []): Response {
87-
echo $this->ifutils->getDeploymentsJson($args['deploy'] ?? false);
88-
return $response->withHeader('Content-Type', 'application/json');
85+
public function getDeployments(Request $request, Response $response, array $args = []): Response
86+
{
87+
$db = new \Glued\Lib\Sql($this->pg, 'if__deployments');
88+
$db->selectModifier = "jsonb_build_object('uri', concat('{$this->settings['glued']['baseuri']}/{$this->settings['routes']['be_if_svc_s4s']['pattern']}v1/', doc->>'uuid'), 'nonce', nonce, 'created_at', created_at, 'updated_at', updated_at) || ";
89+
$data = $db->getAll();
90+
//$db->stmt->debugDumpParams();
91+
return $response->withJson($data);
8992
}
9093

9194
}
@@ -136,28 +139,6 @@ public function services_r1(Request $request, Response $response, array $args =
136139
return $response->withJson($payload);
137140
}
138141
139-
public function deployments_c1(Request $request, Response $response, array $args = []): Response
140-
{
141-
$params = $request->getQueryParams();
142-
$contentTypeHeader = $request->getHeaderLine('Content-Type') ?? '';
143-
if ($contentTypeHeader !== 'application/json') { throw new \Exception('Invalid Content-Type. Please set `Content-Type: application/json', 400); }
144-
$payload = $request->getParsedBody();
145-
foreach ($payload as $item) {
146-
$svc_uuid = \Ramsey\Uuid\Uuid::uuid4()->toString();
147-
$svc_data = json_encode($item['deployment']);
148-
$res = $this->mysqli->execute_query('SELECT bin_to_uuid(`c_uuid`,true) as svc_uuid FROM `t_if__deployments` WHERE JSON_CONTAINS(c_data, ?, "$")', [$svc_data]);
149-
foreach ($res as $r) { $svc_uuid = $r['svc_uuid']; break; }
150-
$this->mysqli->execute_query("INSERT INTO `t_if__deployments` ( `c_uuid`, `c_data` ) VALUES ( UUID_TO_BIN(?, true), ? ) ON DUPLICATE KEY UPDATE `c_data` = values(`c_data`)", [$svc_uuid, $svc_data]);
151-
152-
foreach ($item['actions'] as $a) {
153-
$act_uuid = \Ramsey\Uuid\Uuid::uuid4()->toString();
154-
$data = ['c_deployment_uuid' => $svc_uuid, 'c_uuid' => $act_uuid, 'c_data' => json_encode($a)];
155-
$this->db->rawQuery('INSERT INTO `t_if__actions` ( `c_deployment_uuid`, `c_uuid`, `c_data` ) VALUES ( UUID_TO_BIN(?, true), UUID_TO_BIN(?, true), ? ) ON DUPLICATE KEY UPDATE `c_data` = VALUES(`c_data`)', $data);
156-
}
157-
}
158-
return $response->withJson($payload);
159-
}
160-
161142
162143
public function queue_r1(Request $request, Response $response, array $args = []): Response
163144
{

0 commit comments

Comments
 (0)