original_string: public static function delete_subscription($subscriptionorid, $checkuser = true) {
          global $DB, $USER;
          if (is_object($subscriptionorid)) {
              $subscription = $subscriptionorid;
          } else {
              $subscription = self::get_subscription($subscriptionorid);
          }
          if ($checkuser && $subscription->userid != $USER->id) {
              throw new \coding_exception('Invalid subscription supplied');
          }
  
          // Store the subscription before we delete it.
          $subscription = $DB->get_record('tool_monitor_subscriptions', array('id' => $subscription->id));
  
          $success = $DB->delete_records('tool_monitor_subscriptions', array('id' => $subscription->id));
  
          // If successful trigger a subscription_deleted event.
          if ($success) {
              if (!empty($subscription->courseid) &&
                      ($coursecontext = \context_course::instance($subscription->courseid, IGNORE_MISSING))) {
                  $courseid = $subscription->courseid;
                  $context = $coursecontext;
              } else {
                  $courseid = 0;
                  $context = \context_system::instance();
              }
  
              $params = array(
                  'objectid' => $subscription->id,
                  'courseid' => $courseid,
                  'context' => $context
              );
              $event = \tool_monitor\event\subscription_deleted::create($params);
              $event->add_record_snapshot('tool_monitor_subscriptions', $subscription);
              $event->trigger();
  
              // Let's invalidate the cache.
              $cache = \cache::make('tool_monitor', 'eventsubscriptions');
              $cache->delete($courseid);
          }
  
          return $success;
      }
code: public static function delete_subscription($subscriptionorid, $checkuser = true) {
          global $DB, $USER;
          if (is_object($subscriptionorid)) {
              $subscription = $subscriptionorid;
          } else {
              $subscription = self::get_subscription($subscriptionorid);
          }
          if ($checkuser && $subscription->userid != $USER->id) {
              throw new \coding_exception('Invalid subscription supplied');
          }
  
          // Store the subscription before we delete it.
          $subscription = $DB->get_record('tool_monitor_subscriptions', array('id' => $subscription->id));
  
          $success = $DB->delete_records('tool_monitor_subscriptions', array('id' => $subscription->id));
  
          // If successful trigger a subscription_deleted event.
          if ($success) {
              if (!empty($subscription->courseid) &&
                      ($coursecontext = \context_course::instance($subscription->courseid, IGNORE_MISSING))) {
                  $courseid = $subscription->courseid;
                  $context = $coursecontext;
              } else {
                  $courseid = 0;
                  $context = \context_system::instance();
              }
  
              $params = array(
                  'objectid' => $subscription->id,
                  'courseid' => $courseid,
                  'context' => $context
              );
              $event = \tool_monitor\event\subscription_deleted::create($params);
              $event->add_record_snapshot('tool_monitor_subscriptions', $subscription);
              $event->trigger();
  
              // Let's invalidate the cache.
              $cache = \cache::make('tool_monitor', 'eventsubscriptions');
              $cache->delete($courseid);
          }
  
          return $success;
      }
code_tokens: public static function delete_subscription ( $ subscriptionorid , $ checkuser = true ) { global $ DB , $ USER ; if ( is_object ( $ subscriptionorid ) ) { $ subscription = $ subscriptionorid ; } else { $ subscription = self :: get_subscription ( $ subscriptionorid ) ; } if ( $ checkuser && $ subscription -> userid != $ USER -> id ) { throw new \ coding_exception ( 'Invalid subscription supplied' ) ; } // Store the subscription before we delete it. $ subscription = $ DB -> get_record ( 'tool_monitor_subscriptions' , array ( 'id' => $ subscription -> id ) ) ; $ success = $ DB -> delete_records ( 'tool_monitor_subscriptions' , array ( 'id' => $ subscription -> id ) ) ; // If successful trigger a subscription_deleted event. if ( $ success ) { if ( ! empty ( $ subscription -> courseid ) && ( $ coursecontext = \ context_course :: instance ( $ subscription -> courseid , IGNORE_MISSING ) ) ) { $ courseid = $ subscription -> courseid ; $ context = $ coursecontext ; } else { $ courseid = 0 ; $ context = \ context_system :: instance ( ) ; } $ params = array ( 'objectid' => $ subscription -> id , 'courseid' => $ courseid , 'context' => $ context ) ; $ event = \ tool_monitor \ event \ subscription_deleted :: create ( $ params ) ; $ event -> add_record_snapshot ( 'tool_monitor_subscriptions' , $ subscription ) ; $ event -> trigger ( ) ; // Let's invalidate the cache. $ cache = \ cache :: make ( 'tool_monitor' , 'eventsubscriptions' ) ; $ cache -> delete ( $ courseid ) ; } return $ success ; }
docstring: Delete a subscription.
  
  @param subscription|int $subscriptionorid an instance of subscription class or id.
  @param bool $checkuser Check if the subscription belongs to current user before deleting.
  
  @return bool
  @throws \coding_exception if $checkuser is true and the subscription doesn't belong to the current user.
docstring_tokens: Delete a subscription .