function sharerich_update_8300 in Sharerich 8
Migrate sharerich sets and blocks.
File
- ./
sharerich.install, line 41 - Install, update, and uninstall functions for the sharerich module.
Code
function sharerich_update_8300() {
$query = \Drupal::database()
->select('config', 'c');
$query
->addField('c', 'name');
$query
->addField('c', 'data');
$query
->condition('data', '%sharerich%', 'LIKE');
$result = $query
->execute();
$records = $result
->fetchAll();
foreach ($records as $item) {
if (substr($item->name, 0, 11) == 'block.block') {
// Migrate blocks.
$data = unserialize($item->data);
if ($data['plugin'] == 'sharerich_block') {
$data['plugin'] = 'sharerich';
$data['settings']['id'] = $data['id'];
\Drupal::database()
->update('config')
->condition('name', $item->name)
->fields([
'data' => serialize($data),
])
->execute();
}
}
if (substr($item->name, 0, 19) == 'sharerich.sharerich') {
// Migrate sharerich sets.
\Drupal::database()
->update('config')
->condition('name', $item->name)
->fields([
'name' => str_replace('sharerich.sharerich', 'sharerich.set', $item->name),
])
->execute();
}
}
}