Skip to content

CINX-2518: Fix Read to handle fgets == false behavior #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 20 additions & 18 deletions src/MySQLImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(mysqli $connection, string $charset = 'utf8mb4')
/**
* Loads dump from the file.
*/
public function load(string $file): int
public function load(string $file) : int
{
$handle = strcasecmp(substr($file, -3), '.gz') ? fopen($file, 'rb') : gzopen($file, 'rb');
if (!$handle) {
Expand All @@ -51,7 +51,7 @@ public function load(string $file): int
* Reads dump from logical file.
* @param resource
*/
public function read($handle): int
public function read($handle) : int
{
if (!is_resource($handle) || get_resource_type($handle) !== 'stream') {
throw new Exception('Argument must be stream resource.');
Expand All @@ -65,23 +65,25 @@ public function read($handle): int

while (!feof($handle)) {
$s = fgets($handle);
$size += strlen($s);
if (strtoupper(substr($s, 0, 10)) === 'DELIMITER ') {
$delimiter = trim(substr($s, 10));

} elseif (substr($ts = rtrim($s), -strlen($delimiter)) === $delimiter) {
$sql .= substr($ts, 0, -strlen($delimiter));
if (!$this->connection->query($sql)) {
throw new Exception($this->connection->error . ': ' . $sql);
if ($s) {
$size += strlen($s);
if (strtoupper(substr($s, 0, 10)) === 'DELIMITER ') {
$delimiter = trim(substr($s, 10));

} elseif (substr($ts = rtrim($s), -strlen($delimiter)) === $delimiter) {
$sql .= substr($ts, 0, -strlen($delimiter));
if (!$this->connection->query($sql)) {
throw new Exception($this->connection->error . ': ' . $sql);
}
$sql = '';
$count++;
if ($this->onProgress) {
call_user_func($this->onProgress, $count, isset($stat['size']) ? $size * 100 / $stat['size'] : null);
}

} else {
$sql .= $s;
}
$sql = '';
$count++;
if ($this->onProgress) {
call_user_func($this->onProgress, $count, isset($stat['size']) ? $size * 100 / $stat['size'] : null);
}

} else {
$sql .= $s;
}
}

Expand Down
25 changes: 25 additions & 0 deletions vendor/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

// autoload.php @generated by Composer

if (PHP_VERSION_ID < 50600) {
if (!headers_sent()) {
header('HTTP/1.1 500 Internal Server Error');
}
$err = 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL;
if (!ini_get('display_errors')) {
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
fwrite(STDERR, $err);
} elseif (!headers_sent()) {
echo $err;
}
}
trigger_error(
$err,
E_USER_ERROR
);
}

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInitc60ccf6507a7424f6d7403312e87aae1::getLoader();
Loading