original_string: public static function make_current($versionid) {
          global $DB, $USER;
  
          $policyversion = new policy_version($versionid);
          if (! $policyversion->get('id') || $policyversion->get('archived')) {
              throw new coding_exception('Version not found or is archived');
          }
  
          // Archive current version of this policy.
          if ($currentversionid = $DB->get_field('tool_policy', 'currentversionid', ['id' => $policyversion->get('policyid')])) {
              if ($currentversionid == $versionid) {
                  // Already current, do not change anything.
                  return;
              }
              $DB->set_field('tool_policy_versions', 'archived', 1, ['id' => $currentversionid]);
          }
  
          // Set given version as current.
          $DB->set_field('tool_policy', 'currentversionid', $policyversion->get('id'), ['id' => $policyversion->get('policyid')]);
  
          // Reset the policyagreed flag to force everybody re-accept the policies.
          $DB->set_field('user', 'policyagreed', 0);
  
          // Make sure that the current user is not immediately redirected to the policy acceptance page.
          if (isloggedin() && !isguestuser()) {
              $USER->policyagreed = 1;
          }
      }
code: public static function make_current($versionid) {
          global $DB, $USER;
  
          $policyversion = new policy_version($versionid);
          if (! $policyversion->get('id') || $policyversion->get('archived')) {
              throw new coding_exception('Version not found or is archived');
          }
  
          // Archive current version of this policy.
          if ($currentversionid = $DB->get_field('tool_policy', 'currentversionid', ['id' => $policyversion->get('policyid')])) {
              if ($currentversionid == $versionid) {
                  // Already current, do not change anything.
                  return;
              }
              $DB->set_field('tool_policy_versions', 'archived', 1, ['id' => $currentversionid]);
          }
  
          // Set given version as current.
          $DB->set_field('tool_policy', 'currentversionid', $policyversion->get('id'), ['id' => $policyversion->get('policyid')]);
  
          // Reset the policyagreed flag to force everybody re-accept the policies.
          $DB->set_field('user', 'policyagreed', 0);
  
          // Make sure that the current user is not immediately redirected to the policy acceptance page.
          if (isloggedin() && !isguestuser()) {
              $USER->policyagreed = 1;
          }
      }
code_tokens: public static function make_current ( $ versionid ) { global $ DB , $ USER ; $ policyversion = new policy_version ( $ versionid ) ; if ( ! $ policyversion -> get ( 'id' ) || $ policyversion -> get ( 'archived' ) ) { throw new coding_exception ( 'Version not found or is archived' ) ; } // Archive current version of this policy. if ( $ currentversionid = $ DB -> get_field ( 'tool_policy' , 'currentversionid' , [ 'id' => $ policyversion -> get ( 'policyid' ) ] ) ) { if ( $ currentversionid == $ versionid ) { // Already current, do not change anything. return ; } $ DB -> set_field ( 'tool_policy_versions' , 'archived' , 1 , [ 'id' => $ currentversionid ] ) ; } // Set given version as current. $ DB -> set_field ( 'tool_policy' , 'currentversionid' , $ policyversion -> get ( 'id' ) , [ 'id' => $ policyversion -> get ( 'policyid' ) ] ) ; // Reset the policyagreed flag to force everybody re-accept the policies. $ DB -> set_field ( 'user' , 'policyagreed' , 0 ) ; // Make sure that the current user is not immediately redirected to the policy acceptance page. if ( isloggedin ( ) && ! isguestuser ( ) ) { $ USER -> policyagreed = 1 ; } }
docstring: Make the given version the current active one.
  
  @param int $versionid
docstring_tokens: Make the given version the current active one .