3 namespace Drupal\dblog\Plugin\rest\resource;
5 use Drupal\rest\Plugin\ResourceBase;
6 use Drupal\rest\ResourceResponse;
7 use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
8 use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
11 * Provides a resource for database watchdog log entries.
15 * label = @Translation("Watchdog database log"),
17 * "canonical" = "/dblog/{id}"
21 class DBLogResource extends ResourceBase {
24 * Responds to GET requests.
26 * Returns a watchdog log entry for the specified ID.
29 * The ID of the watchdog log entry.
31 * @return \Drupal\rest\ResourceResponse
32 * The response containing the log entry.
34 * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
35 * Thrown when the log entry was not found.
36 * @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
37 * Thrown when no log entry was provided.
39 public function get($id = NULL) {
41 $record = db_query("SELECT * FROM {watchdog} WHERE wid = :wid", [':wid' => $id])
43 if (!empty($record)) {
44 return new ResourceResponse($record);
47 throw new NotFoundHttpException(t('Log entry with ID @id was not found', ['@id' => $id]));
50 throw new BadRequestHttpException(t('No log entry ID was provided'));