Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
Database Class Reference
Inheritance diagram for Database:
LockManagerInterface

Public Member Functions

 __construct (ResourceConnection $resource, DeploymentConfig $deploymentConfig, string $prefix=null)
 
 lock (string $name, int $timeout=-1)
 
 unlock (string $name)
 
 isLocked (string $name)
 

Detailed Description

LockManager using the DB locks

Definition at line 20 of file Database.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( ResourceConnection  $resource,
DeploymentConfig  $deploymentConfig,
string  $prefix = null 
)
Parameters
ResourceConnection$resource
DeploymentConfig$deploymentConfig
string | null$prefix

Definition at line 47 of file Database.php.

51  {
52  $this->resource = $resource;
53  $this->deploymentConfig = $deploymentConfig;
54  $this->prefix = $prefix;
55  }

Member Function Documentation

◆ isLocked()

isLocked ( string  $name)

Tests of lock is set for name

Parameters
string$namelock name
Returns
bool
Exceptions
InputException

Implements LockManagerInterface.

Definition at line 126 of file Database.php.

126  : bool
127  {
128  $name = $this->addPrefix($name);
129 
130  return (bool)$this->resource->getConnection()->query(
131  "SELECT IS_USED_LOCK(?);",
132  [(string)$name]
133  )->fetchColumn();
134  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ lock()

lock ( string  $name,
int  $timeout = -1 
)

Sets a lock for name

Parameters
string$namelock name
int$timeoutHow long to wait lock acquisition in seconds, negative value means infinite timeout
Returns
bool
Exceptions
InputException
AlreadyExistsException

Before MySQL 5.7.5, only a single simultaneous lock per connection can be acquired. This limitation can be removed once MySQL minimum requirement has been raised, currently we support MySQL 5.6 way only.

Implements LockManagerInterface.

Definition at line 66 of file Database.php.

66  : bool
67  {
68  $name = $this->addPrefix($name);
69 
75  if ($this->currentLock) {
76  throw new AlreadyExistsException(
77  new Phrase(
78  'Current connection is already holding lock for $1, only single lock allowed',
79  [$this->currentLock]
80  )
81  );
82  }
83 
84  $result = (bool)$this->resource->getConnection()->query(
85  "SELECT GET_LOCK(?, ?);",
86  [(string)$name, (int)$timeout]
87  )->fetchColumn();
88 
89  if ($result === true) {
90  $this->currentLock = $name;
91  }
92 
93  return $result;
94  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ unlock()

unlock ( string  $name)

Releases a lock for name

Parameters
string$namelock name
Returns
bool
Exceptions
InputException

Implements LockManagerInterface.

Definition at line 103 of file Database.php.

103  : bool
104  {
105  $name = $this->addPrefix($name);
106 
107  $result = (bool)$this->resource->getConnection()->query(
108  "SELECT RELEASE_LOCK(?);",
109  [(string)$name]
110  )->fetchColumn();
111 
112  if ($result === true) {
113  $this->currentLock = false;
114  }
115 
116  return $result;
117  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

The documentation for this class was generated from the following file: