You are here

function empty_page_update_8101 in Empty Page 8

Implements hook_update_N().

File

./empty_page.install, line 18
Installation file.

Code

function empty_page_update_8101(&$sandbox) {
  if (\Drupal::database()
    ->schema()
    ->tableExists('empty_page')) {
    $id = 0;
    $records = \Drupal::database()
      ->select('empty_page', 't')
      ->fields('t', [])
      ->orderBy('cid', 'ASC')
      ->execute()
      ->fetchAll();
    $config = \Drupal::configFactory()
      ->getEditable('empty_page.settings');
    foreach ($records as $record) {
      $config = $config
        ->set('callback_' . $record->cid, (array) $record);
      $id = $record->cid;
    }
    $config
      ->set('new_id', $id + 1)
      ->save();

    // Delete the table.
    \Drupal::database()
      ->schema()
      ->dropTable('empty_page');
  }
}