Skip to content

Commit c7c7967

Browse files
committed
Merge pull request #344 from magento-firedrakes/MAGETWO-37048
[Firedrakes] Remove model related methods from Magento Object
2 parents a4d4b22 + dcd3929 commit c7c7967

File tree

100 files changed

+2654
-1293
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+2654
-1293
lines changed

app/code/Magento/Backend/Block/Widget/Button/Item.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,25 @@
1616
*/
1717
class Item extends \Magento\Framework\Object
1818
{
19+
/**
20+
* Object delete flag
21+
*
22+
* @var bool
23+
*/
24+
protected $_isDeleted = false;
25+
26+
/**
27+
* Set _isDeleted flag value (if $isDeleted parameter is defined) and return current flag value
28+
*
29+
* @param boolean $isDeleted
30+
* @return bool
31+
*/
32+
public function isDeleted($isDeleted = null)
33+
{
34+
$result = $this->_isDeleted;
35+
if ($isDeleted !== null) {
36+
$this->_isDeleted = $isDeleted;
37+
}
38+
return $result;
39+
}
1940
}

app/code/Magento/Backup/Model/Resource/Db.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ public function getTableStatus($tableName)
124124

125125
if ($row) {
126126
$statusObject = new \Magento\Framework\Object();
127-
$statusObject->setIdFieldName('name');
128127
foreach ($row as $field => $value) {
129128
$statusObject->setData(strtolower($field), $value);
130129
}

app/code/Magento/Bundle/Model/Option.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ protected function _construct()
5353
*/
5454
public function addSelection(\Magento\Catalog\Model\Product $selection)
5555
{
56-
$selections = $this->getDataSetDefault('selections', []);
56+
if (!$this->hasData('selections')) {
57+
$this->setData('selections', []);
58+
}
59+
$selections = $this->getData('selections');
5760
$selections[] = $selection;
5861
$this->setSelections($selections);
5962
}

app/code/Magento/Catalog/Model/Product/Visibility.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ public function __construct(
4949
) {
5050
$this->_eavEntityAttribute = $eavEntityAttribute;
5151
parent::__construct($data);
52-
$this->setIdFieldName('visibility_id');
5352
}
5453

5554
/**

app/code/Magento/Catalog/Model/Resource/Product/Action.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ protected function _construct()
4040
public function updateAttributes($entityIds, $attrData, $storeId)
4141
{
4242
$object = new \Magento\Framework\Object();
43-
$object->setIdFieldName('entity_id')->setStoreId($storeId);
43+
$object->setStoreId($storeId);
4444

4545
$this->_getWriteAdapter()->beginTransaction();
4646
try {
@@ -54,6 +54,7 @@ public function updateAttributes($entityIds, $attrData, $storeId)
5454
foreach ($entityIds as $entityId) {
5555
$i++;
5656
$object->setId($entityId);
57+
$object->setEntityId($entityId);
5758
// collect data for save
5859
$this->_saveAttributeValue($object, $attribute, $value);
5960
// save collected data every 1000 rows

app/code/Magento/Catalog/Model/Resource/Url.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,8 @@ protected function _getCategories($categoryIds, $storeId = null, $path = null)
432432
}
433433

434434
$category = new \Magento\Framework\Object($row);
435-
$category->setIdFieldName('entity_id');
435+
$category->setId($row['entity_id']);
436+
$category->setEntityId($row['entity_id']);
436437
$category->setStoreId($storeId);
437438
$this->_prepareCategoryParentId($category);
438439

@@ -535,7 +536,8 @@ protected function _getProducts($productIds, $storeId, $entityId, &$lastEntityId
535536
$rowSet = $adapter->fetchAll($select, $bind);
536537
foreach ($rowSet as $row) {
537538
$product = new \Magento\Framework\Object($row);
538-
$product->setIdFieldName('entity_id');
539+
$product->setId($row['entity_id']);
540+
$product->setEntityId($row['entity_id']);
539541
$product->setCategoryIds([]);
540542
$product->setStoreId($storeId);
541543
$products[$product->getId()] = $product;

app/code/Magento/CatalogSearch/Model/Indexer/Fulltext/Action/Full.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ protected function getProductEmulator($typeId)
627627
{
628628
if (!isset($this->productEmulators[$typeId])) {
629629
$productEmulator = new \Magento\Framework\Object();
630-
$productEmulator->setIdFieldName('entity_id')->setTypeId($typeId);
630+
$productEmulator->setTypeId($typeId);
631631
$this->productEmulators[$typeId] = $productEmulator;
632632
}
633633
return $this->productEmulators[$typeId];

app/code/Magento/CatalogUrlRewrite/Model/CategoryUrlPathGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function __construct(
5656
/**
5757
* Build category URL path
5858
*
59-
* @param \Magento\Catalog\Api\Data\CategoryInterface|\Magento\Framework\Object $category
59+
* @param \Magento\Catalog\Api\Data\CategoryInterface|\Magento\Framework\Model\AbstractModel $category
6060
* @return string
6161
*/
6262
public function getUrlPath($category)

app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/ObjectRegistryTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ class ObjectRegistryTest extends \PHPUnit_Framework_TestCase
1818

1919
protected function setUp()
2020
{
21-
$this->object = $this->getMock('Magento\Framework\Object');
22-
$this->object->expects($this->any())->method('getId')->will($this->returnValue(1));
21+
$this->object = new \Magento\Framework\Object(['id' => 1]);
2322
$this->objectRegistry = (new ObjectManager($this))->getObject(
2423
'Magento\CatalogUrlRewrite\Model\ObjectRegistry',
2524
['entities' => [$this->object]]

app/code/Magento/Checkout/Model/Cart.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,7 @@ public function updateItems($data)
501501
if ($qty > 0) {
502502
$item->setQty($qty);
503503

504-
$itemInQuote = $this->getQuote()->getItemById($item->getId());
505-
506-
if (!$itemInQuote && $item->getHasError()) {
504+
if ($item->getHasError()) {
507505
throw new \Magento\Framework\Exception\LocalizedException(__($item->getMessage()));
508506
}
509507

@@ -527,6 +525,7 @@ public function updateItems($data)
527525
'checkout_cart_update_items_after',
528526
['cart' => $this, 'info' => $infoDataObject]
529527
);
528+
530529
return $this;
531530
}
532531

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,11 +1152,11 @@ protected function _setAttributeValue($object, $valueRow)
11521152
/**
11531153
* Save entity's attributes into the object's resource
11541154
*
1155-
* @param \Magento\Framework\Object $object
1155+
* @param \Magento\Framework\Model\AbstractModel $object
11561156
* @return $this
11571157
* @throws \Exception
11581158
*/
1159-
public function save(\Magento\Framework\Object $object)
1159+
public function save(\Magento\Framework\Model\AbstractModel $object)
11601160
{
11611161
/**
11621162
* Direct deleted items to delete method
@@ -1245,7 +1245,7 @@ private function _aggregateDeleteData(&$delete, $attribute, $object)
12451245
* 'newObject', 'entityRow', 'insert', 'update', 'delete'
12461246
* )
12471247
*
1248-
* @param \Magento\Framework\Object $newObject
1248+
* @param \Magento\Framework\Model\AbstractModel $newObject
12491249
* @return array
12501250
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
12511251
* @SuppressWarnings(PHPMD.NPathComplexity)
@@ -1723,7 +1723,7 @@ public function delete($object)
17231723
$connection = $this->transactionManager->start($this->_getWriteAdapter());
17241724
if (is_numeric($object)) {
17251725
$id = (int) $object;
1726-
} elseif ($object instanceof \Magento\Framework\Object) {
1726+
} elseif ($object instanceof \Magento\Framework\Model\AbstractModel) {
17271727
$object->beforeDelete();
17281728
$id = (int) $object->getId();
17291729
}
@@ -1748,12 +1748,12 @@ public function delete($object)
17481748

17491749
$this->_afterDelete($object);
17501750

1751-
if ($object instanceof \Magento\Framework\Object) {
1751+
if ($object instanceof \Magento\Framework\Model\AbstractModel) {
17521752
$object->isDeleted(true);
17531753
$object->afterDelete();
17541754
}
17551755
$this->transactionManager->commit();
1756-
if ($object instanceof \Magento\Framework\Object) {
1756+
if ($object instanceof \Magento\Framework\Model\AbstractModel) {
17571757
$object->afterDeleteCommit();
17581758
}
17591759
} catch (\Exception $e) {

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,58 @@ public function __construct(
6666
parent::__construct($data);
6767
}
6868

69+
/**
70+
* Return ID
71+
*
72+
* @codeCoverageIgnore
73+
*
74+
* @return string
75+
*/
76+
public function getId()
77+
{
78+
return $this->getData($this->_idFieldName);
79+
}
80+
81+
/**
82+
* Set ID
83+
*
84+
* @codeCoverageIgnore
85+
*
86+
* @param string $id
87+
* @return $this
88+
*/
89+
public function setId($id)
90+
{
91+
$this->setData($this->_idFieldName, $id);
92+
return $this;
93+
}
94+
95+
/**
96+
* Id field name setter
97+
*
98+
* @codeCoverageIgnore
99+
*
100+
* @param string $name
101+
* @return $this
102+
*/
103+
public function setIdFieldName($name)
104+
{
105+
$this->_idFieldName = $name;
106+
return $this;
107+
}
108+
109+
/**
110+
* Id field name getter
111+
*
112+
* @codeCoverageIgnore
113+
*
114+
* @return string
115+
*/
116+
public function getIdFieldName()
117+
{
118+
return $this->_idFieldName;
119+
}
120+
69121
/**
70122
* Return indexer's view ID
71123
*

app/code/Magento/Quote/Model/AddressDetails.php

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
class AddressDetails extends \Magento\Framework\Model\AbstractExtensibleModel implements
1212
\Magento\Quote\Api\Data\AddressDetailsInterface
1313
{
14+
//@codeCoverageIgnoreStart
1415
/**
1516
* @{inheritdoc}
1617
*/
@@ -75,6 +76,23 @@ public function setFormattedShippingAddress($formattedShippingAddress)
7576
return $this->setData(self::FORMATTED_SHIPPING_ADDRESS, $formattedShippingAddress);
7677
}
7778

79+
/**
80+
* @{inheritdoc}
81+
*/
82+
public function getTotals()
83+
{
84+
return $this->getData(self::TOTALS);
85+
}
86+
87+
/**
88+
* @{inheritdoc}
89+
*/
90+
public function setTotals($totals)
91+
{
92+
return $this->setData(self::TOTALS, $totals);
93+
}
94+
//@codeCoverageIgnoreEnd
95+
7896
/**
7997
* {@inheritdoc}
8098
*
@@ -96,20 +114,4 @@ public function setExtensionAttributes(
96114
) {
97115
return $this->_setExtensionAttributes($extensionAttributes);
98116
}
99-
100-
/**
101-
* @{inheritdoc}
102-
*/
103-
public function getTotals()
104-
{
105-
return $this->getData(self::TOTALS);
106-
}
107-
108-
/**
109-
* @{inheritdoc}
110-
*/
111-
public function setTotals($totals)
112-
{
113-
return $this->setData(self::TOTALS, $totals);
114-
}
115117
}

app/code/Magento/Quote/Model/Quote.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2099,6 +2099,8 @@ public function getErrors()
20992099
/**
21002100
* Sets flag, whether this quote has some error associated with it.
21012101
*
2102+
* @codeCoverageIgnore
2103+
*
21022104
* @param bool $flag
21032105
* @return $this
21042106
*/
@@ -2494,6 +2496,8 @@ public function getCheckoutMethod($originalMethod = false)
24942496
/**
24952497
* Sets the payment method that is used to process the cart.
24962498
*
2499+
* @codeCoverageIgnore
2500+
*
24972501
* @param string $checkoutMethod
24982502
* @return $this
24992503
*/
@@ -2505,6 +2509,8 @@ public function setCheckoutMethod($checkoutMethod)
25052509
/**
25062510
* Prevent quote from saving
25072511
*
2512+
* @codeCoverageIgnore
2513+
*
25082514
* @return $this
25092515
*/
25102516
public function preventSaving()
@@ -2516,6 +2522,8 @@ public function preventSaving()
25162522
/**
25172523
* Check if model can be saved
25182524
*
2525+
* @codeCoverageIgnore
2526+
*
25192527
* @return bool
25202528
*/
25212529
public function isPreventSaving()

0 commit comments

Comments
 (0)