Skip to content

Commit

Permalink
Merge branch '5.5'
Browse files Browse the repository at this point in the history
* 5.5:
  [MediaBundle] Fix php 7.4 incompatibility
  [GeneratorBundle] Fix doctrine fixtures error during install command
  • Loading branch information
acrobat committed May 11, 2020
2 parents 3a87467 + d1cb27f commit 647efde
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 17 deletions.
33 changes: 18 additions & 15 deletions src/Kunstmaan/GeneratorBundle/Command/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
use Symfony\Component\Console\Output\OutputInterface;
use Sensio\Bundle\GeneratorBundle\Command\Validators;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Process\Exception\RuntimeException;
use Sensio\Bundle\GeneratorBundle\Command\Helper\QuestionHelper;
use Symfony\Component\Process\Process;

/**
* Kunstmaan installer
Expand Down Expand Up @@ -152,7 +152,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
->executeCommand($output, 'doctrine:database:create')
->executeCommand($output, 'doctrine:schema:drop', ['--force' => true])
->executeCommand($output, 'doctrine:schema:create')
->executeCommand($output, 'doctrine:fixtures:load')
->executeCommand($output, 'doctrine:fixtures:load', ['-n' => true], true)
->executeCommand($output, 'assets:install')
;

Expand All @@ -171,26 +171,29 @@ protected function execute(InputInterface $input, OutputInterface $output)
return 0;
}

protected function executeCommand(OutputInterface $output, $command, array $options = [])
protected function executeCommand(OutputInterface $output, $command, array $options = [], $separateProcess = false)
{
$options = array_merge(
[
'--no-debug' => true,
],
$options
);
$options = array_merge(['--no-debug' => true], $options);

++$this->commandSteps;

try {
$updateInput = new ArrayInput($options);
$updateInput->setInteractive(true);
$this->getApplication()->find($command)->run($updateInput, $output);
if ($separateProcess) {
$process = new Process(array_merge(['bin/console', $command], array_keys($options)));
$process->setTty(true);
$process->run();

if (!$process->isSuccessful()) {
throw new \RuntimeException($process->getErrorOutput());
}
} else {
$updateInput = new ArrayInput($options);
$updateInput->setInteractive(true);
$this->getApplication()->find($command)->run($updateInput, $output);
}
$output->writeln(sprintf('<info>Step %d: "%s" - [OK]</info>', $this->commandSteps, $command));
} catch (RuntimeException $exception) {
$output->writeln(sprintf('<error>Step %d: "%s" - [FAILED]</error>', $this->commandSteps, $command));
} catch (\Throwable $e) {
$output->writeln(sprintf('<error>Step %d: "%s" - [FAILED]</error>', $this->commandSteps, $command));
$output->writeln(sprintf('<error>Step %d: "%s" - [FAILED] Message: %s</error>', $this->commandSteps, $command, $e->getMessage()));
}

return $this;
Expand Down
7 changes: 5 additions & 2 deletions src/Kunstmaan/MediaBundle/Helper/Image/ImageHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,11 @@ public function prepareMedia(Media $media)

if ($media->getContent()) {
$imageInfo = getimagesize($media->getContent());
$width = $imageInfo[0];
$height = $imageInfo[1];

$width = $height = null;
if (false !== $imageInfo) {
list($width, $height) = $imageInfo;
}

$media
->setMetadataValue('original_width', $width)
Expand Down
4 changes: 4 additions & 0 deletions src/Kunstmaan/MediaBundle/Tests/unit/Fixtures/sample.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Kunstmaan\MediaBundle\Tests\Helper\Image;

use Kunstmaan\MediaBundle\Entity\Media;
use Kunstmaan\MediaBundle\Helper\ExtensionGuesserFactory;
use Kunstmaan\MediaBundle\Helper\Image\ImageHandler;
use Kunstmaan\MediaBundle\Helper\MimeTypeGuesserFactory;
use Kunstmaan\UtilitiesBundle\Helper\Slugifier;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\File\File;

class ImageHandlerTest extends TestCase
{
public function testPrepareWithSvg()
{
$media = new Media();
$media->setContent(new File(__DIR__.'/../../Fixtures/sample.svg'));

$handler = new ImageHandler(1, new MimeTypeGuesserFactory(), new ExtensionGuesserFactory(), 'aviaryKey');
$handler->setSlugifier(new Slugifier());

$handler->prepareMedia($media);

$this->assertSame(['original_width' => null, 'original_height' => null], $media->getMetadata());
}
}

0 comments on commit 647efde

Please sign in to comment.