original_string: public static function set_context_instance($record) {
          if ($instance = context_instance::get_record_by_contextid($record->contextid, false)) {
              // Update.
              $instance->from_record($record);
  
              if (empty($record->purposeid) && empty($record->categoryid)) {
                  // We accept one of them to be null but we delete it if both are null.
                  self::unset_context_instance($instance);
                  return;
              }
  
          } else {
              // Add.
              $instance = new context_instance(0, $record);
          }
          $instance->save();
  
          return $instance;
      }
code: public static function set_context_instance($record) {
          if ($instance = context_instance::get_record_by_contextid($record->contextid, false)) {
              // Update.
              $instance->from_record($record);
  
              if (empty($record->purposeid) && empty($record->categoryid)) {
                  // We accept one of them to be null but we delete it if both are null.
                  self::unset_context_instance($instance);
                  return;
              }
  
          } else {
              // Add.
              $instance = new context_instance(0, $record);
          }
          $instance->save();
  
          return $instance;
      }
code_tokens: public static function set_context_instance ( $ record ) { if ( $ instance = context_instance :: get_record_by_contextid ( $ record -> contextid , false ) ) { // Update. $ instance -> from_record ( $ record ) ; if ( empty ( $ record -> purposeid ) && empty ( $ record -> categoryid ) ) { // We accept one of them to be null but we delete it if both are null. self :: unset_context_instance ( $ instance ) ; return ; } } else { // Add. $ instance = new context_instance ( 0 , $ record ) ; } $ instance -> save ( ) ; return $ instance ; }
docstring: Sets the context instance purpose and category.
  
  @param \stdClass $record
  @return \tool_dataprivacy\context_instance
docstring_tokens: Sets the context instance purpose and category .