-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add column size in LazaretFiles table
add command bin/maintenance lazaret:set_sizes
- Loading branch information
Showing
4 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
lib/Alchemy/Phrasea/Command/Maintenance/LazaretFilesSetSizeCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
|
||
->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); | ||
|
||
$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))); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters