1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Inventory\Model\ResourceModel;
use Exception;
use Magento\Framework\Model\AbstractModel;
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
use Magento\Framework\Model\ResourceModel\Db\Context;
use Magento\InventoryApi\Model\SourceCarrierLinkManagementInterface;
use Magento\InventoryApi\Api\Data\SourceInterface;
use Magento\Framework\Model\ResourceModel\PredefinedId;
/**
* Implementation of basic operations for Source entity for specific db layer
*/
class Source extends AbstractDb
{
/**
* Provides possibility of saving entity with predefined/pre-generated id
*/
use PredefinedId;
/**#@+
* Constants related to specific db layer
*/
const TABLE_NAME_SOURCE = 'inventory_source';
/**#@-*/
/**
* Primary key auto increment flag
*
* @var bool
*/
protected $_isPkAutoIncrement = false;
/**
* @var SourceCarrierLinkManagementInterface
*/
private $sourceCarrierLinkManagement;
/**
* @param Context $context
* @param SourceCarrierLinkManagementInterface $sourceCarrierLinkManagement
* @param null $connectionName
*/
public function __construct(
Context $context,
SourceCarrierLinkManagementInterface $sourceCarrierLinkManagement,
$connectionName = null
) {
parent::__construct($context, $connectionName);
$this->sourceCarrierLinkManagement = $sourceCarrierLinkManagement;
}
/**
* @inheritdoc
*/
protected function _construct()
{
$this->_init(self::TABLE_NAME_SOURCE, SourceInterface::SOURCE_CODE);
}
/**
* @inheritdoc
*/
public function load(AbstractModel $object, $value, $field = null)
{
parent::load($object, $value, $field);
/** @var SourceInterface $object */
$this->sourceCarrierLinkManagement->loadCarrierLinksBySource($object);
return $this;
}
/**
* @inheritdoc
*/
public function save(AbstractModel $object)
{
$connection = $this->getConnection();
$connection->beginTransaction();
try {
parent::save($object);
/** @var SourceInterface $object */
$this->sourceCarrierLinkManagement->saveCarrierLinksBySource($object);
$connection->commit();
} catch (Exception $e) {
$connection->rollBack();
throw $e;
}
return $this;
}
}