File tree Expand file tree Collapse file tree 6 files changed +79
-2
lines changed
Catalog/Controller/Adminhtml/Product/Set
lib/internal/Magento/Framework Expand file tree Collapse file tree 6 files changed +79
-2
lines changed Original file line number Diff line number Diff line change @@ -101,6 +101,12 @@ public function execute()
101
101
}
102
102
$ model ->save ();
103
103
$ this ->messageManager ->addSuccess (__ ('You saved the attribute set. ' ));
104
+ } catch (\Magento \Framework \Exception \AlreadyExistsException $ e ) {
105
+ $ this ->messageManager ->addExceptionMessage (
106
+ $ e ,
107
+ __ ('Attribute group with same code is already exist. Please enter other Group name ' )
108
+ );
109
+ $ hasError = true ;
104
110
} catch (\Magento \Framework \Exception \LocalizedException $ e ) {
105
111
$ this ->messageManager ->addError ($ e ->getMessage ());
106
112
$ hasError = true ;
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright © 2016 Magento. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+
7
+ namespace Magento \Eav \Setup ;
8
+
9
+ use Magento \Framework \Setup \UpgradeSchemaInterface ;
10
+ use Magento \Framework \Setup \ModuleContextInterface ;
11
+ use Magento \Framework \Setup \SchemaSetupInterface ;
12
+
13
+ /**
14
+ * Upgrade the Eav module DB scheme
15
+ */
16
+ class UpgradeSchema implements UpgradeSchemaInterface
17
+ {
18
+ /**
19
+ * {@inheritdoc}
20
+ */
21
+ public function upgrade (SchemaSetupInterface $ setup , ModuleContextInterface $ context )
22
+ {
23
+ $ setup ->startSetup ();
24
+
25
+ if (version_compare ($ context ->getVersion (), '2.1.0 ' , '< ' )) {
26
+ $ this ->addUniqueKeyToEavAttributeGroupTable ($ setup );
27
+ }
28
+
29
+ $ setup ->endSetup ();
30
+ }
31
+
32
+ /**
33
+ * @param SchemaSetupInterface $setup
34
+ * @return void
35
+ */
36
+ protected function addUniqueKeyToEavAttributeGroupTable (SchemaSetupInterface $ setup )
37
+ {
38
+ $ setup ->getConnection ()->addIndex (
39
+ $ setup ->getTable ('eav_attribute_group ' ),
40
+ $ setup ->getIdxName (
41
+ 'catalog_category_product ' ,
42
+ ['attribute_set_id ' , 'attribute_group_code ' ],
43
+ \Magento \Framework \DB \Adapter \AdapterInterface::INDEX_TYPE_UNIQUE
44
+ ),
45
+ ['attribute_set_id ' , 'attribute_group_code ' ],
46
+ \Magento \Framework \DB \Adapter \AdapterInterface::INDEX_TYPE_UNIQUE
47
+ );
48
+ }
49
+ }
Original file line number Diff line number Diff line change 6
6
*/
7
7
-->
8
8
<config xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance" xsi : noNamespaceSchemaLocation =" urn:magento:framework:Module/etc/module.xsd" >
9
- <module name =" Magento_Eav" setup_version =" 2.0 .0" >
9
+ <module name =" Magento_Eav" setup_version =" 2.1 .0" >
10
10
<sequence >
11
11
<module name =" Magento_Store" />
12
12
</sequence >
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright © 2016 Magento. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+ namespace Magento \Framework \DB \Adapter ;
7
+
8
+ /**
9
+ * Database duplicate exception
10
+ */
11
+ class DuplicateException extends \Zend_Db_Adapter_Exception
12
+ {
13
+ }
Original file line number Diff line number Diff line change 14
14
use Magento \Framework \DB \Adapter \AdapterInterface ;
15
15
use Magento \Framework \DB \Adapter \ConnectionException ;
16
16
use Magento \Framework \DB \Adapter \DeadlockException ;
17
+ use Magento \Framework \DB \Adapter \DuplicateException ;
17
18
use Magento \Framework \DB \Adapter \LockWaitException ;
18
19
use Magento \Framework \DB \Ddl \Table ;
19
20
use Magento \Framework \DB \ExpressionConverter ;
@@ -232,6 +233,8 @@ public function __construct(
232
233
1205 => LockWaitException::class,
233
234
// SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock
234
235
1213 => DeadlockException::class,
236
+ // SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry
237
+ 1062 => DuplicateException::class,
235
238
];
236
239
try {
237
240
parent ::__construct ($ config );
Original file line number Diff line number Diff line change 10
10
use Magento \Framework \Exception \AlreadyExistsException ;
11
11
use Magento \Framework \Exception \LocalizedException ;
12
12
use Magento \Framework \Model \ResourceModel \AbstractResource ;
13
+ use Magento \Framework \DB \Adapter \DuplicateException ;
13
14
14
15
/**
15
16
* Abstract resource model class
@@ -409,7 +410,12 @@ public function save(\Magento\Framework\Model\AbstractModel $object)
409
410
}
410
411
$ this ->addCommitCallback ([$ object , 'afterCommitCallback ' ])->commit ();
411
412
$ object ->setHasDataChanges (false );
412
- } catch (\Exception $ e ) {
413
+ } catch (DuplicateException $ e ) {
414
+ $ this ->rollBack ();
415
+ $ object ->setHasDataChanges (true );
416
+ throw new AlreadyExistsException (__ ('Database duplicate value found ' ));
417
+ }
418
+ catch (\Exception $ e ) {
413
419
$ this ->rollBack ();
414
420
$ object ->setHasDataChanges (true );
415
421
throw $ e ;
You can’t perform that action at this time.
0 commit comments