Skip to content

Commit

Permalink
Merge pull request #2 from DivanteLtd/develop-pimcore-x
Browse files Browse the repository at this point in the history
Release 2.0 compatibility with Pimcore X
  • Loading branch information
fszenborn authored May 14, 2022
2 parents 1e28f72 + adc6793 commit 22b6746
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use Divante\ClassificationstoreBundle\Export\Exporter;
use Pimcore\Model\Asset;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -19,8 +19,14 @@
* Class ClassificationstoreExportCommand
* @package Divante\ClassificationstoreBundle\Command
*/
class ClassificationstoreExportCommand extends ContainerAwareCommand
class ClassificationstoreExportCommand extends Command
{

public function __construct(Exporter $exporter)
{
$this->exporter = $exporter;
parent::__construct();
}
/**
* @inheritdoc
*/
Expand Down Expand Up @@ -51,10 +57,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$store = $input->getOption('store');

/** @var Exporter $exporter */
$exporter = $this->getContainer()->get(Exporter::class);

$csv = $exporter->getCsv($delimiter, $enclosure, $store);
$csv = $this->exporter->getCsv($delimiter, $enclosure, $store);

$asset = $input->getOption('asset');

Expand All @@ -66,6 +69,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
$file = $input->getOption('file');
file_put_contents($file, $csv);
}

return 0;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,26 @@
use Divante\ClassificationstoreBundle\Constants;
use Divante\ClassificationstoreBundle\Import\Interfaces\ItemInterface;
use Pimcore\Model\Asset;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Serializer\SerializerInterface;

/**
* Class ClassificationstoreImportCommand
* @package Divante\ClassificationstoreBundle\Command
*/
class ClassificationstoreImportCommand extends ContainerAwareCommand
class ClassificationstoreImportCommand extends Command
{

public function __construct(Importer $importer, SerializerInterface $serializer)
{
$this->importer = $importer;
$this->serializer = $serializer;
parent::__construct();
}
/**
* @inheritdoc
*/
Expand Down Expand Up @@ -60,7 +68,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$assetObj = Asset::getByPath($asset);
if (!$assetObj instanceof Asset) {
$output->writeln("<info>Asset doesn't exist</info>");
return;
return 0;
}
$file = PIMCORE_ASSET_DIRECTORY . $assetObj->getFullPath();
} else {
Expand All @@ -72,23 +80,19 @@ protected function execute(InputInterface $input, OutputInterface $output)

if (!file_exists($file)) {
$output->writeln("<info>File " . $file . " doesn't exist</info>");
return;
return 0;
}

// for count only
$csvData = file_get_contents($file);
$serializer = $this->getContainer()->get('serializer');
$data = $serializer->decode($csvData, 'csv', ['csv_delimiter' => $delimiter, 'csv_enclosure' => $enclosure]);
$data = $this->serializer->decode($csvData, 'csv', ['csv_delimiter' => $delimiter, 'csv_enclosure' => $enclosure]);
$count = count($data);
$output->writeln('<info>Importing `' . $count . '` lines.</info>');
// for count only - end

$progressBar = new ProgressBar($output, $count);
$progressBar->start();

/** @var Importer $importer */
$importer = $this->getContainer()->get(Importer::class);

$file = new \SplFileObject($file);
$file->setFlags(\SplFileObject::READ_CSV);
$file->setCsvControl($delimiter, $enclosure);
Expand All @@ -102,7 +106,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$counter++;
try {
$item = $importer->importItem($data);
$item = $this->importer->importItem($data);
$success++;
$output->writeln("imported: " . $item->getItemType() . " name: " . $item->getName());
} catch (\Exception $exception) {
Expand All @@ -120,5 +124,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
if ($counter > $success) {
$output->writeln('<error>Failed: ' . ($counter - $success) . ' items.</error>');
}

return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class Configuration implements ConfigurationInterface
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('classificationstore');
$treeBuilder = new TreeBuilder('classificationstore');
//$rootNode = $treeBuilder->root('classificationstore');

// Here you should define the parameters that are allowed to
// configure your bundle. See the documentation linked above for
Expand Down

0 comments on commit 22b6746

Please sign in to comment.