You are here

function opigno_module_opigno_activity_update in Opigno module 8

Same name and namespace in other branches
  1. 3.x opigno_module.module \opigno_module_opigno_activity_update()

Implements hook_ENTITY_TYPE_update().

File

./opigno_module.module, line 1225
Contains opigno_module.module.

Code

function opigno_module_opigno_activity_update(Drupal\Core\Entity\EntityInterface $entity) {

  /* @var \Drupal\opigno_module\Entity\OpignoActivity $entity */
  $database = \Drupal::database();

  // Update module-activity relationships if new revision for activity was created.
  $query = $database
    ->select('opigno_module_relationship', 'omr')
    ->condition('omr.child_id', $entity
    ->id())
    ->fields('omr', [
    'omr_id',
    'child_id',
    'child_vid',
  ]);
  $relationships = $query
    ->execute()
    ->fetchAll();
  if ($relationships) {

    // Update each table where current activity is a part of a module.
    foreach ($relationships as $item) {
      if ($entity
        ->getRevisionId() != $item->child_vid) {
        $database
          ->update('opigno_module_relationship')
          ->condition('omr_id', $item->omr_id)
          ->fields([
          'child_vid' => $entity
            ->getRevisionId(),
        ])
          ->execute();
      }
    }
  }
}