示例#1
0
 /**
  * Implements CollectionAbstract::loadSourceData().
  *
  * Executes a `git log -p [commit] -1` command to get the data, parses the
  * log entry into an associative array of parts.
  *
  * @return array
  */
 public function loadSourceData(QueueMessage $message)
 {
     $identifier = $message->getBody();
     list($commit, $repository) = explode(':', $identifier, 2);
     $git = $this->getGit($repository);
     $options = array('p' => $commit, '1' => true);
     $log = $git->log(null, null, $options);
     list($headers, $message, $diff) = explode("\n\n", $log);
     // Re-append a line break for lookahead pattern matching.
     $headers .= "\n";
     $data = array('id' => $identifier, 'commit' => $commit, 'repository' => $repository, 'message' => trim($message), 'diff' => trim($diff));
     $patterns = array('author' => '/Author:\\s+(.+)(?=\\n)/s', 'committer' => '/Committer:\\s+(.+)(?=\\n)/s', 'date' => '/Date:\\s+(.+)(?=\\n)/s');
     foreach ($patterns as $field_name => $pattern) {
         if (preg_match($pattern, $headers, $match)) {
             $data[$field_name] = $match[1];
         }
     }
     return $data;
 }
 /**
  * Implements CollectionAbstract::loadSourceData().
  */
 public function loadSourceData(QueueMessage $message)
 {
     $item_id = $message->getBody();
     if (isset($this->_scheduledItems[$item_id])) {
         return $this->_scheduledItems[$item_id];
     }
     // @todo Handle the error. This is only an issue in parallel indexing
     // configurations.
     return false;
 }
示例#3
0
 /**
  * Indexes an item that is queued for indexing into the search engine.
  */
 public function indexQueuedItem(QueueMessage $message)
 {
     $log = $this->getLogger();
     $context = array('engine' => get_class($this->_searchEngine), 'item' => $message->getBody());
     // Load the source data form the message. The message usually contains a
     // unique identifier in the body. Skip processing if false is returned
     // as the source data.
     $collection = $message->getCollection();
     $data = $collection->loadSourceData($message);
     if ($data) {
         $context['collection'] = $collection->getId();
         $log->debug('Data fetched from source', $context);
         // Build an index document from the source data.
         $document = $this->_searchEngine->newDocument($this);
         $collection->buildDocument($document, $data);
         $log->debug('Document prepared for indexing', $context);
         // Index the document, sandwich indexing with events.
         $event = new IndexDocumentEvent($this, $document, $data);
         $this->dispatchEvent(SearchEvents::DOCUMENT_PRE_INDEX, $event);
         $this->_searchEngine->indexDocument($collection, $document);
         $this->dispatchEvent(SearchEvents::DOCUMENT_POST_INDEX, $event);
         $log->debug('Document processed for indexing', $context);
     } else {
         $log->critical('Data could not be loaded from source', $context);
     }
 }