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

Public Member Functions

 __construct (\Magento\Framework\App\ResourceConnection $resource, $connectionName=ModuleDataSetupInterface::DEFAULT_SETUP_CONNECTION)
 
 getConnection ($connectionName=null)
 
 setTable ($tableName, $realTableName)
 
 getTablePlaceholder ($tableName)
 
 getTable ($tableName, $connectionName=ResourceConnection::DEFAULT_CONNECTION)
 
 tableExists ($table, $connectionName=ResourceConnection::DEFAULT_CONNECTION)
 
 run ($sql)
 
 startSetup ()
 
 endSetup ()
 
- Public Member Functions inherited from SetupInterface
 getConnection ()
 
 getTable ($tableName)
 
 tableExists ($table)
 

Detailed Description

Definition at line 14 of file Setup.php.

Constructor & Destructor Documentation

◆ __construct()

Init

Parameters
\Magento\Framework\App\ResourceConnection$resource
string$connectionName

Definition at line 50 of file Setup.php.

53  {
54  $this->resourceModel = $resource;
55  $this->connectionName = $connectionName;
56  }
$resource
Definition: bulk.php:12

Member Function Documentation

◆ endSetup()

endSetup ( )

Prepare database after install/upgrade

Returns
$this

Implements SetupInterface.

Definition at line 184 of file Setup.php.

185  {
186  $this->getConnection()->endSetup();
187  return $this;
188  }

◆ getConnection()

getConnection (   $connectionName = null)

Get connection object

Parameters
string | null$connectionName
Returns
\Magento\Framework\DB\Adapter\AdapterInterface

Definition at line 64 of file Setup.php.

65  {
66  if ($connectionName !== null) {
67  try {
68  return $this->resourceModel->getConnectionByName($connectionName);
69  } catch (\DomainException $exception) {
70  //Fallback to default connection
71  }
72  }
73  return $this->getDefaultConnection();
74  }

◆ getTable()

getTable (   $tableName,
  $connectionName = ResourceConnection::DEFAULT_CONNECTION 
)

Get table name (validated by db adapter) by table placeholder

Parameters
string | array$tableName
string$connectionName
Returns
string

Definition at line 120 of file Setup.php.

121  {
122  $cacheKey = $this->_getTableCacheName($tableName);
123  if (!isset($this->tables[$cacheKey])) {
124  $this->tables[$cacheKey] = $this->resourceModel->getTableName($tableName, $connectionName);
125  }
126  return $this->tables[$cacheKey];
127  }
$tableName
Definition: trigger.php:13

◆ getTablePlaceholder()

getTablePlaceholder (   $tableName)

Gets table placeholder by table name

Parameters
string$tableName
Returns
string

Implements SetupInterface.

Definition at line 108 of file Setup.php.

109  {
110  return $this->resourceModel->getTablePlaceholder($tableName);
111  }
$tableName
Definition: trigger.php:13

◆ run()

run (   $sql)

Run plain SQL query(ies)

Parameters
string$sql
Returns
$this

Implements SetupInterface.

Definition at line 162 of file Setup.php.

163  {
164  $this->getConnection()->query($sql);
165  return $this;
166  }

◆ setTable()

setTable (   $tableName,
  $realTableName 
)

Add table placeholder/table name relation

Parameters
string$tableName
string$realTableName
Returns
$this

Implements SetupInterface.

Definition at line 96 of file Setup.php.

97  {
98  $this->tables[$tableName] = $realTableName;
99  return $this;
100  }
$tableName
Definition: trigger.php:13

◆ startSetup()

startSetup ( )

Prepare database before install/upgrade

Returns
$this

Implements SetupInterface.

Definition at line 173 of file Setup.php.

174  {
175  $this->getConnection()->startSetup();
176  return $this;
177  }

◆ tableExists()

tableExists (   $table,
  $connectionName = ResourceConnection::DEFAULT_CONNECTION 
)

Check is table exists

Parameters
string$table
string$connectionName
Returns
bool

Definition at line 150 of file Setup.php.

151  {
152  $table = $this->getTable($table, $connectionName);
153  return $this->getConnection($connectionName)->isTableExists($table);
154  }
$table
Definition: trigger.php:14
getTable($tableName, $connectionName=ResourceConnection::DEFAULT_CONNECTION)
Definition: Setup.php:120

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