entity_share_client.install in Entity Share 8.3
File
modules/entity_share_client/entity_share_client.install
View source
<?php
declare (strict_types=1);
use Drupal\Core\Config\Entity\ConfigEntityType;
use Drupal\Core\Entity\ContentEntityType;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\entity_share_client\ClientAuthorization\ClientAuthorizationInterface;
use Drupal\entity_share_client\Entity\Remote;
use Drupal\Core\Utility\UpdateException;
function entity_share_client_uninstall() {
$key_value_store = \Drupal::keyValue(ClientAuthorizationInterface::LOCAL_STORAGE_KEY_VALUE_COLLECTION);
$key_value_store
->deleteAll();
}
function entity_share_client_update_8301() {
\Drupal::entityDefinitionUpdateManager()
->installEntityType(new ContentEntityType([
'id' => 'entity_import_status',
'label' => new TranslatableMarkup('Entity import status'),
'base_table' => 'entity_import_status',
'entity_keys' => [
'id' => 'id',
'langcode' => 'langcode',
],
]));
}
function entity_share_client_update_8302() {
\Drupal::entityDefinitionUpdateManager()
->installEntityType(new ConfigEntityType([
'id' => 'import_config',
'label' => new TranslatableMarkup('Import config'),
'entity_keys' => [
'id' => 'id',
'label' => 'label',
'uuid' => 'uuid',
],
]));
}
function entity_share_client_update_8303() {
$manager = \Drupal::service('plugin.manager.entity_share_client_authorization');
$state = \Drupal::state();
$remotes = Remote::loadMultiple();
foreach ($remotes as $remote) {
if (!is_null($remote
->get('auth'))) {
continue;
}
if (!empty($remote
->get('basic_auth_username')) && !empty($remote
->get('basic_auth_password'))) {
$plugin = $manager
->createInstance('basic_auth');
$configuration = $plugin
->getConfiguration();
$configuration['uuid'] = $remote
->uuid();
$credentials = [];
$credentials['username'] = $remote
->get('basic_auth_username');
$credentials['password'] = $remote
->get('basic_auth_password');
$state
->set($configuration['uuid'], $credentials);
}
else {
$plugin = $manager
->createInstance('anonymous');
$configuration = $plugin
->getConfiguration();
$configuration['uuid'] = $remote
->uuid();
}
unset($remote->basic_auth_username);
unset($remote->basic_auth_password);
$configuration['data'] = [
'credential_provider' => 'entity_share',
'storage_key' => $configuration['uuid'],
];
$plugin
->setConfiguration($configuration);
$remote
->mergePluginConfig($plugin);
$remote
->save();
}
}
function entity_share_client_update_8304() {
try {
$import_config_items = \Drupal::entityTypeManager()
->getStorage('import_config')
->loadMultiple();
foreach ($import_config_items as $item) {
$settings = $item
->get('import_processor_settings');
if (isset($settings['physical_file']) && !isset($settings['physical_file']['rename'])) {
$settings['physical_file']['rename'] = FALSE;
$item
->set('import_processor_settings', $settings)
->save();
}
}
} catch (Exception $exception) {
throw new UpdateException($exception
->getMessage());
}
}
function entity_share_client_update_8305() {
if (\Drupal::moduleHandler()
->moduleExists('diff')) {
\Drupal::service('module_installer')
->install([
'entity_share_diff',
]);
}
}