original_string: public static function update_rule($ruledata) {
          global $DB;
          if (!self::get_rule($ruledata->id)) {
              throw new \coding_exception('Invalid rule ID.');
          }
          $ruledata->timemodified = time();
  
          $success = $DB->update_record('tool_monitor_rules', $ruledata);
  
          // If successful trigger a rule updated event.
          if ($success) {
              // If we do not have the course id we need to retrieve it.
              if (!isset($ruledata->courseid)) {
                  $courseid = $DB->get_field('tool_monitor_rules', 'courseid', array('id' => $ruledata->id), MUST_EXIST);
              } else {
                  $courseid = $ruledata->courseid;
              }
  
              if (!empty($courseid)) {
                  $context = \context_course::instance($courseid);
              } else {
                  $context = \context_system::instance();
              }
  
              $params = array(
                  'objectid' => $ruledata->id,
                  'courseid' => $courseid,
                  'context' => $context
              );
              $event = \tool_monitor\event\rule_updated::create($params);
              $event->trigger();
          }
  
          return $success;
      }
code: public static function update_rule($ruledata) {
          global $DB;
          if (!self::get_rule($ruledata->id)) {
              throw new \coding_exception('Invalid rule ID.');
          }
          $ruledata->timemodified = time();
  
          $success = $DB->update_record('tool_monitor_rules', $ruledata);
  
          // If successful trigger a rule updated event.
          if ($success) {
              // If we do not have the course id we need to retrieve it.
              if (!isset($ruledata->courseid)) {
                  $courseid = $DB->get_field('tool_monitor_rules', 'courseid', array('id' => $ruledata->id), MUST_EXIST);
              } else {
                  $courseid = $ruledata->courseid;
              }
  
              if (!empty($courseid)) {
                  $context = \context_course::instance($courseid);
              } else {
                  $context = \context_system::instance();
              }
  
              $params = array(
                  'objectid' => $ruledata->id,
                  'courseid' => $courseid,
                  'context' => $context
              );
              $event = \tool_monitor\event\rule_updated::create($params);
              $event->trigger();
          }
  
          return $success;
      }
code_tokens: public static function update_rule ( $ ruledata ) { global $ DB ; if ( ! self :: get_rule ( $ ruledata -> id ) ) { throw new \ coding_exception ( 'Invalid rule ID.' ) ; } $ ruledata -> timemodified = time ( ) ; $ success = $ DB -> update_record ( 'tool_monitor_rules' , $ ruledata ) ; // If successful trigger a rule updated event. if ( $ success ) { // If we do not have the course id we need to retrieve it. if ( ! isset ( $ ruledata -> courseid ) ) { $ courseid = $ DB -> get_field ( 'tool_monitor_rules' , 'courseid' , array ( 'id' => $ ruledata -> id ) , MUST_EXIST ) ; } else { $ courseid = $ ruledata -> courseid ; } if ( ! empty ( $ courseid ) ) { $ context = \ context_course :: instance ( $ courseid ) ; } else { $ context = \ context_system :: instance ( ) ; } $ params = array ( 'objectid' => $ ruledata -> id , 'courseid' => $ courseid , 'context' => $ context ) ; $ event = \ tool_monitor \ event \ rule_updated :: create ( $ params ) ; $ event -> trigger ( ) ; } return $ success ; }
docstring: Update rule data.
  
  @throws \coding_exception if $record->ruleid is invalid.
  @param object $ruledata rule data to be updated.
  
  @return bool
docstring_tokens: Update rule data .