1111use Magento \Framework \Model \ResourceModel \AbstractResource ;
1212use Magento \Framework \DB \Adapter \DuplicateException ;
1313use Magento \Framework \Phrase ;
14+ use Magento \Framework \DB \Adapter \AdapterInterface ;
1415
1516/**
1617 * Abstract resource model
@@ -301,7 +302,7 @@ public function getTable($tableName)
301302 * Get connection by resource name
302303 *
303304 * @param string $resourceName
304- * @return \Magento\Framework\DB\Adapter\ AdapterInterface|false
305+ * @return AdapterInterface|false
305306 */
306307 protected function _getConnection ($ resourceName )
307308 {
@@ -320,7 +321,7 @@ protected function _getConnection($resourceName)
320321 /**
321322 * Get connection
322323 *
323- * @return \Magento\Framework\DB\Adapter\ AdapterInterface|false
324+ * @return AdapterInterface|false
324325 */
325326 public function getConnection ()
326327 {
@@ -793,13 +794,10 @@ protected function saveNewObject(\Magento\Framework\Model\AbstractModel $object)
793794 */
794795 protected function updateObject (\Magento \Framework \Model \AbstractModel $ object )
795796 {
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 ());
803801 $ condition = $ this ->getIdFieldName () . '= ' . $ preparedValue ;
804802
805803 /**
@@ -808,22 +806,22 @@ protected function updateObject(\Magento\Framework\Model\AbstractModel $object)
808806 if ($ this ->_isPkAutoIncrement ) {
809807 $ data = $ this ->prepareDataForUpdate ($ object );
810808 if (!empty ($ data )) {
811- $ this -> getConnection () ->update ($ this ->getMainTable (), $ data , $ condition );
809+ $ connection ->update ($ this ->getMainTable (), $ data , $ condition );
812810 }
813811 } else {
814- $ select = $ this -> getConnection () ->select ()->from (
812+ $ select = $ connection ->select ()->from (
815813 $ this ->getMainTable (),
816814 [$ this ->getIdFieldName ()]
817815 )->where (
818816 $ condition
819817 );
820- if ($ this -> getConnection () ->fetchOne ($ select ) !== false ) {
818+ if ($ connection ->fetchOne ($ select ) !== false ) {
821819 $ data = $ this ->prepareDataForUpdate ($ object );
822820 if (!empty ($ data )) {
823- $ this -> getConnection () ->update ($ this ->getMainTable (), $ data , $ condition );
821+ $ connection ->update ($ this ->getMainTable (), $ data , $ condition );
824822 }
825823 } else {
826- $ this -> getConnection () ->insert (
824+ $ connection ->insert (
827825 $ this ->getMainTable (),
828826 $ this ->_prepareDataForSave ($ object )
829827 );
0 commit comments