Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add output for better UX
  • Loading branch information
DavidPatzke committed Jul 17, 2017
1 parent bd6ffca commit 5515472
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/Mapbender/CoreBundle/Command/DatabaseUpgradeCommand.php
Expand Up @@ -9,6 +9,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Helper\ProgressBar;

/**
* Class DatabaseUpgradeCommand
Expand All @@ -33,15 +34,15 @@ protected function configure() {
*/

protected function execute(InputInterface $input, OutputInterface $output) {
$this->changeMapsImagePath();
$this->changeMapsImagePath($input, $output);
}

/**
* Change imagesPath configuration value from all MB3 map elements in the database
* from "bundles/mapbendercore/mapquery/lib/openlayers/img"
* to "components/mapquery/lib/openlayers/img"
*/
protected function changeMapsImagePath(){
protected function changeMapsImagePath(InputInterface $input, OutputInterface $output){

/**
* @var EntityManager $em
Expand All @@ -50,16 +51,27 @@ protected function changeMapsImagePath(){
$doctrine=$this->getContainer()->get('doctrine');
$em = $doctrine->getManager();
$maps = $em->getRepository('MapbenderCoreBundle:Element')->findBy(array('class'=>'Mapbender\CoreBundle\Element\Map'));
$output->writeln('Updating map elements image path values');
$output->writeln('Found ' . count($maps) . ' map elements');
$progressBar = new ProgressBar($output, count($maps) );
foreach ($maps as $map) {
$config = $map->getConfiguration();

$progressBar->advance();
if ($config['imgPath'] == 'bundles/mapbendercore/mapquery/lib/openlayers/img') {
$progressBar->setMessage('Found old image path');
$config['imgPath']= 'components/mapquery/lib/openlayers/img';
$map->setConfiguration($config);
$em->persist($map);
$progressBar->setMessage('Old image path successfully changed');
} else {
$progressBar->setMessage('Map element already up-to-date');
}
}
$em->flush();
$progressBar->finish();
$output->writeln('');
$output->writeln('All image path values are now up-to-date');
$output->writeln('Exiting now');
}
}

0 comments on commit 5515472

Please sign in to comment.