You are here

function notifications_widget_update_8101 in Notifications widget 8

Update existing messsage value (adding class in message).

File

./notifications_widget.install, line 183
Install, update and uninstall functions for the notification module module.

Code

function notifications_widget_update_8101() {
  $connection = Drupal::database();
  $query = $connection
    ->select('notifications', 'n');
  $query
    ->fields('n', [
    'id',
    'message',
    'status',
  ]);
  $query
    ->condition('n.message', '%%class = "noti-store-msg"%%', 'NOT LIKE');
  $query
    ->orderBy('n.created', 'DESC');
  $res = $query
    ->execute();
  while ($notification = $res
    ->fetchObject()) {
    $keys = [
      'id' => $notification->id,
    ];
    $replacedStr = 'class="noti-store-msg" href="javascript:;"';
    $fields = [
      'message' => str_replace('href="javascript:;"', $replacedStr, $notification->message),
    ];
    $connection
      ->merge('notifications')
      ->key($keys)
      ->fields($fields)
      ->execute();
  }
}