Skip to content

Commit

Permalink
make Imagick dependency optional (only when pdf previews are enabled)
Browse files Browse the repository at this point in the history
kuma:media:create-pdf-previews should only be enabled if enable_pdf_preview is true
  • Loading branch information
wimvds committed Jan 30, 2015
1 parent b184742 commit 3c32a39
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 26 deletions.
13 changes: 13 additions & 0 deletions Command/CreatePdfPreviewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ public function execute(InputInterface $input, OutputInterface $output)
$output->writeln('<info>PDF preview images have been created.</info>');
}

/**
* Checks whether the command is enabled or not in the current environment.
*
* Override this to check for x or y and return false if the command can not
* run properly under the current conditions.
*
* @return bool
*/
public function isEnabled()
{
return $this->getContainer()->getParameter('kunstmaan_media.enable_pdf_preview');
}

protected function configure()
{
parent::configure();
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public function getConfigTreeBuilder()
->booleanNode('dailymotion')->defaultTrue()->end()
->end()
->end()
->booleanNode('enable_pdf_preview')->defaultFalse()->end()
->end();


return $treeBuilder;
}
}
5 changes: 5 additions & 0 deletions DependencyInjection/KunstmaanMediaExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ public function load(array $configs, ContainerBuilder $container)
);
$container->setParameter('kunstmaan_media.soundcloud_api_key', $config['soundcloud_api_key']);
$container->setParameter('kunstmaan_media.remote_video', $config['remote_video']);
$container->setParameter('kunstmaan_media.enable_pdf_preview', $config['enable_pdf_preview']);

$loader->load('services.yml');
$loader->load('handlers.yml');

if ($config['enable_pdf_preview'] === true) {
$loader->load('pdf_preview.yml');
}
}

public function prepend(ContainerBuilder $container)
Expand Down
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ If you want to use this bundle for a Symfony 2.2 release, use the 2.2 branch.

## Audio

If you want to use your own api key for SoundCloud, you can define this in the config.yml of your application but it works fine without it aswell.
If you want to use your own api key for SoundCloud, you can define this in the config.yml of your application but it works fine without it as well.

```yml
kunstmaan_media:
Expand All @@ -44,7 +44,7 @@ $builder
);
```

## Generating PDF thumbnails
## Generating PDF preview thumbnails

For this functionality to work, you need to install the ImageMagick extension with PDF support (using
Ghostscript). You will also have to make sure that the Ghostscript executable (gs) can be found
Expand All @@ -65,3 +65,10 @@ On OS X with apache you will probably have to add that path to the apache enviro
```

Where ```/path/to/gs``` is just the actual path where the gs binary is stored.

*NOTE:* This functionality has to be enabled by setting the ```enable_pdf_preview``` configuration option to true, ie. :

```yml
kunstmaan_media:
enable_pdf_preview: true
```
10 changes: 0 additions & 10 deletions Resources/config/handlers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ parameters:
kunstmaan_media.media_handler.remote_audio.class: 'Kunstmaan\MediaBundle\Helper\RemoteAudio\RemoteAudioHandler'
kunstmaan_media.media_handler.image.class: 'Kunstmaan\MediaBundle\Helper\Image\ImageHandler'
kunstmaan_media.media_handler.file.class: 'Kunstmaan\MediaBundle\Helper\File\FileHandler'
kunstmaan_media.media_handler.pdf.class: 'Kunstmaan\MediaBundle\Helper\File\PdfHandler'
aviary_api_key: null

services:
Expand Down Expand Up @@ -40,12 +39,3 @@ services:
- [ setMediaPath, [ "%kernel.root_dir%" ] ]
tags:
- { name: 'kunstmaan_media.media_handler' }

kunstmaan_media.media_handlers.pdf:
class: "%kunstmaan_media.media_handler.pdf.class%"
arguments: ["@kunstmaan_media.mimetype_guesser.factory"]
calls:
- [ setMediaPath, [ "%kernel.root_dir%" ] ]
- [ setPdfTransformer, [ "@kunstmaan_media.pdf_transformer" ]]
tags:
- { name: 'kunstmaan_media.media_handler' }
25 changes: 25 additions & 0 deletions Resources/config/pdf_preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
parameters:
kunstmaan_media.pdf_transformer.class: 'Kunstmaan\MediaBundle\Helper\Transformer\PdfTransformer'
kunstmaan_media.media_handler.pdf.class: 'Kunstmaan\MediaBundle\Helper\File\PdfHandler'

services:
kunstmaan_media.imagick:
class: "Imagick"

kunstmaan_media.pdf_transformer:
class: "%kunstmaan_media.pdf_transformer.class%"
arguments: ["@kunstmaan_media.imagick"]

kunstmaan_media.command.createpdfpreview:
class: Kunstmaan\MediaBundle\Command\CreatePdfPreviewCommand
calls:
- [setContainer, ["@service_container"] ]

kunstmaan_media.media_handlers.pdf:
class: "%kunstmaan_media.media_handler.pdf.class%"
arguments: ["@kunstmaan_media.mimetype_guesser.factory"]
calls:
- [ setMediaPath, [ "%kernel.root_dir%" ] ]
- [ setPdfTransformer, [ "@kunstmaan_media.pdf_transformer" ]]
tags:
- { name: 'kunstmaan_media.media_handler' }
13 changes: 0 additions & 13 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ parameters:
kunstmaan_media.icon_font_manager.class: 'Kunstmaan\MediaBundle\Helper\IconFont\IconFontManager'
kunstmaan_media.icon_font.default_loader.class: 'Kunstmaan\MediaBundle\Helper\IconFont\DefaultIconFontLoader'
kunstmaan_media.media_creator_service.class: 'Kunstmaan\MediaBundle\Helper\Services\MediaCreatorService'
kunstmaan_media.pdf_transformer.class: 'Kunstmaan\MediaBundle\Helper\Transformer\PdfTransformer'
kunstmaan_media.mimetype_guesser.factory.class: 'Kunstmaan\MediaBundle\Helper\MimeTypeGuesserFactory'

services:
Expand Down Expand Up @@ -80,13 +79,6 @@ services:
class: "%kunstmaan_media.folder_manager.class%"
arguments: ["@kunstmaan_media.repository.folder"]

kunstmaan_media.imagick:
class: "Imagick"

kunstmaan_media.pdf_transformer:
class: "%kunstmaan_media.pdf_transformer.class%"
arguments: ["@kunstmaan_media.imagick"]

kunstmaan_media.mimetype_guesser.factory:
class: "%kunstmaan_media.mimetype_guesser.factory.class%"

Expand All @@ -99,8 +91,3 @@ services:
class: Kunstmaan\MediaBundle\Command\RebuildFolderTreeCommand
calls:
- [setContainer, ["@service_container"] ]

kunstmaan_media.command.createpdfpreview:
class: Kunstmaan\MediaBundle\Command\CreatePdfPreviewCommand
calls:
- [setContainer, ["@service_container"] ]

0 comments on commit 3c32a39

Please sign in to comment.