Skip to content

Commit

Permalink
Merge branch '2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
dpfaffenbauer committed Jan 7, 2020
2 parents c012d50 + 1197407 commit 49cab0c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 13 deletions.
12 changes: 10 additions & 2 deletions docs/03_Development/08_Index_and_Filters/01_Index/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,16 @@ Every field has some properties that needs to be configured

## Re-Index

If you make changes to the index, you need to re-index all of your products. To do that, there is a cli Command
If you make changes to the index, you need to re-index all of your products. To do that, there is a CLI command.

```bash
$ php bin/console coreshop:index
```
```

If you don't want to re-index all of your indices, you can pass the corresponding IDs or names of the indices separated
with a space as arguments to the CLI command. The following example will only re-index indices with IDs 1 and 2 and name
"Products". If none of those indices exist, nothing will be re-indexed.

```bash
$ php bin/console coreshop:index 1 2 Products
```
48 changes: 45 additions & 3 deletions src/CoreShop/Bundle/IndexBundle/Command/IndexCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Pimcore\Model\DataObject\Listing;
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\EventDispatcher\EventDispatcherInterface;
Expand Down Expand Up @@ -66,7 +67,13 @@ protected function configure()
{
$this
->setName('coreshop:index')
->setDescription('Reindex all Objects');
->setDescription('Reindex all Objects')
->addArgument(
'indices',
InputArgument::IS_ARRAY | InputArgument::OPTIONAL,
'IDs or names of Indices which are re-indexed',
null
);
}

/**
Expand All @@ -79,8 +86,43 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$indices = $this->indexRepository->findAll();
$classesToUpdate = [];
$indices = $classesToUpdate = [];
$indexIds = $input->getArgument('indices');

if (null === $indexIds) {
$indices = $this->indexRepository->findAll();
} else {
foreach ($indexIds as $id) {
if (is_numeric($id)) {
$index = $this->indexRepository->find($id);
} else {
$index = $this->indexRepository->findOneBy(['name' => $id]);
}

if (null === $index) {
continue;
}

$indices[] = $index;
}
}

if (empty($indices)) {
if (null === $indexIds) {
$output->writeln('<info>No Indices available, you have to first create an Index.</info>');
$this->dispatchInfo('status', 'No Indices available, you have to first create an Index.');
} else {
$output->writeln(
sprintf('<info>No Indices found for %s</info>', implode(', ', $indexIds))
);
$this->dispatchInfo(
'status',
sprintf('No Indices found for %s', implode(', ', $indexIds))
);
}

return 0;
}

/**
* @var IndexInterface $index
Expand Down
8 changes: 0 additions & 8 deletions src/CoreShop/Component/Pimcore/DataObject/ObjectService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

use Pimcore\Model\DataObject\Concrete;
use Pimcore\Model\DataObject\Service;
use Webmozart\Assert\Assert;

class ObjectService implements ObjectServiceInterface
{
Expand All @@ -31,13 +30,6 @@ public function createFolderByPath($path)
*/
public function copyObject(Concrete $fromObject, Concrete $toObject)
{
/**
* @var $fromObject Concrete
* @var $toObject Concrete
*/
Assert::isInstanceOf($fromObject, Concrete::class);
Assert::isInstanceOf($toObject, Concrete::class);

//load all in case of lazy loading fields
$toFd = $toObject->getClass()->getFieldDefinitions();

Expand Down

0 comments on commit 49cab0c

Please sign in to comment.