techdivision /
import-attribute-set
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * TechDivision\Import\Attribute\Set\Observers\ClearAttributeObserver |
||
| 5 | * |
||
| 6 | * PHP version 7 |
||
| 7 | * |
||
| 8 | * @author Tim Wagner <[email protected]> |
||
| 9 | * @copyright 2019 TechDivision GmbH <[email protected]> |
||
| 10 | * @license https://opensource.org/licenses/MIT |
||
| 11 | * @link https://github.com/techdivision/import-attribute-set |
||
| 12 | * @link http://www.techdivision.com |
||
| 13 | */ |
||
| 14 | |||
| 15 | namespace TechDivision\Import\Attribute\Set\Observers; |
||
| 16 | |||
| 17 | use TechDivision\Import\Attribute\Set\Utils\ColumnKeys; |
||
| 18 | use TechDivision\Import\Attribute\Set\Utils\MemberNames; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Observer that removes the EAV attribute with the code found in the CSV file. |
||
| 22 | * |
||
| 23 | * @author Tim Wagner <[email protected]> |
||
| 24 | * @copyright 2019 TechDivision GmbH <[email protected]> |
||
| 25 | * @license https://opensource.org/licenses/MIT |
||
| 26 | * @link https://github.com/techdivision/import-attribute-set |
||
| 27 | * @link http://www.techdivision.com |
||
| 28 | */ |
||
| 29 | class ClearAttributeSetObserver extends AbstractAttributeSetObserver |
||
| 30 | { |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Process the observer's business logic. |
||
| 34 | * |
||
| 35 | * @return array The processed row |
||
| 36 | */ |
||
| 37 | protected function process() |
||
| 38 | { |
||
| 39 | |||
| 40 | // load the entity type code and attribute set name |
||
| 41 | $entityTypeCode = $this->getValue(ColumnKeys::ENTITY_TYPE_CODE); |
||
| 42 | $attributeSetName = $this->getValue(ColumnKeys::ATTRIBUTE_SET_NAME); |
||
| 43 | |||
| 44 | // query whether or not we've found a line with a attribute group definition |
||
| 45 | if ($entityTypeCode === null && $attributeSetName === null) { |
||
| 46 | return; |
||
| 47 | } |
||
| 48 | |||
| 49 | // query whether or not, we've found a new entity type code/attribute set name => means we've found a new attribute set |
||
| 50 | if ($this->hasBeenProcessed($entityTypeCode, $attributeSetName)) { |
||
| 51 | return; |
||
| 52 | } |
||
| 53 | |||
| 54 | // try to load the EAV attribute set with the given entity type code and attribute set name found in the CSV file |
||
| 55 | $attributeSet = $this->loadAttributeSetByEntityTypeCodeAndAttributeSetName($entityTypeCode, $attributeSetName); |
||
| 56 | if (!$attributeSet) { |
||
|
0 ignored issues
–
show
|
|||
| 57 | $this->getSubject() |
||
| 58 | ->getSystemLogger() |
||
| 59 | ->debug(sprintf('AttributeSet with code "%s" and Name "%s" can\'t be loaded!', $entityTypeCode, $attributeSetName)); |
||
| 60 | return; |
||
| 61 | } |
||
| 62 | // delete the EAV attribute set |
||
| 63 | $this->deleteAttributeSet(array(MemberNames::ATTRIBUTE_SET_ID => $attributeSet[MemberNames::ATTRIBUTE_SET_ID])); |
||
| 64 | } |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Load's and return's the EAV attribute set with the passed entity type code and attribute set name. |
||
| 68 | * |
||
| 69 | * @param string $entityTypeCode The entity type code of the EAV attribute set to load |
||
| 70 | * @param string $attributeSetName The attribute set name of the EAV attribute set to return |
||
| 71 | * |
||
| 72 | * @return array The EAV attribute set |
||
| 73 | */ |
||
| 74 | protected function loadAttributeSetByEntityTypeCodeAndAttributeSetName($entityTypeCode, $attributeSetName) |
||
| 75 | { |
||
| 76 | return $this->getAttributeSetBunchProcessor()->loadAttributeSetByEntityTypeCodeAndAttributeSetName($entityTypeCode, $attributeSetName); |
||
| 77 | } |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Delete's the EAV attribute set with the passed attributes. |
||
| 81 | * |
||
| 82 | * @param array $row The attributes of the EAV attribute set to delete |
||
| 83 | * @param string|null $name The name of the prepared statement that has to be executed |
||
| 84 | * |
||
| 85 | * @return void |
||
| 86 | */ |
||
| 87 | protected function deleteAttributeSet($row, $name = null) |
||
| 88 | { |
||
| 89 | $this->getAttributeSetBunchProcessor()->deleteAttributeSet($row, $name); |
||
| 90 | } |
||
| 91 | } |
||
| 92 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.