8 – How to unflag/reset a flag again, when matching some conditions in onFlag event?

in my custom module I have an event subscriber service for flag module. I used the tutorial here as a base for learning: Link to Tutorial

Here is my code:

namespace DrupalMYMODULEEventSubscriber;

use SymfonyComponentEventDispatcherEventSubscriberInterface;
use DrupalflagEventFlagEvents;
use DrupalflagEventFlaggingEvent;
use DrupalflagEventUnflaggingEvent;
use DrupaluserUserInterface;
use DrupaluserEntityUser;

class MYMODULEFlagSubscriber implements EventSubscriberInterface {

  /**
   * Do the logic when the upgrade flag is triggered to flag.
   */
  public function onFlag(FlaggingEvent $event) {
    $flagging = $event->getFlagging();
    $flag = $flagging->getFlag();
    $flag_machine_name = $flag->id();
    if ($flag_machine_name === 'my_awesome_flag') {
      $entity_nid = $flagging->getFlaggable()->id();
      $user = User::load($entity_nid);
      $user_is_active = $user->isActive();
      $field_1 = $user->get('field_1')->value;
      $field_2 = $user->get('field_2')->value;
      $break_with_error = FALSE;
      $upgrade_message = '';
      $roles_to_ignore = (
        'administrator_junior',
        'team_sales',
        'administrator',
      );
      if (!$user->hasRole('authenticated_level_2')) {
        if (($user_is_active == TRUE) && ($field_1 == 1) && ($field_2 == 1)) {
          foreach ($roles_to_ignore as $role_to_ignore) {
            if ($user->hasRole($role_to_ignore)) {
              $break_with_error = TRUE;
              $upgrade_message = 'The User has a company role already and can not being upgraded as a Level 2 user.';
              break;
            }
          }
        }
        else {
          $break_with_error = TRUE;
          $upgrade_message = 'The User can not being upgraded as a Level 2 User. Reasons: 2. The account is not activated yet, 3. The user has not yet checked field 2';
        }
      }
      else {
        $break_with_error = TRUE;
        $upgrade_message = 'The User was upgraded as a Level 2 User already.';
      }

      switch ($break_with_error) {
        case TRUE:
          Drupal::messenger()->addError($upgrade_message);
          $flagging->unflag($flag_machine_name, $entity_nid);
          return;

        case FALSE:
          $user->addRole('authenticated_level_2');
          $user->save();
          Drupal::messenger()->addStatus('The User was upgraded as a Level 2 User sucessfully.');
          return;
      }

    }
  }

My Problem is

How can I unflag the flag again, when my logic checks settings and my variable $break_with_error becomes true?

$flagging->unflag($flag_machine_name, $entity_nid);

throws me an PHP error.

Update:

My intention was the following:

I use the flag here as a substitute for a link/button to trigger the “business logic” checks and to give the user a additional role with more privileges if the checks are passed.

In my opinion it’s a easy way to quickly have a link/button in multiple variants (e.g. in a view or as a field in user account). Another advantage is, that other people (in my case sales team or other admins) see the business logic checks have performed already when the user entity is flagged. But in case the logic checks are failing, the user entity should unflagged again.

For other opportunities to have a “business logic trigger” I’m open and thankful of course. 🙂

8 – Flag EventSubscriber: How to unflag/reset a flag again, when matching some conditions in onFlag event?

in my custom module I have an event subscriber service for flag module. I used the tutorial here as a base for learning: Link to Tutorial

Here is my code:

namespace DrupalMYMODULEEventSubscriber;

use SymfonyComponentEventDispatcherEventSubscriberInterface;
use DrupalflagEventFlagEvents;
use DrupalflagEventFlaggingEvent;
use DrupalflagEventUnflaggingEvent;
use DrupaluserUserInterface;
use DrupaluserEntityUser;

class MYMODULEFlagSubscriber implements EventSubscriberInterface {

  /**
   * Do the logic when the upgrade flag is triggered to flag.
   */
  public function onFlag(FlaggingEvent $event) {
    $flagging = $event->getFlagging();
    $flag = $flagging->getFlag();
    $flag_machine_name = $flag->id();
    if ($flag_machine_name === 'my_awesome_flag') {
      $entity_nid = $flagging->getFlaggable()->id();
      $user = User::load($entity_nid);
      $user_is_active = $user->isActive();
      $field_1 = $user->get('field_1')->value;
      $field_2 = $user->get('field_2')->value;
      $break_with_error = FALSE;
      $upgrade_message = '';
      $roles_to_ignore = (
        'administrator_junior',
        'team_sales',
        'administrator',
      );
      if (!$user->hasRole('authenticated_level_2')) {
        if (($user_is_active == TRUE) && ($field_1 == 1) && ($field_2 == 1)) {
          foreach ($roles_to_ignore as $role_to_ignore) {
            if ($user->hasRole($role_to_ignore)) {
              $break_with_error = TRUE;
              $upgrade_message = 'The User has a company role already and can not being upgraded as a Level 2 user.';
              break;
            }
          }
        }
        else {
          $break_with_error = TRUE;
          $upgrade_message = 'The User can not being upgraded as a Level 2 User. Reasons: 2. The account is not activated yet, 3. The user has not yet checked field 2';
        }
      }
      else {
        $break_with_error = TRUE;
        $upgrade_message = 'The User was upgraded as a Level 2 User already.';
      }

      switch ($break_with_error) {
        case TRUE:
          Drupal::messenger()->addError($upgrade_message);
          $flagging->unflag($flag_machine_name, $entity_nid);
          return;

        case FALSE:
          $user->addRole('authenticated_level_2');
          $user->save();
          Drupal::messenger()->addStatus('The User was upgraded as a Level 2 User sucessfully.');
          return;
      }

    }
  }

My Problem is

How can I unflag the flag again, when my logic checks settings and my variable $break_with_error becomes true?

$flagging->unflag($flag_machine_name, $entity_nid);

throws me an PHP error.

Thanks in advance 🙂

sql server 2016 – Sql_text Data Missing When Querying Extended Event File Target Using TSQL

I set up an Extended Events session to capture SQL Server error events.

Below is the TSQL I used to create the XE session:

CREATE EVENT SESSION (ErrorCapture) ON SERVER 
ADD EVENT sqlserver.error_reported(
    ACTION(sqlserver.client_hostname
    ,sqlserver.database_id
    ,sqlserver.sql_text
    ,sqlserver.username)
    WHERE ((severity)>=(11)))
ADD TARGET package0.event_file(SET filename=N'D:ErrorCapture.xel')
WITH (MAX_MEMORY=4096 KB,EVENT_RETENTION_MODE=ALLOW_SINGLE_EVENT_LOSS,MAX_DISPATCH_LATENCY=30 SECONDS,MAX_EVENT_SIZE=0 KB,MEMORY_PARTITION_MODE=NONE,TRACK_CAUSALITY=OFF,STARTUP_STATE=ON)
GO

Using SSMS, I am able to view all of the available event data, including sql_text. However, when suing TSQL to query the event file, data for the sql_text action shows up as NULL. Below is the query used. Any thoughts on why this might be?

with ErrorCaptureEventData as
(
  select convert(xml, event_data) as EventData
  from sys.fn_xe_file_target_read_file(N'D:ErrorCapture*.xel', NULL, NULL, NULL)
) 
select EventData.value('(event/@timestamp)(1)', 'datetime2(7)') as TimeStamp
       ,EventData.value('(event/data(@name="error_number")/value)(1)', 'int') AS (Error_Number)
       ,EventData.value('(event/data(@name="message")/value)(1)', N'nvarchar(max)') AS (Error_Message)
       ,EventData.value('(event/data(@name="sql_text")/value)(1)', N'nvarchar(max)') AS SQL_Text
       ,EventData.value('(event/data(@name="statement")/value)(1)', N'nvarchar(max)') AS SQL_Statement
       ,EventData.value('(event/data(@name="severity")/value)(1)', N'nvarchar(max)') AS Severity
       ,DB_NAME(EventData.value('(event/action(@name="database_id")/value)(1)', N'nvarchar(max)')) AS (DB_Name)
       ,EventData.value('(event/action(@name="username")/value)(1)', N'nvarchar(max)') AS (User_Name)
 from ErrorCaptureEventData
 order by timestamp desc

sleep wake – Autologin at external keyboard event

I’m wondering why (since I’ve installed macOS Big Sur) my Mac wakes up from standby without requesting me a password when I press a key (usually Ctrl) on my (Keychron) external USB keyboard.

No, I don’t have autologin set up.


P.S. I love it, and I’m not trying to change this behaviour. I’m just curious about why this is happening at all in first place.

spfx – Create a SharePoint List item when an Outlook/Teams/group event is created

In SharePoint Online I want to create sub-items in Document library/List and wish to reference a Teams, Group or Outlook calendar event.

Is it possible to create a SharePoint List item when an event is created in the above calendars? Then this could be used as a lookup for other document libraries.

Alternatively, is there an Outlook equivalent custom calendar that I can add to SharePoint that allows the same functionality (Create Team meetings, etc ..). Potentially I could add additional functionality to allow a SharePoint list item to be created

I’m looking for an option that can be deployed easily as want to automate the replication of solution for many projects. I think using Power Automate / Power Apps may not be suitable as I cannot create replications easily.

java – What are the best way to publish application event in a spring boot application?

My goal is to collect/publish different types of information from the application. We use Kafka for the event bus. Consider the following sample code.

class UserService {

public User userUpdateService(String username) {

    try {
        userRepo.save(new User(username));
    } catch (Exception e) {

        // this is a direct method call to publish error event in case of error
        publishEvent.asyncPublishUserUpdateErrorEvent(username, e);

        throw new RuntimeException();
    }

    // As the execution reach the last statement, assuming user update success 
    publishEvent.asyncPublishUserUpdateSuccessEvent(username);
}

}

As you see, currently I am calling the method in a UserService class to publish the error or success event. I call this method every time a new event needs to be collected and called directly from the code. I know that the ELK stack can be useful in my use-case, but that’s not an option for me.

One benefit I’ve seen in this direct method call is that I have more control over what kind of information is to be published. But by using this method I have to change the class, which I think violates many OO principles.

So, in practice, how can this type of task be accomplished? I’m using the Spring Boot framework.

powershell – Scheduled Task keeps running with Event Viewer ‘audit failure’ SeTcbPrivilege error

On Windows Server 2012, I’m trying to create a Scheduled Task, that runs as a Domain user, that copies a file from a different server to the local server, then deletes the file locally if the date modified is older than 30 minutes.

The powershell script I have works when I run it as my own admin account with Powershell and finishes without error.

I created the Scheduled Task and it too runs and the file is copied, and deleted if older than 30 minutes, but the task keeps running and never finishes.

The Event Log gives an Audit Failure error mentioning “SeTcbPrivilege”.

The Domain user has permission to run batch scripts.

Powershell execution policy is Unrestricted.

I’ve tried configuring the Task with different arguments, including:

-ExecutionPolicy Bypass -file "C:scriptsscript01.ps1"

The task is set to store the password, run if not logged on, with highest privileges.

What else could I be missing?

I suppose the process could be finishing but the Task Scheduler GUI just isn’t updating but in that case I’m concerned with the Audit Failure error.

I don’t think the powershell script matters but this is the gist of it:

Copy-Item -Path \server.example.comdirectoryfile.txt -Destination D:directoryfile.txt
Get-ChildItem -path D:directory | where {$_.Lastwritetime -lt (date).addminutes(-30)} | remove-item

dnd 5e – Is the gelatinous ice cube familiar from the “D&D Celebration 2020” event official?

It is Adventurers League-eligible for Season 10 and legacy characters.

This September 2020 tweet by the D&D Adventurers League account states that the Celebration legacy awards are eligible for use with Season 10 and Legacy Characters:

“Legacy Awards” have been spotted in the wild, during D&D Celebration!
They’re cute and cool! But we realize the name itself is confusing and
that will be addressed soon.

If you found any, each cert is available for a season 10 or Legacy
player character. Your choice!

For other games, ask your DM.

For other games, obviously, ask your DM. The oblex spawn is significantly more powerful than all of the usual options for find familiar. It is not normally a valid familiar option, as this certificate is not official D&D 5e rules content.

Percona Mysql 8.0.19-10 Slave SQL: Could not execute Update_rows event on table

we have this architecture: 3 db nodes master-master cluster replication, 1 slave db node (readonly, on offsite) without replication for backup purposes with binlogs application.
A db offline datadir snapshot is created on one master node of the cluster. Binlogs are periodically generated on the same master node (flush-logs binary).
The contents of the snapshot are copied to the slave, where the slave db is running above it. Subsequently, events from binlogs generated in the time since the master
node was stopped are replayed on slave db.
In some cases, an errors occurs when replaying binlogs events on the db slave, for example:
2020-10-23T11:20:09.500552Z 63 (ERROR) (MY-010584) (Repl) Slave SQL: Could not execute Update_rows event on table xxx.yyy;
Can’t find record in ‘yyy’, Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event’s master log FIRST, end_log_pos 2046, Error_code: MY-001032

Replication errors do not occur on cluster nodes.

We use this configuration on the nodes:
gtid_mode=ON
enforce_gtid_consistency
binlog_format=ROW

(mysqld 8.0.19-10) Percona XtraDB Cluster (GPL), Release rel10, Revision 727f180, WSREP version 26.4.3.

What could be the cause of this error, and how it can be fixed?
Thanks