Fail-safe when update class cannot be correctly reconstructed or loaded.

Previously, if the wrong base class name was written to the database, attempts to load update information could trigger a warning because there was no class_exists() check in the "updateBaseClass is set" branch. To fix that, I've moved the class_exists() closer to the place where the class name is actually used.

StateStore will still fail to load a stored update if the class name is invalid, but without a PHP warning this time. The invalid stored update information should be overwritten the next time PUC checks for updates.
This commit is contained in:
Yahnis Elsts 2022-07-28 16:01:14 +03:00
parent b4c5a82cc8
commit 3347254e0d
1 changed files with 2 additions and 2 deletions

View File

@ -180,11 +180,11 @@ if ( !class_exists('Puc_v4p12_StateStore', false) ):
$updateClass = null;
if ( isset($state->updateBaseClass) ) {
$updateClass = $this->getLibPrefix() . $state->updateBaseClass;
} else if ( isset($state->updateClass) && class_exists($state->updateClass) ) {
} else if ( isset($state->updateClass) ) {
$updateClass = $state->updateClass;
}
if ( $updateClass !== null ) {
if ( ($updateClass !== null) && class_exists($updateClass) ) {
$this->update = call_user_func(array($updateClass, 'fromObject'), $state->update);
}
}