original_string: protected function delete_instance_as_record($taginstance, $fullobject = false) {
          global $DB;
  
          $this->ensure_fields_exist(array('name', 'rawname', 'isstandard'), 'delete_instance_as_record');
  
          $DB->delete_records('tag_instance', array('id' => $taginstance->id));
  
          // We can not fire an event with 'null' as the contextid.
          if (is_null($taginstance->contextid)) {
              $taginstance->contextid = context_system::instance()->id;
          }
  
          // Trigger tag removed event.
          $taginstance->tagid = $this->id;
          \core\event\tag_removed::create_from_tag_instance($taginstance, $this->name, $this->rawname, $fullobject)->trigger();
  
          // If there are no other instances of the tag then consider deleting the tag as well.
          if (!$this->isstandard) {
              if (!$DB->record_exists('tag_instance', array('tagid' => $this->id))) {
                  self::delete_tags($this->id);
              }
          }
  
          return true;
      }
code: protected function delete_instance_as_record($taginstance, $fullobject = false) {
          global $DB;
  
          $this->ensure_fields_exist(array('name', 'rawname', 'isstandard'), 'delete_instance_as_record');
  
          $DB->delete_records('tag_instance', array('id' => $taginstance->id));
  
          // We can not fire an event with 'null' as the contextid.
          if (is_null($taginstance->contextid)) {
              $taginstance->contextid = context_system::instance()->id;
          }
  
          // Trigger tag removed event.
          $taginstance->tagid = $this->id;
          \core\event\tag_removed::create_from_tag_instance($taginstance, $this->name, $this->rawname, $fullobject)->trigger();
  
          // If there are no other instances of the tag then consider deleting the tag as well.
          if (!$this->isstandard) {
              if (!$DB->record_exists('tag_instance', array('tagid' => $this->id))) {
                  self::delete_tags($this->id);
              }
          }
  
          return true;
      }
code_tokens: protected function delete_instance_as_record ( $ taginstance , $ fullobject = false ) { global $ DB ; $ this -> ensure_fields_exist ( array ( 'name' , 'rawname' , 'isstandard' ) , 'delete_instance_as_record' ) ; $ DB -> delete_records ( 'tag_instance' , array ( 'id' => $ taginstance -> id ) ) ; // We can not fire an event with 'null' as the contextid. if ( is_null ( $ taginstance -> contextid ) ) { $ taginstance -> contextid = context_system :: instance ( ) -> id ; } // Trigger tag removed event. $ taginstance -> tagid = $ this -> id ; \ core \ event \ tag_removed :: create_from_tag_instance ( $ taginstance , $ this -> name , $ this -> rawname , $ fullobject ) -> trigger ( ) ; // If there are no other instances of the tag then consider deleting the tag as well. if ( ! $ this -> isstandard ) { if ( ! $ DB -> record_exists ( 'tag_instance' , array ( 'tagid' => $ this -> id ) ) ) { self :: delete_tags ( $ this -> id ) ; } } return true ; }
docstring: Deletes the tag instance given the record from tag_instance DB table
  
  @param stdClass $taginstance
  @param bool $fullobject whether $taginstance contains all fields from DB table tag_instance
  (in this case it is safe to add a record snapshot to the event)
  @return bool
docstring_tokens: Deletes the tag instance given the record from tag_instance DB table