diff --git a/lib/Alchemy/Phrasea/Command/BuildMissingSubdefs.php b/lib/Alchemy/Phrasea/Command/BuildMissingSubdefs.php index f78e6eac76..58c1aaf216 100644 --- a/lib/Alchemy/Phrasea/Command/BuildMissingSubdefs.php +++ b/lib/Alchemy/Phrasea/Command/BuildMissingSubdefs.php @@ -11,7 +11,8 @@ 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\Output\OutputInterface; @@ -35,14 +36,19 @@ class BuildMissingSubdefs extends Command protected function doExecute(InputInterface $input, OutputInterface $output) { $start = microtime(true); + $progressBar = new ProgressBar($output); $n = 0; + /** @var SubdefGenerator $subdefGenerator */ + $subdefGenerator = $this->container['subdef.generator']; + foreach ($this->container->getDataboxes() as $databox) { $sql = 'SELECT record_id FROM record WHERE parent_record_id = 0'; $stmt = $databox->get_connection()->prepare($sql); $stmt->execute(); $rs = $stmt->fetchAll(\PDO::FETCH_ASSOC); $stmt->closeCursor(); + $progressBar->start(count($rs)); foreach ($rs as $row) { $record = $databox->get_record($row['record_id']); @@ -50,7 +56,7 @@ class BuildMissingSubdefs extends Command $wanted_subdefs = $record->get_missing_subdefs(); if (count($wanted_subdefs) > 0) { - $record->generate_subdefs($databox, $this->container, $wanted_subdefs); + $subdefGenerator->generateSubdefs($record, $wanted_subdefs); foreach ($wanted_subdefs as $subdef) { $this->container['monolog']->addInfo("generate " .$subdef . " for record " . $record->get_record_id()); @@ -59,7 +65,10 @@ class BuildMissingSubdefs extends Command } unset($record); + $progressBar->advance(); } + + $progressBar->finish(); } $this->container['monolog']->addInfo($n . " subdefs done"); @@ -67,6 +76,7 @@ class BuildMissingSubdefs extends Command $duration = $stop - $start; $this->container['monolog']->addInfo(sprintf("process took %s, (%f sd/s.)", $this->getFormattedDuration($duration), round($n / $duration, 3))); + $progressBar->finish(); return; } diff --git a/lib/classes/record/adapter.php b/lib/classes/record/adapter.php index 4bd6bececd..6f0632c226 100644 --- a/lib/classes/record/adapter.php +++ b/lib/classes/record/adapter.php @@ -1088,9 +1088,12 @@ class record_adapter implements RecordInterface, cache_cacheableInterface { $databox = $this->app->findDataboxById($this->get_sbas_id()); $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->execute([':record_id' => $this->get_record_id()]); + $stmt->execute([ + ':record_id' => $this->getRecordId(), + 'make_subdef_mask' => PhraseaTokens::MAKE_SUBDEF, + ]); $stmt->closeCursor(); return $this; @@ -1098,7 +1101,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface public function get_missing_subdefs() { - $databox = $this->get_databox(); + $databox = $this->getDatabox(); try { $this->get_hd_file(); @@ -1106,15 +1109,15 @@ class record_adapter implements RecordInterface, cache_cacheableInterface return array(); } - $subDefDefinitions = $databox->get_subdef_structure()->getSubdefGroup($this->get_type()); + $subDefDefinitions = $databox->get_subdef_structure()->getSubdefGroup($this->getType()); if (!$subDefDefinitions) { return array(); } $record = $this; - $wanted_subdefs = array_map(function(media_subdef $subDef) { + $wanted_subdefs = array_map(function(databox_subdef $subDef) { 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()); }));