Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHRAS-4085_data-volumes-api #4529

Merged
merged 12 commits into from
Jul 17, 2024
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 @@ -405,6 +405,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,54 @@
<?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-run', null, InputOption::VALUE_NONE, 'dry run, count')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better use --dry like in recent commands

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok


->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-run')) {
/** @var LazaretFile $lazaretNullSize */
foreach ($lazaretNullSizes as $lazaretNullSize) {
$lazaretFileName = $path .'/'.$lazaretNullSize->getFilename();
$media = $this->container->getMediaFromUri($lazaretFileName);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrap in a try/catch just in case of missing file, and set size to 0 in case of error.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok


$lazaretNullSize->setSize($media->getFile()->getSize());
$em->persist($lazaretNullSize);
}

$em->flush();

$output->writeln(sprintf("%d LazaretFiles done!", count($lazaretNullSizes)));
} else {
$output->writeln(sprintf("%d LazaretFiles to update!", count($lazaretNullSizes)));
}
}
}
28 changes: 28 additions & 0 deletions lib/Alchemy/Phrasea/Model/Entities/LazaretFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ class LazaretFile
*/
private $session;

/**
* @ORM\Column(type="bigint", nullable=true)
*/
private $size;

/**
* Constructor
*/
Expand Down Expand Up @@ -322,6 +327,29 @@ public function setUpdated(\DateTime $updated)
return $this;
}

/**
* Set size
*
* @param integer $size
* @return LazaretFile
*/
public function setSize($size)
{
$this->size = $size;

return $this;
}

/**
* Get size
*
* @return integer
*/
public function getSize()
{
return $this->size;
}

/**
* Get updated
*
Expand Down