47 $this->connection =
$resource->getConnection();
60 if (!$this->connection) {
61 throw new \Exception(
"The write connection to the database isn't available. Please try again later.");
73 $changelogTableName = $this->resource->getTableName($this->
getName());
74 if (!$this->connection->isTableExists($changelogTableName)) {
75 $table = $this->connection->newTable(
79 \
Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
81 [
'identity' =>
true,
'unsigned' =>
true,
'nullable' =>
false,
'primary' =>
true],
85 \
Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
87 [
'unsigned' =>
true,
'nullable' =>
false,
'default' =>
'0'],
90 $this->connection->createTable(
$table);
102 $changelogTableName = $this->resource->getTableName($this->
getName());
103 if (!$this->connection->isTableExists($changelogTableName)) {
107 $this->connection->dropTable($changelogTableName);
119 $changelogTableName = $this->resource->getTableName($this->
getName());
120 if (!$this->connection->isTableExists($changelogTableName)) {
124 $this->connection->delete($changelogTableName, [
'version_id < ?' => (
int)$versionId]);
137 public function getList($fromVersionId, $toVersionId)
139 $changelogTableName = $this->resource->getTableName($this->
getName());
140 if (!$this->connection->isTableExists($changelogTableName)) {
144 $select = $this->connection->select()->distinct(
157 return $this->connection->fetchCol(
$select);
168 $changelogTableName = $this->resource->getTableName($this->
getName());
169 if (!$this->connection->isTableExists($changelogTableName)) {
172 $row = $this->connection->fetchRow(
'SHOW TABLE STATUS LIKE ?', [$changelogTableName]);
173 if (isset(
$row[
'Auto_increment'])) {
174 return (
int)
$row[
'Auto_increment'] - 1;
176 throw new \Exception(
"Table status for `{$changelogTableName}` is incorrect. Can`t fetch version id.");
190 if (strlen($this->viewId) == 0) {
191 throw new \Exception(
"View's identifier is not set");
__construct(\Magento\Framework\App\ResourceConnection $resource)
getList($fromVersionId, $toVersionId)