-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from cybex-gmbh/master
v2.0.0
- Loading branch information
Showing
16 changed files
with
520 additions
and
404 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace Cybex\Protector\Classes; | ||
|
||
use Cybex\Protector\Protector; | ||
use Exception; | ||
use Illuminate\Database\Connection; | ||
use Illuminate\Database\Schema\MySqlSchemaState; | ||
use Illuminate\Database\Schema\SchemaState; | ||
use Symfony\Component\Process\Process; | ||
|
||
/** | ||
* This abstract class provides proxies to protected methods within the related MySqlSchemaState. | ||
*/ | ||
abstract class AbstractMySqlSchemaStateProxy extends MySqlSchemaState | ||
{ | ||
public function __construct(protected MySqlSchemaState $schemaState, protected Protector $protector) | ||
{ | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function dump(Connection $connection, $path) | ||
{ | ||
$this->schemaState->dump(...func_get_args()); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function load($path) | ||
{ | ||
$this->schemaState->load(...func_get_args()); | ||
} | ||
|
||
protected function executeDumpProcess(Process $process, $output, array $variables): Process | ||
{ | ||
return $this->schemaState->executeDumpProcess(...func_get_args()); | ||
} | ||
|
||
protected function baseDumpCommand(): string | ||
{ | ||
return $this->schemaState->baseDumpCommand(); | ||
} | ||
|
||
protected function baseVariables(mixed $config): array | ||
{ | ||
return $this->schemaState->baseVariables(...func_get_args()); | ||
} | ||
|
||
protected function removeAutoIncrementingState(string $path): void | ||
{ | ||
$this->schemaState->removeAutoIncrementingState(...func_get_args()); | ||
} | ||
|
||
protected function appendMigrationData(string $path): void | ||
{ | ||
$this->schemaState->appendMigrationData(...func_get_args()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
namespace Cybex\Protector\Classes; | ||
|
||
use Illuminate\Database\Connection; | ||
|
||
/** | ||
* This is a proxy to the MySqlSchemaState class which allows us to override methods to match our own requirements. | ||
* Unfortunately, the class is not bound to the IOC container and thus cannot be switched out at framework level. | ||
* However, you may extend this proxy, and override its app container binding with your custom implementation. | ||
*/ | ||
class MySqlSchemaStateProxy extends AbstractMySqlSchemaStateProxy | ||
{ | ||
/** | ||
* @inheritDoc | ||
*/ | ||
public function dump(Connection $connection, $path) | ||
{ | ||
$this->executeDumpProcess( | ||
$this->schemaState->makeProcess( | ||
$this->getCommandString() | ||
), | ||
$this->schemaState->output, | ||
array_merge( | ||
$this->baseVariables($this->schemaState->connection->getConfig()), | ||
['LARAVEL_LOAD_PATH' => $path,] | ||
) | ||
); | ||
|
||
if ($this->protector->shouldRemoveAutoIncrementingState()) { | ||
$this->removeAutoIncrementingState($path); | ||
} | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function load($path) | ||
{ | ||
$this->schemaState->load(...func_get_args()); | ||
} | ||
|
||
/** | ||
* Get the dump command for MySQL as a string. | ||
*/ | ||
protected function getCommandString(): string | ||
{ | ||
$command = 'mysqldump '.$this->schemaState->connectionString().' '; | ||
|
||
$conditionalParameters = [ | ||
'--set-gtid-purged=OFF' => !$this->schemaState->connection->isMaria(), | ||
'--no-create-db' => !$this->protector->shouldCreateDb(), | ||
'--skip-comments' => !$this->protector->shouldDumpComments(), | ||
'--skip-set-charset' => !$this->protector->shouldDumpCharsets(), | ||
'--no-data' => !$this->protector->shouldDumpData(), | ||
]; | ||
|
||
$parameters = [ | ||
'--add-locks', | ||
'--routines', | ||
'--tz-utc', | ||
'--column-statistics=0', | ||
'--result-file="${:LARAVEL_LOAD_PATH}"', | ||
'--max-allowed-packet='.$this->protector->getMaxPacketLength(), | ||
...array_keys(array_filter($conditionalParameters)), | ||
'"${:LARAVEL_LOAD_DATABASE}"', | ||
]; | ||
|
||
return $command.implode(' ', $parameters); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.