You are here

public static function ProblemsStorage::replace_problem in Node Accessibility 8

This stores validation problems for a single node to the database.

This will delete all pre-existing problems for the given node.

Parameters

int $nid: The node id.

int $vid: The node revision id.

array $problems: An array of arrays of test data containing the test problems

  • each nested array should containt the following keys:

    • nid: The node id of the node.
    • vid: The node revision id of the node.
    • test_id: The id of the problem.
    • test_severity: The severity of the problem.
    • line: The line number of the problem.
    • element: The html markup of the problem.

Return value

int|false The return states of either FALSE, SAVED_NEW, or SAVED_UPDATED.

1 call to ProblemsStorage::replace_problem()
ProblemsStorage::save_node_problems in src/ProblemsStorage.php
Saves the node report data to the database.

File

src/ProblemsStorage.php, line 429

Class

ProblemsStorage
Class DatabaseStorage.

Namespace

Drupal\node_accessibility

Code

public static function replace_problem($nid, $vid, $problems) {
  if (!is_numeric($nid)) {
    return FALSE;
  }
  if (!is_numeric($vid)) {
    return FALSE;
  }
  if (!is_array($problems)) {
    return FALSE;
  }
  $result = FALSE;
  $transaction = \Drupal::database()
    ->startTransaction();
  try {
    $query = \Drupal::database()
      ->delete('node_accessibility_problems');
    $query
      ->condition('nid', $nid);
    $query
      ->condition('vid', $vid);
    $query
      ->execute();
    foreach ($problems as $problem) {
      $result = self::save_problem($problem, $transaction);
    }
  } catch (Exception $e) {
    $transaction
      ->rollback();
    \Drupal::logger('node_accessibility')
      ->error("Failed to replace problem for nid=@nid, vid=@vid.", [
      '@nid' => $nid,
      '@vid' => $vid,
    ]);
    return FALSE;
  } catch (Error $e) {
    $transaction
      ->rollback();
    \Drupal::logger('node_accessibility')
      ->error("Failed to replace problem for nid=@nid, vid=@vid.", [
      '@nid' => $nid,
      '@vid' => $vid,
    ]);
    return FALSE;
  }
  return $result;
}