original_string: protected function check_page_order($page1, $page2) {
          global $DB;
          if (empty($page1)) {
              if ($page2->prevpageid != 0) {
                  debugging("***prevpageid of page " . $page2->id . " set to 0***");
                  $page2->prevpageid = 0;
                  $DB->set_field("lesson_pages", "prevpageid", 0, array("id" => $page2->id));
              }
          } else if (empty($page2)) {
              if ($page1->nextpageid != 0) {
                  debugging("***nextpageid of page " . $page1->id . " set to 0***");
                  $page1->nextpageid = 0;
                  $DB->set_field("lesson_pages", "nextpageid", 0, array("id" => $page1->id));
              }
          } else {
              if ($page1->nextpageid != $page2->id) {
                  debugging("***nextpageid of page " . $page1->id . " set to " . $page2->id . "***");
                  $page1->nextpageid = $page2->id;
                  $DB->set_field("lesson_pages", "nextpageid", $page2->id, array("id" => $page1->id));
              }
              if ($page2->prevpageid != $page1->id) {
                  debugging("***prevpageid of page " . $page2->id . " set to " . $page1->id . "***");
                  $page2->prevpageid = $page1->id;
                  $DB->set_field("lesson_pages", "prevpageid", $page1->id, array("id" => $page2->id));
              }
          }
      }
code: protected function check_page_order($page1, $page2) {
          global $DB;
          if (empty($page1)) {
              if ($page2->prevpageid != 0) {
                  debugging("***prevpageid of page " . $page2->id . " set to 0***");
                  $page2->prevpageid = 0;
                  $DB->set_field("lesson_pages", "prevpageid", 0, array("id" => $page2->id));
              }
          } else if (empty($page2)) {
              if ($page1->nextpageid != 0) {
                  debugging("***nextpageid of page " . $page1->id . " set to 0***");
                  $page1->nextpageid = 0;
                  $DB->set_field("lesson_pages", "nextpageid", 0, array("id" => $page1->id));
              }
          } else {
              if ($page1->nextpageid != $page2->id) {
                  debugging("***nextpageid of page " . $page1->id . " set to " . $page2->id . "***");
                  $page1->nextpageid = $page2->id;
                  $DB->set_field("lesson_pages", "nextpageid", $page2->id, array("id" => $page1->id));
              }
              if ($page2->prevpageid != $page1->id) {
                  debugging("***prevpageid of page " . $page2->id . " set to " . $page1->id . "***");
                  $page2->prevpageid = $page1->id;
                  $DB->set_field("lesson_pages", "prevpageid", $page1->id, array("id" => $page2->id));
              }
          }
      }
code_tokens: protected function check_page_order ( $ page1 , $ page2 ) { global $ DB ; if ( empty ( $ page1 ) ) { if ( $ page2 -> prevpageid != 0 ) { debugging ( "***prevpageid of page " . $ page2 -> id . " set to 0***" ) ; $ page2 -> prevpageid = 0 ; $ DB -> set_field ( "lesson_pages" , "prevpageid" , 0 , array ( "id" => $ page2 -> id ) ) ; } } else if ( empty ( $ page2 ) ) { if ( $ page1 -> nextpageid != 0 ) { debugging ( "***nextpageid of page " . $ page1 -> id . " set to 0***" ) ; $ page1 -> nextpageid = 0 ; $ DB -> set_field ( "lesson_pages" , "nextpageid" , 0 , array ( "id" => $ page1 -> id ) ) ; } } else { if ( $ page1 -> nextpageid != $ page2 -> id ) { debugging ( "***nextpageid of page " . $ page1 -> id . " set to " . $ page2 -> id . "***" ) ; $ page1 -> nextpageid = $ page2 -> id ; $ DB -> set_field ( "lesson_pages" , "nextpageid" , $ page2 -> id , array ( "id" => $ page1 -> id ) ) ; } if ( $ page2 -> prevpageid != $ page1 -> id ) { debugging ( "***prevpageid of page " . $ page2 -> id . " set to " . $ page1 -> id . "***" ) ; $ page2 -> prevpageid = $ page1 -> id ; $ DB -> set_field ( "lesson_pages" , "prevpageid" , $ page1 -> id , array ( "id" => $ page2 -> id ) ) ; } } }
docstring: This function detects errors in the ordering between 2 pages and updates the page records.
  
  @param stdClass $page1 Either the first of 2 pages or null if the $page2 param is the first in the list.
  @param stdClass $page1 Either the second of 2 pages or null if the $page1 param is the last in the list.
docstring_tokens: This function detects errors in the ordering between 2 pages and updates the page records .