diff --git a/error_report.php b/error_report.php
index 3ac3c9ed80..a30998e777 100644
--- a/error_report.php
+++ b/error_report.php
@@ -6,8 +6,10 @@
* @package PhpMyAdmin
*/
use PhpMyAdmin\ErrorReport;
+use PhpMyAdmin\Message;
use PhpMyAdmin\Response;
use PhpMyAdmin\UserPreferences;
+use PhpMyAdmin\Utils\HttpRequest;
require_once 'libraries/common.inc.php';
@@ -19,6 +21,8 @@ if (!isset($_REQUEST['exception_type'])
$response = Response::getInstance();
+$errorReport = new ErrorReport(new HttpRequest());
+
if (isset($_REQUEST['send_error_report'])
&& ($_REQUEST['send_error_report'] == true
|| $_REQUEST['send_error_report'] == '1')
@@ -47,10 +51,10 @@ if (isset($_REQUEST['send_error_report'])
);
}
}
- $reportData = ErrorReport::getReportData($_REQUEST['exception_type']);
+ $reportData = $errorReport->getData($_REQUEST['exception_type']);
// report if and only if there were 'actual' errors.
if (count($reportData) > 0) {
- $server_response = ErrorReport::send($reportData);
+ $server_response = $errorReport->send($reportData);
if ($server_response === false) {
$success = false;
} else {
@@ -87,9 +91,9 @@ if (isset($_REQUEST['send_error_report'])
/* Create message object */
if ($success) {
- $msg = PhpMyAdmin\Message::notice($msg);
+ $msg = Message::notice($msg);
} else {
- $msg = PhpMyAdmin\Message::error($msg);
+ $msg = Message::error($msg);
}
/* Add message to response */
@@ -122,7 +126,7 @@ if (isset($_REQUEST['send_error_report'])
$response->addJSON('report_setting', $GLOBALS['cfg']['SendErrorReports']);
} else {
if ($_REQUEST['exception_type'] == 'js') {
- $response->addHTML(ErrorReport::getForm());
+ $response->addHTML($errorReport->getForm());
} else {
// clear previous errors & save new ones.
$GLOBALS['error_handler']->savePreviousErrors();
diff --git a/libraries/classes/ErrorReport.php b/libraries/classes/ErrorReport.php
index e914413c59..d512123458 100644
--- a/libraries/classes/ErrorReport.php
+++ b/libraries/classes/ErrorReport.php
@@ -1,7 +1,7 @@
httpRequest = $httpRequest;
+ $this->submissionUrl = 'https://reports.phpmyadmin.net/incidents/create';
+ }
+
+ /**
+ * Returns the pretty printed error report data collected from the
* current configuration or from the request parameters sent by the
* error reporting js code.
*
- * @return String the report
+ * @return string the report
*/
- public static function getPrettyReportData()
+ private function getPrettyData()
{
- $report = self::getReportData();
+ $report = $this->getData();
return json_encode($report, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
}
/**
- * returns the error report data collected from the current configuration or
+ * Returns the error report data collected from the current configuration or
* from the request parameters sent by the error reporting js code.
*
- * @param string $exception_type whether exception is 'js' or 'php'
+ * @param string $exceptionType whether exception is 'js' or 'php'
*
* @return array error report if success, Empty Array otherwise
*/
- public static function getReportData($exception_type = 'js')
+ public function getData($exceptionType = 'js')
{
$relParams = Relation::getRelationsParam();
// common params for both, php & js exceptions
- $report = array(
- "pma_version" => PMA_VERSION,
- "browser_name" => PMA_USR_BROWSER_AGENT,
- "browser_version" => PMA_USR_BROWSER_VER,
- "user_os" => PMA_USR_OS,
- "server_software" => $_SERVER['SERVER_SOFTWARE'],
- "user_agent_string" => $_SERVER['HTTP_USER_AGENT'],
- "locale" => $_COOKIE['pma_lang'],
- "configuration_storage" =>
- is_null($relParams['db']) ? "disabled" :
- "enabled",
- "php_version" => phpversion()
- );
+ $report = [
+ "pma_version" => PMA_VERSION,
+ "browser_name" => PMA_USR_BROWSER_AGENT,
+ "browser_version" => PMA_USR_BROWSER_VER,
+ "user_os" => PMA_USR_OS,
+ "server_software" => $_SERVER['SERVER_SOFTWARE'],
+ "user_agent_string" => $_SERVER['HTTP_USER_AGENT'],
+ "locale" => $_COOKIE['pma_lang'],
+ "configuration_storage" =>
+ is_null($relParams['db']) ? "disabled" : "enabled",
+ "php_version" => phpversion()
+ ];
- if ($exception_type == 'js') {
+ if ($exceptionType == 'js') {
if (empty($_REQUEST['exception'])) {
- return array();
+ return [];
}
$exception = $_REQUEST['exception'];
- $exception["stack"] = self::translateStacktrace($exception["stack"]);
- List($uri, $script_name) = self::sanitizeUrl($exception["url"]);
+ $exception["stack"] = $this->translateStacktrace($exception["stack"]);
+ list($uri, $scriptName) = $this->sanitizeUrl($exception["url"]);
$exception["uri"] = $uri;
unset($exception["url"]);
- $report ["exception_type"] = 'js';
- $report ["exception"] = $exception;
- $report ["script_name"] = $script_name;
- $report ["microhistory"] = $_REQUEST['microhistory'];
+ $report["exception_type"] = 'js';
+ $report["exception"] = $exception;
+ $report["script_name"] = $scriptName;
+ $report["microhistory"] = $_REQUEST['microhistory'];
if (! empty($_REQUEST['description'])) {
$report['steps'] = $_REQUEST['description'];
}
- } elseif ($exception_type == 'php') {
- $errors = array();
+ } elseif ($exceptionType == 'php') {
+ $errors = [];
// create php error report
$i = 0;
if (!isset($_SESSION['prev_errors'])
|| $_SESSION['prev_errors'] == ''
) {
- return array();
+ return [];
}
foreach ($_SESSION['prev_errors'] as $errorObj) {
/* @var $errorObj PhpMyAdmin\Error */
@@ -98,26 +114,25 @@ class ErrorReport
&& $errorObj->getType()
&& $errorObj->getNumber() != E_USER_WARNING
) {
- $errors[$i++] = array(
+ $errors[$i++] = [
"lineNum" => $errorObj->getLine(),
"file" => $errorObj->getFile(),
"type" => $errorObj->getType(),
"msg" => $errorObj->getOnlyMessage(),
"stackTrace" => $errorObj->getBacktrace(5),
"stackhash" => $errorObj->getHash()
- );
-
+ ];
}
}
// if there were no 'actual' errors to be submitted.
if ($i==0) {
- return array(); // then return empty array
+ return []; // then return empty array
}
- $report ["exception_type"] = 'php';
+ $report["exception_type"] = 'php';
$report["errors"] = $errors;
} else {
- return array();
+ return [];
}
return $report;
@@ -131,11 +146,11 @@ class ErrorReport
* hostname and identifying query params. The second is the name of the
* php script in the url
*
- * @param String $url the url to sanitize
+ * @param string $url the url to sanitize
*
* @return array the uri and script name
*/
- public static function sanitizeUrl($url)
+ private function sanitizeUrl($url)
{
$components = parse_url($url);
if (isset($components["fragment"])
@@ -149,25 +164,25 @@ class ErrorReport
// get script name
preg_match("<([a-zA-Z\-_\d]*\.php)$>", $components["path"], $matches);
if (count($matches) < 2) {
- $script_name = 'index.php';
+ $scriptName = 'index.php';
} else {
- $script_name = $matches[1];
+ $scriptName = $matches[1];
}
// remove deployment specific details to make uri more generic
if (isset($components["query"])) {
- parse_str($components["query"], $query_array);
- unset($query_array["db"]);
- unset($query_array["table"]);
- unset($query_array["token"]);
- unset($query_array["server"]);
- $query = http_build_query($query_array);
+ parse_str($components["query"], $queryArray);
+ unset($queryArray["db"]);
+ unset($queryArray["table"]);
+ unset($queryArray["token"]);
+ unset($queryArray["server"]);
+ $query = http_build_query($queryArray);
} else {
$query = '';
}
- $uri = $script_name . "?" . $query;
- return array($uri, $script_name);
+ $uri = $scriptName . "?" . $query;
+ return [$uri, $scriptName];
}
/**
@@ -175,13 +190,12 @@ class ErrorReport
*
* @param array $report the report info to be sent
*
- * @return String the reply of the server
+ * @return string the reply of the server
*/
- public static function send(array $report)
+ public function send(array $report)
{
- $httpRequest = new HttpRequest();
- $response = $httpRequest->create(
- self::SUBMISSION_URL,
+ $response = $this->httpRequest->create(
+ $this->submissionUrl,
"POST",
false,
json_encode($report),
@@ -191,14 +205,14 @@ class ErrorReport
}
/**
- * translates the cumulative line numbers in the stack trace as well as sanitize
+ * Translates the cumulative line numbers in the stack trace as well as sanitize
* urls and trim long lines in the context
*
* @param array $stack the stack trace
*
* @return array $stack the modified stack trace
*/
- public static function translateStacktrace(array $stack)
+ private function translateStacktrace(array $stack)
{
foreach ($stack as &$level) {
foreach ($level["context"] as &$line) {
@@ -207,9 +221,9 @@ class ErrorReport
}
}
unset($level["context"]);
- List($uri, $script_name) = self::sanitizeUrl($level["url"]);
+ list($uri, $scriptName) = $this->sanitizeUrl($level["url"]);
$level["uri"] = $uri;
- $level["scriptname"] = $script_name;
+ $level["scriptname"] = $scriptName;
unset($level["url"]);
}
unset($level);
@@ -217,25 +231,24 @@ class ErrorReport
}
/**
- * generates the error report form to collect user description and preview the
+ * Generates the error report form to collect user description and preview the
* report before being sent
*
- * @return String the form
+ * @return string the form
*/
- public static function getForm()
+ public function getForm()
{
- $datas = array(
- 'report_data' => self::getPrettyReportData(),
+ $datas = [
+ 'report_data' => $this->getPrettyData(),
'hidden_inputs' => Url::getHiddenInputs(),
'hidden_fields' => null,
- );
+ ];
- $reportData = self::getReportData();
+ $reportData = $this->getData();
if (!empty($reportData)) {
$datas['hidden_fields'] = Url::getHiddenFields($reportData);
}
- return Template::get('error/report_form')
- ->render($datas);
+ return Template::get('error/report_form')->render($datas);
}
}
diff --git a/libraries/classes/Normalization.php b/libraries/classes/Normalization.php
index f591128596..0fe950b739 100644
--- a/libraries/classes/Normalization.php
+++ b/libraries/classes/Normalization.php
@@ -1,7 +1,7 @@
dbi = $dbi;
+ }
+
/**
* build the html for columns of $colTypeCategory category
* in form of given $listType in a table
@@ -34,25 +51,30 @@ class Normalization
*
* @return string HTML for list of columns in form of given list types
*/
- public static function getHtmlForColumnsList(
- $db, $table, $colTypeCategory='all', $listType='dropdown'
+ public function getHtmlForColumnsList(
+ $db,
+ $table,
+ $colTypeCategory = 'all',
+ $listType = 'dropdown'
) {
- $columnTypeList = array();
+ $columnTypeList = [];
if ($colTypeCategory != 'all') {
- $types = $GLOBALS['dbi']->types->getColumns();
+ $types = $this->dbi->types->getColumns();
$columnTypeList = $types[$colTypeCategory];
}
- $GLOBALS['dbi']->selectDb($db);
- $columns = $GLOBALS['dbi']->getColumns(
- $db, $table, null,
+ $this->dbi->selectDb($db);
+ $columns = $this->dbi->getColumns(
+ $db,
+ $table,
+ null,
true
);
$type = "";
$selectColHtml = "";
foreach ($columns as $column => $def) {
if (isset($def['Type'])) {
- $extracted_columnspec = Util::extractColumnSpec($def['Type']);
- $type = $extracted_columnspec['type'];
+ $extractedColumnSpec = Util::extractColumnSpec($def['Type']);
+ $type = $extractedColumnSpec['type'];
}
if (empty($columnTypeList)
|| in_array(mb_strtoupper($type), $columnTypeList)
@@ -76,78 +98,79 @@ class Normalization
/**
* get the html of the form to add the new column to given table
*
- * @param integer $num_fields number of columns to add
+ * @param integer $numFields number of columns to add
* @param string $db current database
* @param string $table current table
* @param array $columnMeta array containing default values for the fields
*
* @return string HTML
*/
- public static function getHtmlForCreateNewColumn(
- $num_fields, $db, $table, array $columnMeta = array()
+ public function getHtmlForCreateNewColumn(
+ $numFields,
+ $db,
+ $table,
+ array $columnMeta = []
) {
$cfgRelation = Relation::getRelationsParam();
- $content_cells = array();
- $available_mime = array();
- $mime_map = array();
+ $contentCells = [];
+ $availableMime = [];
+ $mimeMap = [];
if ($cfgRelation['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
- $mime_map = Transformations::getMIME($db, $table);
- $available_mime = Transformations::getAvailableMIMEtypes();
+ $mimeMap = Transformations::getMIME($db, $table);
+ $availableMime = Transformations::getAvailableMIMEtypes();
}
- $comments_map = Relation::getComments($db, $table);
- for ($columnNumber = 0; $columnNumber < $num_fields; $columnNumber++) {
- $content_cells[$columnNumber] = array(
+ $commentsMap = Relation::getComments($db, $table);
+ for ($columnNumber = 0; $columnNumber < $numFields; $columnNumber++) {
+ $contentCells[$columnNumber] = [
'column_number' => $columnNumber,
'column_meta' => $columnMeta,
'type_upper' => '',
'length_values_input_size' => 8,
'length' => '',
- 'extracted_columnspec' => array(),
+ 'extracted_columnspec' => [],
'submit_attribute' => null,
- 'comments_map' => $comments_map,
+ 'comments_map' => $commentsMap,
'fields_meta' => null,
'is_backup' => true,
- 'move_columns' => array(),
+ 'move_columns' => [],
'cfg_relation' => $cfgRelation,
- 'available_mime' => isset($available_mime)?$available_mime:array(),
- 'mime_map' => $mime_map
- );
+ 'available_mime' => isset($availableMime) ? $availableMime : [],
+ 'mime_map' => $mimeMap
+ ];
}
return Template::get(
'columns_definitions/table_fields_definitions'
- )
- ->render(
- array(
- 'is_backup' => true,
- 'fields_meta' => null,
- 'mimework' => $cfgRelation['mimework'],
- 'content_cells' => $content_cells,
- 'change_column' => $_REQUEST['change_column'],
- 'is_virtual_columns_supported' => Util::isVirtualColumnsSupported(),
- 'browse_mime' => $GLOBALS['cfg']['BrowseMIME'],
- 'server_type' => Util::getServerType(),
- 'max_rows' => intval($GLOBALS['cfg']['MaxRows']),
- 'char_editing' => $GLOBALS['cfg']['CharEditing'],
- 'attribute_types' => $GLOBALS['dbi']->types->getAttributes(),
- 'privs_available' => $GLOBALS['col_priv'] && $GLOBALS['is_reload_priv'],
- 'max_length' => $GLOBALS['dbi']->getVersion() >= 50503 ? 1024 : 255,
- 'dbi' => $GLOBALS['dbi'],
- 'disable_is' => $GLOBALS['cfg']['Server']['DisableIS'],
- )
- );
+ )->render([
+ 'is_backup' => true,
+ 'fields_meta' => null,
+ 'mimework' => $cfgRelation['mimework'],
+ 'content_cells' => $contentCells,
+ 'change_column' => $_REQUEST['change_column'],
+ 'is_virtual_columns_supported' => Util::isVirtualColumnsSupported(),
+ 'browse_mime' => $GLOBALS['cfg']['BrowseMIME'],
+ 'server_type' => Util::getServerType(),
+ 'max_rows' => intval($GLOBALS['cfg']['MaxRows']),
+ 'char_editing' => $GLOBALS['cfg']['CharEditing'],
+ 'attribute_types' => $this->dbi->types->getAttributes(),
+ 'privs_available' => $GLOBALS['col_priv'] && $GLOBALS['is_reload_priv'],
+ 'max_length' => $this->dbi->getVersion() >= 50503 ? 1024 : 255,
+ 'dbi' => $this->dbi,
+ 'disable_is' => $GLOBALS['cfg']['Server']['DisableIS'],
+ ]);
}
+
/**
* build the html for step 1.1 of normalization
*
* @param string $db current database
* @param string $table current table
* @param string $normalizedTo up to which step normalization will go,
- * possible values 1nf|2nf|3nf
+ * possible values 1nf|2nf|3nf
*
* @return string HTML for step 1.1
*/
- public static function getHtmlFor1NFStep1($db, $table, $normalizedTo)
+ public function getHtmlFor1NFStep1($db, $table, $normalizedTo)
{
$step = 1;
$stepTxt = __('Make all columns atomic');
@@ -176,7 +199,7 @@ class Normalization
. '"
. ""
- . self::getHtmlForColumnsList(
+ . $this->getHtmlForColumnsList(
$db,
$table,
_pgettext('string types', 'String')
@@ -200,7 +223,7 @@ class Normalization
*
* @return string HTML contents for step 1.2
*/
- public static function getHtmlContentsFor1NFStep2($db, $table)
+ public function getHtmlContentsFor1NFStep2($db, $table)
{
$step = 2;
$stepTxt = __('Have a primary key');
@@ -220,7 +243,8 @@ class Normalization
);
$subText = ''
. Util::getIcon(
- 'b_index_add', __(
+ 'b_index_add',
+ __(
'Add a primary key on existing column(s)'
)
)
@@ -232,13 +256,13 @@ class Normalization
. ''
. __('+ Add a new primary key column') . '';
}
- $res = array(
+ $res = [
'legendText' => $legendText,
'headText' => $headText,
'subText' => $subText,
'hasPrimaryKey' => $hasPrimaryKey,
'extra' => $extra
- );
+ ];
return $res;
}
@@ -250,7 +274,7 @@ class Normalization
*
* @return string HTML contents for step 1.4
*/
- public static function getHtmlContentsFor1NFStep4($db, $table)
+ public function getHtmlContentsFor1NFStep4($db, $table)
{
$step = 4;
$stepTxt = __('Remove redundant columns');
@@ -265,18 +289,18 @@ class Normalization
"Check the columns which are redundant and click on remove. "
. "If no redundant column, click on 'No redundant column'"
);
- $extra = self::getHtmlForColumnsList($db, $table, 'all', "checkbox") . ""
+ $extra = $this->getHtmlForColumnsList($db, $table, 'all', "checkbox") . ""
. ''
. '';
- $res = array(
+ $res = [
'legendText' => $legendText,
'headText' => $headText,
'subText' => $subText,
'extra' => $extra
- );
+ ];
return $res;
}
@@ -288,7 +312,7 @@ class Normalization
*
* @return string HTML contents for step 1.3
*/
- public static function getHtmlContentsFor1NFStep3($db, $table)
+ public function getHtmlContentsFor1NFStep3($db, $table)
{
$step = 3;
$stepTxt = __('Move repeating groups');
@@ -305,7 +329,7 @@ class Normalization
"Check the columns which form a repeating group. "
. "If no such group, click on 'No repeating group'"
);
- $extra = self::getHtmlForColumnsList($db, $table, 'all', "checkbox") . ""
+ $extra = $this->getHtmlForColumnsList($db, $table, 'all', "checkbox") . ""
. ''
. 'getColumns();
- $pk = array();
+ $pk = [];
$subText = '';
$selectPkForm = "";
$extra = "";
@@ -352,9 +376,10 @@ class Normalization
}
$key = implode(', ', $pk);
if (count($primarycols) > 1) {
- $GLOBALS['dbi']->selectDb($db);
- $columns = (array) $GLOBALS['dbi']->getColumnNames(
- $db, $table
+ $this->dbi->selectDb($db);
+ $columns = (array) $this->dbi->getColumnNames(
+ $db,
+ $table
);
if (count($pk) == count($columns)) {
$headText = sprintf(
@@ -362,7 +387,8 @@ class Normalization
'No partial dependencies possible as '
. 'no non-primary column exists since primary key ( %1$s ) '
. 'is composed of all the columns in the table.'
- ), htmlspecialchars($key)
+ ),
+ htmlspecialchars($key)
) . '
';
$extra = '