D
D
dez64ru2019-09-12 08:47:35
MODX
dez64ru, 2019-09-12 08:47:35

Why does php crash after 6 iterations with memory overflow?

Modx 2.7.1
Upgraded the modResource table by adding extId and parentExtId
after importing the categories, fixing the resource parent dependencies with this script.

foreach ($this->modx->getIterator('modResource', ['extId:!=' => null]) as $obj) {//Берем все р-сы где не пусто extID
            $parentObj = $this->modx->getObject('modResource', ['extId' => $obj->parentExtId]); //Ищем родителя по extId родителя и parentExtId текущего рес-са

            $parentId = null !== $parentObj ? $parentObj->id : $this->getConfig('root_catalog_id'); //Если такого нет, то ставим дефолного родителя.

            $obj->set('parent', $parentId); //Установка родителя

            if ($obj->save()) { //сохраняем
                $this->log("Succes set parent {$parentId} for {$obj->id}");
            } else {
                $this->log("Error set parent {$parentId} for {$obj->id}");
            }

            unset($obj, $parentObj, $parentId);
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dez64ru, 2019-09-12
@dez64ru

Didn't take into account that $obj->parentExtId can be null.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question