11
11
use Magento \Framework \Model \ResourceModel \AbstractResource ;
12
12
use Magento \Framework \DB \Adapter \DuplicateException ;
13
13
use Magento \Framework \Phrase ;
14
+ use Magento \Framework \DB \Adapter \AdapterInterface ;
14
15
15
16
/**
16
17
* Abstract resource model
@@ -301,7 +302,7 @@ public function getTable($tableName)
301
302
* Get connection by resource name
302
303
*
303
304
* @param string $resourceName
304
- * @return \Magento\Framework\DB\Adapter\ AdapterInterface|false
305
+ * @return AdapterInterface|false
305
306
*/
306
307
protected function _getConnection ($ resourceName )
307
308
{
@@ -320,7 +321,7 @@ protected function _getConnection($resourceName)
320
321
/**
321
322
* Get connection
322
323
*
323
- * @return \Magento\Framework\DB\Adapter\ AdapterInterface|false
324
+ * @return AdapterInterface|false
324
325
*/
325
326
public function getConnection ()
326
327
{
@@ -793,13 +794,10 @@ protected function saveNewObject(\Magento\Framework\Model\AbstractModel $object)
793
794
*/
794
795
protected function updateObject (\Magento \Framework \Model \AbstractModel $ object )
795
796
{
796
- $ tableDescription = $ this ->getConnection ()
797
- ->describeTable ($ this ->getMainTable ());
798
- $ preparedValue = $ this ->getConnection ()
799
- ->prepareColumnValue (
800
- $ tableDescription [$ this ->getIdFieldName ()],
801
- $ object ->getId ()
802
- );
797
+ /** @var AdapterInterface $connection */
798
+ $ connection = $ this ->getConnection ();
799
+ $ tableDescription = $ connection ->describeTable ($ this ->getMainTable ());
800
+ $ preparedValue = $ connection ->prepareColumnValue ($ tableDescription [$ this ->getIdFieldName ()], $ object ->getId ());
803
801
$ condition = $ this ->getIdFieldName () . '= ' . $ preparedValue ;
804
802
805
803
/**
@@ -808,22 +806,22 @@ protected function updateObject(\Magento\Framework\Model\AbstractModel $object)
808
806
if ($ this ->_isPkAutoIncrement ) {
809
807
$ data = $ this ->prepareDataForUpdate ($ object );
810
808
if (!empty ($ data )) {
811
- $ this -> getConnection () ->update ($ this ->getMainTable (), $ data , $ condition );
809
+ $ connection ->update ($ this ->getMainTable (), $ data , $ condition );
812
810
}
813
811
} else {
814
- $ select = $ this -> getConnection () ->select ()->from (
812
+ $ select = $ connection ->select ()->from (
815
813
$ this ->getMainTable (),
816
814
[$ this ->getIdFieldName ()]
817
815
)->where (
818
816
$ condition
819
817
);
820
- if ($ this -> getConnection () ->fetchOne ($ select ) !== false ) {
818
+ if ($ connection ->fetchOne ($ select ) !== false ) {
821
819
$ data = $ this ->prepareDataForUpdate ($ object );
822
820
if (!empty ($ data )) {
823
- $ this -> getConnection () ->update ($ this ->getMainTable (), $ data , $ condition );
821
+ $ connection ->update ($ this ->getMainTable (), $ data , $ condition );
824
822
}
825
823
} else {
826
- $ this -> getConnection () ->insert (
824
+ $ connection ->insert (
827
825
$ this ->getMainTable (),
828
826
$ this ->_prepareDataForSave ($ object )
829
827
);
0 commit comments