Skip to content

Commit

Permalink
Update AppPluginZipCommand.php
Browse files Browse the repository at this point in the history
  • Loading branch information
walkor authored Aug 19, 2024
1 parent c8ba614 commit 94a67ff
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/Commands/AppPluginZipCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,21 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln("Plugin $name not exists");
return self::FAILURE;
}
$this->zipDirectory($sourceDir, $zipFilePath);
if (is_file($zipFilePath)) {
unlink($zipFilePath);
}
$this->zipDirectory($name, $sourceDir, $zipFilePath);
return self::SUCCESS;
}

/**
* @param $name
* @param $sourceDir
* @param $zipFilePath
* @return mixed
* @return bool
* @throws Exception
*/
protected function zipDirectory($sourceDir, $zipFilePath) {
protected function zipDirectory($name, $sourceDir, $zipFilePath) {
$zip = new ZipArchive();

if ($zip->open($zipFilePath, ZipArchive::CREATE | ZipArchive::OVERWRITE) !== TRUE) {
Expand All @@ -69,7 +74,7 @@ protected function zipDirectory($sourceDir, $zipFilePath) {
foreach ($files as $file) {
if (!$file->isDir()) {
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen($sourceDir) + 1);
$relativePath = $name . DIRECTORY_SEPARATOR . substr($filePath, strlen($sourceDir) + 1);
$zip->addFile($filePath, $relativePath);
}
}
Expand Down

0 comments on commit 94a67ff

Please sign in to comment.