Fix bugs thorugh tests

This commit is contained in:
Dennis Eichhorn 2017-10-01 10:26:55 +02:00
parent b6680a6d1b
commit 5a878e30f6
2 changed files with 14 additions and 11 deletions

View File

@ -67,12 +67,14 @@ class Zip implements ArchiveInterface
continue;
}
$file = realpath($file);
$absolute = realpath($file);
$absolute = str_replace('\\', '/', $absolute);
$dir = str_replace($source . '/', '', $relative . '/' . $absolute);
if (is_dir($file)) {
$zip->addEmptyDir(str_replace($relative . '/', '', $file . '/'));
} elseif (is_file($file)) {
$zip->addFile(str_replace($relative . '/', '', $file), $file);
if (is_dir($absolute)) {
$zip->addEmptyDir($dir . '/');
} elseif (is_file($absolute)) {
$zip->addFile($absolute, $dir);
}
}
} elseif (is_file($source)) {
@ -88,18 +90,19 @@ class Zip implements ArchiveInterface
*/
public static function unpack(string $source, string $destination) : bool
{
$destination = str_replace('\\', '/', realpath($destination));
if (file_exists($destination)) {
if(!file_exists($source)) {
return false;
}
$destination = str_replace('\\', '/', $destination);
$destination = rtrim($destination, '/');
$zip = new \ZipArchive();
if (!$zip->open($destination)) {
if (!$zip->open($source)) {
return false;
}
$zip->extractTo($destination);
$zip->extractTo($destination . '/');
return $zip->close();
}

View File

@ -42,6 +42,6 @@ class DateTime
$startDate = strtotime($start);
$endDate = strtotime($end);
return new \DateTime(date('Y-m-d H:i:s', rand($startDate, $endDate)));
return new \DateTime(date('Y-m-d H:i:s', mt_rand($startDate, $endDate)));
}
}