Skip to content

Commit

Permalink
Throw exception in Concrete:getClass(), if class not found (pimcore#1…
Browse files Browse the repository at this point in the history
…3795)

* Throw exception in Concrete:getClass(), if class not found

* Throw exception in Concrete:getClass(), if class not found

* Add upgrade notes

* added error logging

Co-authored-by: Corepex <[email protected]>
  • Loading branch information
dvesh3 and Corepex authored Jan 16, 2023
1 parent 4e97b65 commit 07b6146
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2837,7 +2837,7 @@ private function validateManyToManyRelationAssetType(array $context, string $fil
&& 'object' === $context['containerType']
&& $object = Concrete::getById($context['objectId'])
) {
$fieldDefinition = $object->getClass()?->getFieldDefinition($context['fieldname']);
$fieldDefinition = $object->getClass()->getFieldDefinition($context['fieldname']);
if (!$fieldDefinition instanceof ManyToManyRelation) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ Please make sure to set your preferred storage location ***before*** migration.
- [DataObjects] Text data types now set their corresponding database columns to `null` instead of `''` (empty string) when empty.
- [Ecommerce][Product Interfaces] Changed return type-hints of `CheckoutableInterface` methods `getOSPrice`, `getOSPriceInfo`, `getOSAvailabilityInfo`, `getPriceSystemName`, `getAvailabilitySystemName`, `getPriceSystemImplementation`, `getAvailabilitySystemImplementation` to be non-nullable.
- [Elements] Removed the deprecated `Pimcore\Model\Element\Service::getType()`, use `Pimcore\Model\Element\Service::getElementType()` instead.
- [DataObjects] Method `Concrete::getClass()` throws NotFoundException if class is not found for an object.
- [Asset] Asset/Asset Thumbnail Update messages are now routed to different queue
instead of `pimcore_core`. please add option `pimcore_asset_update` to command `bin/console messenger:consume pimcore_core... pimcore_asset_update` to post process assets on update.
Also run command `bin/console messenger:consume pimcore_core` before the upgrade, so that `AssetUpdateTasksMessage` on the queue gets consumed.
Expand Down
1 change: 1 addition & 0 deletions models/DataObject/AbstractObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ public static function getById(int|string $id, array $params = []): ?static
throw new Model\Exception\NotFoundException('No entry for object id ' . $id);
}
} catch (Model\Exception\NotFoundException $e) {
Logger::error($e->getMessage());
return null;
}
} else {
Expand Down
12 changes: 10 additions & 2 deletions models/DataObject/Concrete.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,18 @@ public function setClass(?ClassDefinition $class): static
return $this;
}

public function getClass(): ?ClassDefinition
/**
* @throws \Exception
*/
public function getClass(): ClassDefinition
{
if (!$this->class) {
$this->setClass(ClassDefinition::getById($this->getClassId()));
$class = ClassDefinition::getById($this->getClassId());
if (!$class instanceof ClassDefinition) {
throw new Model\Exception\NotFoundException('class not found for object id: ' . $this->getId());
}

$this->setClass($class);
}

return $this->class;
Expand Down
12 changes: 3 additions & 9 deletions models/DataObject/Concrete/Dao.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,6 @@ public function getRelationData(string $field, bool $forOwner, ?string $remoteCl
*/
public function getData(): void
{
if (empty($this->model->getClass())) {
return;
}

if (!$data = $this->db->fetchAssociative('SELECT * FROM object_store_' . $this->model->getClassId() . ' WHERE oo_id = ?', [$this->model->getId()])) {
return;
}
Expand Down Expand Up @@ -423,11 +419,9 @@ public function saveChildData(): void
public function delete(): void
{
// delete fields which have their own delete algorithm
if ($this->model->getClass()) {
foreach ($this->model->getClass()->getFieldDefinitions() as $fd) {
if ($fd instanceof CustomResourcePersistingInterface) {
$fd->delete($this->model);
}
foreach ($this->model->getClass()->getFieldDefinitions() as $fd) {
if ($fd instanceof CustomResourcePersistingInterface) {
$fd->delete($this->model);
}
}

Expand Down

0 comments on commit 07b6146

Please sign in to comment.