Exemplo n.º 1
0
 /**
  * Object constructor.
  *
  * @param string  $dataSchema      Data schema name.
  * @param string  $auditSchema     Audit schema name.
  * @param string  $tableName       The table name.
  * @param array[] $theAuditColumns Audit columns from config file.
  * @param bool    $fullOption      If set append table options to rows.
  */
 public function __construct($dataSchema, $auditSchema, $tableName, $theAuditColumns, $fullOption)
 {
     $this->auditColumns = $theAuditColumns;
     $this->fullOption = $fullOption;
     $this->auditTableOptions = AuditDataLayer::getTableOptions($auditSchema, $tableName);
     $this->dataTableOptions = AuditDataLayer::getTableOptions($dataSchema, $tableName);
 }
Exemplo n.º 2
0
 /**
  * Returns a SQL statement for creating the audit table.
  *
  * @return string
  */
 public function buildStatement()
 {
     $code = new MySqlCompoundSyntaxCodeStore();
     $code->append(sprintf('create table `%s`.`%s`', $this->auditSchemaName, $this->tableName));
     // Create SQL for columns.
     $code->append('(');
     $code->append($this->getColumnDefinitions());
     // Create SQL for table options.
     $tableOptions = AuditDataLayer::getTableOptions($this->dataSchemaName, $this->tableName);
     $code->append(sprintf(') engine=%s character set=%s collate=%s', $tableOptions['engine'], $tableOptions['character_set_name'], $tableOptions['table_collation']));
     return $code->getCode();
 }
Exemplo n.º 3
0
 /**
  * Test audit table is created correctly.
  */
 public function test01()
 {
     $application = new Application();
     $application->add(new AuditCommand());
     /** @var AuditCommand $command */
     $command = $application->find('audit');
     $command->setRewriteConfigFile(false);
     $commandTester = new CommandTester($command);
     $commandTester->execute(['command' => $command->getName(), 'config file' => __DIR__ . '/config/audit.json']);
     $this->assertSame(0, $commandTester->getStatusCode());
     // Reconnect to DB.
     AuditDataLayer::connect('localhost', 'test', 'test', self::$dataSchema);
     $table1_data = AuditDataLayer::getTableOptions('test_data', 'TABLE1');
     $table1_audit = AuditDataLayer::getTableOptions('test_audit', 'TABLE1');
     $this->assertEquals($table1_data, $table1_audit, 'TABLE1');
     $table1_data = AuditDataLayer::getTableOptions('test_data', 'TABLE2');
     $table1_audit = AuditDataLayer::getTableOptions('test_audit', 'TABLE2');
     $this->assertEquals($table1_data, $table1_audit, 'TABLE2');
     $table1_data = AuditDataLayer::getTableOptions('test_data', 'TABLE3');
     $table1_audit = AuditDataLayer::getTableOptions('test_audit', 'TABLE3');
     $this->assertEquals($table1_data, $table1_audit, 'TABLE3');
 }