protected function execute(InputInterface $input, OutputInterface $output)
 {
     $logger = $this->getService('logger');
     $relsFile = $input->getOption('file');
     $style = new OutputFormatterStyle(null, null, array('bold'));
     $output->getFormatter()->setStyle('b', $style);
     if (!is_readable($relsFile)) {
         $logger->error("Unable to access relationships file {$relsFile}.");
         $output->writeln('');
         $output->writeln("Use \"{$this->getProgramName()} rels:dump\" first to dump the current table state.");
         return ExitCode::EXIT_RELS_NOT_FOUND;
     }
     try {
         $meta = new Relationship($logger, $this->getService('sugarcrm.pdo'), $relsFile);
         $relsFromFile = $meta->loadFromFile();
         $relsFromDb = $meta->loadFromDb();
         $diff = $meta->diff($relsFromDb, $relsFromFile);
         if (empty($diff[Relationship::ADD]) && empty($diff[Relationship::UPDATE]) && empty($diff[Relationship::DEL])) {
             $output->writeln('<info>Relationships are synced</info>');
             return;
         }
         $this->writeAdd($output, $diff[Relationship::ADD]);
         $this->writeUpdate($output, $diff[Relationship::UPDATE]);
         $this->writeDel($output, $diff[Relationship::DEL]);
         if ($input->getOption('quiet') && (!empty($diff[Relationship::ADD]) || !empty($diff[Relationship::DEL]) || !empty($diff[Relationship::UPDATE]))) {
             return ExitCode::EXIT_STATUS_MODIFICATIONS;
         }
     } catch (SugarException $e) {
         $logger->error('An error occured.');
         $logger->error($e->getMessage());
         return ExitCode::EXIT_UNKNOWN_SUGAR_ERROR;
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $logger = $this->getService('logger');
     $relsFile = $input->getOption('file');
     $diffMode = $this->getDiffMode($input);
     if (!is_readable($relsFile)) {
         $logger->error("Unable to access relationships file {$relsFile}.");
         $output->writeln('');
         $output->writeln("Use \"{$this->getProgramName()} rels:dump\" first to dump the current table state.");
         return ExitCode::EXIT_RELS_NOT_FOUND;
     }
     try {
         $meta = new Relationship($logger, $this->getService('sugarcrm.pdo'), $relsFile);
         $relsFromFile = array();
         if (is_readable($relsFile)) {
             $relsFromFile = $meta->loadFromFile();
         }
         $relsFromDb = $meta->loadFromDb();
         $diffRes = $meta->diff($relsFromDb, $relsFromFile, $diffMode);
         $logger->info("Fields relationships loaded from {$relsFile}.");
         if ($input->getOption('sql')) {
             $output->writeln($meta->generateSqlQueries($diffRes));
         }
         if ($input->getOption('force')) {
             $meta->executeQueries($diffRes);
             $output->writeln('DB updated successfuly.');
         } else {
             $output->writeln('No action done. Use --force to execute the queries.');
         }
     } catch (SugarException $e) {
         $logger->error('An error occured while loading the relationships.');
         $logger->error($e->getMessage());
         return ExitCode::EXIT_UNKNOWN_SUGAR_ERROR;
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $logger = $this->getService('logger');
     $relsFile = $input->getOption('file');
     $diffMode = $this->getDiffMode($input);
     try {
         $meta = new Relationship($logger, $this->getService('sugarcrm.pdo'), $relsFile);
         $relsFromFile = array();
         if (is_readable($relsFile)) {
             $relsFromFile = $meta->loadFromFile();
         }
         $relsFromDb = $meta->loadFromDb();
         $diffRes = $meta->diff($relsFromFile, $relsFromDb, $diffMode);
         $logger->info('Fields metadata loaded from DB.');
         $meta->writeFile($diffRes);
         $output->writeln("Updated file {$relsFile}.");
     } catch (SugarException $e) {
         $logger->error('An error occured while dumping the metadata.');
         $logger->error($e->getMessage());
         return ExitCode::EXIT_UNKNOWN_SUGAR_ERROR;
     }
 }
Ejemplo n.º 4
0
 public function testRealDb()
 {
     $meta = new Relationship(new NullLogger(), $this->getPdo());
     $db = $meta->loadFromDb();
     $meta->setDefFile(__DIR__ . '/relationships/metadata_base.yaml');
     $base = $meta->loadFromFile();
     $this->assertEquals($base, $db);
     $meta->setDefFile(__DIR__ . '/relationships/metadata_new.yaml');
     $new = $meta->loadFromFile();
     $diff = $meta->diff($base, $new);
     $meta->executeQueries($diff);
     $expected = new \PHPUnit_Extensions_Database_DataSet_YamlDataSet(__DIR__ . '/relationships/db_new_dataset.yaml');
     $queryTable = $this->getConnection()->createQueryTable('relationships', 'SELECT * FROM relationships ORDER BY BINARY id ASC');
     $this->assertTablesEqual($expected->getTable('relationships'), $queryTable);
 }