PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.2.0
Independent Analytics – WordPress Analytics Plugin v2.2.0
2.15.5 2.15.4 2.15.3 2.15.2 2.15.1 2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / vendor / illuminate / database / Schema / MySqlSchemaState.php
independent-analytics / vendor / illuminate / database / Schema Last commit date
Grammars 2 years ago Blueprint.php 2 years ago Builder.php 2 years ago ColumnDefinition.php 2 years ago ForeignIdColumnDefinition.php 2 years ago ForeignKeyDefinition.php 2 years ago MySqlBuilder.php 2 years ago MySqlSchemaState.php 2 years ago PostgresBuilder.php 2 years ago PostgresSchemaState.php 2 years ago SQLiteBuilder.php 2 years ago SchemaState.php 2 years ago SqlServerBuilder.php 2 years ago SqliteSchemaState.php 2 years ago
MySqlSchemaState.php
117 lines
1 <?php
2
3 namespace IAWP_SCOPED\Illuminate\Database\Schema;
4
5 use Exception;
6 use IAWP_SCOPED\Illuminate\Database\Connection;
7 use IAWP_SCOPED\Illuminate\Support\Str;
8 use IAWP_SCOPED\Symfony\Component\Process\Process;
9 /** @internal */
10 class MySqlSchemaState extends SchemaState
11 {
12 /**
13 * Dump the database's schema into a file.
14 *
15 * @param \Illuminate\Database\Connection $connection
16 * @param string $path
17 * @return void
18 */
19 public function dump(Connection $connection, $path)
20 {
21 $this->executeDumpProcess($this->makeProcess($this->baseDumpCommand() . ' --routines --result-file="${:LARAVEL_LOAD_PATH}" --no-data'), $this->output, \array_merge($this->baseVariables($this->connection->getConfig()), ['LARAVEL_LOAD_PATH' => $path]));
22 $this->removeAutoIncrementingState($path);
23 $this->appendMigrationData($path);
24 }
25 /**
26 * Remove the auto-incrementing state from the given schema dump.
27 *
28 * @param string $path
29 * @return void
30 */
31 protected function removeAutoIncrementingState(string $path)
32 {
33 $this->files->put($path, \preg_replace('/\\s+AUTO_INCREMENT=[0-9]+/iu', '', $this->files->get($path)));
34 }
35 /**
36 * Append the migration data to the schema dump.
37 *
38 * @param string $path
39 * @return void
40 */
41 protected function appendMigrationData(string $path)
42 {
43 $process = $this->executeDumpProcess($this->makeProcess($this->baseDumpCommand() . ' ' . $this->migrationTable . ' --no-create-info --skip-extended-insert --skip-routines --compact'), null, \array_merge($this->baseVariables($this->connection->getConfig()), []));
44 $this->files->append($path, $process->getOutput());
45 }
46 /**
47 * Load the given schema file into the database.
48 *
49 * @param string $path
50 * @return void
51 */
52 public function load($path)
53 {
54 $command = 'mysql ' . $this->connectionString() . ' --database="${:LARAVEL_LOAD_DATABASE}" < "${:LARAVEL_LOAD_PATH}"';
55 $process = $this->makeProcess($command)->setTimeout(null);
56 $process->mustRun(null, \array_merge($this->baseVariables($this->connection->getConfig()), ['LARAVEL_LOAD_PATH' => $path]));
57 }
58 /**
59 * Get the base dump command arguments for MySQL as a string.
60 *
61 * @return string
62 */
63 protected function baseDumpCommand()
64 {
65 $command = 'mysqldump ' . $this->connectionString() . ' --no-tablespaces --skip-add-locks --skip-comments --skip-set-charset --tz-utc --column-statistics=0';
66 if (!$this->connection->isMaria()) {
67 $command .= ' --set-gtid-purged=OFF';
68 }
69 return $command . ' "${:LARAVEL_LOAD_DATABASE}"';
70 }
71 /**
72 * Generate a basic connection string (--socket, --host, --port, --user, --password) for the database.
73 *
74 * @return string
75 */
76 protected function connectionString()
77 {
78 $value = ' --user="${:LARAVEL_LOAD_USER}" --password="${:LARAVEL_LOAD_PASSWORD}"';
79 $value .= $this->connection->getConfig()['unix_socket'] ?? \false ? ' --socket="${:LARAVEL_LOAD_SOCKET}"' : ' --host="${:LARAVEL_LOAD_HOST}" --port="${:LARAVEL_LOAD_PORT}"';
80 return $value;
81 }
82 /**
83 * Get the base variables for a dump / load command.
84 *
85 * @param array $config
86 * @return array
87 */
88 protected function baseVariables(array $config)
89 {
90 $config['host'] = $config['host'] ?? '';
91 return ['LARAVEL_LOAD_SOCKET' => $config['unix_socket'] ?? '', 'LARAVEL_LOAD_HOST' => \is_array($config['host']) ? $config['host'][0] : $config['host'], 'LARAVEL_LOAD_PORT' => $config['port'] ?? '', 'LARAVEL_LOAD_USER' => $config['username'], 'LARAVEL_LOAD_PASSWORD' => $config['password'] ?? '', 'LARAVEL_LOAD_DATABASE' => $config['database']];
92 }
93 /**
94 * Execute the given dump process.
95 *
96 * @param \Symfony\Component\Process\Process $process
97 * @param callable $output
98 * @param array $variables
99 * @return \Symfony\Component\Process\Process
100 */
101 protected function executeDumpProcess(Process $process, $output, array $variables)
102 {
103 try {
104 $process->setTimeout(null)->mustRun($output, $variables);
105 } catch (Exception $e) {
106 if (Str::contains($e->getMessage(), ['column-statistics', 'column_statistics'])) {
107 return $this->executeDumpProcess(Process::fromShellCommandLine(\str_replace(' --column-statistics=0', '', $process->getCommandLine())), $output, $variables);
108 }
109 if (Str::contains($e->getMessage(), ['set-gtid-purged'])) {
110 return $this->executeDumpProcess(Process::fromShellCommandLine(\str_replace(' --set-gtid-purged=OFF', '', $process->getCommandLine())), $output, $variables);
111 }
112 throw $e;
113 }
114 return $process;
115 }
116 }
117