public function populateDefaults($elements = 'all') { $log = ''; if ($elements == 'all') { $elements = $this->ElementService->findAll()->getResults(); } else { $elementSlugs = StringUtils::smartExplode($elements); $elements = array(); foreach ($elementSlugs as $eSlug) { $elements[] = $this->ElementService->getBySlug($eSlug); } } foreach ($elements as $element) { $offset = 0; $nq = new NodeQuery(); $nq->setParameter('Elements.in', $element->getSlug()); $nq->setParameter('Meta.select', 'all'); $nq->setLimit(1000); $nq->setOffset($offset); $nq->asObjects(); $nq->isRetrieveTotalRecords(true); $nq = $this->NodeService->findAll($nq, true); $nodes = $nq->getResults(); $tCount = $nq->getTotalRecords(); $count = 0; while (count($nodes) > 0) { foreach ($nodes as $node) { $this->NodeMapper->defaultsOnNode($node); $this->NodeService->edit($node); ++$count; } $offset += 1000; $nq = new NodeQuery(); $nq->setParameter('Elements.in', $element->getSlug()); $nq->setParameter('Meta.select', 'all'); $nq->setLimit(1000); $nq->setOffset($offset); $nq->asObjects(); $nodes = $this->NodeService->findAll($nq)->getResults(); } $log .= 'Updated defaults on ' . $count . ' of ' . $tCount . ' ' . $element->getSlug() . " nodes.\n"; } return $log; }