Skip to content

Commit cda8ff7

Browse files
ENGCOM-5140: Mview Indexers getList should return integer values of id's and not strings #22920
- Merge Pull Request #22920 from mhodge13/magento2:2.3-develop-convert-mview-ids - Merged commits: 1. 1242fbd 2. b880f57 3. 900f716 4. c8259f6 5. e520fa7 6. d1847d1 7. ae74f8b 8. a6bc7c4 9. deb56bc 10. 528a56d 11. c3fdc92 12. ec25987 13. 505ed08
2 parents b5dbf38 + 505ed08 commit cda8ff7

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

lib/internal/Magento/Framework/Mview/Test/Unit/View/ChangelogTest.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77
namespace Magento\Framework\Mview\Test\Unit\View;
88

9+
/**
10+
* Test Coverage for Changelog View.
11+
*
12+
* @see \Magento\Framework\Mview\View\Changelog
13+
*/
914
class ChangelogTest extends \PHPUnit\Framework\TestCase
1015
{
1116
/**
@@ -45,7 +50,7 @@ public function testInstanceOf()
4550
}
4651

4752
/**
48-
* @expectedException \Exception
53+
* @expectedException \Magento\Framework\DB\Adapter\ConnectionException
4954
* @expectedExceptionMessage The write connection to the database isn't available. Please try again later.
5055
*/
5156
public function testCheckConnectionException()
@@ -74,7 +79,7 @@ public function testGetViewId()
7479
}
7580

7681
/**
77-
* @expectedException \Exception
82+
* @expectedException \DomainException
7883
* @expectedExceptionMessage View's identifier is not set
7984
*/
8085
public function testGetNameWithException()
@@ -101,6 +106,10 @@ public function testGetVersion()
101106
$this->assertEquals(10, $this->model->getVersion());
102107
}
103108

109+
/**
110+
* @expectedException \Magento\Framework\Exception\RuntimeException
111+
* @expectedExceptionMessage Table status for viewIdtest_cl is incorrect. Can`t fetch version id.
112+
*/
104113
public function testGetVersionWithExceptionNoAutoincrement()
105114
{
106115
$changelogTableName = 'viewIdtest_cl';
@@ -111,8 +120,6 @@ public function testGetVersionWithExceptionNoAutoincrement()
111120
->method('fetchRow')
112121
->will($this->returnValue([]));
113122

114-
$this->expectException('Exception');
115-
$this->expectExceptionMessage("Table status for `{$changelogTableName}` is incorrect. Can`t fetch version id.");
116123
$this->model->setViewId('viewIdtest');
117124
$this->model->getVersion();
118125
}
@@ -215,10 +222,10 @@ public function testGetList()
215222
$this->connectionMock->expects($this->once())
216223
->method('fetchCol')
217224
->with($selectMock)
218-
->will($this->returnValue(['some_data']));
225+
->will($this->returnValue([1]));
219226

220227
$this->model->setViewId('viewIdtest');
221-
$this->assertEquals(['some_data'], $this->model->getList(1, 2));
228+
$this->assertEquals([1], $this->model->getList(1, 2));
222229
}
223230

224231
public function testGetListWithException()

lib/internal/Magento/Framework/Mview/View.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ public function update()
285285
for ($vsFrom = $lastVersionId; $vsFrom < $currentVersionId; $vsFrom += $versionBatchSize) {
286286
// Don't go past the current version for atomicy.
287287
$versionTo = min($currentVersionId, $vsFrom + $versionBatchSize);
288-
$ids = array_map('intval', $this->getChangelog()->getList($vsFrom, $versionTo));
288+
$ids = $this->getChangelog()->getList($vsFrom, $versionTo);
289289

290290
// We run the actual indexer in batches.
291291
// Chunked AFTER loading to avoid duplicates in separate chunks.

lib/internal/Magento/Framework/Mview/View/Changelog.php

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@
66

77
namespace Magento\Framework\Mview\View;
88

9+
use Magento\Framework\DB\Adapter\ConnectionException;
10+
use Magento\Framework\Exception\RuntimeException;
911
use Magento\Framework\Phrase;
1012

13+
/**
14+
* Class Changelog for manipulations with the mview_state table.
15+
*/
1116
class Changelog implements ChangelogInterface
1217
{
1318
/**
@@ -41,6 +46,7 @@ class Changelog implements ChangelogInterface
4146

4247
/**
4348
* @param \Magento\Framework\App\ResourceConnection $resource
49+
* @throws ConnectionException
4450
*/
4551
public function __construct(\Magento\Framework\App\ResourceConnection $resource)
4652
{
@@ -53,12 +59,14 @@ public function __construct(\Magento\Framework\App\ResourceConnection $resource)
5359
* Check DB connection
5460
*
5561
* @return void
56-
* @throws \Exception
62+
* @throws ConnectionException
5763
*/
5864
protected function checkConnection()
5965
{
6066
if (!$this->connection) {
61-
throw new \Exception("The write connection to the database isn't available. Please try again later.");
67+
throw new ConnectionException(
68+
new Phrase("The write connection to the database isn't available. Please try again later.")
69+
);
6270
}
6371
}
6472

@@ -154,14 +162,15 @@ public function getList($fromVersionId, $toVersionId)
154162
(int)$toVersionId
155163
);
156164

157-
return $this->connection->fetchCol($select);
165+
return array_map('intval', $this->connection->fetchCol($select));
158166
}
159167

160168
/**
161169
* Get maximum version_id from changelog
170+
*
162171
* @return int
163172
* @throws ChangelogTableNotExistsException
164-
* @throws \Exception
173+
* @throws RuntimeException
165174
*/
166175
public function getVersion()
167176
{
@@ -173,7 +182,9 @@ public function getVersion()
173182
if (isset($row['Auto_increment'])) {
174183
return (int)$row['Auto_increment'] - 1;
175184
} else {
176-
throw new \Exception("Table status for `{$changelogTableName}` is incorrect. Can`t fetch version id.");
185+
throw new RuntimeException(
186+
new Phrase("Table status for %1 is incorrect. Can`t fetch version id.", [$changelogTableName])
187+
);
177188
}
178189
}
179190

@@ -182,13 +193,15 @@ public function getVersion()
182193
*
183194
* Build a changelog name by concatenating view identifier and changelog name suffix.
184195
*
185-
* @throws \Exception
196+
* @throws \DomainException
186197
* @return string
187198
*/
188199
public function getName()
189200
{
190201
if (strlen($this->viewId) == 0) {
191-
throw new \Exception("View's identifier is not set");
202+
throw new \DomainException(
203+
new Phrase("View's identifier is not set")
204+
);
192205
}
193206
return $this->viewId . '_' . self::NAME_SUFFIX;
194207
}
@@ -216,6 +229,8 @@ public function setViewId($viewId)
216229
}
217230

218231
/**
232+
* Get view's identifier
233+
*
219234
* @return string
220235
*/
221236
public function getViewId()

0 commit comments

Comments
 (0)