Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
hh_format everything
Browse files Browse the repository at this point in the history
  • Loading branch information
fredemmott committed Jun 4, 2015
1 parent 65983c5 commit 7e7af29
Show file tree
Hide file tree
Showing 26 changed files with 549 additions and 544 deletions.
7 changes: 5 additions & 2 deletions base/BuildChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ private static function MakeCheckedValue(array $foo): CheckedValue {
invariant(array_key_exists('OK', $foo), 'invalid JSON data');
invariant(array_key_exists('Value', $foo), 'invalid JSON data');
invariant(array_key_exists('Required Value', $foo), 'invalid JSON data');
invariant($foo['OK'] === true || $foo['OK'] === false, 'invalid JSON data');
invariant(
$foo['OK'] === true || $foo['OK'] === false,
'invalid JSON data',
);
// UNSAFE
return $foo;
}
Expand Down Expand Up @@ -60,7 +63,7 @@ public static function Check(
STDERR,
"Exiting due to invalid config. You can run anyway with ".
"--i-am-not-benchmarking, but the results will not be suitable for ".
"any kind of comparison.\n"
"any kind of comparison.\n",
);
exit(1);
}
Expand Down
64 changes: 28 additions & 36 deletions base/DatabaseInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ final class DatabaseInstaller {
private ?string $username;
private ?string $password = null;

public function __construct(private PerfOptions $options): void {
}
public function __construct(private PerfOptions $options): void {}

public function getUsername() : ?string {
public function getUsername(): ?string {
return $this->username ? $this->username : $this->databaseName;
}

public function getPassword() : ?string {
public function getPassword(): ?string {
return $this->password !== null ? $this->password : $this->databaseName;
}

Expand All @@ -41,7 +40,7 @@ public function installDatabase(): bool {
$dump = $this->dumpFile;
invariant(
$db !== null && $dump !== null,
'database and dump must be specified'
'database and dump must be specified',
);
if ($this->options->skipDatabaseInstall) {
$this->checkMySQLConnectionLimit();
Expand All @@ -61,19 +60,14 @@ public function installDatabase(): bool {
}

shell_exec(
Utils::EscapeCommand(Vector {
$this->options->dumpIsCompressed ? 'zcat' : 'cat',
$dump,
}).
Utils::EscapeCommand(
Vector {$this->options->dumpIsCompressed ? 'zcat' : 'cat', $dump},
).
'|'.
$sed .
Utils::EscapeCommand(Vector {
'mysql',
'-h', '127.0.0.1',
$db,
'-u', $db,
'-p'.$db
})
$sed.
Utils::EscapeCommand(
Vector {'mysql', '-h', '127.0.0.1', $db, '-u', $db, '-p'.$db},
),
);
return true;
}
Expand All @@ -85,40 +79,32 @@ private function getRootConnection(): resource {
$this->password = trim(fgets(STDIN));
$conn = mysql_connect('127.0.0.1', $this->username, $this->password);
if ($conn === false) {
throw new Exception(
'Failed to connect: '.mysql_error()
);
throw new Exception('Failed to connect: '.mysql_error());
}
return $conn;
}

private function checkMySQLConnectionLimit(): void {
$conn = mysql_connect(
'127.0.0.1', $this->getUsername(), $this->getPassword()
);
$conn =
mysql_connect('127.0.0.1', $this->getUsername(), $this->getPassword());
if ($conn === false) {
throw new Exception(
'Failed to connect: '.mysql_error()
);
throw new Exception('Failed to connect: '.mysql_error());
}
$data = mysql_fetch_assoc(
mysql_query(
"SHOW variables WHERE Variable_name = 'max_connections'",
$conn
)
$conn,
),
);
mysql_close($conn);
if ($data['Value'] < 1000) {
fprintf(
STDERR,
"Connection limit is too low - some benchmarks will have connection ".
"errors. This can be fixed for you..\n"
"errors. This can be fixed for you..\n",
);
$conn = $this->getRootConnection();
mysql_query(
'SET GLOBAL max_connections = 1000',
$conn
);
mysql_query('SET GLOBAL max_connections = 1000', $conn);
mysql_close($conn);
}
}
Expand All @@ -131,7 +117,7 @@ private function createMySQLDatabase(): void {
'%s',
"Can't connect to database ".
"(mysql -h 127.0.0.1 -p$db -u $db $db). This can be ".
"fixed for you.\n"
"fixed for you.\n",
);
$conn = $this->getRootConnection();
$edb = mysql_real_escape_string($db);
Expand All @@ -146,8 +132,14 @@ private function createMySQLDatabase(): void {
* grant
*/
mysql_query(
'GRANT ALL PRIVILEGES ON '.$edb.'.* TO "'.$edb.'"@"%" '.
'IDENTIFIED BY "'.$edb.'"',
'GRANT ALL PRIVILEGES ON '.
$edb.
'.* TO "'.
$edb.
'"@"%" '.
'IDENTIFIED BY "'.
$edb.
'"',
$conn,
);
mysql_query(
Expand Down
Loading

0 comments on commit 7e7af29

Please sign in to comment.