Skip to content
Snippets Groups Projects

Issue #3015287 by johannijdam, seanB, ricovandevin: Allow usage records to be...

Open Issue #3015287 by johannijdam, seanB, ricovandevin: Allow usage records to be...
11 unresolved threads
11 unresolved threads

Issue #3015287 by johannijdam, seanB, ricovandevin: Allow usage records to be registered in background

Closes #3015287

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
54 54 Go to the URL /admin/config/entity-usage/batch-update in order to start the
55 55 batch operation.
56 56
57 Tracking using background process
58 ============
59 The module supports tracking entity usage via a background process. When the
60 entity usage is tracked via a background process, the tracking information will
61 be updated after the page was loaded in the background.
62
63 Since this is for advanced users only, this setting is not exposed in the UI.
  • Contributor

    Nowadays I believe instead of doing "headless" config, just use a $setting. Or, personally I prefer container paramters.

  • Please register or sign in to reply
  • dpi
    dpi @dpi started a thread on the diff
  • 84 case static::OPERATION_TRANSLATION_DELETE:
    85 $this->entityUsageUpdateManager->trackUpdateOnDeletion($entity, 'translation');
    86 break;
    87
    88 case static::OPERATION_REVISION_DELETE:
    89 $this->entityUsageUpdateManager->trackUpdateOnDeletion($entity, 'revision');
    90 break;
    91 }
    92 }
    93 }
    94 }
    95
    96 /**
    97 * Add an entity for background tracking.
    98 *
    99 * @param string $operation
  • dpi
    dpi @dpi started a thread on the diff
  • 1 <?php
    2
    3 namespace Drupal\entity_usage;
    4
    5 use Drupal\Core\DestructableInterface;
    6 use Drupal\Core\Entity\EntityInterface;
    7
    8 /**
    9 * Track entity usage in the background.
    10 */
    11 class EntityUsageBackgroundTracking implements DestructableInterface {
  • dpi
    dpi @dpi started a thread on the diff
  • 1 <?php
    2
    3 namespace Drupal\entity_usage;
    4
    5 use Drupal\Core\DestructableInterface;
    6 use Drupal\Core\Entity\EntityInterface;
    7
    8 /**
    9 * Track entity usage in the background.
    10 */
    11 class EntityUsageBackgroundTracking implements DestructableInterface {
    12
    13 /**
    14 * Key for the insert operation.
    15 */
    16 const OPERATION_INSERT = 'insert';
  • dpi
    dpi @dpi started a thread on the diff
  • 19 19 arguments: ['@entity_type.manager', '@config.factory']
    20 20 tags:
    21 21 - { name: event_subscriber }
    22 entity_usage.background_tracking:
    23 class: Drupal\entity_usage\EntityUsageBackgroundTracking
    24 arguments: ['@entity_usage.entity_update_manager']
  • dpi
    dpi @dpi started a thread on the diff
  • 19 19 arguments: ['@entity_type.manager', '@config.factory']
    20 20 tags:
    21 21 - { name: event_subscriber }
    22 entity_usage.background_tracking:
    • Contributor

      if above interface feedback is executed, a autowiring alias should also be added here for the interface.

      if not, an autowiring alias for the concrete class should be added.

    • Please register or sign in to reply
  • dpi
    dpi @dpi started a thread on the diff
  • 56 * Constructs a new background tracking service.
    57 *
    58 * @param \Drupal\entity_usage\EntityUpdateManager $entity_usage_update_manager
    59 * The entity usage update manager.
    60 */
    61 public function __construct(EntityUpdateManager $entity_usage_update_manager) {
    62 $this->entityUsageUpdateManager = $entity_usage_update_manager;
    63 }
    64
    65 /**
    66 * {@inheritdoc}
    67 */
    68 public function destruct() {
    69 foreach ($this->entity_operations as $operation => $entities) {
    70 foreach ($entities as $entity) {
    71 switch ($operation) {
  • dpi
    dpi @dpi started a thread on the diff
  • 31 const OPERATION_TRANSLATION_DELETE = 'translation_delete';
    32
    33 /**
    34 * Key for the revision delete operation.
    35 */
    36 const OPERATION_REVISION_DELETE = 'revision_delete';
    37
    38 /**
    39 * A list of entities that should be tracked per operation.
    40 *
    41 * The nested array is keyed by operation and has arrays of entities to index
    42 * for the specific operation as values.
    43 *
    44 * @var \Drupal\Core\Entity\EntityInterface[][]
    45 */
    46 protected $entity_operations = [];
  • dpi
    dpi @dpi started a thread on the diff
  • 31 const OPERATION_TRANSLATION_DELETE = 'translation_delete';
    32
    33 /**
    34 * Key for the revision delete operation.
    35 */
    36 const OPERATION_REVISION_DELETE = 'revision_delete';
    37
    38 /**
    39 * A list of entities that should be tracked per operation.
    40 *
    41 * The nested array is keyed by operation and has arrays of entities to index
    42 * for the specific operation as values.
    43 *
    44 * @var \Drupal\Core\Entity\EntityInterface[][]
    45 */
    46 protected $entity_operations = [];
    • Contributor

      are we sure tracking a fully loaded entity is advisable (as opposed to IDs or UUIDs). There could be memory issues...

    • Please register or sign in to reply
  • dpi
    dpi @dpi started a thread on the diff
  • 90 break;
    91 }
    92 }
    93 }
    94 }
    95
    96 /**
    97 * Add an entity for background tracking.
    98 *
    99 * @param string $operation
    100 * The operation causing changes in entity usage.
    101 * @param \Drupal\Core\Entity\EntityInterface $entity
    102 * The entity to track.
    103 */
    104 public function registerEntity($operation, EntityInterface $entity) {
    105 $this->entity_operations[$operation][] = clone $entity;
    • Contributor

      if its switched to enum, instead of enum use a different PHP data structure than array, since an enum cant be an array, and using string backed doesnt make sense.

    • Please register or sign in to reply
  • dpi
    dpi @dpi started a thread on the diff
  • 2
    3 namespace Drupal\entity_usage;
    4
    5 use Drupal\Core\DestructableInterface;
    6 use Drupal\Core\Entity\EntityInterface;
    7
    8 /**
    9 * Track entity usage in the background.
    10 */
    11 class EntityUsageBackgroundTracking implements DestructableInterface {
    12
    13 /**
    14 * Key for the insert operation.
    15 */
    16 const OPERATION_INSERT = 'insert';
    17
    • Contributor

      Use of the term 'operation' also is incorrect. Operations are a different thing in Drupal, and typically map to permission/access-control. These are more like entity-events.

    • Please register or sign in to reply
  • Contributor

    I think technically this shouldnt use destruct/request-erminate, but should use either Queue or something Messenger-alike.

    Edited by dpi
  • Please register or sign in to reply
    Loading