/**
  * Auto expand the tree
  *
  * @throws \Exception
  */
 public function autoExpandTree()
 {
     $session = Session::getInstance()->getData();
     if ($session['seo_serp_expand_tree'] !== 'tl_page' && !Input::get('serp_tests_expand')) {
         return;
     }
     $nodes = Database::getInstance()->execute("SELECT DISTINCT pid FROM tl_page WHERE pid>0");
     // Reset the array first
     $session['tl_page_tree'] = [];
     // Expand the tree
     while ($nodes->next()) {
         $session['tl_page_tree'][$nodes->pid] = 1;
     }
     // Avoid redirect loop
     $session['seo_serp_expand_tree'] = null;
     Session::getInstance()->setData($session);
     Backend::redirect(str_replace('serp_tests_expand=1', '', Environment::get('request')));
 }