mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-14 05:23:21 +00:00
Fixup build-missing-subdef command.
PHRAS-855
This commit is contained in:
@@ -11,7 +11,8 @@
|
|||||||
|
|
||||||
namespace Alchemy\Phrasea\Command;
|
namespace Alchemy\Phrasea\Command;
|
||||||
|
|
||||||
use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
|
use Alchemy\Phrasea\Media\SubdefGenerator;
|
||||||
|
use Symfony\Component\Console\Helper\ProgressBar;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
@@ -35,14 +36,19 @@ class BuildMissingSubdefs extends Command
|
|||||||
protected function doExecute(InputInterface $input, OutputInterface $output)
|
protected function doExecute(InputInterface $input, OutputInterface $output)
|
||||||
{
|
{
|
||||||
$start = microtime(true);
|
$start = microtime(true);
|
||||||
|
$progressBar = new ProgressBar($output);
|
||||||
$n = 0;
|
$n = 0;
|
||||||
|
|
||||||
|
/** @var SubdefGenerator $subdefGenerator */
|
||||||
|
$subdefGenerator = $this->container['subdef.generator'];
|
||||||
|
|
||||||
foreach ($this->container->getDataboxes() as $databox) {
|
foreach ($this->container->getDataboxes() as $databox) {
|
||||||
$sql = 'SELECT record_id FROM record WHERE parent_record_id = 0';
|
$sql = 'SELECT record_id FROM record WHERE parent_record_id = 0';
|
||||||
$stmt = $databox->get_connection()->prepare($sql);
|
$stmt = $databox->get_connection()->prepare($sql);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
$rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||||
$stmt->closeCursor();
|
$stmt->closeCursor();
|
||||||
|
$progressBar->start(count($rs));
|
||||||
|
|
||||||
foreach ($rs as $row) {
|
foreach ($rs as $row) {
|
||||||
$record = $databox->get_record($row['record_id']);
|
$record = $databox->get_record($row['record_id']);
|
||||||
@@ -50,7 +56,7 @@ class BuildMissingSubdefs extends Command
|
|||||||
$wanted_subdefs = $record->get_missing_subdefs();
|
$wanted_subdefs = $record->get_missing_subdefs();
|
||||||
|
|
||||||
if (count($wanted_subdefs) > 0) {
|
if (count($wanted_subdefs) > 0) {
|
||||||
$record->generate_subdefs($databox, $this->container, $wanted_subdefs);
|
$subdefGenerator->generateSubdefs($record, $wanted_subdefs);
|
||||||
|
|
||||||
foreach ($wanted_subdefs as $subdef) {
|
foreach ($wanted_subdefs as $subdef) {
|
||||||
$this->container['monolog']->addInfo("generate " .$subdef . " for record " . $record->get_record_id());
|
$this->container['monolog']->addInfo("generate " .$subdef . " for record " . $record->get_record_id());
|
||||||
@@ -59,7 +65,10 @@ class BuildMissingSubdefs extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
unset($record);
|
unset($record);
|
||||||
|
$progressBar->advance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$progressBar->finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->container['monolog']->addInfo($n . " subdefs done");
|
$this->container['monolog']->addInfo($n . " subdefs done");
|
||||||
@@ -67,6 +76,7 @@ class BuildMissingSubdefs extends Command
|
|||||||
$duration = $stop - $start;
|
$duration = $stop - $start;
|
||||||
|
|
||||||
$this->container['monolog']->addInfo(sprintf("process took %s, (%f sd/s.)", $this->getFormattedDuration($duration), round($n / $duration, 3)));
|
$this->container['monolog']->addInfo(sprintf("process took %s, (%f sd/s.)", $this->getFormattedDuration($duration), round($n / $duration, 3)));
|
||||||
|
$progressBar->finish();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -1088,9 +1088,12 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
|||||||
{
|
{
|
||||||
$databox = $this->app->findDataboxById($this->get_sbas_id());
|
$databox = $this->app->findDataboxById($this->get_sbas_id());
|
||||||
$connbas = $databox->get_connection();
|
$connbas = $databox->get_connection();
|
||||||
$sql = 'UPDATE record SET jeton=(jeton | ' . PhraseaTokens::MAKE_SUBDEF . ') WHERE record_id = :record_id';
|
$sql = 'UPDATE record SET jeton=(jeton | :make_subdef_mask) WHERE record_id = :record_id';
|
||||||
$stmt = $connbas->prepare($sql);
|
$stmt = $connbas->prepare($sql);
|
||||||
$stmt->execute([':record_id' => $this->get_record_id()]);
|
$stmt->execute([
|
||||||
|
':record_id' => $this->getRecordId(),
|
||||||
|
'make_subdef_mask' => PhraseaTokens::MAKE_SUBDEF,
|
||||||
|
]);
|
||||||
$stmt->closeCursor();
|
$stmt->closeCursor();
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@@ -1098,7 +1101,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
|||||||
|
|
||||||
public function get_missing_subdefs()
|
public function get_missing_subdefs()
|
||||||
{
|
{
|
||||||
$databox = $this->get_databox();
|
$databox = $this->getDatabox();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->get_hd_file();
|
$this->get_hd_file();
|
||||||
@@ -1106,15 +1109,15 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
|||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
$subDefDefinitions = $databox->get_subdef_structure()->getSubdefGroup($this->get_type());
|
$subDefDefinitions = $databox->get_subdef_structure()->getSubdefGroup($this->getType());
|
||||||
if (!$subDefDefinitions) {
|
if (!$subDefDefinitions) {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
$record = $this;
|
$record = $this;
|
||||||
$wanted_subdefs = array_map(function(media_subdef $subDef) {
|
$wanted_subdefs = array_map(function(databox_subdef $subDef) {
|
||||||
return $subDef->get_name();
|
return $subDef->get_name();
|
||||||
}, array_filter($subDefDefinitions, function(media_subdef $subDef) use ($record) {
|
}, array_filter($subDefDefinitions, function(databox_subdef $subDef) use ($record) {
|
||||||
return !$record->has_subdef($subDef->get_name());
|
return !$record->has_subdef($subDef->get_name());
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user