Skip to content

Commit e7816af

Browse files
ENGCOM-6253: Fix issue #22240: Running cron jobs fails if database name is too long #25472
- Merge Pull Request #25472 from vpashovski/magento2:issue-22240 - Merged commits: 1. 08972b4 2. 4dce93e 3. 34f870e
2 parents 6da226d + 34f870e commit e7816af

File tree

2 files changed

+8
-18
lines changed

2 files changed

+8
-18
lines changed

lib/internal/Magento/Framework/Lock/Backend/Database.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
use Magento\Framework\App\ResourceConnection;
1212
use Magento\Framework\Config\ConfigOptionsListConstants;
1313
use Magento\Framework\Exception\AlreadyExistsException;
14-
use Magento\Framework\Exception\InputException;
1514
use Magento\Framework\Phrase;
15+
use Magento\Framework\DB\ExpressionConverter;
1616

1717
/**
1818
* Implementation of the lock manager on the basis of MySQL.
@@ -68,7 +68,6 @@ public function __construct(
6868
* @param string $name lock name
6969
* @param int $timeout How long to wait lock acquisition in seconds, negative value means infinite timeout
7070
* @return bool
71-
* @throws InputException
7271
* @throws AlreadyExistsException
7372
* @throws \Zend_Db_Statement_Exception
7473
*/
@@ -110,7 +109,6 @@ public function lock(string $name, int $timeout = -1): bool
110109
*
111110
* @param string $name lock name
112111
* @return bool
113-
* @throws InputException
114112
* @throws \Zend_Db_Statement_Exception
115113
*/
116114
public function unlock(string $name): bool
@@ -138,7 +136,6 @@ public function unlock(string $name): bool
138136
*
139137
* @param string $name lock name
140138
* @return bool
141-
* @throws InputException
142139
* @throws \Zend_Db_Statement_Exception
143140
*/
144141
public function isLocked(string $name): bool
@@ -162,15 +159,11 @@ public function isLocked(string $name): bool
162159
*
163160
* @param string $name
164161
* @return string
165-
* @throws InputException
166162
*/
167163
private function addPrefix(string $name): string
168164
{
169-
$name = $this->getPrefix() . '|' . $name;
170-
171-
if (strlen($name) > 64) {
172-
throw new InputException(new Phrase('Lock name too long: %1...', [substr($name, 0, 64)]));
173-
}
165+
$prefix = $this->getPrefix() ? $this->getPrefix() . '|' : '';
166+
$name = ExpressionConverter::shortenEntityName($prefix . $name, $prefix);
174167

175168
return $name;
176169
}

lib/internal/Magento/Framework/Lock/Test/Unit/Backend/DatabaseTest.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ protected function setUp()
8686

8787
/**
8888
* @throws \Magento\Framework\Exception\AlreadyExistsException
89-
* @throws \Magento\Framework\Exception\InputException
9089
* @throws \Zend_Db_Statement_Exception
9190
*/
9291
public function testLock()
@@ -104,22 +103,23 @@ public function testLock()
104103

105104
/**
106105
* @throws \Magento\Framework\Exception\AlreadyExistsException
107-
* @throws \Magento\Framework\Exception\InputException
108106
* @throws \Zend_Db_Statement_Exception
109-
* @expectedException \Magento\Framework\Exception\InputException
110107
*/
111108
public function testlockWithTooLongName()
112109
{
113110
$this->deploymentConfig
114111
->method('isDbAvailable')
115112
->with()
116113
->willReturn(true);
117-
$this->database->lock('BbXbyf9rIY5xuAVdviQJmh76FyoeeVHTDpcjmcImNtgpO4Hnz4xk76ZGEyYALvrQu');
114+
$this->statement->expects($this->once())
115+
->method('fetchColumn')
116+
->willReturn(true);
117+
118+
$this->assertTrue($this->database->lock('BbXbyf9rIY5xuAVdviQJmh76FyoeeVHTDpcjmcImNtgpO4Hnz4xk76ZGEyYALvrQu'));
118119
}
119120

120121
/**
121122
* @throws \Magento\Framework\Exception\AlreadyExistsException
122-
* @throws \Magento\Framework\Exception\InputException
123123
* @throws \Zend_Db_Statement_Exception
124124
* @expectedException \Magento\Framework\Exception\AlreadyExistsException
125125
*/
@@ -139,7 +139,6 @@ public function testlockWithAlreadyAcquiredLockInSameSession()
139139

140140
/**
141141
* @throws \Magento\Framework\Exception\AlreadyExistsException
142-
* @throws \Magento\Framework\Exception\InputException
143142
* @throws \Zend_Db_Statement_Exception
144143
*/
145144
public function testLockWithUnavailableDeploymentConfig()
@@ -153,7 +152,6 @@ public function testLockWithUnavailableDeploymentConfig()
153152
}
154153

155154
/**
156-
* @throws \Magento\Framework\Exception\InputException
157155
* @throws \Zend_Db_Statement_Exception
158156
*/
159157
public function testUnlockWithUnavailableDeploymentConfig()
@@ -167,7 +165,6 @@ public function testUnlockWithUnavailableDeploymentConfig()
167165
}
168166

169167
/**
170-
* @throws \Magento\Framework\Exception\InputException
171168
* @throws \Zend_Db_Statement_Exception
172169
*/
173170
public function testIsLockedWithUnavailableDB()

0 commit comments

Comments
 (0)