Skip to content

Commit

Permalink
style: Format code with standardjs and php-cs-fixer
Browse files Browse the repository at this point in the history
Format code with standardjs and php-cs-fixer

This commit fixes the style issues introduced in 13aa21a according to the output
from standardjs and php-cs-fixer.

Details: https://deepsource.io/gh/smalos/nubuilder_dev/transform/380d56cf-ff13-40c6-b78b-8a099b940710/
  • Loading branch information
deepsource-autofix[bot] committed Mar 30, 2023
1 parent 13aa21a commit f83ad9c
Show file tree
Hide file tree
Showing 160 changed files with 74,164 additions and 75,170 deletions.
76 changes: 36 additions & 40 deletions core/libs/mysqldump/Mysqldump.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,19 @@
*/
class Mysqldump
{

// Same as mysqldump.
const MAXLINESIZE = 1000000;
public const MAXLINESIZE = 1000000;

// List of available compression methods as constants.
const GZIP = 'Gzip';
const BZIP2 = 'Bzip2';
const NONE = 'None';
const GZIPSTREAM = 'Gzipstream';
public const GZIP = 'Gzip';
public const BZIP2 = 'Bzip2';
public const NONE = 'None';
public const GZIPSTREAM = 'Gzipstream';

// List of available connection strings.
const UTF8 = 'utf8';
const UTF8MB4 = 'utf8mb4';
const BINARY = 'binary';
public const UTF8 = 'utf8';
public const UTF8MB4 = 'utf8mb4';
public const BINARY = 'binary';

/**
* Database username.
Expand Down Expand Up @@ -175,7 +174,6 @@ public function __construct(
$dumpSettings = array(),
$pdoSettings = array()
) {

$this->user = $user;
$this->pass = $pass;
$this->parseDsn($dsn);
Expand Down Expand Up @@ -283,22 +281,22 @@ public function getTableLimit($tableName)
*/
public function restore($path)
{
if(!$path || !is_file($path)){
if (!$path || !is_file($path)) {
throw new Exception("File {$path} does not exist.");
}

$handle = fopen($path , 'rb');
$handle = fopen($path, 'rb');

if(!$handle){
if (!$handle) {
throw new Exception("Failed reading file {$path}. Check access permissions.");
}

if(!$this->dbHandler){
if (!$this->dbHandler) {
$this->connect();
}

$buffer = '';
while ( !feof($handle) ) {
while (!feof($handle)) {
$line = trim(fgets($handle));

if (substr($line, 0, 2) == '--' || !$line) {
Expand Down Expand Up @@ -747,7 +745,6 @@ private function exportTriggers()
foreach ($this->triggers as $trigger) {
$this->getTriggerStructure($trigger);
}

}

/**
Expand Down Expand Up @@ -1384,7 +1381,7 @@ public static function create($c)

$method = __NAMESPACE__."\\"."Compress".$c;

return new $method;
return new $method();
}
}

Expand Down Expand Up @@ -1509,29 +1506,28 @@ class CompressGzipstream extends CompressManagerFactory
*/
public function open($filename)
{
$this->fileHandler = fopen($filename, "wb");
if (false === $this->fileHandler) {
throw new Exception("Output file is not writable");
}
$this->fileHandler = fopen($filename, "wb");
if (false === $this->fileHandler) {
throw new Exception("Output file is not writable");
}

$this->compressContext = deflate_init(ZLIB_ENCODING_GZIP, array('level' => 9));
return true;
$this->compressContext = deflate_init(ZLIB_ENCODING_GZIP, array('level' => 9));
return true;
}

public function write($str)
{

$bytesWritten = fwrite($this->fileHandler, deflate_add($this->compressContext, $str, ZLIB_NO_FLUSH));
if (false === $bytesWritten) {
throw new Exception("Writting to file failed! Probably, there is no more free space left?");
}
return $bytesWritten;
$bytesWritten = fwrite($this->fileHandler, deflate_add($this->compressContext, $str, ZLIB_NO_FLUSH));
if (false === $bytesWritten) {
throw new Exception("Writting to file failed! Probably, there is no more free space left?");
}
return $bytesWritten;
}

public function close()
{
fwrite($this->fileHandler, deflate_add($this->compressContext, '', ZLIB_FINISH));
return fclose($this->fileHandler);
fwrite($this->fileHandler, deflate_add($this->compressContext, '', ZLIB_FINISH));
return fclose($this->fileHandler);
}
}

Expand Down Expand Up @@ -1815,7 +1811,7 @@ class TypeAdapterSqlite extends TypeAdapterFactory

class TypeAdapterMysql extends TypeAdapterFactory
{
const DEFINER_RE = 'DEFINER=`(?:[^`]|``)*`@`(?:[^`]|``)*`';
public const DEFINER_RE = 'DEFINER=`(?:[^`]|``)*`@`(?:[^`]|``)*`';


// Numerical Mysql types
Expand Down Expand Up @@ -1856,7 +1852,7 @@ class TypeAdapterMysql extends TypeAdapterFactory
public function databases()
{
if ($this->dumpSettings['no-create-db']) {
return "";
return "";
}

$this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
Expand Down Expand Up @@ -1923,8 +1919,8 @@ public function create_table($row)
$createTable = preg_replace($match, $replace, $createTable);
}

if ($this->dumpSettings['if-not-exists'] ) {
$createTable = preg_replace('/^CREATE TABLE/', 'CREATE TABLE IF NOT EXISTS', $createTable);
if ($this->dumpSettings['if-not-exists']) {
$createTable = preg_replace('/^CREATE TABLE/', 'CREATE TABLE IF NOT EXISTS', $createTable);
}

$ret = "/*!40101 SET @saved_cs_client = @@character_set_client */;".PHP_EOL.
Expand Down Expand Up @@ -2026,7 +2022,7 @@ public function create_function($row)
$characterSetClient = $row['character_set_client'];
$collationConnection = $row['collation_connection'];
$sqlMode = $row['sql_mode'];
if ( $this->dumpSettings['skip-definer'] ) {
if ($this->dumpSettings['skip-definer']) {
if ($functionStmtReplaced = preg_replace(
'/^(CREATE)\s+('.self::DEFINER_RE.')?\s+(FUNCTION\s.*)$/s',
'\1 \3',
Expand Down Expand Up @@ -2104,8 +2100,8 @@ public function create_event($row)
"/*!50003 SET collation_connection = @saved_col_connection */ ;;".PHP_EOL.
"DELIMITER ;".PHP_EOL.
"/*!50106 SET TIME_ZONE= @save_time_zone */ ;".PHP_EOL.PHP_EOL;
// Commented because we are doing this in restore_parameters()
// "/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;" . PHP_EOL . PHP_EOL;
// Commented because we are doing this in restore_parameters()
// "/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;" . PHP_EOL . PHP_EOL;

return $ret;
}
Expand Down Expand Up @@ -2325,7 +2321,7 @@ public function backup_parameters()
}

if ($this->dumpSettings['no-autocommit']) {
$ret .= "/*!40101 SET @OLD_AUTOCOMMIT=@@AUTOCOMMIT */;".PHP_EOL;
$ret .= "/*!40101 SET @OLD_AUTOCOMMIT=@@AUTOCOMMIT */;".PHP_EOL;
}

$ret .= "/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;".PHP_EOL.
Expand All @@ -2345,7 +2341,7 @@ public function restore_parameters()
}

if ($this->dumpSettings['no-autocommit']) {
$ret .= "/*!40101 SET AUTOCOMMIT=@OLD_AUTOCOMMIT */;".PHP_EOL;
$ret .= "/*!40101 SET AUTOCOMMIT=@OLD_AUTOCOMMIT */;".PHP_EOL;
}

$ret .= "/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;".PHP_EOL.
Expand Down
75 changes: 37 additions & 38 deletions core/libs/nudb/config.inc.php
Original file line number Diff line number Diff line change
@@ -1,46 +1,45 @@
<?php

declare(strict_types=1);

require_once(dirname(__FILE__). '/../../../nuconfig.php');

if (! isset($nuPmaNotAuth)) {

$sessionId = isset($_COOKIE['nu_PMA']) ? $_COOKIE["nu_PMA"] : '';

if ($sessionId == '') {
nuAuthFailed();
}

$DBCharset = 'utf8';

try {
$pdo = new PDO("mysql:host=$nuConfigDBHost;dbname=$nuConfigDBName;charset=$DBCharset", $nuConfigDBUser, $nuConfigDBPassword);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
die();
}

$stmt = $pdo->prepare("SELECT sss_access FROM `zzzzsys_session` WHERE zzzzsys_session_id = ?");
$stmt->execute([$sessionId]);
$result = $stmt->fetch(PDO::FETCH_OBJ);

if ($result) {
$json = json_decode($result->sss_access, true);

if ($json['session']['global_access'] != 1) {
nuAuthFailed();
}

} else {
nuAuthFailed();
}

$sessionId = isset($_COOKIE['nu_PMA']) ? $_COOKIE["nu_PMA"] : '';

if ($sessionId == '') {
nuAuthFailed();
}

$DBCharset = 'utf8';

try {
$pdo = new PDO("mysql:host=$nuConfigDBHost;dbname=$nuConfigDBName;charset=$DBCharset", $nuConfigDBUser, $nuConfigDBPassword);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
die();
}

$stmt = $pdo->prepare("SELECT sss_access FROM `zzzzsys_session` WHERE zzzzsys_session_id = ?");
$stmt->execute([$sessionId]);
$result = $stmt->fetch(PDO::FETCH_OBJ);

if ($result) {
$json = json_decode($result->sss_access, true);

if ($json['session']['global_access'] != 1) {
nuAuthFailed();
}
} else {
nuAuthFailed();
}
}

function nuAuthFailed() {
echo "Please log into nuBuilder";
die();
function nuAuthFailed()
{
echo "Please log into nuBuilder";
die();
}

/**
Expand Down Expand Up @@ -69,8 +68,8 @@ function nuAuthFailed() {



if ( $_COOKIE["nuConfigDBPasswordBlank"] == 'BLANK' ) {
$cfg['Servers'][$i]['password'] = '';
if ($_COOKIE["nuConfigDBPasswordBlank"] == 'BLANK') {
$cfg['Servers'][$i]['password'] = '';
}

$cfg['Servers'][$i]['compress'] = false;
Expand Down Expand Up @@ -202,4 +201,4 @@ function nuAuthFailed() {
/**
* You can find more configuration options in the documentation
* in the doc/ folder or at <https://docs.phpmyadmin.net/>.
*/
*/
Loading

0 comments on commit f83ad9c

Please sign in to comment.