Commit 62e3d75b authored by Thomas Seidl's avatar Thomas Seidl
Browse files

Issue #3370934 by drunken monkey: Fixed missing log messages in Drush.

parent 42154514
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
Search API 1.x, dev (xxxx-xx-xx):
---------------------------------
- #3370934 by drunken monkey: Fixed missing log messages in Drush.
- #3390686 by FeyP, drunken monkey: Fixed RenderedItem processor to always
  switch back to previous account.
- #3365370 by Nick_vh, drunken monkey: Added the .gitlab-ci.yml file.
+29 −10
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ use Drupal\search_api\Event\SearchApiEvents;
use Drupal\search_api\IndexBatchHelper;
use Drupal\search_api\IndexInterface;
use Drupal\search_api\SearchApiException;
use Drush\Log\SuccessInterface;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
@@ -289,7 +290,7 @@ class CommandHelper implements LoggerAwareInterface {
      $remaining = $tracker->getTotalItemsCount() - $tracker->getIndexedItemsCount();

      if (!$remaining) {
        $this->logger->info($this->t("The index @index is up to date.", ['@index' => $index->label()]));
        $this->logSuccess($this->t("The index @index is up to date.", ['@index' => $index->label()]));
        continue;
      }
      else {
@@ -298,7 +299,7 @@ class CommandHelper implements LoggerAwareInterface {
          '@limit' => $limit ?: $this->t('all'),
          '@index' => $index->label(),
        ];
        $this->logger->info($this->t("Found @remaining items to index for @index. Indexing @limit items.", $arguments));
        $this->logSuccess($this->t("Found @remaining items to index for @index. Indexing @limit items.", $arguments));
      }

      // If we pass NULL, it would be used as "no items". -1 is the correct way
@@ -326,7 +327,7 @@ class CommandHelper implements LoggerAwareInterface {
        '@limit' => $current_limit,
        '@batch_size' => $currentBatchSize,
      ];
      $this->logger->info($this->t("Indexing a maximum number of @limit items (@batch_size items per batch run) for the index '@index'.", $arguments));
      $this->logSuccess($this->t("Indexing a maximum number of @limit items (@batch_size items per batch run) for the index '@index'.", $arguments));

      // Create the batch.
      try {
@@ -385,11 +386,11 @@ class CommandHelper implements LoggerAwareInterface {
          '@index' => $index->label(),
          '@datasources' => implode(', ', $reindexed_datasources),
        ];
        $this->logger->info($this->t('The following datasources of @index were successfully scheduled for reindexing: @datasources.', $arguments));
        $this->logSuccess($this->t('The following datasources of @index were successfully scheduled for reindexing: @datasources.', $arguments));
      }
      else {
        $index->reindex();
        $this->logger->info($this->t('@index was successfully scheduled for reindexing.', ['@index' => $index->label()]));
        $this->logSuccess($this->t('@index was successfully scheduled for reindexing.', ['@index' => $index->label()]));
      }
    }

@@ -415,7 +416,7 @@ class CommandHelper implements LoggerAwareInterface {
    foreach ($indexes as $index) {
      if ($index->status()) {
        $index->rebuildTracker();
        $this->logger->info($this->t('The tracking information for search index %name will be rebuilt.', ['%name' => $index->label()]));
        $this->logSuccess($this->t('The tracking information for search index %name will be rebuilt.', ['%name' => $index->label()]));
      }
    }
    return TRUE;
@@ -443,7 +444,7 @@ class CommandHelper implements LoggerAwareInterface {
    foreach ($indexes as $index) {
      if ($index->status()) {
        $index->clear();
        $this->logger->info($this->t('@index was successfully cleared.', ['@index' => $index->label()]));
        $this->logSuccess($this->t('@index was successfully cleared.', ['@index' => $index->label()]));
      }
    }

@@ -637,7 +638,7 @@ class CommandHelper implements LoggerAwareInterface {
      $index = $this->reloadEntityOverrideFree($index);
      $index->setServer($server);
      $index->save();
      $this->logger->info($this->t('Index @index has been set to use server @server and items have been queued for indexing.', ['@index' => $indexId, '@server' => $serverId]));
      $this->logSuccess($this->t('Index @index has been set to use server @server and items have been queued for indexing.', ['@index' => $indexId, '@server' => $serverId]));
    }
    catch (EntityStorageException $e) {
      $this->logger->warning($e->getMessage());
@@ -700,7 +701,7 @@ class CommandHelper implements LoggerAwareInterface {
    $method = $enable ? 'enable' : 'disable';

    if ($index->status() == $enable) {
      $this->logger->info($this->t("The index @index is already @desired_state.", ['@index' => $index->label(), '@desired_state' => $state_label]));
      $this->logSuccess($this->t("The index @index is already @desired_state.", ['@index' => $index->label(), '@desired_state' => $state_label]));
      return;
    }
    if (!$index->getServerId()) {
@@ -710,7 +711,7 @@ class CommandHelper implements LoggerAwareInterface {

    $index = $this->reloadEntityOverrideFree($index);
    $index->$method()->save();
    $this->logger->info($this->t("The index @index was successfully @desired_state.", ['@index' => $index->label(), '@desired_state' => $state_label]));
    $this->logSuccess($this->t("The index @index was successfully @desired_state.", ['@index' => $index->label(), '@desired_state' => $state_label]));
  }

  /**
@@ -752,4 +753,22 @@ class CommandHelper implements LoggerAwareInterface {
    ]);
  }

  /**
   * Logs a success message.
   *
   * Needed because Drush has a custom "success" log level that is incompatible
   * with other loggers, but doesn't display "info" messages by default.
   *
   * @param string $message
   *   The message to log.
   */
  protected function logSuccess(string $message) {
    if ($this->logger instanceof SuccessInterface) {
      $this->logger->success($message);
    }
    else {
      $this->logger->info($message);
    }
  }

}