monster_menus-9.0.x-dev/monster_menus.install

monster_menus.install
<?php

/**
 * @file
 * Installation routines for Monster Menus
 */

use Drupal\block\Entity\Block;
use Drupal\Component\Uuid\Php;
use Drupal\Core\Database\Database;
use Drupal\Core\Url;
use Drupal\monster_menus\Constants;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;

/**
 * Implements hook_requirements().
 */
function monster_menus_requirements($phase) {
  $requirements = [];

  if ($phase == 'runtime') {
    // Check jQuery UI modules for D9.
    if (version_compare(\Drupal::VERSION, 9) >= 0) {
      foreach (['jquery_ui_tooltip' => 'Tooltip'] as $module => $description) {
        if (!\Drupal::moduleHandler()->moduleExists($module)) {
          $requirements['monster_menus_' . $module] = [
            'title' => t('Monster Menus'),
            'value' => t('jQuery UI :description not enabled', [':description' => $description]),
            'description' => t('Some features of Monster Menus will not work correctly in this version of Drupal without the <a href=":link" target="_blank">jQuery UI :description</a> module.', [':description' => $description, ':link' => 'https://www.drupal.org/project/' . $module]),
            'severity' => REQUIREMENT_WARNING,
          ];
        }
      }
    }

    if (!file_exists('vendor://vakata/jstree/dist/jstree.min.js')) {
      $requirements['monster_menus_jstree'] = [
        'title' => t('Monster Menus'),
        'value' => t('jsTree missing'),
        'description' => t('Without the jsTree library you will not be able to choose pages, content or groups in a tree browser window. It can be installed by running:<br /><code>composer require vakata/jstree</code>'),
        'severity' => REQUIREMENT_WARNING,
      ];
    }

    if (!file_exists('vendor://datatables.net/datatables.net/js/dataTables.min.js')) {
      $requirements['monster_menus_datatables'] = [
        'title' => t('Monster Menus'),
        'value' => t('Datatables missing'),
        'description' => t('Without the Datatables library you will not be able to view long lists of users or group members. It can be installed by running:<br /><code>composer require datatables.net/datatables.net-dt</code>'),
        'severity' => REQUIREMENT_WARNING,
      ];
    }

    if (!NodeType::loadMultiple()) {
      $requirements['monster_menus_no_types'] = [
        'title' => t('Monster Menus'),
        'value' => t('No content types'),
        'description' => t('Monster Menus cannot function when there are no content types defined. You should define some at <code>/admin/structure/types</code>'),
        'severity' => REQUIREMENT_WARNING,
      ];
    }
  }

  return $requirements;
}

/**
 * Implements hook_install()
 */
function monster_menus_install() {
  \Drupal::service('config.factory')->getEditable('monster_menus.settings')
    ->set('vgroup.errors_email', ini_get('sendmail_from'))
    ->save();

  $top       = 1;
  $groups    = 2;
  $vgroup    = 3;
  $users     = 4;
  $default   = 5;
  $home      = 7;
  $disabled  = 8;
  $system    = 9;
  $not_found = 10;
  $denied    = 11;
  $pic       = 12;

  \Drupal::service('config.factory')->getEditable('system.site')
    ->set('page.403', "/mm/$denied")
    ->set('page.404', "/mm/$not_found")
    ->save();

  $list = [
    ['mmtid', 'name', 'alias', 'parent', 'uid', 'default_mode', 'theme', 'hidden', 'vid'],
    [$top, '[top]', '', 0, 1, Constants::MM_PERMS_READ, '', 0],
    [$groups, Constants::MM_ENTRY_NAME_GROUPS, 'groups', $top, 1, Constants::MM_PERMS_READ, '', 0],
    [$vgroup, Constants::MM_ENTRY_NAME_VIRTUAL_GROUP, '', $groups, 1, Constants::MM_PERMS_READ, '', 0],
    [$users, Constants::MM_ENTRY_NAME_USERS, 'users', $top, 1, Constants::MM_PERMS_READ, '', 0],
    [$default, Constants::MM_ENTRY_NAME_DEFAULT_USER, '', $users, 1, Constants::MM_PERMS_READ, '', 0],
    [$home, 'Home', '', $top, 1, Constants::MM_PERMS_READ, '', 0],
    [$disabled, Constants::MM_ENTRY_NAME_DISABLED_USER, '', $users, 1, '', '', 0],
    [$system, Constants::MM_ENTRY_NAME_SYSTEM, Constants::MM_ENTRY_ALIAS_SYSTEM, $home, 1, Constants::MM_PERMS_READ, '', 1],
    [$not_found, 'Not Found', 'not-found', $system, 1, Constants::MM_PERMS_READ, '', 1],
    [$denied, 'Authorization Required', 'denied', $system, 1, Constants::MM_PERMS_READ, '', 1],
    [$pic, 'Picture block', 'default-image', $home, 1, Constants::MM_PERMS_READ, '', 0],
  ];

  $vid = 1;
  $php = new Php();
  $cols = array_shift($list);
  $db = Database::getConnection();
  $mm_tree_revision = $db->insert('mm_tree_revision')->fields($cols);
  $cols[] = 'uuid';
  $mm_tree = $db->insert('mm_tree')->fields($cols);
  foreach ($list as $entry) {
    $entry[] = $vid++;
    $entry[] = $php->generate();
    $entry = array_combine($cols, $entry);
    $mm_tree->values($entry);
    unset($entry['uuid']);
    $mm_tree_revision->values($entry);
  }
  $mm_tree->execute();
  $mm_tree_revision->execute();

  mm_content_update_parents(NULL, NULL, FALSE, TRUE);
  // Update the mm_tree column containing the sort index.
  mm_content_update_sort();
  mm_content_groups_mmtid();
  mm_content_users_mmtid();

  $db->insert('mm_tree_flags')
    ->fields(['mmtid',  'flag',           'data'])
    ->values([$default, 'limit_alias', ''])
    ->values([$default, 'limit_delete', ''])
    ->values([$default, 'limit_hidden', ''])
    ->values([$default, 'limit_location', ''])
    ->values([$default, 'limit_move', ''])
    ->values([$default, 'limit_name', ''])
    ->values([$default, 'limit_write', ''])
    ->values([$system, 'limit_alias', ''])
    ->values([$system, 'limit_delete', ''])
    ->values([$system, 'limit_hidden', ''])
    ->values([$system, 'limit_location', ''])
    ->values([$system, 'limit_move', ''])
    ->values([$system, 'limit_name', ''])
    ->values([$system, 'limit_write', ''])
    ->values([$system, 'no_breadcrumb', ''])
    ->execute();

  // MM blocks
  $default_theme = \Drupal::service('config.factory')->get('system.theme')->get('default');

  $create_block = function($id, $settings) use ($default_theme) {
    $settings += [
      'delta' => $id,
      'id' => "mmtreeblock_$id",
      'plugin' => 'mm_tree_block',
      'region' => 'sidebar_first',
      'theme' => $default_theme,
      'title' => '',
      'visibility' => [],
      'label_display' => FALSE,
      'weight' => 0,
    ];
    $values = [];
    foreach (['region', 'id', 'theme', 'plugin', 'weight', 'visibility'] as $key) {
      $values[$key] = $settings[$key];
      unset($settings[$key]);
    }
    $values['settings'] = $settings;
    Block::create($values)->save();
  };

  $pic_block = Constants::MM_MENU_BID . '_2';
  $sidebar   = Constants::MM_MENU_BID . '_3';
  $create_block(Constants::MM_MENU_BID, [
    'label' => 'New sub-section',
    'title_is_cat' => 0,
    'show_node_contents' => 0,
    'help' => t('Creates a new left navigation menu section and makes this page the top page of the section.'),
  ]);
  $create_block($pic_block, [
    'label' => 'Picture block',
    'title_is_cat' => 0,
    'show_node_contents' => 1,
    'help' => t('Lets you upload an image to appear on the parent page and all sub-pages.'),
  ]);
  $create_block($sidebar, [
    'label' => 'Sidebar block',
    'title_is_cat' => 0,
    'show_node_contents' => 1,
    'help' => t('The contents of the current page will appear in the sidebar block of the parent page and all sub-pages.'),
  ]);

  // Assign MM blocks to default nodes
  $db->insert('mm_tree_block')
    ->fields(['mmtid', 'bid', 'max_depth', 'max_parents'])
    ->values([$groups, Constants::MM_MENU_BID, -1, 5])
    ->values([$users, Constants::MM_MENU_BID, -1, -1])
    ->values([$default, Constants::MM_MENU_BID, -1, -1])
    ->values([$home, Constants::MM_MENU_BID, -1, -1])
    ->values([$pic, $pic_block, -1, -1])
    ->execute();

  // Enable some default content types
  $allowed = array_intersect(['story', 'page'], array_keys(NodeType::loadMultiple()));
  if ($allowed) {
    $settings = ['allowed_node_types' => $allowed];
    mm_content_set_cascaded_settings($users, $settings, FALSE);
    mm_content_set_cascaded_settings($home, $settings, FALSE);
  }

  // Default virtual groups
  foreach ([
             'All logged-in users' => ['uid', 'FROM {users} WHERE uid > 0'],
           ] as $name => $list) {
    mm_content_insert_or_update(TRUE, $vgroup, [
        'name' => $name,
        'default_mode' => Constants::MM_PERMS_APPLY . ',' . Constants::MM_PERMS_READ,
        'qfield' => $list[0],
        'qfrom' => $list[1],
      ]
    );
  }

  // After creating virtual groups, update the mm_virtual_group results table.
  mm_regenerate_vgroup();

  // Look for the first node type with a body field.
  $type = '';
  $storage = \Drupal::service('entity_field.manager')->getActiveFieldStorageDefinitions('node');
  if (isset($storage['body']) && ($bundles = $storage['body']->getBundles())) {
    $type = reset($bundles);
  }

  if (empty($type)) {
    \Drupal::messenger()->addStatus(t('<p>There is no content type containing a body field. Default contents could not be created.</p>'));
  }
  else {
    _mm_install_node_add($type, [
      'title' => 'Not Found', 'body' => '<p>The page you tried to access was not found.</p>',
      'mm_catlist' => [$not_found => 'Not Found']]);
    _mm_install_node_add($type, [
      'title' => 'Authorization Required', 'body' => 'You do not have permission to read the contents of this page. <p>If you are not already logged into the system, you may be able to access the page once you do so.</p>',
      'mm_catlist' => [$denied => 'Authorization Required']]);
  }

  \Drupal::messenger()->addStatus(t('<p>Monster Menus has been enabled.</p> <p>To see the menu tree within your pages, go to <a href=":url">:url</a> and add the block "New subsection" to a region in each of your themes.</p>', [':url' => Url::fromRoute('block.admin_display')->toString()]));
}

/**
 * Implements hook_uninstall().
 */
function monster_menus_uninstall() {
  $unset = [
    'monster_menus.cron_run_count',
    'monster_menus.cron_run_last',
    'monster_menus.cron_run_since',
    'monster_menus.finegrain_comment_readability_ever_set',
    'monster_menus.fix_node_urls_chunksize',
    'monster_menus.fix_node_urls_hostname_regex',
    'monster_menus.groups_mmtid',
    'monster_menus.hidden_user_names',
    'monster_menus.mysql_max_joins',
    'monster_menus.reserved_alias',
    'monster_menus.users_alias',
    'monster_menus.users_mmtid',
    'monster_menus.vgroup_regen_semaphore',
  ];
  \Drupal::state()->deleteMultiple($unset);

  $site = \Drupal::service('config.factory')->getEditable('system.site');
  if (str_starts_with($site->get('page.403'), 'mm/')) {
    $site->clear('page.403');
  }
  if (str_starts_with($site->get('page.404'), 'mm/')) {
    $site->clear('page.404');
  }
  $site->save();

  \Drupal::messenger()->addStatus(t('You may need to correct the values for "Default 403 (access denied)" and "Default 404 (not found) page" on <a href=":link">@path</a>.', ['@path' => 'admin/config/system/site-information', ':link' => Url::fromRoute('system.site_information_settings')->toString()]));
}

/**
 * Implements hook_schema().
 */
function monster_menus_schema() {
  $schema = [];
  $schema['mm_access_cache'] = [
    'fields' => [
      'cid' => [
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => ''],
      'data' => [
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => ''],
      'expire' => [
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0],
      'created' => [
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0],
      'uid' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0],
      'nid' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0],
      'mmtid' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0],
      'serialized' => [
        'type' => 'int',
        'size' => 'small',
        'not null' => TRUE,
        'default' => 0],
    ],
    'primary key' => ['cid'],
    'indexes' => [
      'expire' => ['expire'],
      'uid' => ['uid'],
      'nid' => ['nid'],
      'mmtid' => ['mmtid'],
    ],
  ];
  $schema['mm_archive'] = [
    'fields' => [
      'main_mmtid' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'archive_mmtid' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'frequency' => [
        'type' => 'varchar',
        'length' => '5',
        'not null' => TRUE,
      ],
      'main_nodes' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
    ],
    'primary key' => ['main_mmtid'],
    'foreign keys' => [
      'mm_tree' => [
        'table' => 'mm_tree',
        'columns' => [
          'main_mmtid' => 'mmtid',
          'archive_mmtid' => 'mmtid',
        ],
      ],
    ],
    'indexes' => [
      'archive_mmtid' => ['archive_mmtid'],
    ],
  ];
  $schema['mm_cascaded_settings'] = [
    'fields' => [
      'id' => [
        'type' => 'serial',
        'size' => 'big',
        'not null' => TRUE,
      ],
      'mmtid' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'name' => [
        'type' => 'varchar',
        'length' => '32',
        'not null' => TRUE,
      ],
      'data_type' => [
        'type' => 'varchar',
        'length' => '10',
        'not null' => TRUE,
      ],
      'multiple' => [
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 0,
      ],
      'array_key' => [
        'type' => 'varchar',
        'length' => '32',
        'not null' => TRUE,
      ],
      'data' => [
        'type' => 'varchar',
        'length' => '512',
        'not null' => FALSE,
      ],
    ],
    'primary key' => ['id'],
    'foreign keys' => [
      'mm_tree' => [
        'table' => 'mm_tree',
        'columns' => [
          'mmtid' => 'mmtid',
        ],
      ],
    ],
    'indexes' => [
      'mmtid' => ['mmtid'],
      'name' => ['name'],
      'data' => [['data', 255]],
      'array_key' => ['array_key'],
    ],
  ];
  $schema['mm_group'] = [
    'fields' => [
      'gid' => [
        'type' => 'int',
        'not null' => TRUE,
      ],
      'uid' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'vgid' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ],
    ],
    'primary key' => ['gid', 'uid'],
    'foreign keys' => [
      'mm_tree' => [
        'table' => 'mm_tree',
        'columns' => [
          'gid' => 'mmtid',
        ],
      ],
      'users' => [
        'table' => 'users',
        'columns' => [
          'uid' => 'uid',
        ],
      ],
      'mm_vgroup_query' => [
        'table' => 'mm_vgroup_query',
        'columns' => [
          'vgid' => 'vgid',
        ],
      ],
    ],
    'indexes' => [
      'vgid' => ['vgid'],
      'gid' => ['gid'],
      'uid' => ['uid'],
    ],
  ];
  $schema['mm_group_temp'] = [
    'fields' => [
      'gid' => [
        'type' => 'int',
        'not null' => TRUE,
      ],
      'uid' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'sessionid' => [
        'type' => 'varchar',
        'not null' => TRUE,
        'length' => '64',
        'default' => '',
      ],
      'token' => [
        'type' => 'varchar',
        'length' => '128',
        'not null' => TRUE,
        'default' => '',
      ],
      'expire' => [
        'type' => 'int',
        'default' => 0,
        'not null' => TRUE,
      ],
    ],
    'primary key' => ['gid', 'uid', 'sessionid', 'token'],
    'foreign keys' => [
      'mm_tree' => [
        'table' => 'mm_tree',
        'columns' => [
          'gid' => 'mmtid',
        ],
      ],
      'users' => [
        'table' => 'users',
        'columns' => [
          'uid' => 'uid',
        ],
      ],
    ],
    'indexes' => [
      'sessionid' => ['sessionid'],
      'gid' => ['gid'],
      'uid' => ['uid'],
      'token' => ['token'],
    ],
  ];
  $schema['mm_node2tree'] = [
    'fields' => [
      'nid' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'mmtid' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
    ],
    'primary key' => ['nid', 'mmtid'],
    'foreign keys' => [
      'node' => [
        'table' => 'node',
        'columns' => [
          'nid' => 'nid',
        ],
      ],
      'mm_tree' => [
        'table' => 'mm_tree',
        'columns' => [
          'mmtid' => 'mmtid',
        ],
      ],
    ],
    'indexes' => [
      'nid' => ['nid'],
      'mmtid' => ['mmtid'],
    ],
  ];
  $schema['mm_node_info'] = [
    'fields' => [
      'nid' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'show_node_info' => [
        'type' => 'int',
        'size' => 'tiny',
        'not null' => FALSE,
      ],
      'comments_readable' => [
        'type' => 'varchar',
        'length' => '128',
        'default' => '',
      ],
    ],
    'primary key' => ['nid'],
    'foreign keys' => [
      'node' => [
        'table' => 'node',
        'columns' => [
          'nid' => 'nid',
        ],
      ],
    ],
  ];
  $schema['mm_node_redir'] = [
    'fields' => [
      'nid' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'vid' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'url' => [
        'type' => 'blob',
        'not null' => FALSE,
      ],
      'mmtid' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => FALSE,
      ],
    ],
    'primary key' => ['nid', 'vid'],
    'foreign keys' => [
      'node' => [
        'table' => 'node',
        'columns' => [
          'nid' => 'nid',
          'vid' => 'vid',
        ],
      ],
      'mm_tree' => [
        'table' => 'mm_tree',
        'columns' => [
          'mmtid' => 'mmtid',
        ],
      ],
    ],
    'indexes' => [
      'mmtid' => ['mmtid'],
    ],
  ];
  $schema['mm_node_reorder'] = [
    'fields' => [
      'mmtid' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'nid' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'weight' => [
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ],
      'region' => [
        'type' => 'varchar',
        'length' => '64',
        'default' => NULL,
        'not null' => FALSE,
      ],
    ],
    'primary key' => ['mmtid', 'nid'],
    'foreign keys' => [
      'node' => [
        'table' => 'node',
        'columns' => [
          'nid' => 'nid',
        ],
      ],
      'mm_tree' => [
        'table' => 'mm_tree',
        'columns' => [
          'mmtid' => 'mmtid',
        ],
      ],
    ],
    'indexes' => [
      'region' => ['region'],
    ],
  ];
  $schema['mm_node_schedule'] = [
    'fields' => [
      'nid' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'publish_on' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ],
      'unpublish_on' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ],
      'set_change_date' => [
        'type' => 'int',
        'size' => 'tiny',
        'default' => 0,
      ],
    ],
    'primary key' => ['nid'],
    'foreign keys' => [
      'node' => [
        'table' => 'node',
        'columns' => [
          'nid' => 'nid',
        ],
      ],
    ],
  ];
  $schema['mm_node_write'] = [
    'fields' => [
      'id' => [
        'type' => 'serial',
        'unsigned' => TRUE,
        'size' => 'big',
        'not null' => TRUE,
      ],
      'nid' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'gid' => [
        'type' => 'int',
        'not null' => TRUE,
      ],
    ],
    'primary key' => ['id'],
    'foreign keys' => [
      'node' => [
        'table' => 'node',
        'columns' => [
          'nid' => 'nid',
        ],
      ],
      'mm_tree' => [
        'table' => 'mm_tree',
        'columns' => [
          'gid' => 'mmtid',
        ],
      ],
    ],
    'indexes' => [
      'nid' => ['nid'],
      'gid' => ['gid'],
      'gid_nid' => ['gid', 'nid'],
    ],
  ];
  $schema['mm_recycle'] = [
    'fields' => [
      'type' => [
        'type' => 'varchar',
        'length' => 4,
        'not null' => TRUE,
      ],
      'id' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'from_mmtid' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ],
      'bin_mmtid' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ],
      'recycle_date' => [
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ],
    ],
    'primary key' => ['type', 'id', 'from_mmtid'],
    'foreign keys' => [
      'mm_tree' => [
        'table' => 'mm_tree',
        'columns' => [
          'from_mmtid' => 'mmtid',
          'bin_mmtid' => 'mmtid',
        ],
      ],
    ],
    'indexes' => [
      'id' => ['id'],
      'type' => ['type'],
      'bin_mmtid' => ['bin_mmtid'],
    ],
  ];
  $schema['mm_tree_access'] = [
    'fields' => [
      'mmtid' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'gid' => [
        'type' => 'int',
        'not null' => TRUE,
      ],
      'mode' => [
        'type' => 'varchar',
        'length' => 1,
        'not null' => TRUE,
      ],
    ],
    'primary key' => ['mmtid', 'gid', 'mode'],
    'foreign keys' => [
      'mm_tree' => [
        'table' => 'mm_tree',
        'columns' => [
          'mmtid' => 'mmtid',
          'gid' => 'mmtid',
        ],
      ],
    ],
    'indexes' => [
      'mmtid' => ['mmtid'],
      'gid' => ['gid'],
      'mode' => ['mode'],
    ],
  ];
  $schema['mm_tree_block'] = [
    'fields' => [
      'mmtid' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'bid' => [
        'type' => 'varchar',
        'length' => 63,
        'not null' => TRUE,
        'default' => '-1',
      ],
      'max_depth' => [
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => -1,
      ],
      'max_parents' => [
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => -1,
      ],
    ],
    'primary key' => ['mmtid', 'bid'],
    'foreign keys' => [
      'mm_tree' => [
        'table' => 'mm_tree',
        'columns' => [
          'mmtid' => 'mmtid',
        ],
      ],
    ],
    'indexes' => [
      'mmtid' => ['mmtid'],
      'bid' => ['bid'],
    ],
  ];
  $schema['mm_tree_bookmarks'] = [
    'fields' => [
      'uid' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'type' => [
        'type' => 'varchar',
        'length' => '20',
        'not null' => TRUE,
      ],
      'weight' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'data' => [
        'type' => 'text',
        'size' => 'big',
        'not null' => TRUE,
      ],
    ],
    'primary key' => ['uid', 'type', 'weight'],
    'foreign keys' => [
      'users' => [
        'table' => 'users',
        'columns' => [
          'uid' => 'uid',
        ],
      ],
    ],
  ];
  $schema['mm_tree_flags'] = [
    'fields' => [
      'mmtid' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'flag' => [
        'type' => 'varchar',
        'length' => '64',
        'not null' => TRUE,
      ],
      'data' => [
        'type' => 'varchar',
        'length' => '255',
        'not null' => FALSE,
      ],
    ],
    'primary key' => ['mmtid', 'flag'],
    'foreign keys' => [
      'mm_tree' => [
        'table' => 'mm_tree',
        'columns' => [
          'mmtid' => 'mmtid',
        ],
      ],
    ],
    'indexes' => [
      'data' => ['data'],
      'flag' => ['flag'],
    ],
  ];
  $schema['mm_tree_parents'] = [
    'fields' => [
      'mmtid' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'parent' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'depth' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'size' => 'small',
        'not null' => TRUE,
      ],
    ],
    'primary key' => ['mmtid', 'parent'],
    'foreign keys' => [
      'mm_tree' => [
        'table' => 'mm_tree',
        'columns' => [
          'mmtid' => 'mmtid',
          'parent' => 'mmtid',
        ],
      ],
    ],
    'indexes' => [
      'depth' => ['depth'],
      'mmtid' => ['mmtid'],
      'parent' => ['parent'],
    ],
  ];
  $schema['mm_vgroup_query'] = [
    'fields' => [
      'vgid' => [
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'field' => [
        'type' => 'varchar',
        'length' => '40',
        'not null' => TRUE,
      ],
      'qfrom' => [
        'type' => 'text',
        'not null' => FALSE,
      ],
      'dirty' => [
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 0,
      ],
    ],
    'primary key' => ['vgid'],
    'indexes' => [
      'dirty' => ['dirty'],
    ],
  ];
  $schema['mm_virtual_group'] = [
    'fields' => [
      'vgid' => [
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ],
      'uid' => [
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ],
      'preview' => [
        'type' => 'int',
        'size' => 'small',
        'not null' => FALSE,
      ],
    ],
    'primary key' => ['vgid', 'uid'],
    'foreign keys' => [
      'mm_vgroup_query' => [
        'table' => 'mm_vgroup_query',
        'columns' => [
          'vgid' => 'vgid',
        ],
      ],
      'users' => [
        'table' => 'users',
        'columns' => [
          'uid' => 'uid',
        ],
      ],
    ],
    'indexes' => [
      'preview' => ['preview'],
      'vgid' => ['vgid'],
      'uid' => ['uid'],
    ],
  ];
  return $schema;
}

function _mm_install_node_add($type, $arr, $format = 'full_html') {
  if (isset($arr['body'])) {
    $arr['body'] = [['value' => $arr['body'], 'format' => $format]];
  }
  $arr = array_merge($arr, [
    'type' => $type,
    'nid' => '',
    'vid' => '',
    'groups_w' => [],
    'users_w' => [],
    'others_w' => 0,
    'comment' => 0,
    'teaser' => '',
    'status' => 1,
    'moderate' => '',
    'promote' => '',
    'sticky' => '',
    'revision' => 1,
  ]);
  $node = Node::create($arr);
  $node->setOwnerId(1);
  $node->save();
}

/**
 * Implements hook_mm_verify_integrity()
 */
function monster_menus_mm_verify_integrity() {
  return ['Monster Menus' => [
    (string) t('mm_archive.main_mmtid refers to missing mm_tree.mmtid') =>
      "{mm_archive} x LEFT JOIN {mm_tree} t ON t.mmtid=x.main_mmtid WHERE t.mmtid IS NULL",

    (string) t('mm_archive.archive_mmtid refers to missing mm_tree.mmtid') =>
      "{mm_archive} x LEFT JOIN {mm_tree} t ON t.mmtid=x.archive_mmtid WHERE t.mmtid IS NULL",

    (string) t('mm_cascaded_settings.mmtid refers to missing mm_tree.mmtid') =>
      "{mm_cascaded_settings} x LEFT JOIN {mm_tree} t ON t.mmtid=x.mmtid WHERE t.mmtid IS NULL",

    (string) t('mm_group.gid refers to missing mm_tree.mmtid') =>
      "{mm_group} x LEFT JOIN {mm_tree} t ON t.mmtid=x.gid WHERE t.mmtid IS NULL AND x.gid>0 AND x.vgid=0",
    (string) t('mm_group.uid refers to missing users.uid') =>
      "{mm_group} x LEFT JOIN {users} u ON u.uid=x.uid WHERE u.uid IS NULL AND x.uid>0",
    (string) t('mm_group.vgid refers to missing mm_vgroup_query.vgid') =>
      "{mm_group} x LEFT JOIN {mm_vgroup_query} v ON v.vgid=x.vgid WHERE v.vgid IS NULL AND x.vgid>0",

    (string) t('mm_node2tree.mmtid refers to missing mm_tree.mmtid') =>
      "{mm_node2tree} x LEFT JOIN {mm_tree} t ON t.mmtid=x.mmtid WHERE t.mmtid IS NULL",
    (string) t('mm_node2tree.nid refers to missing node.nid') =>
      "{mm_node2tree} x LEFT JOIN {node} n ON n.nid=x.nid WHERE n.nid IS NULL",

    (string) t('mm_node_info.nid refers to missing node.nid') =>
      "{mm_node_info} x LEFT JOIN {node} n ON n.nid=x.nid WHERE n.nid IS NULL",

    (string) t('mm_node_redir.nid refers to missing node.nid') =>
      "{mm_node_redir} x LEFT JOIN {node} n ON n.nid=x.nid WHERE n.nid IS NULL",
    (string) t('mm_node_redir.mmtid refers to missing mm_tree.mmtid') =>
      "{mm_node_redir} x LEFT JOIN {mm_tree} t ON t.mmtid=x.mmtid WHERE x.mmtid>0 AND t.mmtid IS NULL",

    (string) t('mm_node_reorder.mmtid refers to missing mm_tree.mmtid') =>
      "{mm_node_reorder} x LEFT JOIN {mm_tree} t ON t.mmtid=x.mmtid WHERE t.mmtid IS NULL",
    (string) t('mm_node_reorder.nid refers to missing node.nid') =>
      "{mm_node_reorder} x LEFT JOIN {node} n ON n.nid=x.nid WHERE n.nid IS NULL",

    (string) t('mm_node_schedule.nid refers to missing node.nid') =>
      "{mm_node_schedule} x LEFT JOIN {node} n ON n.nid=x.nid WHERE n.nid IS NULL",

    (string) t('mm_node_write.nid refers to missing node.nid') =>
      "{mm_node_write} x LEFT JOIN {node} n ON n.nid=x.nid WHERE n.nid IS NULL",
    (string) t('mm_node_write.gid refers to missing mm_tree.mmtid') =>
      "{mm_node_write} x LEFT JOIN {mm_tree} t ON t.mmtid=x.gid WHERE x.gid>0 AND t.mmtid IS NULL",
    (string) t('mm_node_write.gid refers to missing mm_group.gid') =>
      "{mm_node_write} x LEFT JOIN {mm_group} g ON g.gid=x.gid WHERE x.gid<0 AND g.gid IS NULL",

    (string) t('mm_recycle.id refers to missing mm_tree.mmtid (when type=cat)') =>
      "{mm_recycle} x LEFT JOIN {mm_tree} t ON t.mmtid=x.id WHERE x.type='cat' AND t.mmtid IS NULL",
    (string) t('mm_recycle.id refers to missing node.nid (when type=node)') =>
      "{mm_recycle} x LEFT JOIN {node} n ON n.nid=x.id WHERE x.type='node' AND n.nid IS NULL",
    (string) t('mm_recycle.from_mmtid refers to missing mm_tree.mmtid') =>
      "{mm_recycle} x LEFT JOIN {mm_tree} t ON t.mmtid=x.from_mmtid WHERE x.from_mmtid>0 AND t.mmtid IS NULL",
    (string) t('mm_recycle.bin_mmtid refers to missing mm_tree.mmtid') =>
      "{mm_recycle} x LEFT JOIN {mm_tree} t ON t.mmtid=x.bin_mmtid WHERE t.mmtid IS NULL",

    (string) t('mm_tree.parent refers to missing mm_tree.mmtid') =>
      "{mm_tree} x LEFT JOIN {mm_tree} t ON t.mmtid=x.parent WHERE x.parent>0 AND t.mmtid IS NULL",
    (string) t('mm_tree.uid refers to missing users.uid') =>
      "{mm_tree} x LEFT JOIN {users} u ON u.uid=x.uid WHERE u.uid IS NULL AND x.uid>0",
    (string) t('mm_tree.vid refers to missing mm_tree_revision.vid') =>
      "{mm_tree} x LEFT JOIN {mm_tree_revision} t ON t.vid=x.vid WHERE t.vid IS NULL",

    (string) t('mm_tree_access.mmtid refers to missing mm_tree.mmtid') =>
      "{mm_tree_access} x LEFT JOIN {mm_tree} t ON t.mmtid=x.mmtid WHERE t.mmtid IS NULL",
    (string) t('mm_tree_access.gid refers to missing mm_tree.mmtid') =>
      "{mm_tree_access} x LEFT JOIN {mm_tree} t ON t.mmtid=x.gid WHERE x.gid>0 AND t.mmtid IS NULL",

    (string) t('mm_tree_block.mmtid refers to missing mm_tree.mmtid') =>
      "{mm_tree_block} x LEFT JOIN {mm_tree} t ON t.mmtid=x.mmtid WHERE t.mmtid IS NULL",

    (string) t('mm_tree_bookmarks.uid refers to missing users.uid') =>
      "{mm_tree_bookmarks} x LEFT JOIN {users} u ON u.uid=x.uid WHERE u.uid IS NULL",

    (string) t('mm_tree_flags.mmtid refers to missing mm_tree.mmtid') =>
      "{mm_tree_flags} x LEFT JOIN {mm_tree} t ON t.mmtid=x.mmtid WHERE t.mmtid IS NULL",

    (string) t('mm_tree_parents.mmtid refers to missing mm_tree.mmtid') =>
      "{mm_tree_parents} x LEFT JOIN {mm_tree} t ON t.mmtid=x.mmtid WHERE t.mmtid IS NULL",
    (string) t('mm_tree_parents.parent refers to missing mm_tree.mmtid') =>
      "{mm_tree_parents} x LEFT JOIN {mm_tree} t ON t.mmtid=x.parent WHERE x.parent>0 AND t.mmtid IS NULL",

    (string) t('mm_virtual_group.vgid refers to missing mm_vgroup_query.vgid') =>
      "{mm_virtual_group} x LEFT JOIN {mm_vgroup_query} v ON v.vgid=x.vgid WHERE v.vgid IS NULL",
    (string) t('mm_virtual_group.uid refers to missing users.uid') =>
      "{mm_virtual_group} x LEFT JOIN {users} u ON u.uid=x.uid WHERE u.uid IS NULL",
  ]];
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc