You are here

public static function GoogleAnalyticsCounterHelper::gacRemoveQueuedItems in Google Analytics Counter 8.3

Remove queued items from the database.

2 calls to GoogleAnalyticsCounterHelper::gacRemoveQueuedItems()
google_analytics_counter_uninstall in ./google_analytics_counter.install
Implements hook_uninstall().
google_analytics_counter_update_8007 in ./google_analytics_counter.install
Issue #3009673: Remove stale queued items from the database.

File

src/GoogleAnalyticsCounterHelper.php, line 15

Class

GoogleAnalyticsCounterHelper
Provides Google Analytics Counter helper functions.

Namespace

Drupal\google_analytics_counter

Code

public static function gacRemoveQueuedItems() {
  $quantity = 200000;
  $connection = \Drupal::database();
  $query = $connection
    ->select('queue', 'q');
  $query
    ->addExpression('COUNT(*)');
  $query
    ->condition('name', 'google_analytics_counter_worker');
  $queued_workers = $query
    ->execute()
    ->fetchField();
  $chunks = $queued_workers / $quantity;

  // Todo: get $t_arg working.
  $t_arg = [
    '@quantity' => $quantity,
  ];
  for ($x = 0; $x <= $chunks; $x++) {
    \Drupal::database()
      ->query("DELETE FROM {queue} WHERE name = 'google_analytics_counter_worker' LIMIT 200000");
  }
}