Skip to content

Commit

Permalink
[Bug]: versions 500 error when field collection is removed (pimcore#1…
Browse files Browse the repository at this point in the history
…3957)

* [Bug]: versions 500 error when field collection is removed

* Fix PhpStan
  • Loading branch information
blankse authored Jan 3, 2023
1 parent 1b3878f commit 0afd723
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ pimcore.object.fieldcollection = Class.create({

addFieldComplete: function (button, value, object) {

var isValidName = /^[a-zA-Z]+$/;
var isValidName = /^[a-zA-Z][a-zA-Z0-9]*$/;

if (button == "ok" && value.length > 2 && isValidName.test(value) && !in_arrayi(value, this.forbiddenNames)) {
Ext.Ajax.request({
Expand Down
15 changes: 14 additions & 1 deletion models/DataObject/Fieldcollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

namespace Pimcore\Model\DataObject;

use Pimcore\Logger;
use Pimcore\Model;
use Pimcore\Model\DataObject;
use Pimcore\Model\Element\DirtyIndicatorInterface;
Expand All @@ -33,7 +34,7 @@ class Fieldcollection extends Model\AbstractModel implements \Iterator, DirtyInd
/**
* @internal
*
* @var TItem[]
* @var array<TItem|\__PHP_Incomplete_Class>
*/
protected $items = [];

Expand Down Expand Up @@ -366,4 +367,16 @@ public function loadLazyData()
}
}
}

public function __wakeup()
{
if (is_array($this->items)) {
foreach ($this->items as $key => $item) {
if ($item instanceof \__PHP_Incomplete_Class) {
unset($this->items[$key]);
Logger::error('fieldcollection item ' . $key . ' does not exist anymore');
}
}
}
}
}
4 changes: 1 addition & 3 deletions models/DataObject/Objectbrick.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,6 @@ public function __sleep(): array

public function __wakeup()
{
$brickGetter = null;

// for backwards compatibility
if ($this->object) {
$this->objectId = $this->object->getId();
Expand All @@ -339,7 +337,7 @@ public function __wakeup()
foreach ($this->items as $key => $item) {
if ($item instanceof \__PHP_Incomplete_Class) {
unset($this->items[$key]);
Logger::error('brick ' . $brickGetter . ' does not exist anymore');
Logger::error('brick item ' . $key . ' does not exist anymore');
}
}
}
Expand Down

0 comments on commit 0afd723

Please sign in to comment.