original_string: public final function add_record_snapshot($tablename, $record) {
          global $DB, $CFG;
  
          if ($this->triggered) {
              throw new \coding_exception('It is not possible to add snapshots after triggering of events');
          }
  
          // Special case for course module, allow instance of cm_info to be passed instead of stdClass.
          if ($tablename === 'course_modules' && $record instanceof \cm_info) {
              $record = $record->get_course_module_record();
          }
  
          // NOTE: this might use some kind of MUC cache,
          //       hopefully we will not run out of memory here...
          if ($CFG->debugdeveloper) {
              if (!($record instanceof \stdClass)) {
                  debugging('Argument $record must be an instance of stdClass.', DEBUG_DEVELOPER);
              }
              if (!$DB->get_manager()->table_exists($tablename)) {
                  debugging("Invalid table name '$tablename' specified, database table does not exist.", DEBUG_DEVELOPER);
              } else {
                  $columns = $DB->get_columns($tablename);
                  $missingfields = array_diff(array_keys($columns), array_keys((array)$record));
                  if (!empty($missingfields)) {
                      debugging("Fields list in snapshot record does not match fields list in '$tablename'. Record is missing fields: ".
                              join(', ', $missingfields), DEBUG_DEVELOPER);
                  }
              }
          }
          $this->recordsnapshots[$tablename][$record->id] = $record;
      }
code: public final function add_record_snapshot($tablename, $record) {
          global $DB, $CFG;
  
          if ($this->triggered) {
              throw new \coding_exception('It is not possible to add snapshots after triggering of events');
          }
  
          // Special case for course module, allow instance of cm_info to be passed instead of stdClass.
          if ($tablename === 'course_modules' && $record instanceof \cm_info) {
              $record = $record->get_course_module_record();
          }
  
          // NOTE: this might use some kind of MUC cache,
          //       hopefully we will not run out of memory here...
          if ($CFG->debugdeveloper) {
              if (!($record instanceof \stdClass)) {
                  debugging('Argument $record must be an instance of stdClass.', DEBUG_DEVELOPER);
              }
              if (!$DB->get_manager()->table_exists($tablename)) {
                  debugging("Invalid table name '$tablename' specified, database table does not exist.", DEBUG_DEVELOPER);
              } else {
                  $columns = $DB->get_columns($tablename);
                  $missingfields = array_diff(array_keys($columns), array_keys((array)$record));
                  if (!empty($missingfields)) {
                      debugging("Fields list in snapshot record does not match fields list in '$tablename'. Record is missing fields: ".
                              join(', ', $missingfields), DEBUG_DEVELOPER);
                  }
              }
          }
          $this->recordsnapshots[$tablename][$record->id] = $record;
      }
code_tokens: public final function add_record_snapshot ( $ tablename , $ record ) { global $ DB , $ CFG ; if ( $ this -> triggered ) { throw new \ coding_exception ( 'It is not possible to add snapshots after triggering of events' ) ; } // Special case for course module, allow instance of cm_info to be passed instead of stdClass. if ( $ tablename === 'course_modules' && $ record instanceof \ cm_info ) { $ record = $ record -> get_course_module_record ( ) ; } // NOTE: this might use some kind of MUC cache, //       hopefully we will not run out of memory here... if ( $ CFG -> debugdeveloper ) { if ( ! ( $ record instanceof \ stdClass ) ) { debugging ( 'Argument $record must be an instance of stdClass.' , DEBUG_DEVELOPER ) ; } if ( ! $ DB -> get_manager ( ) -> table_exists ( $ tablename ) ) { debugging ( "Invalid table name '$tablename' specified, database table does not exist." , DEBUG_DEVELOPER ) ; } else { $ columns = $ DB -> get_columns ( $ tablename ) ; $ missingfields = array_diff ( array_keys ( $ columns ) , array_keys ( ( array ) $ record ) ) ; if ( ! empty ( $ missingfields ) ) { debugging ( "Fields list in snapshot record does not match fields list in '$tablename'. Record is missing fields: " . join ( ', ' , $ missingfields ) , DEBUG_DEVELOPER ) ; } } } $ this -> recordsnapshots [ $ tablename ] [ $ record -> id ] = $ record ; }
docstring: Add cached data that will be most probably used in event observers.
  
  This is used to improve performance, but it is required for data
  that was just deleted.
  
  @param string $tablename
  @param \stdClass $record
  
  @throws \coding_exception if used after ::trigger()
docstring_tokens: Add cached data that will be most probably used in event observers .