Example #1
0
 /**
  * Executa comando
  *
  * @param Object $oInput
  * @param Object $oOutput
  * @access public
  * @return void
  */
 public function execute($oInput, $oOutput)
 {
     $oOutput->write("baixando atualizações...\r");
     $oComando = $this->getApplication()->execute('cvs update -dRP');
     $aRetornoComandoUpdate = $oComando->output;
     $iStatusComandoUpdate = $oComando->code;
     /**
      * Caso CVS encontre conflito, retorna erro 1
      */
     if ($iStatusComandoUpdate > 1) {
         $oOutput->writeln('<error>Erro nº ' . $iStatusComandoUpdate . ' ao execurar cvs update -dR:' . "\n" . $this->getApplication()->getLastError() . '</error>');
         return $iStatusComandoUpdate;
     }
     $oOutput->writeln(str_repeat(' ', \Shell::columns()) . "\r" . "Atualizações baixados");
     $sComandoRoot = '';
     /**
      * Senha do root
      */
     $sSenhaRoot = $this->getApplication()->getConfig('senhaRoot');
     /**
      * Executa comando como root 
      * - caso for existir senha no arquivo de configuracoes
      */
     if (!empty($sSenhaRoot)) {
         $sComandoRoot = "echo '{$sSenhaRoot}' | sudo -S ";
     }
     $oComando = $this->getApplication()->execute($sComandoRoot . 'chmod 777 -R ' . getcwd());
     $aRetornoComandoPermissoes = $oComando->output;
     $iStatusComandoPermissoes = $oComando->code;
     if ($iStatusComandoPermissoes > 0) {
         throw new Exception("Erro ao atualizar permissões dos arquivos, configura a senha do root: cvsgit config -e");
     }
 }
Example #2
0
 /**
  * Importa historicos do CVS para usar em consultas locais
  *
  * @access public
  * @return boolean
  */
 public function importarHistorico()
 {
     $oModel = $this->oModel;
     $oDataBase = $this->oDataBase;
     $oDataBase->begin();
     $aLogRepositorio = $this->getLogRepository();
     $iTotalArquivos = count($aLogRepositorio);
     $iArquivosImportados = 0;
     foreach ($aLogRepositorio as $sArquivo => $oDadosArquivo) {
         try {
             $iArquivosImportados++;
             $sArquivoBusca = getcwd() . '/' . $sArquivo;
             $sArquivoBusca = strtr($sArquivo, array(' ' => '\\ ', '(' => '\\(', ')' => '\\)', "'" => "\\'"));
             $this->oOutput->write("\r" . str_repeat(' ', \Shell::columns()) . "\r[{$iArquivosImportados}/{$iTotalArquivos}] Processando arquivo: {$sArquivoBusca}");
             $aDadosHistoricoArquivoSalvo = $oDataBase->selectAll("\n          SELECT id \n            FROM history_file \n           WHERE project_id = " . $oModel->getProjeto()->id . "\n             AND name = '{$sArquivoBusca}' \n        ");
             if (!empty($aDadosHistoricoArquivoSalvo)) {
                 foreach ($aDadosHistoricoArquivoSalvo as $oDadosHistoricoArquivoSalvo) {
                     $oDataBase->delete('history_file', 'id = ' . $oDadosHistoricoArquivoSalvo->id);
                     $oDataBase->delete('history_file_tag', 'history_file_id = ' . $oDadosHistoricoArquivoSalvo->id);
                 }
             }
             foreach ($oDadosArquivo->aLog as $iVersao => $oDadosVersao) {
                 $data = str_replace('/', '-', $oDadosVersao->sData . ' ' . $oDadosVersao->sHora);
                 $data = strtotime($data);
                 $sData = date('Y-m-d H:s:i', $data);
                 $sMensagem = str_replace("'", '"', $oDadosVersao->sMensagem);
                 $iHistorico = $oDataBase->insert('history_file', array('project_id' => $oModel->getProjeto()->id, 'name' => $sArquivoBusca, 'revision' => $oDadosVersao->iVersao, 'message' => $sMensagem, 'author' => $oDadosVersao->sAutor, 'date' => $sData));
                 foreach ($oDadosVersao->aTags as $sTag) {
                     $oDataBase->insert('history_file_tag', array('history_file_id' => $iHistorico, 'tag' => $sTag));
                 }
             }
         } catch (\PDOException $oErro) {
             $this->oOutput->write("\r" . str_repeat(' ', \Shell::columns()) . "\r\n<error>  - Arquivo não processado: {$sArquivo}\n  {$oErro->getMessage()}</error>\n\n");
         }
     }
     // endforeach - dados do log
     $oDataBase->commit();
     $this->oOutput->write("\r" . str_repeat(' ', \Shell::columns()) . "\r<info>Histórico de {$iArquivosImportados} arquivo(s) importado.</info>\n");
     return true;
 }
Example #3
0
 /**
  * Executa o comando
  *
  * @param Object $oInput
  * @param Object $oOutput
  * @access public
  * @return void
  */
 public function execute($oInput, $oOutput)
 {
     $sArquivo = $oInput->getArgument('arquivo');
     $sArquivo = $this->getApplication()->clearPath($sArquivo);
     /**
      * Lista somenta as tags
      */
     $oComando = $this->getApplication()->execute('cvs log -h ' . escapeshellarg($sArquivo));
     $aRetornoComandoTags = $oComando->output;
     $iStatusComandoTags = $oComando->code;
     if ($iStatusComandoTags > 0) {
         throw new Exception('Erro ao execurar cvs log -h ' . escapeshellarg($sArquivo) . PHP_EOL . $this->getApplication()->getLastError(), $iStatusComandoTags);
     }
     $aTagsPorVersao = array();
     $iVersaoAtual = 0;
     $lInicioListaTags = false;
     foreach ($aRetornoComandoTags as $iIndiceTags => $sLinhaRetornoTag) {
         if (strpos($sLinhaRetornoTag, 'head:') !== false) {
             $iVersaoAtual = trim(str_replace('head:', '', $sLinhaRetornoTag));
             continue;
         }
         if (strpos($sLinhaRetornoTag, 'symbolic names:') !== false) {
             $lInicioListaTags = true;
             continue;
         }
         if ($lInicioListaTags) {
             if (strpos($sLinhaRetornoTag, 'keyword substitution') !== false) {
                 break;
             }
             if (strpos($sLinhaRetornoTag, 'total revisions') !== false) {
                 break;
             }
             $aLinhaTag = explode(':', $sLinhaRetornoTag);
             $iVersao = trim($aLinhaTag[1]);
             $sTag = trim($aLinhaTag[0]);
             $aTagsPorVersao[$iVersao][] = $sTag;
         }
     }
     /**
      * Lista informacoes do commit, sem as tags
      */
     $oComando = $this->getApplication()->execute('cvs log -N ' . escapeshellarg($sArquivo));
     $aRetornoComandoInformacoes = $oComando->output;
     $iStatusComandoInformacoes = $oComando->code;
     if ($iStatusComandoInformacoes > 0) {
         throw new Exception('Erro ao execurar cvs log -N ' . escapeshellarg($sArquivo) . PHP_EOL . $this->getApplication()->getLastError(), $iStatusComandoInformacoes);
     }
     $aLog = array();
     $iLinhaInformacaoCommit = 0;
     $oTabela = new Table();
     $oTabela->setHeaders(array('Autor', 'Data', 'Versao', 'Tag', 'Mensagem'));
     $aLinhas = array();
     $iVersao = null;
     $sAutor = null;
     $sData = null;
     $sMensagem = null;
     foreach ($aRetornoComandoInformacoes as $iIndice => $sLinhaRetorno) {
         if (strpos($sLinhaRetorno, '------') !== false) {
             continue;
         }
         if ($iLinhaInformacaoCommit == 0 && $iIndice > 11) {
             $sTagsPorVersao = null;
             if (!empty($aTagsPorVersao[$iVersao])) {
                 $sTagsPorVersao = implode(', ', $aTagsPorVersao[$iVersao]);
             }
             $oTabela->addRow(array($sAutor, $sData, $iVersao, $sTagsPorVersao, Encode::toUTF8($sMensagem)));
             $iVersao = '';
             $sAutor = '';
             $sData = '';
             $sMensagem = '';
         }
         if ($iLinhaInformacaoCommit > 0) {
             $iLinhaInformacaoCommit--;
         }
         /**
          * Versao
          */
         if (strpos($sLinhaRetorno, 'revision') !== false && strpos($sLinhaRetorno, 'revision') === 0) {
             $iLinhaInformacaoCommit = 2;
         }
         /**
          * Versao
          */
         if ($iLinhaInformacaoCommit == 2) {
             $iVersao = trim(str_replace('revision', '', $sLinhaRetorno));
             continue;
         }
         /**
          * Data e autor 
          */
         if ($iLinhaInformacaoCommit == 1) {
             $sLinhaRetorno = strtr($sLinhaRetorno, array('date:' => '', 'author:' => ''));
             $aLinhaInformacoesCommit = explode(';', $sLinhaRetorno);
             $sLinhaData = array_shift($aLinhaInformacoesCommit);
             $aLinhaData = explode(' ', $sLinhaData);
             $sData .= implode('/', array_reverse(explode('-', $aLinhaData[1])));
             $sAutor = trim(array_shift($aLinhaInformacoesCommit));
             continue;
         }
         /**
          * Mensagem 
          */
         if ($iLinhaInformacaoCommit == 0) {
             $sMensagem = $sLinhaRetorno;
         }
     }
     $sOutput = Encode::toUTF8($oTabela->render());
     $iColunas = array_sum($oTabela->getWidths());
     $iColunas += count($oTabela->getWidths()) * 2;
     $iColunas += count($oTabela->getWidths()) - 1;
     if ($iColunas > \Shell::columns()) {
         $this->getApplication()->less($sOutput);
         return;
     }
     $oOutput->writeln($sOutput);
 }