1
0
mirror of https://github.com/ToxicCrack/PrintABrick.git synced 2025-05-16 12:20:09 -07:00

Update ModelLoader.php

Added iteration counter for parent models
This commit is contained in:
Daniel 2020-03-19 17:19:59 +01:00 committed by GitHub
parent 4d0cc7cebc
commit 0255e0b71d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -215,8 +215,12 @@ class ModelLoader extends BaseLoader
* *
* @return Model|null|false * @return Model|null|false
*/ */
public function loadModel($file) public function loadModel($file, $iteration=0)
{ {
if($iteration >= 20) {
$this->logger->error("Too many submodels. Skipping", [$file]);
return false;
}
/** @var ModelRepository $modelRepository */ /** @var ModelRepository $modelRepository */
$modelRepository = $this->em->getRepository(Model::class); $modelRepository = $this->em->getRepository(Model::class);
@ -238,7 +242,7 @@ class ModelLoader extends BaseLoader
if ($this->isModelIncluded($modelArray)) { if ($this->isModelIncluded($modelArray)) {
// Recursively load model parent (if any) and add model id as alias of parent // Recursively load model parent (if any) and add model id as alias of parent
if (($parentId = $this->getParentId($modelArray)) && ($parentModelFile = $this->findSubmodelFile($parentId)) !== null) { if (($parentId = $this->getParentId($modelArray)) && ($parentModelFile = $this->findSubmodelFile($parentId)) !== null) {
if ($parentModel = $this->loadModel($parentModelFile)) { if ($parentModel = $this->loadModel($parentModelFile, $iteration+1)) {
// Remove old model if ~moved to // Remove old model if ~moved to
if ($this->rewrite && ($old = $modelRepository->find($modelArray['id'])) != null) { if ($this->rewrite && ($old = $modelRepository->find($modelArray['id'])) != null) {
$modelRepository->delete($old); $modelRepository->delete($old);