/**
  * Runs another command.
  *
  * @param string $name      Command name.
  * @param array  $arguments Arguments.
  *
  * @return integer
  */
 protected function runOtherCommand($name, array $arguments = array())
 {
     $arguments['command'] = $name;
     $cleanup_command = $this->getApplication()->find($name);
     $input = new ArrayInput($arguments);
     return $cleanup_command->run($input, $this->io->getOutput());
 }
Пример #2
0
 /**
  * Displays plugin activity statistics.
  *
  * @return void
  */
 private function _displayPluginActivityStatistics()
 {
     $statistics = array();
     // Combine statistics from all plugins.
     foreach ($this->_plugins as $plugin) {
         $statistics = array_merge($statistics, array_filter($plugin->getStatistics()));
     }
     // Show statistics.
     $this->_io->writeln('<debug>Combined Plugin Statistics:</debug>');
     foreach ($statistics as $statistic_type => $occurrences) {
         $this->_io->writeln('<debug> * ' . $statistic_type . ': ' . $occurrences . '</debug>');
     }
 }
    /**
     * Refreshes database.
     *
     * @return void
     * @throws \LogicException When "$this->io" wasn't set upfront.
     */
    public function refresh()
    {
        if (!isset($this->io)) {
            throw new \LogicException('The "$this->io" must be set prior to calling "$this->refresh()".');
        }
        //ReflectionEngine::$maximumCachedFiles = 10;
        ReflectionEngine::init($this->detectClassLocator());
        $sql = 'UPDATE Files
				SET Found = 0';
        $this->db->perform($sql);
        $files = array();
        $this->io->write('Searching for files ... ');
        foreach ($this->getFinders() as $finder) {
            $files = array_merge($files, array_keys(iterator_to_array($finder)));
        }
        $file_count = count($files);
        $this->io->writeln(array('<info>' . $file_count . ' found</info>', ''));
        $progress_bar = $this->io->createProgressBar($file_count + 2);
        $progress_bar->setMessage('');
        $progress_bar->setFormat('%message%' . PHP_EOL . '%current%/%max% [%bar%] <info>%percent:3s%%</info> %elapsed:6s%/%estimated:-6s% <info>%memory:-10s%</info>');
        $progress_bar->start();
        foreach ($files as $file) {
            $progress_bar->setMessage('Processing File: <info>' . $this->removeProjectPath($file) . '</info>');
            $progress_bar->display();
            $this->processFile($file);
            $progress_bar->advance();
        }
        $sql = 'SELECT Id
				FROM Files
				WHERE Found = 0';
        $deleted_files = $this->db->fetchCol($sql);
        if ($deleted_files) {
            $progress_bar->setMessage('Deleting Files ...');
            $progress_bar->display();
            $sql = 'SELECT Id
					FROM Classes
					WHERE FileId IN (:file_ids)';
            $deleted_classes = $this->db->fetchCol($sql, array('file_ids' => $deleted_files));
            foreach ($deleted_classes as $deleted_class_id) {
                $this->deleteClass($deleted_class_id);
            }
            $progress_bar->advance();
        }
        $progress_bar->setMessage('Processing Class Relations ...');
        $progress_bar->display();
        $this->processClassRawRelations();
        $progress_bar->advance();
        $progress_bar->finish();
        $progress_bar->clear();
    }
Пример #4
0
 /**
  * Queries missing revision data.
  *
  * @param integer $from_revision From revision.
  * @param integer $to_revision   To revision.
  *
  * @return void
  */
 private function _queryRevisionData($from_revision, $to_revision)
 {
     $range_start = $from_revision;
     $project_url = $this->_repositoryConnector->getProjectUrl($this->_repositoryUrl);
     $progress_bar = $this->_io->createProgressBar(ceil(($to_revision - $from_revision) / 1000));
     $progress_bar->setFormat(' * Reading missing revisions: %current%/%max% [%bar%] %percent:3s%%');
     $progress_bar->start();
     while ($range_start < $to_revision) {
         $range_end = min($range_start + 1000, $to_revision);
         $command = $this->_repositoryConnector->getCommand('log', '-r ' . $range_start . ':' . $range_end . ' --xml --verbose --use-merge-history {' . $project_url . '}');
         $this->_parseLog($command->run());
         $range_start = $range_end + 1;
         $progress_bar->advance();
     }
     $progress_bar->finish();
     $this->_io->writeln('');
 }
Пример #5
0
 /**
  * Returns file-based cache storage.
  *
  * @param string  $name     Cache name.
  * @param integer $duration Duration in seconds.
  *
  * @return ICacheStorage
  * @throws \InvalidArgumentException When namespace is missing in the name.
  */
 private function _getStorage($name, $duration = null)
 {
     $name_parts = explode(':', $name, 2);
     if (count($name_parts) != 2) {
         throw new \InvalidArgumentException('The $name parameter must be in "namespace:name" format.');
     }
     $filename_parts = array($name_parts[0], substr(hash_hmac('sha1', $name_parts[1], 'svn-buddy'), 0, 8), 'D' . (isset($duration) ? $duration : 'INF'));
     $cache_filename = $this->_workingDirectory . DIRECTORY_SEPARATOR . implode('_', $filename_parts) . '.cache';
     if (isset($this->_io) && $this->_io->isVerbose()) {
         $message = $cache_filename;
         if (file_exists($cache_filename)) {
             $message .= ' (hit: ' . $this->_sizeHelper->formatSize(filesize($cache_filename)) . ')';
         } else {
             $message .= ' (miss)';
         }
         $this->_io->writeln(array('', '<debug>[cache]: ' . $message . '</debug>'));
     }
     return new FileCacheStorage($cache_filename);
 }
Пример #6
0
 /**
  * Runs the command.
  *
  * @param callable|null $callback Callback.
  *
  * @return string
  * @throws RepositoryCommandException When command execution failed.
  */
 private function _doRun($callback = null)
 {
     $process = $this->_processFactory->createProcess($this->_commandLine, 1200);
     try {
         $start = microtime(true);
         $process->mustRun($callback);
         if ($this->_io->isVerbose()) {
             $runtime = sprintf('%01.2f', microtime(true) - $start);
             $this->_io->writeln(array('', '<debug>[svn, ' . round($runtime, 2) . 's]: ' . $this->_commandLine . '</debug>'));
         }
         $output = (string) $process->getOutput();
         if ($this->_io->isDebug()) {
             $this->_io->writeln($output, OutputInterface::OUTPUT_RAW);
         }
         return $output;
     } catch (ProcessFailedException $e) {
         throw new RepositoryCommandException($this->_commandLine, $process->getErrorOutput());
     }
 }
Пример #7
0
 /**
  * Returns URL of the working copy.
  *
  * @param string $wc_path Working copy path.
  *
  * @return string
  * @throws RepositoryCommandException When repository command failed to execute.
  */
 public function getWorkingCopyUrl($wc_path)
 {
     if ($this->isUrl($wc_path)) {
         return $this->removeCredentials($wc_path);
     }
     try {
         $wc_url = (string) $this->_getSvnInfoEntry($wc_path, self::SVN_INFO_CACHE_DURATION)->url;
     } catch (RepositoryCommandException $e) {
         if ($e->getCode() == RepositoryCommandException::SVN_ERR_WC_UPGRADE_REQUIRED) {
             $message = explode(PHP_EOL, $e->getMessage());
             $this->_io->writeln(array('', '<error>' . end($message) . '</error>', ''));
             if ($this->_io->askConfirmation('Run "svn upgrade"', false)) {
                 $this->getCommand('upgrade', '{' . $wc_path . '}')->runLive();
                 return $this->getWorkingCopyUrl($wc_path);
             }
         }
         throw $e;
     }
     return $wc_url;
 }
Пример #8
0
 /**
  * Runs the command.
  *
  * @param callable|null $callback Callback.
  *
  * @return string
  * @throws RepositoryCommandException When command execution failed.
  */
 private function _doRun($callback = null)
 {
     try {
         $start = microtime(true);
         $this->_process->mustRun($callback);
         if ($this->_io->isVerbose()) {
             $runtime = sprintf('%01.2f', microtime(true) - $start);
             $command_line = $this->_process->getCommandLine();
             $this->_io->writeln(PHP_EOL . '<fg=white;bg=magenta>[svn, ' . round($runtime, 2) . 's]: ' . $command_line . '</>');
         }
     } catch (ProcessFailedException $e) {
         $process = $e->getProcess();
         throw new RepositoryCommandException($process->getCommandLine(), $process->getErrorOutput());
     }
     $output = (string) $this->_process->getOutput();
     if ($this->_io->isDebug()) {
         $this->_io->writeln($output, OutputInterface::OUTPUT_RAW);
     }
     return $output;
 }
 /**
  * Adds a profile entry.
  *
  * @param float  $duration    The query duration.
  * @param string $function    The PDO method that made the entry.
  * @param string $statement   The SQL query statement.
  * @param array  $bind_values The values bound to the statement.
  *
  * @return void
  * @throws \PDOException When duplicate statement is detected.
  */
 public function addProfile($duration, $function, $statement, array $bind_values = array())
 {
     if (!$this->isActive() || $function === 'prepare' || !$statement) {
         return;
     }
     $normalized_statement = $this->normalizeStatement($statement);
     $profile_key = $this->createProfileKey($normalized_statement, $bind_values);
     if ($this->trackDuplicates && !in_array($normalized_statement, $this->ignoredDuplicateStatements) && isset($this->profiles[$profile_key])) {
         $substituted_normalized_statement = $this->substituteParameters($normalized_statement, $bind_values);
         $error_msg = 'Duplicate statement:' . PHP_EOL . $substituted_normalized_statement;
         throw new \PDOException($error_msg);
     }
     $this->profiles[$profile_key] = array('duration' => $duration, 'function' => $function, 'statement' => $statement, 'bind_values' => $bind_values);
     if ($this->_debugMode) {
         $trace = debug_backtrace($this->_backtraceOptions);
         do {
             $trace_line = array_shift($trace);
         } while ($trace && strpos($trace_line['file'], 'aura/sql') !== false);
         $runtime = sprintf('%01.2f', $duration);
         $substituted_normalized_statement = $this->substituteParameters($normalized_statement, $bind_values);
         $trace_file = substr($trace_line['file'], strpos($trace_line['file'], '/src/')) . ':' . $trace_line['line'];
         $this->_io->writeln(array('', '<debug>[db, ' . round($runtime, 2) . 's]: ' . $substituted_normalized_statement . '</debug>', '<debug>[db origin]: ' . $trace_file . '</debug>'));
     }
 }
Пример #10
0
 public function testGetOutput()
 {
     $this->assertSame($this->output->reveal(), $this->io->getOutput());
 }