AcsfDuplicationScrubTruncateTablesHandler.php in Acquia Cloud Site Factory Connector 8
File
src/Event/AcsfDuplicationScrubTruncateTablesHandler.php
View source
<?php
namespace Drupal\acsf\Event;
class AcsfDuplicationScrubTruncateTablesHandler extends AcsfEventHandler {
public function handle() {
drush_print(dt('Entered @class', [
'@class' => get_class($this),
]));
$tables = [];
if (\Drupal::moduleHandler()
->moduleExists('search')) {
if (version_compare(\Drupal::VERSION, '8.8.0', '>=')) {
try {
\Drupal::service('search.index')
->clear();
} catch (\Exception $e) {
drush_print(dt('Error occurred during clearing search indexes: @error', [
'@error' => $e
->getMessage(),
]));
}
}
else {
call_user_func('search_index_clear');
}
$tables[] = 'search_total';
}
$tables[] = 'node_counter';
$tables[] = 'batch';
$tables[] = 'queue';
$tables[] = 'semaphore';
$tables[] = 'sessions';
$tables[] = 'themebuilder_session';
$this
->truncateTables($tables);
}
public function truncateTables(array $tables = []) {
$connection = \Drupal::database();
foreach ($tables as $table) {
if ($connection
->schema()
->tableExists($table)) {
$connection
->truncate($table)
->execute();
}
}
}
}