/** * Replaces content in optimized tables. * * @param AbstractClassContent $content * * @return IndexationRepository */ public function replaceOptContentTable(AbstractClassContent $content) { if (null === $content->getMainNode()) { return $this; } $command = 'REPLACE'; if (!$this->replaceSupported) { // REPLACE command not supported, remove first then insert $this->removeOptContentTable($content); $command = 'INSERT'; } $meta = $this->_em->getClassMetadata('BackBee\\ClassContent\\Indexes\\OptContentByModified'); $query = $command . ' INTO ' . $meta->getTableName() . ' (' . $meta->getColumnName('_uid') . ', ' . $meta->getColumnName('_label') . ', ' . $meta->getColumnName('_classname') . ', ' . $meta->getColumnName('_node_uid') . ', ' . $meta->getColumnName('_modified') . ', ' . $meta->getColumnName('_created') . ')' . ' VALUES (:uid, :label, :classname, :node_uid, :modified, :created)'; $params = array('uid' => $content->getUid(), 'label' => $content->getLabel(), 'classname' => AbstractClassContent::getShortClassname($content), 'node_uid' => $content->getMainNode()->getUid(), 'modified' => date('Y-m-d H:i:s', $content->getModified()->getTimestamp()), 'created' => date('Y-m-d H:i:s', $content->getCreated()->getTimestamp())); $types = array(\Doctrine\DBAL\Connection::PARAM_STR_ARRAY, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY); return $this->_executeQuery($query, $params, $types); }
/** * Update mainnode of the content if need during clonage. * * @param AbstractClassContent $content The cloned content. * @param array $cloningPages The cloned pages array. * @param BBUserToken|null $token Optional, the BBuser token to allow the update of revisions if set. * * @return PageRepository */ private function updateMainNodePostCloning(AbstractClassContent $content, array $cloningPages, BBUserToken $token = null) { $mainnode = $content->getMainNode(); if (null !== $mainnode && 0 < count($cloningPages) && true === in_array($mainnode->getUid(), array_keys($cloningPages))) { // Loading draft for content if (null !== $token && null !== ($draft = $this->_em->getRepository('BackBee\\ClassContent\\Revision')->getDraft($content, $token, true))) { $content->setDraft($draft); } $content->setMainNode($cloningPages[$mainnode->getUid()]); } return $this; }
/** * Sets the main node value of $content to $page. * Recompute $content if need. * * @param AbstractClassContent $content * @param Page $page */ private function setMainNode(AbstractClassContent $content, Page $page) { if (null !== $content->getMainNode()) { return; } $content->setMainNode($page); if (null !== $this->entityManager) { $uow = $this->entityManager->getUnitOfWork(); $meta = $this->entityManager->getClassMetadata(get_class($content)); if ($uow->isEntityScheduled($content)) { $uow->recomputeSingleEntityChangeSet($meta, $content); } elseif ($uow->isEntityScheduled($page)) { $uow->computeChangeSet($meta, $content); } } }