/**
  * This listener is run when the KernelEvents::EXCEPTION event is triggered
  *
  * @param GetResponseForExceptionEvent $event
  * @return null
  */
 public function on_kernel_exception(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     $message = $exception->getMessage();
     if ($exception instanceof \phpbb\exception\exception_interface) {
         $message = $this->language->lang_array($message, $exception->get_parameters());
     }
     if (!$event->getRequest()->isXmlHttpRequest()) {
         page_header($this->language->lang('INFORMATION'));
         $this->template->assign_vars(array('MESSAGE_TITLE' => $this->language->lang('INFORMATION'), 'MESSAGE_TEXT' => $message));
         $this->template->set_filenames(array('body' => 'message_body.html'));
         page_footer(true, false, false);
         $response = new Response($this->template->assign_display('body'), 500);
     } else {
         $data = array();
         if (!empty($message)) {
             $data['message'] = $message;
         }
         if (defined('DEBUG')) {
             $data['trace'] = $exception->getTrace();
         }
         $response = new JsonResponse($data, 500);
     }
     if ($exception instanceof HttpExceptionInterface) {
         $response->setStatusCode($exception->getStatusCode());
         $response->headers->add($exception->getHeaders());
     }
     $event->setResponse($response);
 }
 /**
  * {@inheritdoc}
  */
 public function write($message, $verbosity)
 {
     if ($verbosity <= migrator_output_handler_interface::VERBOSITY_VERBOSE) {
         $final_message = $this->language->lang_array(array_shift($message), $message);
         echo $final_message . "<br />\n";
     }
 }
Esempio n. 3
0
 public function test_lang_array()
 {
     $this->assertEquals($this->lang->lang_array('FOO'), 'BAR');
     $this->assertEquals($this->lang->lang_array('VOID'), 'VOID');
     $this->assertEquals($this->lang->lang_array('ARRY', [0]), 'No posts');
     $this->assertEquals($this->lang->lang_array('FOO', [2, 3, 'BARZ']), 'BAR');
 }
 /**
  * This listener is run when the KernelEvents::EXCEPTION event is triggered
  *
  * @param GetResponseForExceptionEvent	$event
  */
 public function on_kernel_exception(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     $message = $exception->getMessage();
     if ($exception instanceof exception_interface) {
         $message = $this->language->lang_array($message, $exception->get_parameters());
     }
     if (!$event->getRequest()->isXmlHttpRequest()) {
         $this->template->assign_vars(array('TITLE' => $this->language->lang('INFORMATION'), 'BODY' => $message));
         $response = $this->controller_helper->render('installer_main.html', $this->language->lang('INFORMATION'), false, 500);
     } else {
         $data = array();
         if (!empty($message)) {
             $data['message'] = $message;
         }
         if (defined('DEBUG')) {
             $data['trace'] = $exception->getTrace();
         }
         $response = new JsonResponse($data, 500);
     }
     if ($exception instanceof HttpExceptionInterface) {
         $response->setStatusCode($exception->getStatusCode());
         $response->headers->add($exception->getHeaders());
     }
     $event->setResponse($response);
 }
 /**
  * {@inheritdoc}
  */
 public function write($message, $verbosity)
 {
     $this->migrator->write($message, $verbosity);
     if ($this->file_handle !== false) {
         $translated_message = $this->language->lang_array(array_shift($message), $message);
         if ($verbosity <= migrator_output_handler_interface::VERBOSITY_NORMAL) {
             $translated_message = '[INFO] ' . $translated_message;
         } else {
             $translated_message = '[DEBUG] ' . $translated_message;
         }
         fwrite($this->file_handle, $translated_message);
         fflush($this->file_handle);
     }
 }
Esempio n. 6
0
 /**
  * Validates settings form
  *
  * @param string	$convertor
  */
 public function proccess_settings_form($convertor)
 {
     global $phpbb_root_path, $phpEx, $get_info;
     $phpbb_root_path = $this->phpbb_root_path;
     $phpEx = $this->php_ext;
     $get_info = true;
     require_once $this->phpbb_root_path . 'includes/constants.' . $this->php_ext;
     require_once $this->phpbb_root_path . 'includes/functions_convert.' . $this->php_ext;
     // Include convertor if available
     $convertor_file_path = $this->phpbb_root_path . 'install/convertors/convert_' . $convertor . '.' . $this->php_ext;
     include $convertor_file_path;
     // We expect to have an AJAX request here
     $src_dbms = $this->request->variable('src_dbms', $convertor_data['dbms']);
     $src_dbhost = $this->request->variable('src_dbhost', $convertor_data['dbhost']);
     $src_dbport = $this->request->variable('src_dbport', $convertor_data['dbport']);
     $src_dbuser = $this->request->variable('src_dbuser', $convertor_data['dbuser']);
     $src_dbpasswd = $this->request->variable('src_dbpasswd', $convertor_data['dbpasswd']);
     $src_dbname = $this->request->variable('src_dbname', $convertor_data['dbname']);
     $src_table_prefix = $this->request->variable('src_table_prefix', $convertor_data['table_prefix']);
     $forum_path = $this->request->variable('forum_path', $convertor_data['forum_path']);
     $refresh = $this->request->variable('refresh', 1);
     // Default URL of the old board
     // @todo Are we going to use this for attempting to convert URL references in posts, or should we remove it?
     //		-> We should convert old urls to the new relative urls format
     // $src_url = $request->variable('src_url', 'Not in use at the moment');
     // strip trailing slash from old forum path
     $forum_path = strlen($forum_path) && $forum_path[strlen($forum_path) - 1] == '/' ? substr($forum_path, 0, -1) : $forum_path;
     $error = array();
     if (!file_exists($this->phpbb_root_path . $forum_path . '/' . $test_file)) {
         $error[] = $this->language->lang('COULD_NOT_FIND_PATH', $forum_path);
     }
     $connect_test = false;
     $available_dbms = $this->db_helper->get_available_dbms(false, true, true);
     if (!isset($available_dbms[$src_dbms]) || !$available_dbms[$src_dbms]['AVAILABLE']) {
         $error[] = $this->language->lang('INST_ERR_NO_DB');
     } else {
         $connect_test = $this->db_helper->check_database_connection($src_dbms, $src_dbhost, $src_dbport, $src_dbuser, $src_dbpasswd, $src_dbname, $src_table_prefix);
     }
     extract($this->config_php_file->get_all());
     // The forum prefix of the old and the new forum can only be the same if two different databases are used.
     if ($src_table_prefix === $table_prefix && $src_dbms === $dbms && $src_dbhost === $dbhost && $src_dbport === $dbport && $src_dbname === $dbname) {
         $error[] = $this->language->lang('TABLE_PREFIX_SAME', $src_table_prefix);
     }
     if (!$connect_test) {
         $error[] = $this->language->lang('INST_ERR_DB_CONNECT');
     }
     $src_dbms = $this->config_php_file->convert_30_dbms_to_31($src_dbms);
     // Check table prefix
     if (empty($error)) {
         // initiate database connection to old db if old and new db differ
         global $src_db, $same_db;
         $src_db = $same_db = false;
         if ($src_dbms != $dbms || $src_dbhost != $dbhost || $src_dbport != $dbport || $src_dbname != $dbname || $src_dbuser != $dbuser) {
             /** @var \phpbb\db\driver\driver_interface $src_db */
             $src_db = new $src_dbms();
             $src_db->sql_connect($src_dbhost, $src_dbuser, htmlspecialchars_decode($src_dbpasswd), $src_dbname, $src_dbport, false, true);
             $same_db = false;
         } else {
             $src_db = $this->db;
             $same_db = true;
         }
         $src_db->sql_return_on_error(true);
         $this->db->sql_return_on_error(true);
         // Try to select one row from the first table to see if the prefix is OK
         $result = $src_db->sql_query_limit('SELECT * FROM ' . $src_table_prefix . $tables[0], 1);
         if (!$result) {
             $prefixes = array();
             $db_tools_factory = new \phpbb\db\tools\factory();
             $db_tools = $db_tools_factory->get($src_db);
             $tables_existing = $db_tools->sql_list_tables();
             $tables_existing = array_map('strtolower', $tables_existing);
             foreach ($tables_existing as $table_name) {
                 compare_table($tables, $table_name, $prefixes);
             }
             unset($tables_existing);
             foreach ($prefixes as $prefix => $count) {
                 if ($count >= sizeof($tables)) {
                     $possible_prefix = $prefix;
                     break;
                 }
             }
             $msg = '';
             if (!empty($convertor_data['table_prefix'])) {
                 $msg .= $this->language->lang_array('DEFAULT_PREFIX_IS', array($convertor_data['forum_name'], $convertor_data['table_prefix']));
             }
             if (!empty($possible_prefix)) {
                 $msg .= '<br />';
                 $msg .= $possible_prefix == '*' ? $this->language->lang('BLANK_PREFIX_FOUND') : $this->language->lang_array('PREFIX_FOUND', array($possible_prefix));
                 $src_table_prefix = $possible_prefix == '*' ? '' : $possible_prefix;
             }
             $error[] = $msg;
         }
         $src_db->sql_freeresult($result);
         $src_db->sql_return_on_error(false);
     }
     if (empty($error)) {
         // Save convertor Status
         $this->config->set('convert_progress', serialize(array('step' => '', 'table_prefix' => $src_table_prefix, 'tag' => $convertor)), false);
         $this->config->set('convert_db_server', serialize(array('dbms' => $src_dbms, 'dbhost' => $src_dbhost, 'dbport' => $src_dbport, 'dbname' => $src_dbname)), false);
         $this->config->set('convert_db_user', serialize(array('dbuser' => $src_dbuser, 'dbpasswd' => $src_dbpasswd)), false);
         // Save options
         $this->config->set('convert_options', serialize(array('forum_path' => $this->phpbb_root_path . $forum_path, 'refresh' => $refresh)), false);
         $url = $this->controller_helper->route('phpbb_convert_convert', array('converter' => $convertor));
         $this->iohandler->redirect($url);
         $this->iohandler->send_response(true);
     } else {
         $this->render_settings_form($error);
     }
 }