Skip to content

Commit b990290

Browse files
author
Dmytro Poperechnyy
committed
MAGETWO-33845: Replace obsolete EAV exception
1 parent 7122bd6 commit b990290

File tree

17 files changed

+98
-90
lines changed

17 files changed

+98
-90
lines changed

app/code/Magento/Catalog/Model/Entity/Attribute.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,14 @@ public function __construct(
135135
* Processing object before save data
136136
*
137137
* @return \Magento\Framework\Model\AbstractModel
138-
* @throws \Magento\Eav\Exception
138+
* @throws \Magento\Framework\Exception\EavException
139139
*/
140140
public function beforeSave()
141141
{
142142
try {
143143
$this->attrLockValidator->validate($this);
144144
} catch (\Magento\Framework\Exception\LocalizedException $exception) {
145-
throw new \Magento\Eav\Exception($exception->getMessage());
145+
throw new \Magento\Framework\Exception\EavException($exception->getMessage());
146146
}
147147

148148
$this->setData('modulePrefix', self::MODULE_NAME);

app/code/Magento/Catalog/Model/Product/Attribute/Backend/Sku.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,24 @@ public function __construct(\Magento\Framework\Stdlib\String $string)
4343
* Validate SKU
4444
*
4545
* @param Product $object
46-
* @throws \Magento\Framework\Exception\LocalizedException
4746
* @return bool
47+
* @throws \Magento\Framework\Exception\EavException
48+
* @throws \Magento\Framework\Exception\LocalizedException
4849
*/
4950
public function validate($object)
5051
{
5152
$attrCode = $this->getAttribute()->getAttributeCode();
5253
$value = $object->getData($attrCode);
5354
if ($this->getAttribute()->getIsRequired() && strlen($value) === 0) {
54-
throw new \Magento\Eav\Exception(__('The value of attribute "%1" must be set', $attrCode));
55+
throw new \Magento\Framework\Exception\EavException(
56+
__('The value of attribute "%1" must be set', $attrCode)
57+
);
5558
}
5659

5760
if ($this->string->strlen($object->getSku()) > self::SKU_MAX_LENGTH) {
58-
throw new \Magento\Framework\Exception\LocalizedException(__('SKU length should be %1 characters maximum.', self::SKU_MAX_LENGTH));
61+
throw new \Magento\Framework\Exception\LocalizedException(
62+
__('SKU length should be %1 characters maximum.', self::SKU_MAX_LENGTH)
63+
);
5964
}
6065
return true;
6166
}

app/code/Magento/CatalogRule/Model/Indexer/IndexBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ protected function calcRuleProductPrice($ruleData, $productData = null)
563563
* @param int $websiteId
564564
* @param int|null $productId
565565
* @return \Zend_Db_Statement_Interface
566-
* @throws \Magento\Eav\Exception
566+
* @throws \Magento\Framework\Exception\EavException
567567
*/
568568
protected function getRuleProductsStmt($websiteId, $productId = null)
569569
{

app/code/Magento/Eav/Model/Entity/AbstractEntity.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource;
1515
use Magento\Framework\App\Config\Element;
1616
use Magento\Framework\Model\AbstractModel;
17-
use Magento\Framework\Exception\LocalizedException;
17+
use Magento\Framework\Exception\EavException;
1818

1919
/**
2020
* Entity/Attribute/Model - entity abstract
@@ -332,12 +332,12 @@ public function setType($type)
332332
* Retrieve current entity config
333333
*
334334
* @return Type
335-
* @throws \Magento\Framework\Exception\LocalizedException
335+
* @throws EavException
336336
*/
337337
public function getEntityType()
338338
{
339339
if (empty($this->_type)) {
340-
throw new \Magento\Eav\Exception(__('Entity is not initialized'));
340+
throw new EavException(__('Entity is not initialized'));
341341
}
342342
return $this->_type;
343343
}
@@ -370,7 +370,7 @@ public function getTypeId()
370370
*
371371
* @param array|string|null $attributes
372372
* @return $this
373-
* @throws \Magento\Framework\Exception\LocalizedException
373+
* @throws EavException
374374
*/
375375
public function unsetAttributes($attributes = null)
376376
{
@@ -385,7 +385,7 @@ public function unsetAttributes($attributes = null)
385385
}
386386

387387
if (!is_array($attributes)) {
388-
throw new \Magento\Eav\Exception(__('Unknown parameter'));
388+
throw new EavException(__('Unknown parameter'));
389389
}
390390

391391
foreach ($attributes as $attrCode) {

app/code/Magento/Eav/Model/Entity/Attribute.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
namespace Magento\Eav\Model\Entity;
77

8-
use Magento\Eav\Exception;
8+
use Magento\Framework\Exception\EavException;
99
use Magento\Framework\Api\AttributeValueFactory;
1010

1111
/**
@@ -209,15 +209,15 @@ public function loadEntityAttributeIdBySet()
209209
* Prepare data for save
210210
*
211211
* @return $this
212-
* @throws Exception
212+
* @throws EavException
213213
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
214214
* @SuppressWarnings(PHPMD.NPathComplexity)
215215
*/
216216
public function beforeSave()
217217
{
218218
// prevent overriding product data
219219
if (isset($this->_data['attribute_code']) && $this->reservedAttributeList->isReservedAttribute($this)) {
220-
throw new Exception(
220+
throw new EavException(
221221
__(
222222
'The attribute code \'%1\' is reserved by system. Please try another attribute code',
223223
$this->_data['attribute_code']
@@ -236,7 +236,7 @@ public function beforeSave()
236236
['max' => self::ATTRIBUTE_CODE_MAX_LENGTH]
237237
)
238238
) {
239-
throw new Exception(
239+
throw new EavException(
240240
__('Maximum length of attribute code must be less than %1 symbols', self::ATTRIBUTE_CODE_MAX_LENGTH)
241241
);
242242
}
@@ -250,7 +250,7 @@ public function beforeSave()
250250
['locale' => $this->_localeResolver->getLocaleCode()]
251251
)
252252
) {
253-
throw new Exception(__('Invalid default decimal value'));
253+
throw new EavException(__('Invalid default decimal value'));
254254
}
255255

256256
try {
@@ -259,7 +259,7 @@ public function beforeSave()
259259
);
260260
$this->setDefaultValue($filter->filter($defaultValue));
261261
} catch (\Exception $e) {
262-
throw new Exception(__('Invalid default decimal value'));
262+
throw new EavException(__('Invalid default decimal value'));
263263
}
264264
}
265265

@@ -281,7 +281,7 @@ public function beforeSave()
281281
$defaultValue = $this->_localeDate->date($defaultValue, $format, null, false)->toValue();
282282
$this->setDefaultValue($defaultValue);
283283
} catch (\Exception $e) {
284-
throw new Exception(__('Invalid default date'));
284+
throw new EavException(__('Invalid default date'));
285285
}
286286
}
287287
}

app/code/Magento/Eav/Model/Entity/Attribute/AbstractAttribute.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Magento\Eav\Model\Entity\Attribute;
88

9+
use Magento\Framework\Exception\EavException;
910
use Magento\Framework\Api\AttributeValueFactory;
1011

1112
/**
@@ -173,7 +174,7 @@ protected function _construct()
173174
* @param string|int|\Magento\Eav\Model\Entity\Type $entityType
174175
* @param string $code
175176
* @return $this
176-
* @throws \Magento\Eav\Exception
177+
* @throws EavException
177178
*/
178179
public function loadByCode($entityType, $code)
179180
{
@@ -187,7 +188,7 @@ public function loadByCode($entityType, $code)
187188
$entityTypeId = $entityType->getId();
188189
}
189190
if (empty($entityTypeId)) {
190-
throw new \Magento\Eav\Exception(__('Invalid entity supplied'));
191+
throw new EavException(__('Invalid entity supplied'));
191192
}
192193
$this->_getResource()->loadByCode($this, $entityTypeId, $code);
193194
$this->_afterLoad();
@@ -442,7 +443,7 @@ public function getEntityIdField()
442443
* Retrieve backend instance
443444
*
444445
* @return \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend
445-
* @throws \Magento\Framework\Exception\LocalizedException
446+
* @throws EavException
446447
*/
447448
public function getBackend()
448449
{
@@ -452,7 +453,7 @@ public function getBackend()
452453
}
453454
$backend = $this->_universalFactory->create($this->getBackendModel());
454455
if (!$backend) {
455-
throw new \Magento\Eav\Exception(__('Invalid backend model specified: ' . $this->getBackendModel()));
456+
throw new EavException(__('Invalid backend model specified: ' . $this->getBackendModel()));
456457
}
457458
$this->_backend = $backend->setAttribute($this);
458459
}
@@ -481,7 +482,7 @@ public function getFrontend()
481482
* Retrieve source instance
482483
*
483484
* @return \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource
484-
* @throws \Magento\Framework\Exception\LocalizedException
485+
* @throws EavException
485486
*/
486487
public function getSource()
487488
{
@@ -491,7 +492,7 @@ public function getSource()
491492
}
492493
$source = $this->_universalFactory->create($this->getSourceModel());
493494
if (!$source) {
494-
throw new \Magento\Eav\Exception(
495+
throw new EavException(
495496
__(
496497
'Source model "%1" not found for attribute "%2"',
497498
$this->getSourceModel(),

app/code/Magento/Eav/Model/Entity/Attribute/Backend/AbstractBackend.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Eav\Model\Entity\Attribute\Backend;
77

8+
use Magento\Framework\Exception\EavException;
9+
810
/**
911
* Entity/Attribute/Model - attribute backend abstract
1012
* @SuppressWarnings(PHPMD.NumberOfChildren)
@@ -211,8 +213,8 @@ public function getDefaultValue()
211213
* Validate object
212214
*
213215
* @param \Magento\Framework\Object $object
214-
* @throws \Magento\Eav\Exception
215216
* @return bool
217+
* @throws EavException
216218
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
217219
*/
218220
public function validate($object)
@@ -221,7 +223,7 @@ public function validate($object)
221223
$attrCode = $attribute->getAttributeCode();
222224
$value = $object->getData($attrCode);
223225
if ($attribute->getIsVisible() && $attribute->getIsRequired() && $attribute->isValueEmpty($value)) {
224-
throw new \Magento\Eav\Exception(__('The value of attribute "%1" must be set', $attrCode));
226+
throw new EavException(__('The value of attribute "%1" must be set', $attrCode));
225227
}
226228

227229
if ($attribute->getIsUnique()
@@ -234,7 +236,7 @@ public function validate($object)
234236
if ($attribute->getIsUnique()) {
235237
if (!$attribute->getEntity()->checkAttributeUniqueValue($attribute, $object)) {
236238
$label = $attribute->getFrontend()->getLabel();
237-
throw new \Magento\Eav\Exception(__('The value of attribute "%1" must be unique', $label));
239+
throw new EavException(__('The value of attribute "%1" must be unique', $label));
238240
}
239241
}
240242

app/code/Magento/Eav/Model/Entity/Attribute/Backend/Datetime.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
namespace Magento\Eav\Model\Entity\Attribute\Backend;
1010

11-
use Magento\Eav\Exception as EavException;
12-
1311
class Datetime extends \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend
1412
{
1513
/**
@@ -32,7 +30,7 @@ public function __construct(\Magento\Framework\Stdlib\DateTime\TimezoneInterface
3230
* necessary for further process, else date string
3331
*
3432
* @param \Magento\Framework\Object $object
35-
* @throws EavException
33+
* @throws \Magento\Framework\Exception\EavException
3634
* @return $this
3735
*/
3836
public function beforeSave($object)
@@ -43,7 +41,7 @@ public function beforeSave($object)
4341
try {
4442
$value = $this->formatDate($object->getData($attributeName));
4543
} catch (\Exception $e) {
46-
throw new EavException(__('Invalid date'));
44+
throw new \Magento\Framework\Exception\EavException(__('Invalid date'));
4745
}
4846

4947
if (is_null($value)) {

app/code/Magento/Eav/Model/Entity/Attribute/Set.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
namespace Magento\Eav\Model\Entity\Attribute;
2121

2222
use Magento\Eav\Model\Entity\Type;
23+
use Magento\Framework\Exception\EavException;
2324
use Magento\Framework\Api\AttributeValueFactory;
2425

2526
/**
@@ -244,17 +245,17 @@ public function organizeData($data)
244245
* Validate attribute set name
245246
*
246247
* @return bool
247-
* @throws \Magento\Eav\Exception
248+
* @throws EavException
248249
*/
249250
public function validate()
250251
{
251252
$attributeSetName = $this->getAttributeSetName();
252253
if ($attributeSetName == '') {
253-
throw new \Magento\Eav\Exception(__('Attribute set name is empty.'));
254+
throw new EavException(__('Attribute set name is empty.'));
254255
}
255256

256257
if (!$this->_getResource()->validate($this, $attributeSetName)) {
257-
throw new \Magento\Eav\Exception(
258+
throw new EavException(
258259
__('An attribute set with the "%1" name already exists.', $attributeSetName)
259260
);
260261
}

app/code/Magento/Eav/Model/Entity/Attribute/Source/Config.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct(array $options)
3030
/**
3131
* Retrieve all options for the source from configuration
3232
*
33-
* @throws \Magento\Eav\Exception
33+
* @throws \Magento\Framework\Exception\EavException
3434
* @return array
3535
*/
3636
public function getAllOptions()
@@ -39,7 +39,7 @@ public function getAllOptions()
3939
$this->_options = [];
4040

4141
if (empty($this->_optionsData)) {
42-
throw new \Magento\Eav\Exception(__('No options found.'));
42+
throw new \Magento\Framework\Exception\EavException(__('No options found.'));
4343
}
4444
foreach ($this->_optionsData as $option) {
4545
$this->_options[] = ['value' => $option['value'], 'label' => __($option['label'])];

0 commit comments

Comments
 (0)