Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions
Mysql Class Reference
Inheritance diagram for Mysql:
AbstractDb

Public Member Functions

 __construct ($host, $user, $password, $schema, $varPath, \Magento\Framework\Shell $shell)
 
 cleanup ()
 
 isDbDumpExists ()
 
 storeDbDump ()
 
 restoreFromDbDump ()
 
 getVendorName ()
 
- Public Member Functions inherited from AbstractDb
 __construct ($host, $user, $password, $schema, $varPath, \Magento\Framework\Shell $shell)
 
 cleanup ()
 
 isDbDumpExists ()
 
 storeDbDump ()
 
 restoreFromDbDump ()
 
 getVendorName ()
 
 getSchema ()
 
 getHost ()
 
 getUser ()
 
 getPassword ()
 

Data Fields

const DEFAULT_PORT = 3306
 
const DEFAULTS_EXTRA_FILE_NAME = 'defaults_extra.cnf'
 

Protected Member Functions

 getSetupDbDumpFilename ()
 
- Protected Member Functions inherited from AbstractDb
 getSetupDbDumpFilename ()
 
 _createScript ($file, $content)
 
 assertVarPathWritable ()
 

Additional Inherited Members

- Protected Attributes inherited from AbstractDb
 $_host = ''
 
 $_user = ''
 
 $_password = ''
 
 $_schema = ''
 
 $_varPath = ''
 
 $_shell
 

Detailed Description

Definition at line 12 of file Mysql.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $host,
  $user,
  $password,
  $schema,
  $varPath,
\Magento\Framework\Shell  $shell 
)

{}

Definition at line 48 of file Mysql.php.

49  {
50  parent::__construct($host, $user, $password, $schema, $varPath, $shell);
51  $this->_port = self::DEFAULT_PORT;
52  if (strpos($this->_host, ':') !== false) {
53  list($host, $port) = explode(':', $this->_host);
54  $this->_host = $host;
55  $this->_port = (int) $port;
56  }
57  $this->_dbDumpFile = $this->_varPath . '/setup_dump_' . $this->_schema . '.sql';
58  $this->_defaultsExtraFile = rtrim($this->_varPath, '\\/') . '/' . self::DEFAULTS_EXTRA_FILE_NAME;
59  }
if(!file_exists($installConfigFile)) if(!defined('TESTS_INSTALLATION_DB_CONFIG_FILE')) $shell
Definition: bootstrap.php:46
$user
Definition: dummy_user.php:13

Member Function Documentation

◆ cleanup()

cleanup ( )

Remove all DB objects

Definition at line 64 of file Mysql.php.

65  {
66  $this->ensureDefaultsExtraFile();
67  $this->_shell->execute(
68  'mysql --defaults-file=%s --host=%s --port=%s %s -e %s',
69  [
70  $this->_defaultsExtraFile,
71  $this->_host,
72  $this->_port,
73  $this->_schema,
74  "DROP DATABASE `{$this->_schema}`; CREATE DATABASE `{$this->_schema}`"
75  ]
76  );
77  }

◆ getSetupDbDumpFilename()

getSetupDbDumpFilename ( )
protected

Get filename for setup db dump

Returns
string

Definition at line 84 of file Mysql.php.

85  {
86  return $this->_dbDumpFile;
87  }

◆ getVendorName()

getVendorName ( )

{}

Definition at line 130 of file Mysql.php.

131  {
132  return 'mysql';
133  }

◆ isDbDumpExists()

isDbDumpExists ( )

Is dump exists

Returns
bool

Definition at line 94 of file Mysql.php.

95  {
96  return file_exists($this->getSetupDbDumpFilename());
97  }

◆ restoreFromDbDump()

restoreFromDbDump ( )

{}

Exceptions

Definition at line 115 of file Mysql.php.

116  {
117  $this->ensureDefaultsExtraFile();
118  if (!$this->isDbDumpExists()) {
119  throw new \LogicException("DB dump file does not exist: " . $this->getSetupDbDumpFilename());
120  }
121  $this->_shell->execute(
122  'mysql --defaults-file=%s --host=%s --port=%s %s < %s',
123  [$this->_defaultsExtraFile, $this->_host, $this->_port, $this->_schema, $this->getSetupDbDumpFilename()]
124  );
125  }

◆ storeDbDump()

storeDbDump ( )

Store setup db dump

Definition at line 102 of file Mysql.php.

103  {
104  $this->ensureDefaultsExtraFile();
105  $this->_shell->execute(
106  'mysqldump --defaults-file=%s --host=%s --port=%s %s > %s',
107  [$this->_defaultsExtraFile, $this->_host, $this->_port, $this->_schema, $this->getSetupDbDumpFilename()]
108  );
109  }

Field Documentation

◆ DEFAULT_PORT

const DEFAULT_PORT = 3306

Default port

Definition at line 17 of file Mysql.php.

◆ DEFAULTS_EXTRA_FILE_NAME

const DEFAULTS_EXTRA_FILE_NAME = 'defaults_extra.cnf'

Defaults extra file name

Definition at line 22 of file Mysql.php.


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