Skip to content

Commit

Permalink
PHRAS-4085_data-volumes-api (#4529)
Browse files Browse the repository at this point in the history
* new route `/api/v3/monitor/data/?oauth_token=xxx&blocksize=16ko`

* add `unit` parameter for size restults ('', 'o', ''ko', 'mo', 'go'), default '' (=octets, same as 'o')

* new units "octet", "octets"

* fix round error (don't sum rounded values: round the real sum)

* add infos about downloads;
round sizes to 2 decimals

* add `...&details=1` url parameter to get values by collection and subdef name

* add column size in LazaretFiles table

add command bin/maintenance lazaret:set_sizes

* add api monitor data by databox

* fix size
  • Loading branch information
jygaulier authored Jul 17, 2024
1 parent 1979ad0 commit 5556462
Show file tree
Hide file tree
Showing 6 changed files with 429 additions and 0 deletions.
3 changes: 3 additions & 0 deletions bin/maintenance
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use Alchemy\Phrasea\Command\Maintenance\CleanRightsCommand;
use Alchemy\Phrasea\Command\Maintenance\CleanWebhookLogsCommand;
use Alchemy\Phrasea\Command\Maintenance\CleanWorkerRunningJobCommand;
use Alchemy\Phrasea\Command\Maintenance\SessionsCommand;
use Alchemy\Phrasea\Command\Maintenance\LazaretFilesSetSizeCommand;

require_once __DIR__ . '/../lib/autoload.php';

Expand Down Expand Up @@ -59,4 +60,6 @@ $cli->command(new CleanLogViewCommand());

$cli->command(new CleanWebhookLogsCommand());

$cli->command(new LazaretFilesSetSizeCommand());

$cli->run();
2 changes: 2 additions & 0 deletions lib/Alchemy/Phrasea/Border/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,8 @@ protected function createLazaret(File $file, Visa $visa, LazaretSession $session

$lazaretFile->setSession($session);

$lazaretFile->setSize($file->getFile()->getSize());

$this->app['orm.em']->persist($lazaretFile);

foreach ($file->getAttributes() as $fileAttribute) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace Alchemy\Phrasea\Command\Maintenance;

use Alchemy\Phrasea\Command\Command;
use Alchemy\Phrasea\Model\Entities\LazaretFile;
use Alchemy\Phrasea\Model\Repositories\LazaretFileRepository;
use Doctrine\ORM\EntityManager;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class LazaretFilesSetSizeCommand extends Command
{
public function __construct()
{
parent::__construct('lazaret:set_sizes');

$this
->setDescription('Set the null size in the LazaretFiles table')
->addOption('dry', null, InputOption::VALUE_NONE, 'dry run, count')

->setHelp('');
}

public function doExecute(InputInterface $input, OutputInterface $output)
{
/** @var LazaretFileRepository $lazaretRepository */
$lazaretRepository = $this->container['repo.lazaret-files'];

$lazaretNullSizes = $lazaretRepository->findBy(['size' => null]);

$path = $this->container['tmp.lazaret.path'];
/** @var EntityManager $em */
$em = $this->container['orm.em'];

if (!$input->getOption('dry')) {
/** @var LazaretFile $lazaretNullSize */
foreach ($lazaretNullSizes as $lazaretNullSize) {
try {
$lazaretFileName = $path .'/'.$lazaretNullSize->getFilename();
$media = $this->container->getMediaFromUri($lazaretFileName);
$size = $media->getFile()->getSize();
} catch (\Exception $e) {
$size = 0;
}

$lazaretNullSize->setSize($size);
$em->persist($lazaretNullSize);
}

$em->flush();

$output->writeln(sprintf("%d LazaretFiles done!", count($lazaretNullSizes)));
} else {
$output->writeln(sprintf("%d LazaretFiles to update!", count($lazaretNullSizes)));
}
}
}
Loading

0 comments on commit 5556462

Please sign in to comment.