Skip to content

Commit

Permalink
current changes
Browse files Browse the repository at this point in the history
  • Loading branch information
krowinski committed Jul 4, 2017
1 parent 6dfd4d5 commit b4ea173
Show file tree
Hide file tree
Showing 14 changed files with 106 additions and 43 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
- Changed all exception messages moved to MySQLReplicationException
- Added CHANGELOG.md
- Simplify many classes and removed some of them
- Added decorators for server version recognition
- Changed if datetime not recognised will return null (0000-00-00 00:00:00 is invalid date)
- Added 'custom' param to config if some custom params must be set in extended/implemented own classes
- Added new tests

## v2.2.0 (2017-03-10)
- Removed foreign keys from events
Expand Down
2 changes: 1 addition & 1 deletion example/dump_events.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function allEvents(EventDTO $event)
echo $event;

// all events got JsonSerializable implementation
//echo json_encode($event, JSON_PRETTY_PRINT);
echo json_encode($event, JSON_PRETTY_PRINT);

echo 'Memory usage ' . round(memory_get_usage() / 1048576, 2) . ' MB' . PHP_EOL;
}
Expand Down
24 changes: 24 additions & 0 deletions src/MySQLReplication/BinLog/BinLogServerInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,28 @@ public static function getVersion()
{
return self::$serverInfo['version_name'];
}

/**
* @return bool
*/
public static function isMariaDb()
{
return self::MYSQL_VERSION_MARIADB === self::getVersion();
}

/**
* @return bool
*/
public static function isPercona()
{
return self::MYSQL_VERSION_PERCONA === self::getVersion();
}

/**
* @return bool
*/
public static function isGeneric()
{
return self::MYSQL_VERSION_GENERIC === self::getVersion();
}
}
3 changes: 1 addition & 2 deletions src/MySQLReplication/BinLog/BinLogSocketConnect.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public function __construct(
$this->config = $config;
$this->socket = $socket;


$this->socket->connectToStream($this->config->getHost(), $this->config->getPort());
BinLogServerInfo::parsePackage($this->getResponse(false), $this->repository->getVersion());
$this->authenticate();
Expand Down Expand Up @@ -120,10 +119,10 @@ private function isWriteSuccessful($data)
/**
* @throws BinLogException
* @throws \MySQLReplication\Socket\SocketException
* @link http://dev.mysql.com/doc/internals/en/secure-password-authentication.html#packet-Authentication::Native41
*/
private function authenticate()
{
// http://dev.mysql.com/doc/internals/en/secure-password-authentication.html#packet-Authentication::Native41
$data = pack('L', ConstCapabilityFlags::getCapabilities());
$data .= pack('L', $this->binaryDataMaxLength);
$data .= chr(33);
Expand Down
19 changes: 16 additions & 3 deletions src/MySQLReplication/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace MySQLReplication\Config;

use MySQLReplication\Config\ConfigException;

/**
* Class Config
* @package MySQLReplication\Config
Expand Down Expand Up @@ -70,6 +68,10 @@ class Config
* @var int
*/
private $tableCacheSize;
/**
* @var array
*/
private $custom;

/**
* Config constructor.
Expand All @@ -88,6 +90,7 @@ class Config
* @param array $tablesOnly
* @param array $databasesOnly
* @param int $tableCacheSize
* @param array $custom
*/
public function __construct(
$user,
Expand All @@ -104,7 +107,8 @@ public function __construct(
array $eventsIgnore,
array $tablesOnly,
array $databasesOnly,
$tableCacheSize
$tableCacheSize,
array $custom
) {
$this->user = $user;
$this->host = $host;
Expand All @@ -121,6 +125,7 @@ public function __construct(
$this->databasesOnly = $databasesOnly;
$this->mariaDbGtid = $mariaGtid;
$this->tableCacheSize = $tableCacheSize;
$this->custom = $custom;
}

/**
Expand Down Expand Up @@ -190,6 +195,14 @@ public function validate()
}
}

/**
* @return array
*/
public function getCustom()
{
return $this->custom;
}

/**
* @return string
*/
Expand Down
17 changes: 15 additions & 2 deletions src/MySQLReplication/Config/ConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,15 @@ class ConfigBuilder
/**
* @var string
*/
private $mariaDbGtid;
private $mariaDbGtid = '';
/**
* @var int
*/
private $tableCacheSize = 128;
/**
* @var array
*/
private $custom = [];

/**
* @param string $user
Expand Down Expand Up @@ -231,6 +235,14 @@ public function withTableCacheSize($tableCacheSize)
$this->tableCacheSize = $tableCacheSize;
}

/**
* @param array $custom
*/
public function withCustom(array $custom)
{
$this->custom = $custom;
}

/**
* @return Config
*/
Expand All @@ -251,7 +263,8 @@ public function build()
$this->eventsIgnore,
$this->tablesOnly,
$this->databasesOnly,
$this->tableCacheSize
$this->tableCacheSize,
$this->custom
);
}
}
24 changes: 0 additions & 24 deletions src/MySQLReplication/Config/ConfigException.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,4 @@
*/
class ConfigException extends MySQLReplicationException
{
const USER_ERROR_MESSAGE = 'Incorrect user given';
const USER_ERROR_CODE = 1;
const IP_ERROR_MESSAGE = 'Incorrect IP given';
const IP_ERROR_CODE = 2;
const PORT_ERROR_MESSAGE = 'Incorrect port given should be numeric ';
const PORT_ERROR_CODE = 3;
const PASSWORD_ERROR_MESSAGE = 'Incorrect password type';
const PASSWORD_ERROR_CODE = 4;
const DB_NAME_ERROR_MESSAGE = 'Incorrect db name type';
const DB_NAME_ERROR_CODE = 5;
const CHARSET_ERROR_MESSAGE = 'Incorrect charset type';
const CHARSET_ERROR_CODE = 6;
const GTID_ERROR_MESSAGE = 'Incorrect gtid';
const GTID_ERROR_CODE = 7;
const SLAVE_ID_ERROR_MESSAGE = 'Incorrect slave id type';
const SLAVE_ID_ERROR_CODE = 8;
const BIN_LOG_FILE_NAME_ERROR_MESSAGE = 'Incorrect binlog name type';
const BIN_LOG_FILE_NAME_ERROR_CODE = 9;
const BIN_LOG_FILE_POSITION_ERROR_MESSAGE = 'Incorrect binlog position type';
const BIN_LOG_FILE_POSITION_ERROR_CODE = 10;
const MARIADBGTID_ERROR_MESSAGE = 'Maria gtid must be string';
const MARIADBGTID_ERROR_CODE = 11;
const TABLE_CACHE_SIZE_ERROR_MESSAGE = 'Table cache must be integer';
const TABLE_CACHE_SIZE_ERROR_CODE = 12;
}
4 changes: 4 additions & 0 deletions src/MySQLReplication/Config/ConfigFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public function makeConfigFromArray(array $config)
{
$configBuilder->withTableCacheSize($v);
}
if ('custom' === $k)
{
$configBuilder->withCustom($v);
}
}

return $configBuilder->build();
Expand Down
9 changes: 0 additions & 9 deletions src/MySQLReplication/Event/DTO/EventDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,4 @@ abstract public function getType();
* @return string
*/
abstract public function __toString();

/**
* Specify data which should be serialized to JSON
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
* @return mixed data which can be serialized by <b>json_encode</b>,
* which is a value of any type other than a resource.
* @since 5.4.0
*/
abstract public function jsonSerialize();
}
2 changes: 1 addition & 1 deletion src/MySQLReplication/Event/QueryEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function makeQueryDTO()
*/
private function getSizeToRemoveByVersion()
{
if (BinLogServerInfo::MYSQL_VERSION_MARIADB === BinLogServerInfo::getVersion()) {
if (BinLogServerInfo::isMariaDb()) {
return 13;
}

Expand Down
2 changes: 1 addition & 1 deletion src/MySQLReplication/Event/RotateEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function makeRotateEventDTO()
*/
private function getSizeToRemoveByVersion()
{
if (BinLogServerInfo::MYSQL_VERSION_MARIADB !== BinLogServerInfo::getVersion()) {
if (BinLogServerInfo::isMariaDb()) {
return 8;
}

Expand Down
1 change: 1 addition & 0 deletions src/MySQLReplication/Event/RowEvent/RowEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ protected function getString($size)

/**
* Read MySQL's new decimal format introduced in MySQL 5
* https://dev.mysql.com/doc/refman/5.6/en/precision-math-decimal-characteristics.html
* @param array $column
* @return string
* @throws BinaryDataReaderException
Expand Down
25 changes: 25 additions & 0 deletions src/MySQLReplication/Exception/MySQLReplicationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,29 @@ class MySQLReplicationException extends \Exception

const UNKNOWN_JSON_TYPE_MESSAGE = 'Unknown JSON type: ';
const UNKNOWN_JSON_TYPE_CODE = 300;

const USER_ERROR_MESSAGE = 'Incorrect user given';
const USER_ERROR_CODE = 400;
const IP_ERROR_MESSAGE = 'Incorrect IP given';
const IP_ERROR_CODE = 401;
const PORT_ERROR_MESSAGE = 'Incorrect port given should be numeric ';
const PORT_ERROR_CODE = 402;
const PASSWORD_ERROR_MESSAGE = 'Incorrect password type';
const PASSWORD_ERROR_CODE = 403;
const DB_NAME_ERROR_MESSAGE = 'Incorrect db name type';
const DB_NAME_ERROR_CODE = 404;
const CHARSET_ERROR_MESSAGE = 'Incorrect charset type';
const CHARSET_ERROR_CODE = 405;
const GTID_ERROR_MESSAGE = 'Incorrect gtid';
const GTID_ERROR_CODE = 406;
const SLAVE_ID_ERROR_MESSAGE = 'Incorrect slave id type';
const SLAVE_ID_ERROR_CODE = 407;
const BIN_LOG_FILE_NAME_ERROR_MESSAGE = 'Incorrect binlog name type';
const BIN_LOG_FILE_NAME_ERROR_CODE = 408;
const BIN_LOG_FILE_POSITION_ERROR_MESSAGE = 'Incorrect binlog position type';
const BIN_LOG_FILE_POSITION_ERROR_CODE = 409;
const MARIADBGTID_ERROR_MESSAGE = 'Maria gtid must be string';
const MARIADBGTID_ERROR_CODE = 410;
const TABLE_CACHE_SIZE_ERROR_MESSAGE = 'Table cache must be integer';
const TABLE_CACHE_SIZE_ERROR_CODE = 411;
}
13 changes: 13 additions & 0 deletions tests/Integration/TypesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,19 @@ public function shouldBeBrokenDateTime()
self::assertNull($event->getValues()[0]['test']);
}

/**
* @test
*/
public function shouldReturnNullOnZeroDateDateTime()
{
$create_query = "CREATE TABLE test (test DATETIME NOT NULL);";
$insert_query = "INSERT INTO test VALUES('0000-00-00 00:00:00')";

$event = $this->createAndInsertValue($create_query, $insert_query);

self::assertNull($event->getValues()[0]['test']);
}

/**
* @test
*/
Expand Down

0 comments on commit b4ea173

Please sign in to comment.