Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #22240: Running cron jobs fails if database name is too long #25472

Merged
merged 3 commits into from Nov 24, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/internal/Magento/Framework/Lock/Backend/Database.php
Expand Up @@ -13,6 +13,7 @@
use Magento\Framework\Exception\AlreadyExistsException;
use Magento\Framework\Exception\InputException;
use Magento\Framework\Phrase;
use Magento\Framework\DB\ExpressionConverter;

/**
* Implementation of the lock manager on the basis of MySQL.
Expand Down Expand Up @@ -166,7 +167,8 @@ public function isLocked(string $name): bool
*/
private function addPrefix(string $name): string
{
$name = $this->getPrefix() . '|' . $name;
$prefix = $this->getPrefix() ? $this->getPrefix() . '|' : '';
$name = ExpressionConverter::shortenEntityName($prefix . $name, $prefix);

if (strlen($name) > 64) {
throw new InputException(new Phrase('Lock name too long: %1...', [substr($name, 0, 64)]));
Expand Down
Expand Up @@ -106,15 +106,18 @@ public function testLock()
* @throws \Magento\Framework\Exception\AlreadyExistsException
* @throws \Magento\Framework\Exception\InputException
* @throws \Zend_Db_Statement_Exception
* @expectedException \Magento\Framework\Exception\InputException
*/
public function testlockWithTooLongName()
{
$this->deploymentConfig
->method('isDbAvailable')
->with()
->willReturn(true);
$this->database->lock('BbXbyf9rIY5xuAVdviQJmh76FyoeeVHTDpcjmcImNtgpO4Hnz4xk76ZGEyYALvrQu');
$this->statement->expects($this->once())
->method('fetchColumn')
->willReturn(true);

$this->assertTrue($this->database->lock('BbXbyf9rIY5xuAVdviQJmh76FyoeeVHTDpcjmcImNtgpO4Hnz4xk76ZGEyYALvrQu'));
}

/**
Expand Down