Example #1
0
 /**
  * Execute the command.
  */
 public function execute(\Closure $reporter = null)
 {
     // Clear all existing tags.
     $this->database->truncate();
     // Export built-in tags.
     $tags = $this->extensionTags->getTags();
     if ($reporter !== null) {
         $reporter(sprintf("Importing tags for %d built-in modules...\n", count($tags)));
     }
     foreach ($tags as $module => $moduleTags) {
         $this->database->addTags("<{$module}>", $moduleTags);
     }
     // Start indexing the tags and report progress.
     $reporter(sprintf("Importing %d source files...\n", count($this->files)));
     $tagCount = 0;
     foreach ($this->files as $index => $file) {
         try {
             $tags = $this->parser->getTags($file);
             $tagCount += count($tags);
             $this->database->addTags($file, $tags);
         } catch (ParserError $e) {
             if ($reporter !== null) {
                 $reporter(sprintf("\nError '%s' in '%s'\n", $e->getMessage(), $file));
             }
         }
         if ($reporter !== null) {
             $reporter(sprintf("\r  [%d files, %d tags, %d%%]", $index + 1, $tagCount, ceil(($index + 1) / count($this->files) * 100)));
         }
     }
 }