Skip to content

Commit

Permalink
Additional commit for Groups (CFM-38), changes for MySQL
Browse files Browse the repository at this point in the history
  • Loading branch information
Benn Oshrin committed Jun 23, 2022
1 parent 1770206 commit c19a9ac
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 13 deletions.
8 changes: 8 additions & 0 deletions app/config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,14 @@
'file' => 'trace',
'url' => env('LOG_TRACE_URL', null),
'scopes' => ['trace'],
],
// We define a rules level to record application rule execution
'rule' => [
'className' => 'Cake\Log\Engine\FileLog',
'path' => LOGS,
'file' => 'rule',
'url' => env('LOG_TRACE_URL', null),
'scopes' => ['rule'],
]
],

Expand Down
3 changes: 3 additions & 0 deletions app/resources/locales/en_US/menu.po
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
msgid "co.configuration"
msgstr "Configuration"

msgid "co.groups"
msgstr "Groups"

msgid "co.people"
msgstr "People"

Expand Down
7 changes: 6 additions & 1 deletion app/src/Command/DatabaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,14 @@ public function execute(Arguments $args, ConsoleIo $io) {
'user' => $cfg['username'],
'password' => $cfg['password'],
'host' => $cfg['host'],
'driver' => ($cfg['driver'] == 'Cake\Database\Driver\Postgres' ? "pdo_pgsql" : "pdo_mysql")
'driver' => ($cfg['driver'] == 'Cake\Database\Driver\Postgres' ? "pdo_pgsql" : "mysqli")
];

// For MySQL SSL
if(!empty($cfg['ssl_ca'])) {
$cfargs['ssl_ca'] = $cfg['ssl_ca'];
}

$conn = DriverManager::getConnection($cfargs, $config);

$schema = new Schema();
Expand Down
35 changes: 30 additions & 5 deletions app/src/Command/TransmogrifyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ class TransmogrifyCommand extends Command {
// Make some objects more easily accessible
protected $inconn = null;
protected $outconn = null;
// Cache the driver for ease of workarounds
protected $outdriver = null;

/**
* Build an Option Parser.
Expand Down Expand Up @@ -439,9 +441,15 @@ public function execute(Arguments $args, ConsoleIo $io) {
'user' => $incfg['username'],
'password' => $incfg['password'],
'host' => $incfg['host'],
'driver' => ($incfg['driver'] == 'Cake\Database\Driver\Postgres' ? "pdo_pgsql" : "pdo_mysql")
'driver' => ($incfg['driver'] == 'Cake\Database\Driver\Postgres' ? "pdo_pgsql" : "mysqli")
];

// For MySQL SSL
if(!empty($incfg['ssl_ca'])) {
// mysqli supports SSL configuration
$cargs['ssl_ca'] = $incfg['ssl_ca'];
}

$this->inconn = DriverManager::getConnection($cargs, $inconfig);

$outconfig = new \Doctrine\DBAL\Configuration();
Expand All @@ -451,10 +459,17 @@ public function execute(Arguments $args, ConsoleIo $io) {
'user' => $outcfg['username'],
'password' => $outcfg['password'],
'host' => $outcfg['host'],
'driver' => ($outcfg['driver'] == 'Cake\Database\Driver\Postgres' ? "pdo_pgsql" : "pdo_mysql")
'driver' => ($outcfg['driver'] == 'Cake\Database\Driver\Postgres' ? "pdo_pgsql" : "mysqli")
];

// For MySQL SSL
if(!empty($outcfg['ssl_ca'])) {
// mysqli supports SSL configuration
$cargs['ssl_ca'] = $outcfg['ssl_ca'];
}

$this->outconn = DriverManager::getConnection($cargs, $outconfig);
$this->outdriver = $cargs['driver'];

// We accept a list of table names, mostly for testing purposes
$atables = $args->getArguments();
Expand Down Expand Up @@ -516,7 +531,9 @@ public function execute(Arguments $args, ConsoleIo $io) {

$this->mapFields($t, $row);

$this->outconn->insert($t, $row);
// We prefix the database to the table to avoid having to quote
// table names that match (MySQL) reserved keywords (in particular "groups")
$this->outconn->insert($outcfg['database'] . '.' . $t, $row);

$this->cacheResults($t, $row);

Expand Down Expand Up @@ -566,7 +583,11 @@ public function execute(Arguments $args, ConsoleIo $io) {
// Strictly speaking we should use prepared statements, but we control the
// data here, and also we're executing a maintenance operation (so query
// optimization is less important)
$outsql = "ALTER SEQUENCE " . $t . "_id_seq RESTART WITH " . $max;
if($this->outdriver == 'mysqli') {
$outsql = "ALTER TABLE `" . $t . "` AUTO_INCREMENT = " . $max;
} else {
$outsql = "ALTER SEQUENCE " . $t . "_id_seq RESTART WITH " . $max;
}
$this->outconn->executeQuery($outsql);

// Run any post processing functions for the table.
Expand Down Expand Up @@ -636,7 +657,11 @@ protected function fixBooleans(string $table, array &$row) {
// this issue: https://github.com/doctrine/dbal/issues/1847
// We need to (more generically than this hack) convert from boolean to char
// to avoid errors on insert
$row[$a] = ($row[$a] ? 't' : 'f');
if($this->outdriver == 'mysqli') {
$row[$a] = ($row[$a] ? '1' : '0');
} else {
$row[$a] = ($row[$a] ? 't' : 'f');
}
}
}
}
Expand Down
7 changes: 0 additions & 7 deletions app/src/Model/Behavior/TimezoneBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,6 @@ public function beforeMarshal(Event $event, ArrayObject $data, ArrayObject $opti
}
}
}
// XXX
// - adjust back after find
// - afterfind isn't a thing anymore, perhaps use a mutator?
// - note that's on the entity, not the table, so we can't just use the Behavior, maybe need a trait
// - maybe move this behavior to a trait on the entity and do this entirely with accessors and mutators?
// - or on retrieve we should assert values are UTC then convert in the view
// https://stackoverflow.com/questions/49280448/how-to-handle-users-timezone-and-utc-sync-between-application-and-database-in-c
}

/**
Expand Down

0 comments on commit c19a9ac

Please sign in to comment.