コード例 #1
0
 /**
  * Executes the compare command.
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return int
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->io = new StratumStyle($input, $output);
     $this->io->title('Compare dumped files');
     $config_filename = $input->getArgument('config filename');
     $remote_filename = $input->getArgument('remote filename');
     $local_filename = $input->getArgument('local filename');
     $compare_master_data = new CompareMasterData($config_filename, $this->io);
     $compare_master_data->compare($remote_filename, $local_filename);
     return 0;
 }
コード例 #2
0
ファイル: DataLayer.php プロジェクト: setbased/php-data-sync
 /**
  * Logs the query on the console.
  *
  * @param string $query The query.
  */
 private static function logQuery($query)
 {
     $query = trim($query);
     if (strpos($query, "\n") !== false) {
         // Query is a multi line query.
         self::$io->logVeryVerbose('Executing query:');
         self::$io->logVeryVerbose('<sql>%s</sql>', $query);
     } else {
         // Query is a single line query.
         self::$io->logVeryVerbose('Executing query: <sql>%s</sql>', $query);
     }
 }
コード例 #3
0
 /**
  * Executes the actual PhpStratum program. Returns 0 is everything went fine. Otherwise, returns non-zero.
  *
  * @param InputInterface  $input  An InputInterface instance
  * @param OutputInterface $output An OutputInterface instance
  *
  * @return int
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->io = new StratumStyle($input, $output);
     $command = $this->getApplication()->find('constants');
     $ret = $command->execute($input, $output);
     if ($ret != 0) {
         return $ret;
     }
     $command = $this->getApplication()->find('loader');
     $ret = $command->execute($input, $output);
     if ($ret != 0) {
         return $ret;
     }
     $command = $this->getApplication()->find('wrapper');
     $ret = $command->execute($input, $output);
     $this->io->writeln('');
     return $ret;
 }
コード例 #4
0
 /**
  * Writes a file in two phase to the filesystem.
  *
  * First write the data to a temporary file (in the same directory) and than renames the temporary file. If the file
  * already exists and its content is equal to the data that must be written no action  is taken. This has the
  * following advantages:
  * * In case of some write error (e.g. disk full) the original file is kept in tact and no file with partially data
  * is written.
  * * Renaming a file is atomic. So, running processes will never read a partially written data.
  *
  * @param string       $filename The name of the file were the data must be stored.
  * @param string       $data     The data that must be written.
  * @param StratumStyle $io       The output decorator.
  */
 static function writeTwoPhases($filename, $data, $io)
 {
     $write_flag = true;
     if (file_exists($filename)) {
         $old_data = file_get_contents($filename);
         if ($data == $old_data) {
             $write_flag = false;
         }
     }
     if ($write_flag) {
         $tmp_filename = $filename . '.tmp';
         file_put_contents($tmp_filename, $data);
         rename($tmp_filename, $filename);
         $io->text(sprintf('Wrote <fso>%s</fso>', OutputFormatter::escape($filename)));
     } else {
         $io->text(sprintf('File <fso>%s</fso> is up to date', OutputFormatter::escape($filename)));
     }
 }
コード例 #5
0
 /**
  * Outputs information about removed records.
  *
  * @param $record
  */
 private function writeDeletions($record)
 {
     $this->io->text(sprintf('<sql>%s</sql>', OutputFormatter::escape('Deleted:')));
     $output = "(";
     foreach ($record as $field_name => $field) {
         $output = $output . " {$field},";
     }
     $output = rtrim($output, ", ");
     $output = $output . " )";
     $this->io->text(sprintf('%s', $output));
 }
コード例 #6
0
 /**
  * Executes the Dump data command.
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return integer
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->io = new StratumStyle($input, $output);
     $this->io->title('Dump master data');
     $config_filename = $input->getArgument('config filename');
     $dump_data_filename = $input->getArgument('dump-data filename');
     // Open JSON file for getting data.
     $this->config = new Config($config_filename, $this->io);
     // Open connection with database.
     $data_layer = new DataLayer();
     $data_layer::connect($this->config->data['database']['host_name'], $this->config->data['database']['user_name'], $this->config->data['database']['password'], $this->config->data['database']['data_schema']);
     $data_layer::setIo($this->io);
     // Update config file.
     $this->config->updateConfigFile($data_layer);
     // Dumping master data.
     $dump_master_data = new DumpMasterData($this->config, $data_layer, $this->io);
     $dump_master_data->dumpData($dump_data_filename);
     // Drop database connection.
     $data_layer::disconnect();
     return 0;
 }
コード例 #7
0
ファイル: AuditTable.php プロジェクト: setbased/php-audit
 /**
  * Logs info about new, obsolete, and altered columns.
  *
  * @param TableColumnsMetadata $newColumns      The metadata of the new columns.
  * @param TableColumnsMetadata $obsoleteColumns The metadata of the obsolete columns.
  * @param TableColumnsMetadata $alteredColumns  The metadata of the altered columns.
  */
 private function logColumnInfo($newColumns, $obsoleteColumns, $alteredColumns)
 {
     foreach ($newColumns->getColumns() as $column) {
         $this->io->logInfo('New column <dbo>%s.%s</dbo>', $this->configTable->getTableName(), $column->getProperty('column_name'));
     }
     foreach ($obsoleteColumns->getColumns() as $column) {
         $this->io->logInfo('Obsolete column <dbo>%s.%s</dbo>', $this->configTable->getTableName(), $column->getProperty('column_name'));
     }
     foreach ($alteredColumns->getColumns() as $column) {
         $this->io->logInfo('Type of <dbo>%s.%s</dbo> has been altered to <dbo>%s</dbo>', $this->configTable->getTableName(), $column->getProperty('column_name'), $column->getProperty('column_type'));
     }
 }
コード例 #8
0
ファイル: CrudCommand.php プロジェクト: setbased/php-stratum
 /**
  * Main function for asking.
  *
  * @param array[] $tableList All existing tables from data schema.
  */
 private function startAsking($tableList)
 {
     $question = new Question('Please enter <note>TABLE NAME</note>: ');
     $tableName = $this->helper->ask($this->input, $this->output, $question);
     $key = StaticDataLayer::searchInRowSet('table_name', $tableName, $tableList);
     if (!isset($key)) {
         $this->io->logNote('Table \'%s\' not exist.', $tableName);
     } else {
         $this->askForCreateSP('INSERT', $tableName);
         $this->askForCreateSP('UPDATE', $tableName);
         $this->askForCreateSP('DELETE', $tableName);
         $this->askForCreateSP('SELECT', $tableName);
     }
 }
コード例 #9
0
ファイル: Audit.php プロジェクト: setbased/php-audit
 /**
  * Compares the tables listed in the config file and the tables found in the data schema.
  */
 public function unknownTables()
 {
     foreach ($this->dataSchemaTables as $table) {
         if (isset($this->config['tables'][$table['table_name']])) {
             if (!isset($this->config['tables'][$table['table_name']]['audit'])) {
                 $this->io->writeln(sprintf('<info>audit is not set for table %s</info>', $table['table_name']));
             } else {
                 if ($this->config['tables'][$table['table_name']]['audit']) {
                     if (!isset($this->config['tables'][$table['table_name']]['alias'])) {
                         $this->config['tables'][$table['table_name']]['alias'] = AuditTable::getRandomAlias();
                     }
                 }
             }
         } else {
             $this->io->writeln(sprintf('<info>Found new table %s</info>', $table['table_name']));
             $this->config['tables'][$table['table_name']] = ['audit' => false, 'alias' => null, 'skip' => null];
         }
     }
 }
コード例 #10
0
 /**
  * Validates the parameters found the DocBlock in the source of the stored routine against the parameters from the
  * metadata of MySQL and reports missing and unknown parameters names.
  */
 private function validateParameterLists()
 {
     // Make list with names of parameters used in database.
     $database_parameters_names = [];
     foreach ($this->parameters as $parameter_info) {
         $database_parameters_names[] = $parameter_info['parameter_name'];
     }
     // Make list with names of parameters used in dock block of routine.
     $doc_block_parameters_names = [];
     if (isset($this->docBlockPartsSource['parameters'])) {
         foreach ($this->docBlockPartsSource['parameters'] as $parameter) {
             $doc_block_parameters_names[] = $parameter['name'];
         }
     }
     // Check and show warning if any parameters is missing in doc block.
     $tmp = array_diff($database_parameters_names, $doc_block_parameters_names);
     foreach ($tmp as $name) {
         $this->io->logNote('Parameter <dbo>%s</dbo> is missing from doc block', $name);
     }
     // Check and show warning if find unknown parameters in doc block.
     $tmp = array_diff($doc_block_parameters_names, $database_parameters_names);
     foreach ($tmp as $name) {
         $this->io->logNote('Unknown parameter <dbo>%s</dbo> found in doc block', $name);
     }
 }
コード例 #11
0
ファイル: BaseRoutine.php プロジェクト: setbased/php-stratum
 /**
  * Generate main part with name and params.
  *
  * @param array[]     $columns Columns from table.
  * @param string|null $spType  Stored procedure type {insert|update|delete|select}.
  *
  * @return array[]|null
  */
 protected function checkUniqueKeys($columns, $spType = null)
 {
     $primaryKeys = DataLayer::getTablePrimaryKeys($this->dataSchema, $this->tableName);
     $uniqueKeys = DataLayer::getTableUniqueKeys($this->dataSchema, $this->tableName);
     $resultColumns = [];
     if (!isset($spType)) {
         if (count($uniqueKeys) <= 0 && count($primaryKeys) <= 0) {
             return null;
         } else {
             return $columns;
         }
     }
     if (count($primaryKeys) > 0) {
         foreach ($columns as $column) {
             $check = StaticDataLayer::searchInRowSet('Column_name', $column['column_name'], $primaryKeys);
             if (isset($check)) {
                 $resultColumns[] = $column;
             }
         }
         return $resultColumns;
     } else {
         if (count($uniqueKeys) > 0) {
             reset($uniqueKeys);
             $first = key($uniqueKeys);
             if (count($uniqueKeys) > 1) {
                 $this->io->writeln(sprintf('Table <dbo>%s</dbo> has more than one unique key.', $this->tableName));
                 $array = [];
                 foreach ($uniqueKeys as $column) {
                     if (isset($array[$column['Key_name']])) {
                         $array[$column['Key_name']] .= ',';
                         $array[$column['Key_name']] .= $column['Column_name'];
                     } else {
                         $array[$column['Key_name']] = $column['Column_name'];
                     }
                 }
                 $tableArray = [];
                 foreach ($array as $key => $column) {
                     $tableArray[] = [$key, $column];
                 }
                 $table = new Table($this->output);
                 $table->setHeaders(['Name', 'Keys']);
                 $table->setRows($tableArray);
                 $table->render();
                 $question = new Question(sprintf('What unique keys use in statement?(%s): ', $uniqueKeys[$first]['Key_name']), $uniqueKeys[$first]['Key_name']);
                 $uniqueKeys = $this->helper->ask($this->input, $this->output, $question);
                 $uniqueKeys = explode(',', $array[$uniqueKeys]);
                 foreach ($uniqueKeys as $column) {
                     $resultColumns[] = ['column_name' => $column];
                 }
                 return $resultColumns;
             } else {
                 foreach ($uniqueKeys as $column) {
                     $resultColumns[] = ['column_name' => $column['Column_name']];
                 }
                 return $resultColumns;
             }
         } else {
             return null;
         }
     }
 }