You are here

protected static function NodeCreationTest::getWatchdogIdsForTestExceptionRollback in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/node/tests/src/Functional/NodeCreationTest.php \Drupal\Tests\node\Functional\NodeCreationTest::getWatchdogIdsForTestExceptionRollback()
  2. 9 core/modules/node/tests/src/Functional/NodeCreationTest.php \Drupal\Tests\node\Functional\NodeCreationTest::getWatchdogIdsForTestExceptionRollback()

Gets the watchdog IDs of the records with the rollback exception message.

Return value

int[] Array containing the IDs of the log records with the rollback exception message.

File

core/modules/node/tests/src/Functional/NodeCreationTest.php, line 314

Class

NodeCreationTest
Create a node and test saving it.

Namespace

Drupal\Tests\node\Functional

Code

protected static function getWatchdogIdsForTestExceptionRollback() {

  // PostgreSQL doesn't support bytea LIKE queries, so we need to unserialize
  // first to check for the rollback exception message.
  $matches = [];
  $query = Database::getConnection()
    ->select('watchdog', 'w')
    ->fields('w', [
    'wid',
    'variables',
  ])
    ->execute();
  foreach ($query as $row) {
    $variables = (array) unserialize($row->variables);
    if (isset($variables['@message']) && $variables['@message'] === 'Test exception for rollback.') {
      $matches[] = $row->wid;
    }
  }
  return $matches;
}