Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ protected function setFormObjectData()
],
];

foreach ($packageArchive->getUpdateInstructions() as $fromVersion => $updateInstructions) {
foreach ($packageArchive->getAllUpdateInstructions() as $fromVersion => $updateInstructions) {
$versionUpdateInstructions = [];

foreach ($updateInstructions as $instruction) {
Expand Down
39 changes: 2 additions & 37 deletions wcfsetup/install/files/lib/system/package/PackageArchive.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ class PackageArchive
*/
protected $archive;

/**
* package object of an existing package
* @var Package
*/
protected $package;

/**
* tar archive object
* @var Tar
Expand Down Expand Up @@ -95,13 +89,11 @@ class PackageArchive
* Creates a new PackageArchive object.
*
* @param string $archive
* @param Package $package
*/
public function __construct($archive, ?Package $package = null)
public function __construct($archive)
{
$this->archive = $archive; // be careful: this is a string within this class,
// but an object in the packageStartInstallForm.class!
$this->package = $package;
}

/**
Expand Down Expand Up @@ -420,13 +412,6 @@ protected function readPackageInfo()
}
}

// during installations, `Package::$packageVersion` can be `null` which causes issues
// in `PackageArchive::filterUpdateInstructions()`; as update instructions are not needed
// for installations, not filtering update instructions is okay
if ($this->package !== null && $this->package->packageVersion !== null) {
$this->filterUpdateInstructions();
}

// set default values
if (!isset($this->packageInfo['isApplication'])) {
$this->packageInfo['isApplication'] = 0;
Expand All @@ -436,26 +421,6 @@ protected function readPackageInfo()
}
}

/**
* Filters update instructions.
*/
protected function filterUpdateInstructions()
{
$validFromVersion = null;
foreach ($this->instructions['update'] as $fromVersion => $update) {
if (Package::checkFromversion($this->package->packageVersion, $fromVersion)) {
$validFromVersion = $fromVersion;
break;
}
}

if ($validFromVersion === null) {
$this->instructions['update'] = [];
} else {
$this->instructions['update'] = $this->instructions['update'][$validFromVersion];
}
}

/**
* Closes and deletes the tar archive of this package.
*/
Expand Down Expand Up @@ -593,7 +558,7 @@ public function getInstallInstructions()
*
* @return array
*/
public function getUpdateInstructions()
public function getAllUpdateInstructions()
{
return $this->instructions['update'];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ public function getArchive()
}
}

$this->archive = new PackageArchive($this->queue->archive, $this->getPackage());
$this->archive = new PackageArchive($this->queue->archive);
if (!\str_starts_with(\realpath($this->archive->getArchive()), \TMP_DIR)) {
throw new \Exception('Refusing to handle an archive outside of the temporary directory.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,22 @@ protected function buildPluginNodes()
$pluginNodes = [];

$this->emptyNode = true;
$instructions = ($this->installation->getAction() == 'install') ? $this->installation->getArchive()->getInstallInstructions() : $this->installation->getArchive()->getUpdateInstructions();

switch ($this->installation->getAction()) {
case 'install':
$instructions = $this->installation->getArchive()->getInstallInstructions();

break;
case 'update':
$package = $this->installation->getPackage();
$currentPackageVersion = self::$pendingPackages[$package->package] ?? $package->packageVersion;
$instructions = $this->installation->getArchive()->getUpdateInstructionsFor($currentPackageVersion) ?? [];

break;
default:
throw new \LogicException('Unreachable');
}

$count = \count($instructions);

if ($count === 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private function getInstallInstructions(): array

private function getUpdateInstructions(): array
{
$updateInstructions = $this->archive->getUpdateInstructions();
$updateInstructions = $this->archive->getAllUpdateInstructions();
\ksort($updateInstructions);

return \array_map($this->cleanInstructions(...), $updateInstructions);
Expand Down