Skip to content

Instantly share code, notes, and snippets.

@bhelm
Created April 29, 2021 08:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhelm/2d30f0cebcf4a7d8ea41c532ec67cd62 to your computer and use it in GitHub Desktop.
Save bhelm/2d30f0cebcf4a7d8ea41c532ec67cd62 to your computer and use it in GitHub Desktop.
Shopware 5 export image paths
<?php
namespace My\Commands;
use Doctrine\ORM\EntityManager;
use Error;
use Shopware\Commands\ShopwareCommand;
use Shopware\Models\Category\Category;
use Shopware\Models\Category\Repository;
use Shopware\Models\Snippet\Snippet;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Shopware\Models\Media\Media;
/**
this command exports all image paths for migration to a new host
*/
class ExportImagesCommand extends ShopwareCommand {
/**
* @var OutputInterface
*/
private $output;
/**
* @var EntityManager
*/
private $em;
/**
* @var Repository
*/
private $snippetRepository;
/**
* @var Repository
*/
private $categoryRepository;
/**
* {@inheritdoc}
*/
protected function configure() {
$this
->setName('my:image:export')
->setDescription('exports images')
;
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->output = $output;
$mediaService = $this->container->get('shopware_media.media_service');
$mediaRepository = $this->container->get('models')->getRepository(Media::class);
#$allmedia = $mediaRepository->findAll();
$connection = $this->container->get('dbal_connection');
$allmedia = $connection->query("select path from s_media");
foreach($allmedia as $media) {
echo $mediaService->encode($media['path']).PHP_EOL;
}
//echo $mediaService->getUrl('media/image/my-fancy-image.png');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment