Completed
Push — 2761013-watchdog_pager ( 2d12f8 )
by Frédéric G.
02:46
created

Logger::eventCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Drupal\mongodb_watchdog;
4
5
use Drupal\Component\Render\MarkupInterface;
6
use Drupal\Component\Utility\Unicode;
7
use Drupal\Component\Utility\Xss;
8
use Drupal\Core\Config\ConfigFactoryInterface;
9
use Drupal\Core\Logger\LogMessageParserInterface;
10
use Drupal\Core\Logger\RfcLogLevel;
11
use MongoDB\Database;
12
use MongoDB\Driver\Exception\InvalidArgumentException;
13
use MongoDB\Driver\Exception\RuntimeException;
14
use Psr\Log\AbstractLogger;
15
use Symfony\Component\HttpFoundation\RequestStack;
16
17
/**
18
 * Class Logger is a PSR/3 Logger using a MongoDB data store.
19
 *
20
 * @package Drupal\mongodb_watchdog
21
 */
22
class Logger extends AbstractLogger {
23
  const CONFIG_NAME = 'mongodb_watchdog.settings';
24
25
  const TRACKER_COLLECTION = 'watchdog_tracker';
26
  const TEMPLATE_COLLECTION = 'watchdog';
27
  const EVENT_COLLECTION_PREFIX = 'watchdog_event_';
28
  const EVENT_COLLECTIONS_PATTERN = '^watchdog_event_[[:xdigit:]]{32}$';
29
30
  const LEGACY_TYPE_MAP = [
31
    'typeMap' => [
32
      'array' => 'array',
33
      'document' => 'array',
34
      'root' => 'array',
35
    ],
36
  ];
37
38
  /**
39
   * The logger storage.
40
   *
41
   * @var \MongoDB\Database
42
   */
43
  protected $database;
44
45
  /**
46
   * The limit for the capped event collections.
47
   *
48
   * @var int
49
   */
50
  protected $items;
51
52
  /**
53
   * The minimum logging level.
54
   *
55
   * @var int
56
   */
57
  protected $limit;
58
59
  /**
60
   * The message's placeholders parser.
61
   *
62
   * @var \Drupal\Core\Logger\LogMessageParserInterface
63
   */
64
  protected $parser;
65
66
  /**
67
   * The "requests" setting.
68
   *
69
   * @var int
70
   */
71
  protected $requests;
72
73
  /**
74
   * An array of templates already used in this request.
75
   *
76
   * Used only with request tracking enabled.
77
   *
78
   * @var string[]
79
   */
80
  protected $templates = [];
81
82
  /**
83
   * A sequence number for log events during a request.
84
   *
85
   * @var int
86
   */
87
  protected $sequence = 0;
88
89
  /**
90
   * Logger constructor.
91
   *
92
   * @param \MongoDB\Database $database
93
   *   The database object.
94
   * @param \Drupal\Core\Logger\LogMessageParserInterface $parser
95
   *   The parser to use when extracting message variables.
96
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
97
   *   The core config_factory service.
98
   * @param \Symfony\Component\HttpFoundation\RequestStack $stack
99
   *   The core request_stack service.
100
   */
101
  public function __construct(Database $database, LogMessageParserInterface $parser, ConfigFactoryInterface $config_factory, RequestStack $stack) {
102
    $this->database = $database;
103
    $this->parser = $parser;
104
    $this->requestStack = $stack;
105
106
    $config = $config_factory->get(static::CONFIG_NAME);
107
    $this->limit = $config->get('limit');
108
    $this->items = $config->get('items');
109
    $this->requests = $config->get('requests');
110
    $this->requestTracking = $config->get('request_tracking');
111
  }
112
113
  /**
114
   * Fill in the log_entry function, file, and line.
115
   *
116
   * @param array $log_entry
117
   *   An event information to be logger.
118
   * @param array $backtrace
119
   *   A call stack.
120
   */
121
  protected function enhanceLogEntry(array &$log_entry, array $backtrace) {
122
    // Create list of functions to ignore in backtrace.
123
    static $ignored = array(
124
      'call_user_func_array' => 1,
125
      '_drupal_log_error' => 1,
126
      '_drupal_error_handler' => 1,
127
      '_drupal_error_handler_real' => 1,
128
      'Drupal\mongodb_watchdog\Logger::log' => 1,
129
      'Drupal\Core\Logger\LoggerChannel::log' => 1,
130
      'Drupal\Core\Logger\LoggerChannel::alert' => 1,
131
      'Drupal\Core\Logger\LoggerChannel::critical' => 1,
132
      'Drupal\Core\Logger\LoggerChannel::debug' => 1,
133
      'Drupal\Core\Logger\LoggerChannel::emergency' => 1,
134
      'Drupal\Core\Logger\LoggerChannel::error' => 1,
135
      'Drupal\Core\Logger\LoggerChannel::info' => 1,
136
      'Drupal\Core\Logger\LoggerChannel::notice' => 1,
137
      'Drupal\Core\Logger\LoggerChannel::warning' => 1,
138
    );
139
140
    foreach ($backtrace as $bt) {
141
      if (isset($bt['function'])) {
142
        $function = empty($bt['class']) ? $bt['function'] : $bt['class'] . '::' . $bt['function'];
143
        if (empty($ignored[$function])) {
144
          $log_entry['%function'] = $function;
145
          /* Some part of the stack, like the line or file info, may be missing.
146
           *
147
           * @see http://goo.gl/8s75df
148
           *
149
           * No need to fetch the line using reflection: it would be redundant
150
           * with the name of the function.
151
           */
152
          $log_entry['%line'] = isset($bt['line']) ? $bt['line'] : NULL;
153
          if (empty($bt['file'])) {
154
            $reflected_method = new \ReflectionMethod($function);
155
            $bt['file'] = $reflected_method->getFileName();
156
          }
157
158
          $log_entry['%file'] = $bt['file'];
159
          break;
160
        }
161
        elseif ($bt['function'] == '_drupal_exception_handler') {
162
          $e = $bt['args'][0];
163
          $this->enhanceLogEntry($log_entry, $e->getTrace());
164
        }
165
      }
166
    }
167
  }
168
169
  /**
170
   * {@inheritdoc}
171
   */
172
  public function log($level, $template, array $context = []) {
173
    if ($level > $this->limit) {
174
      return;
175
    }
176
177
    // Convert PSR3-style messages to SafeMarkup::format() style, so they can be
178
    // translated too in runtime.
179
    $message_placeholders = $this->parser->parseMessagePlaceholders($template, $context);
180
181
    // If code location information is all present, as for errors/exceptions,
182
    // then use it to build the message template id.
183
    $type = $context['channel'];
184
    $location_info = [
185
      '%type' => 1,
186
      '@message' => 1,
187
      '%function' => 1,
188
      '%file' => 1,
189
      '%line' => 1,
190
    ];
191
    if (!empty(array_diff_key($location_info, $message_placeholders))) {
192
      $this->enhanceLogEntry($message_placeholders, debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 10));
193
    }
194
    $file = $message_placeholders['%file'];
195
    $line = $message_placeholders['%line'];
196
    $function = $message_placeholders['%function'];
197
    $key = "${type}:${level}:${file}:${line}:${function}";
198
    $template_id = md5($key);
199
200
    $selector = ['_id' => $template_id];
201
    $update = [
202
      '$inc' => ['count' => 1],
203
      '$set' => [
204
        '_id' => $template_id,
205
        'message' => $template,
206
        'severity' => $level,
207
        'changed' => time(),
208
        'type' => Unicode::substr($context['channel'], 0, 64),
209
      ],
210
    ];
211
    $options = ['upsert' => TRUE];
212
    $template_result = $this->database
213
      ->selectCollection(static::TEMPLATE_COLLECTION)
214
      ->updateOne($selector, $update, $options);
215
216
    // Only insert each template once per request.
217
    if ($this->requestTracking && !isset($this->templates[$template_id])) {
218
      $request_id = $this->requestStack
219
        ->getCurrentRequest()
220
        ->server
221
        ->get('UNIQUE_ID');
222
223
      $this->templates[$template_id] = 1;
224
      $track = [
225
        'request_id' => $request_id,
226
        'template_id' => $template_id,
227
      ];
228
      $this->trackerCollection()->insertOne($track);
229
    }
230
231
    $event_collection = $this->eventCollection($template_id);
232
    if ($template_result->getUpsertedCount()) {
233
      // Capped collections are actually size-based, not count-based, so "items"
234
      // is only a maximum, assuming event documents weigh 1kB, but the actual
235
      // number of items stored may be lower if items are heavier.
236
      // We do not use 'autoindexid' for greater speed, because:
237
      // - it does not work on replica sets,
238
      // - it is deprecated in MongoDB 3.2 and going away in 3.4.
239
      $options = [
240
        'capped' => TRUE,
241
        'size' => $this->items * 1024,
242
        'max' => $this->items,
243
      ];
244
      $this->database->createCollection($event_collection->getCollectionName(), $options);
245
246
      // Do not create this index by default, as its cost is useless if request
247
      // tracking is not enabled.
248
      if ($this->requestTracking) {
249
        $key = ['requestTracking_id' => 1];
250
        $options = ['name' => 'admin-by-request'];
251
        $event_collection->createIndex($key, $options);
252
      }
253
    }
254
255
    foreach ($message_placeholders as &$placeholder) {
256
      if ($placeholder instanceof MarkupInterface) {
0 ignored issues
show
Bug introduced by
The class Drupal\Component\Render\MarkupInterface does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
257
        $placeholder = Xss::filterAdmin($placeholder);
258
      }
259
    }
260
    $event = [
261
      'hostname' => Unicode::substr($context['ip'], 0, 128),
262
      'link' => $context['link'],
263
      'location' => $context['request_uri'],
264
      'referer' => $context['referer'],
265
      'timestamp' => $context['timestamp'],
266
      'user' => ['uid' => $context['uid']],
267
      'variables' => $message_placeholders,
268
    ];
269
    if ($this->requestTracking) {
270
      // Fetch the current request on each event to support subrequest nesting.
271
      $event['requestTracking_id'] = $request_id;
0 ignored issues
show
Bug introduced by
The variable $request_id does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
272
      $event['requestTracking_sequence'] = $this->sequence;
273
      $this->sequence++;
274
    }
275
    $event_collection->insertOne($event);
276
  }
277
278
  /**
279
   * Ensure a collection is capped with the proper size.
280
   *
281
   * @param string $name
282
   *   The collection name.
283
   * @param int $size
284
   *   The collection size cap.
285
   *
286
   * @return \MongoDB\Collection
287
   *   The collection, usable for additional commands like index creation.
288
   *
289
   * @TODO support sharded clusters: convertToCapped does not support them.
290
   *
291
   * @see https://docs.mongodb.com/manual/reference/command/convertToCapped
292
   *
293
   * Note that MongoDB 3.2 still misses a propert exists() command, which is the
294
   * reason for the weird try/catch logic.
295
   *
296
   * @see https://jira.mongodb.org/browse/SERVER-1938
297
   */
298
  public function ensureCappedCollection($name, $size) {
299
    try {
300
      $stats = $this->database->command([
301
        'collStats' => $name,
302
      ], static::LEGACY_TYPE_MAP)->toArray()[0];
303
    }
304
    catch (RuntimeException $e) {
0 ignored issues
show
Bug introduced by
The class MongoDB\Driver\Exception\RuntimeException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
305
      // 59 is expected if the collection was not found. Other values are not.
306
      if ($e->getCode() !== 59) {
307
        throw $e;
308
      }
309
310
      $this->database->createCollection($name);
311
      $stats = $this->database->command([
312
        'collStats' => $name,
313
      ], static::LEGACY_TYPE_MAP)->toArray()[0];
314
    }
315
316
    $collection = $this->database->selectCollection($name);
317
    if (!empty($stats['capped'])) {
318
      return $collection;
319
    }
320
321
    $this->database->command([
322
      'convertToCapped' => $name,
323
      'size' => $size,
324
    ]);
325
    return $collection;
326
  }
327
328
  /**
329
   * Ensure indexes are set on the collections and tracker collection is capped.
330
   *
331
   * First index is on <line, timestamp> instead of <function, line, timestamp>,
332
   * because we write to this collection a lot, and the smaller index on two
333
   * numbers should be much faster to create than one with a string included.
334
   */
335
  public function ensureSchema() {
336
    $trackerCollection = $this->ensureCappedCollection(static::TRACKER_COLLECTION, $this->requests * 1024);
1 ignored issue
show
introduced by
Variable "trackerCollection" is camel caps format. do not use mixed case (camelCase), use lower case and _
Loading history...
337
    $indexes = [
338
      [
339
        'name' => 'tracker-request',
340
        'key' => ['request_id' => 1],
341
      ],
342
    ];
343
    $trackerCollection->createIndexes($indexes);
1 ignored issue
show
introduced by
Variable "trackerCollection" is camel caps format. do not use mixed case (camelCase), use lower case and _
Loading history...
344
345
    $indexes = [
346
      // Index for adding/updating increments.
347
      [
348
        'name' => 'for-increments',
349
        'key' => ['line' => 1, 'changed' => -1],
350
      ],
351
352
      // Index for overview page without filters.
353
      [
354
        'name' => 'overview-no-filters',
355
        'key' => ['changed' => -1],
356
      ],
357
358
      // Index for overview page filtering by type.
359
      [
360
        'name' => 'overview-by-type',
361
        'key' => ['type' => 1, 'changed' => -1],
362
      ],
363
364
      // Index for overview page filtering by severity.
365
      [
366
        'name' => 'overview-by-severity',
367
        'key' => ['severity' => 1, 'changed' => -1],
368
      ],
369
370
      // Index for overview page filtering by type and severity.
371
      [
372
        'name' => 'overview-by-both',
373
        'key' => ['type' => 1, 'severity' => 1, 'changed' => -1],
374
      ],
375
    ];
376
377
    $this->templateCollection()->createIndexes($indexes);
378
379
  }
380
381
  /**
382
   * Return a collection, given its template id.
383
   *
384
   * @param string $template_id
385
   *   The string representation of a template \MongoId.
386
   *
387
   * @return \MongoDB\Collection
388
   *   A collection object for the specified template id.
389
   */
390
  public function eventCollection($template_id) {
391
    $collection_name = static::EVENT_COLLECTION_PREFIX . $template_id;
392
    if (!preg_match('/' . static::EVENT_COLLECTIONS_PATTERN . '/', $collection_name)) {
393
      throw new InvalidArgumentException(t('Invalid watchdog template id `@id`.', [
394
        '@id' => $collection_name,
395
      ]));
396
    }
397
    $collection = $this->database->selectCollection($collection_name);
398
    return $collection;
399
  }
400
401
  /**
402
   * List the event collections.
403
   *
404
   * @return \MongoDB\Collection[]
405
   *   The collections with a name matching the event pattern.
406
   */
407
  public function eventCollections() {
408
    echo static::EVENT_COLLECTIONS_PATTERN;
409
    $options = [
410
      'filter' => [
411
        'name' => ['$regex' => static::EVENT_COLLECTIONS_PATTERN],
412
      ],
413
    ];
414
    $result = iterator_to_array($this->database->listCollections($options));
415
    return $result;
416
  }
417
418
  /**
419
   * Return the number of events for a template.
420
   *
421
   * @param \Drupal\mongodb_watchdog\EventTemplate $template
422
   *   A template for which to count events.
423
   *
424
   * @return int
425
   *   The number of matching events.
426
   */
427
  /**
0 ignored issues
show
introduced by
Missing short description in doc comment
Loading history...
428
   * @return int
0 ignored issues
show
introduced by
Return comment must be on the next line
Loading history...
429
   */
430
  public function eventCount(EventTemplate $template) {
431
    return $this->eventCollection($template->_id)->count();
432
  }
433
434
  /**
435
   * Return the events having occurred during a given request.
436
   *
437
   * @param string $unsafe_request_id
438
   *   The raw request_id.
439
   *
440
   * @return array<\Drupal\mongodb_watchdog\EventTemplate\Drupal\mongodb_watchdog\Event[]>
441
   *   An array of [template, event] arrays, ordered by occurrence order.
442
   */
443
  public function requestEvents($unsafe_request_id) {
444
    $templates = $this->requestTemplates($unsafe_request_id);
445
    $request_id = "$unsafe_request_id";
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $unsafe_request_id instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
446
    $selector = ['requestTracking_id' => $request_id];
447
    $events = [];
448
    $options = [
449
      'typeMap' => [
450
        'array' => 'array',
451
        'document' => 'array',
452
        'root' => '\Drupal\mongodb_watchdog\Event',
453
      ],
454
    ];
455
456
    /**
457
     * @var string $template_id
458
     * @var \Drupal\mongodb_watchdog\EventTemplate $template
459
     */
460
    foreach ($templates as $template_id => $template) {
461
      $event_collection = $this->eventCollection($template_id);
462
      $cursor = $event_collection->find($selector, $options);
463
      /** @var \Drupal\mongodb_watchdog\Event $event */
464
      foreach ($cursor as $event) {
465
        $events[$event->requestTracking_sequence] = [
466
          $template,
467
          $event,
468
        ];
469
      }
470
    }
471
472
    ksort($events);
473
    return $events;
474
  }
475
476
  /**
477
   * Return the number of event templates.
478
   */
479
  public function templatesCount() {
480
    return $this->templateCollection()->count([]);
481
  }
482
483
    /**
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 2 spaces, found 4
Loading history...
484
   * Return an array of templates uses during a given request.
0 ignored issues
show
Coding Style introduced by
Expected 5 space(s) before asterisk; 3 found
Loading history...
485
   *
0 ignored issues
show
Coding Style introduced by
Expected 5 space(s) before asterisk; 3 found
Loading history...
486
   * @param string $unsafe_request_id
0 ignored issues
show
Coding Style introduced by
Expected 5 space(s) before asterisk; 3 found
Loading history...
487
   *   A request "unique_id".
0 ignored issues
show
Coding Style introduced by
Expected 5 space(s) before asterisk; 3 found
Loading history...
488
   *
0 ignored issues
show
Coding Style introduced by
Expected 5 space(s) before asterisk; 3 found
Loading history...
489
   * @return array
0 ignored issues
show
Coding Style introduced by
Expected 5 space(s) before asterisk; 3 found
Loading history...
490
   *   An array of EventTemplate instances.
0 ignored issues
show
Coding Style introduced by
Expected 5 space(s) before asterisk; 3 found
Loading history...
491
   */
0 ignored issues
show
Coding Style introduced by
Expected 5 space(s) before asterisk; 3 found
Loading history...
492
  public function requestTemplates($unsafe_request_id) {
493
    $request_id = "${unsafe_request_id}";
494
    $selector = [
495
      'request_id' => $request_id,
496
    ];
497
498
    $cursor = $this
499
      ->trackerCollection()
500
      ->find($selector, static::LEGACY_TYPE_MAP + [
501
        'projection' => [
502
          '_id' => 0,
503
          'template_id' => 1
504
        ]
505
      ]);
506
    $template_ids = [];
507
    foreach ($cursor as $request) {
508
      $template_ids[] = $request['template_id'];
509
    }
510
    if (empty($template_ids)) {
511
      return [];
512
    }
513
514
    $selector = ['_id' => ['$in' => $template_ids]];
515
    $options = [
516
      'typeMap' => [
517
        'array' => 'array',
518
        'document' => 'array',
519
        'root' => '\Drupal\mongodb_watchdog\EventTemplate',
520
      ],
521
    ];
522
    $templates = [];
523
    $cursor = $this->templateCollection()->find($selector, $options);
524
    /** @var \Drupal\mongodb_watchdog\EventTemplate $template */
525
    foreach ($cursor as $template) {
526
      $templates[$template->_id] = $template;
527
    }
528
    return $templates;
529
  }
530
531
  /**
532
   * Return the request events tracker collection.
533
   *
534
   * @return \MongoDB\Collection
535
   *   The collection.
536
   */
537
  public function trackerCollection() {
538
    return $this->database->selectCollection(static::TRACKER_COLLECTION);
539
  }
540
541
  /**
542
   * Return the event templates collection.
543
   *
544
   * @return \MongoDB\Collection
545
   *   The collection.
546
   */
547
  public function templateCollection() {
548
    return $this->database->selectCollection(static::TEMPLATE_COLLECTION);
549
  }
550
551
  /**
552
   * Return templates matching type and level criteria.
553
   *
554
   * @param string[] $types
555
   *   An array of EventTemplate types. May be a hash.
556
   * @param string[]|int[] $levels
557
   *   An array of severity levels.
558
   * @param int $skip
559
   *   The number of templates to skip before the first one displayed.
560
   * @param int $limit
561
   *   The maximum number of templates to return.
562
   *
563
   * @return \MongoDB\Driver\Cursor
564
   *   A query result for the templates.
565
   */
566
  public function templates(array $types = [], array $levels = [], $skip = 0, $limit = 0) {
567
    $selector = [];
568
    if (!empty($types)) {
569
      $selector['type'] = ['$in' => array_values($types)];
570
    }
571
    if (!empty($levels) && count($levels) !== count(RfcLogLevel::getLevels())) {
572
      // Severity levels come back from the session as strings, not integers.
573
      $selector['severity'] = ['$in' => array_values(array_map('intval', $levels))];
574
    }
575
    $options = [
576
      'sort' => [
577
        'count' => -1,
578
        'changed' => -1,
579
      ],
580
      'typeMap' => [
581
        'array' => 'array',
582
        'document' => 'array',
583
        'root' => '\Drupal\mongodb_watchdog\EventTemplate',
584
      ],
585
    ];
586
    if ($skip) {
587
      $options['skip'] = $skip;
588
    }
589
    if ($limit) {
590
      $options['limit'] = $limit;
591
    }
592
593
    $cursor = $this->templateCollection()->find($selector, $options);
594
    return $cursor;
595
  }
596
597
  /**
598
   * Return the template types actually present in storage.
599
   *
600
   * @return string[]
601
   *   An array of distinct EventTemplate types.
602
   */
603
  public function templateTypes() {
604
    $ret = $this->templateCollection()->distinct('type');
605
    return $ret;
606
  }
607
608
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
609