Created
April 29, 2021 08:47
-
-
Save bhelm/2d30f0cebcf4a7d8ea41c532ec67cd62 to your computer and use it in GitHub Desktop.
Shopware 5 export image paths
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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