Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.0] change IndexableInterface and pass IndexInterface #1326

Merged
merged 1 commit into from
Mar 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions UPGRADE-3.0.x.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Upgrade to 3.0

# CoreShop\Component\Index\Model\IndexableInterface Signature changed

From

```php
public function getIndexable();
public function getIndexableEnabled();
public function getIndexableName($language);
```

To

```php
public function getIndexable(IndexInterface $index): bool
public function getIndexableEnabled(IndexInterface $index): bool
public function getIndexableName(IndexInterface $index, string $language): string
```


2 changes: 1 addition & 1 deletion src/CoreShop/Behat/Context/Domain/FilterContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public function ifIQueryWithASimpleOrder(FilterInterface $filter, $orderKey, $or
continue;
}

$result[] = $object->getIndexableName('en');
$result[] = $object->getIndexableName($filter->getIndex(), 'en');
}

Assert::eq([$firstResult, $secondResult], $result);
Expand Down
37 changes: 27 additions & 10 deletions src/CoreShop/Behat/Model/Index/TestEnableIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
namespace CoreShop\Behat\Model\Index;

use CoreShop\Component\Index\Model\IndexableInterface;
use CoreShop\Component\Index\Model\IndexInterface;
use CoreShop\Component\Resource\Exception\ImplementedByPimcoreException;
use CoreShop\Component\Resource\Pimcore\Model\AbstractPimcoreModel;

Expand All @@ -23,40 +24,56 @@ class TestEnableIndex extends AbstractPimcoreModel implements IndexableInterface
/**
* {@inheritdoc}
*/
public function getIndexable()
public function getIndexable(IndexInterface $index): bool
{
return $this->getIndexableEnabled() && $this->getPublished();
return $this->getIndexableEnabled($index) && $this->getPublished();
}

/**
* {@inheritdoc}
*/
public function getIndexableEnabled()
public function getIndexableEnabled(IndexInterface $index): bool
{
return $this->getEnabled();
$enabled = $this->getEnabled();

if (is_bool($enabled)) {
return $enabled;
}

return false;
}


/**
* {@inheritdoc}
*/
public function getEnabled()
public function getIndexableName(IndexInterface $index, string $language): string
{
return new ImplementedByPimcoreException(__CLASS__, __METHOD__);
$name = $this->getName($language);

if (null === $name) {
return '';
}

if (!is_string($name)) {
return '';
}

return $name;
}

/**
* {@inheritdoc}
*/
public function getName($language)
public function getEnabled()
{
return new ImplementedByPimcoreException(__CLASS__, __METHOD__);
}

/**
* {@inheritdoc}
*/
public function getIndexableName($language)
public function getName($language)
{
return $this->getName($language);
return new ImplementedByPimcoreException(__CLASS__, __METHOD__);
}
}
23 changes: 18 additions & 5 deletions src/CoreShop/Behat/Model/Index/TestIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
namespace CoreShop\Behat\Model\Index;

use CoreShop\Component\Index\Model\IndexableInterface;
use CoreShop\Component\Index\Model\IndexInterface;
use CoreShop\Component\Resource\Exception\ImplementedByPimcoreException;
use CoreShop\Component\Resource\Pimcore\Model\AbstractPimcoreModel;

Expand All @@ -23,17 +24,23 @@ class TestIndex extends AbstractPimcoreModel implements IndexableInterface
/**
* {@inheritdoc}
*/
public function getIndexable()
public function getIndexable(IndexInterface $index): bool
{
return true;
}

/**
* {@inheritdoc}
*/
public function getIndexableEnabled()
public function getIndexableEnabled(IndexInterface $index): bool
{
return $this->getEnabled();
$enabled = $this->getEnabled();

if (!is_bool($enabled)) {
return false;
}

return $enabled;
}

/**
Expand All @@ -55,8 +62,14 @@ public function getName($language)
/**
* {@inheritdoc}
*/
public function getIndexableName($language)
public function getIndexableName(IndexInterface $index, string $language): string
{
return $this->getName($language);
$name = $this->getName($language);

if (!is_string($name)) {
return '';
}

return $name;
}
}
23 changes: 18 additions & 5 deletions src/CoreShop/Behat/Model/Index/TestIndexFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
namespace CoreShop\Behat\Model\Index;

use CoreShop\Component\Index\Model\IndexableInterface;
use CoreShop\Component\Index\Model\IndexInterface;
use CoreShop\Component\Resource\Exception\ImplementedByPimcoreException;
use CoreShop\Component\Resource\Pimcore\Model\AbstractPimcoreModel;

Expand All @@ -23,17 +24,23 @@ class TestIndexFields extends AbstractPimcoreModel implements IndexableInterface
/**
* {@inheritdoc}
*/
public function getIndexable()
public function getIndexable(IndexInterface $index): bool
{
return true;
}

/**
* {@inheritdoc}
*/
public function getIndexableEnabled()
public function getIndexableEnabled(IndexInterface $index): bool
{
return $this->getEnabled();
$enabled = $this->getEnabled();

if (!is_bool($enabled)) {
return false;
}

return $enabled;
}

/**
Expand All @@ -55,9 +62,15 @@ public function getName($language)
/**
* {@inheritdoc}
*/
public function getIndexableName($language)
public function getIndexableName(IndexInterface $index, string $language): string
{
return $this->getName($language);
$name = $this->getName($language);

if (!is_string($name)) {
return '';
}

return $name;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/CoreShop/Bundle/IndexBundle/Worker/AbstractWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ protected function prepareData(IndexInterface $index, IndexableInterface $object
$extensions = $this->getExtensions($index);

$virtualObjectId = $object->getId();
$virtualObjectActive = $object->getIndexableEnabled();
$virtualObjectActive = $object->getIndexableEnabled($index);

if ($object->getType() === Concrete::OBJECT_TYPE_VARIANT) {
/**
Expand All @@ -154,7 +154,7 @@ protected function prepareData(IndexInterface $index, IndexableInterface $object
}

$virtualObjectId = $parent->getId();
$virtualObjectActive = $object->getIndexableEnabled();
$virtualObjectActive = $object->getIndexableEnabled($index);
}

$data = [
Expand All @@ -173,7 +173,7 @@ protected function prepareData(IndexInterface $index, IndexableInterface $object
}
}

$data['active'] = $object->getIndexableEnabled();
$data['active'] = $object->getIndexableEnabled($index);

if (!is_bool($data['active'])) {
$data['active'] = false;
Expand All @@ -185,7 +185,7 @@ protected function prepareData(IndexInterface $index, IndexableInterface $object
];

foreach (Tool::getValidLanguages() as $language) {
$localizedData['values'][$language]['name'] = $object->getIndexableName($language);
$localizedData['values'][$language]['name'] = $object->getIndexableName($index, $language);
}

$relationData = [];
Expand Down
2 changes: 1 addition & 1 deletion src/CoreShop/Bundle/IndexBundle/Worker/MysqlWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ public function deleteFromIndex(IndexInterface $index, IndexableInterface $objec
*/
public function updateIndex(IndexInterface $index, IndexableInterface $object)
{
$doIndex = $object->getIndexable();
$doIndex = $object->getIndexable($index);

if ($doIndex) {
$preparedData = $this->prepareData($index, $object);
Expand Down
9 changes: 5 additions & 4 deletions src/CoreShop/Component/Core/Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace CoreShop\Component\Core\Model;

use CoreShop\Component\Index\Model\IndexInterface;
use CoreShop\Component\Product\Model\Product as BaseProduct;
use CoreShop\Component\Resource\Exception\ImplementedByPimcoreException;
use CoreShop\Component\Store\Repository\StoreRepositoryInterface;
Expand Down Expand Up @@ -345,23 +346,23 @@ public function setStorePrice($storePrice, \CoreShop\Component\Store\Model\Store
/**
* {@inheritdoc}
*/
public function getIndexableEnabled()
public function getIndexableEnabled(IndexInterface $index): bool
{
return $this->getActive() && $this->getPublished();
}

/**
* {@inheritdoc}
*/
public function getIndexable()
public function getIndexable(IndexInterface $index): bool
{
return $this->getIndexableEnabled();
return $this->getIndexableEnabled($index);
}

/**
* {@inheritdoc}
*/
public function getIndexableName($language)
public function getIndexableName(IndexInterface $index, string $language): string
{
return $this->getName($language);
}
Expand Down
21 changes: 4 additions & 17 deletions src/CoreShop/Component/Index/Model/IndexableInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,6 @@ interface IndexableInterface
*/
public function getId();

/**
* @return bool
*/
public function getIndexableEnabled();

/**
* @return bool
*/
public function getIndexable();

/**
* @return string
*/
Expand All @@ -51,15 +41,12 @@ public function getClassName();
*/
public function getType();

/**
* @param string $language
*
* @return string
*/
public function getIndexableName($language);

/**
* @return mixed
*/
public function getParent();

public function getIndexableEnabled(IndexInterface $index): bool;
public function getIndexable(IndexInterface $index): bool;
public function getIndexableName(IndexInterface $index, string $language): string;
}