1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- /**
- * @file
- * Pre-release update hooks for Domain modules.
- */
- /**
- * Implements hook_install().
- *
- * We accidentally released the 8001 update, which will not run on a fresh install. So
- * lets for it to run now.
- */
- function domain_alpha_install() {
- $sandbox = array();
- domain_alpha_update_8001($sandbox);
- }
- /**
- * Update domain id to new value.
- */
- function domain_alpha_update_8001(&$sandbox) {
- // Set the node_access rebuild flag. Only update if an id changes.
- $rebuild = FALSE;
- // Load all domains and update the id, if necessary.
- $domains = \Drupal::entityTypeManager()->getStorage('domain')->loadMultiple();
- foreach ($domains as $domain) {
- /** @var $domain \Drupal\domain\Entity\Domain */
- // Existing id.
- $id = $domain->getDomainId();
- // New id.
- $domain->createDomainId();
- $new_id = $domain->getDomainId();
- // Check to see if this update is needed.
- if ($id != $new_id) {
- $domain->save();
- $rebuild = TRUE;
- }
- }
- if ($rebuild) {
- // Trigger permissions rebuild action.
- node_access_needs_rebuild(TRUE);
- }
- }
- /**
- * Provide a new update for 8001, for users who never ran 8001.
- *
- * See https://github.com/agentrickard/domain/issues/310.
- */
- function domain_alpha_update_8002(&$sandbox) {
- domain_alpha_update_8001($sandbox);
- }
- /**
- * Set the Domain Admin field to use the proper plugin.
- */
- function domain_alpha_update_8003(&$sandbox) {
- $id = 'user.user.field_domain_admin';
- $storage = \Drupal::entityTypeManager()->getStorage('field_config');
- if ($field = $storage->load($id)) {
- $new_field = $field->toArray();
- if ($new_field['settings']['handler'] != 'domain:domain') {
- $new_field['settings']['handler'] = 'domain:domain';
- $field_config = $storage->create($new_field);
- $field_config->original = $field;
- $field_config->enforceIsNew(FALSE);
- $field_config->save();
- }
- }
- }
- /**
- * Make all affiliates default value configurable.
- */
- function domain_alpha_update_8004() {
- $config = \Drupal::configFactory();
- $field_name = '.' . DOMAIN_ACCESS_ALL_FIELD;
- // Iterate over all node & user fields.
- foreach (['node', 'user'] as $type) {
- foreach ($config->listAll('field.field.' . $type . '.') as $field_id) {
- if (substr($field_id, -strlen($field_name)) === $field_name) {
- $field = $config->getEditable($field_id);
- if ($field->get('default_value_callback') === 'Drupal\domain_access\DomainAccessManager::getDefaultAllValue') {
- $field
- ->clear('default_value_callback')
- ->save(TRUE);
- }
- }
- }
- }
- }
|