Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
4rthem committed Oct 17, 2023
1 parent 014add7 commit 7a5391c
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 47 deletions.
4 changes: 0 additions & 4 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ services:
- ./expose/api:/srv/app
- ./expose/api/docker/supervisor:/etc/supervisor.d

expose-cron:
volumes:
- ./expose/api:/srv/app

uploader-api-php:
environment:
- XDEBUG_ENABLED
Expand Down
5 changes: 0 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -533,11 +533,6 @@ services:
extra_hosts:
- zippy-svc.${PHRASEA_DOMAIN}:${PS_GATEWAY_IP}

expose-cron:
extends:
service: expose-worker
command: ['/srv/app/docker/cron/start-cron.sh']

expose-api-nginx:
profiles:
- expose
Expand Down
3 changes: 0 additions & 3 deletions expose/api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,4 @@ RUN apk add --no-cache \

COPY docker/supervisor/* /etc/supervisor.d/

RUN touch /var/log/cron.log \
&& chmod 755 /srv/app/docker/cron/scripts/*.sh

CMD ["/bin/sh", "-c", "/usr/bin/supervisord -n"]
1 change: 0 additions & 1 deletion expose/api/docker/cron/app-crontab

This file was deleted.

4 changes: 0 additions & 4 deletions expose/api/docker/cron/scripts/matomo-sync-phraseanet.sh

This file was deleted.

13 changes: 0 additions & 13 deletions expose/api/docker/cron/start-cron.sh

This file was deleted.

70 changes: 53 additions & 17 deletions expose/api/src/Matomo/PhraseanetClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,67 @@ public function patchField(array $stat): void
unset($stat['idsubdatatable']);

try {
$res = $this->client->request('PATCH', sprintf('/api/v3/records/%s/%s/', $baseId, $recordId), [
$data = $this->client->request('GET', sprintf('/api/v3/records/%s/%s/', $baseId, $recordId), [
'headers' => [
'Authorization' => 'OAuth '.$this->authToken,
'Accept' => 'application/vnd.phraseanet.record-extended+json',
],
'json' => [
'metadatas' => [
[
'field_name' => 'MatomoMediaMetrics',
'value' => \GuzzleHttp\json_encode($stat)
]
]
]
]);
$code = $res->getStatusCode();
if (in_array($code, [200, 404], true)) {
return;
}

throw new \Exception(sprintf('Got invalid HTTP response code %d: %s', $code, $res->getContent(false)));
])->toArray();
} catch (HttpExceptionInterface $e) {
if (404 !== $e->getResponse()->getStatusCode()) {
if (404 === $e->getResponse()->getStatusCode()) {
return;
}

throw $e;
}

$currentAttr = [];
foreach ($data['response']['metadata'] as $meta) {
if ('MatomoMediaMetrics' === $meta['name']) {
$currentAttr = json_decode($meta['value']['value'], true);
break;
}
}

if (!shouldUpdate($currentAttr, $stat)) {
return;
}

$res = $this->client->request('PATCH', sprintf('/api/v3/records/%s/%s/', $baseId, $recordId), [
'headers' => [
'Authorization' => 'OAuth '.$this->authToken,
],
'json' => [
'metadatas' => [
[
'field_name' => 'MatomoMediaMetrics',
'value' => \GuzzleHttp\json_encode($stat)
]
]
]
]);

$code = $res->getStatusCode();
if (200 !== $code) {
throw new \Exception(sprintf('Got invalid HTTP response code %d: %s', $code, $res->getContent(false)));
}
}
}

function shouldUpdate(array $current, array $new): bool {
if (empty($current)) {
return true;
}

if (count($new) !== count($current)) {
return true;
}

foreach ($new as $k => $v) {
if (!isset($current[$k]) || $current[$k] !== $v) {
return true;
}
}

return false;
}
4 changes: 4 additions & 0 deletions expose/api/src/Storage/AssetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public function createAsset(
$asset->setSlug($options['slug']);
}

if (isset($options['title'])) {
$asset->setTitle($options['title']);
}

if (isset($options['description'])) {
$asset->setDescription($options['description']);
}
Expand Down

0 comments on commit 7a5391c

Please sign in to comment.