You are here

opigno_dashboard.install in Opigno dashboard 8

Same filename and directory in other branches
  1. 3.x opigno_dashboard.install

Install, update and uninstall functions for the alt_aero_log_contacts module.

File

opigno_dashboard.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the alt_aero_log_contacts module.
 */
use Drupal\block\Entity\Block;
use Drupal\opigno_dashboard\BlockService;
use Drupal\user\Entity\Role;

/**
 * Implements hook_schema().
 */
function opigno_dashboard_schema() {
  $schema['opigno_dashboard_positioning'] = [
    'fields' => [
      'pid' => [
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'uid' => [
        'type' => 'int',
        'not null' => TRUE,
      ],
      'columns' => [
        'type' => 'int',
        'not null' => TRUE,
      ],
      'positions' => [
        'type' => 'text',
        'not null' => TRUE,
      ],
    ],
    'primary key' => [
      'pid',
    ],
  ];
  return $schema;
}

/**
 * Implements hook_install().
 */
function opigno_dashboard_install() {
  $blocks = \Drupal::config('opigno_dashboard.settings')
    ->get('blocks');

  // Create block instances.
  \Drupal::service('opigno_dashboard.block')
    ->createBlocksInstances($blocks);
}

/**
 * Update dashboard blocks with Drupal way machine names.
 */
function opigno_dashboard_update_8001() {
  opigno_dashboard_blocks_update();
}

/**
 * Update Opigno dashboard block label typo.
 */
function opigno_dashboard_update_8002() {
  $connection = \Drupal::database();
  $positioning = $connection
    ->select('opigno_dashboard_positioning', 'p')
    ->fields('p')
    ->execute()
    ->fetchAll();
  if ($positioning) {
    foreach ($positioning as $key => $pos) {
      if (strpos($pos->positions, 'evalueated') !== FALSE) {
        $position = str_replace('evalueated', 'evaluated', $pos->positions);
        try {
          $connection
            ->merge('opigno_dashboard_positioning')
            ->keys([
            'pid' => $pos->pid,
          ])
            ->fields([
            'positions' => $position,
          ])
            ->execute();
        } catch (\Exception $e) {
          \Drupal::logger('opigno_dashboard')
            ->error($e
            ->getMessage());
          \Drupal::messenger()
            ->addMessage($e
            ->getMessage(), 'error');
        }
      }
    }
  }
}

/**
 * Grant 'opigno dashboard layout access' permission.
 */
function opigno_dashboard_update_8003() {
  $roles = Role::loadMultiple();
  foreach ($roles as $role) {
    $role
      ->grantPermission('opigno dashboard layout access');
    $role
      ->save();
  }
}

Functions

Namesort descending Description
opigno_dashboard_install Implements hook_install().
opigno_dashboard_schema Implements hook_schema().
opigno_dashboard_update_8001 Update dashboard blocks with Drupal way machine names.
opigno_dashboard_update_8002 Update Opigno dashboard block label typo.
opigno_dashboard_update_8003 Grant 'opigno dashboard layout access' permission.