url_redirect.install in Url Redirect 8.2
File
url_redirect.install
View source
<?php
function url_redirect_update_8101() {
$redirects = \Drupal::entityTypeManager()
->getStorage('url_redirect')
->getQuery()
->notExists('user')
->execute();
foreach ($redirects as $redirect) {
$entity = \Drupal::entityTypeManager()
->getStorage('url_redirect')
->load($redirect);
$entity
->set('user', [
[
'target_id' => '0',
],
]);
$entity
->save();
}
}
function url_redirect_update_8102() {
$manager = \Drupal::entityDefinitionUpdateManager();
$entity_type = $manager
->getEntityType('url_redirect');
$entity_keys = $entity_type
->getKeys();
$entity_keys['negate'] = 'negate';
$entity_type
->set('entity_keys', $entity_keys);
$manager
->updateEntityType($entity_type);
}
function url_redirect_update_8103() {
$db_connection = \Drupal::database();
if ($db_connection
->schema()
->tableExists('url_redirect')) {
$query = $db_connection
->select('url_redirect', 'ur');
$query
->fields('ur');
$all_data = $query
->execute()
->fetchAll();
foreach ($all_data as $key => $data) {
$values = array(
'label' => 'Migrated Redirect',
'id' => 'migrated_' . $key . '_' . time(),
'path' => $data->path,
'redirect_path' => $data->redirect_path,
'roles' => Drupal\Component\Serialization\Json::decode($data->roles),
'users' => Drupal\Component\Serialization\Json::decode($data->users),
'status' => $data->status,
'message' => $data->message,
'checked_for' => $data->check_for,
);
$url_redirect_entity = \Drupal\url_redirect\Entity\UrlRedirect::create($values);
$url_redirect_entity
->save();
}
}
}