public function __construct(Revision $revision) { $this->revision = $revision; if ($revision->getContentType()) { $message = "Not enough privilege the manipulate the object " . $revision->getContentType()->getName() . ":" . $revision->getOuuid(); } else { throw new \Exception("Not enough privilege the manipulate the object"); } parent::__construct($message, 0, null); }
/** * @Route("/data/revisions/revert/{id}", name="revision.revert")) * @Method({"POST"}) */ public function revertRevisionAction(Revision $revision, Request $request) { $type = $revision->getContentType()->getName(); $ouuid = $revision->getOuuid(); $newestRevision = $this->getNewestRevision($type, $ouuid); if ($newestRevision->getDraft()) { //TODO: ???? } $revertedRevsision = $this->initNewDraft($type, $ouuid, $revision); $this->addFlash('notice', 'Revision ' . $revision->getId() . ' reverted as draft'); return $this->redirectToRoute('revision.edit', ['revisionId' => $revertedRevsision->getId()]); }
public function __construct(Revision $revision) { $this->revision = $revision; $message = "Revision " . $revision->getStartTime()->format("c") . " of the object " . $revision->getContentType()->getName() . ":" . $revision->getOuuid() . " is locked by " . $revision->getLockBy() . " until " . $revision->getLockUntil()->format("c"); parent::__construct($message, 0, null); }
protected function execute(InputInterface $input, OutputInterface $output) { /** @var EntityManager $em */ $em = $this->doctrine->getManager(); $contentTypeNameFrom = $input->getArgument('contentTypeNameFrom'); $contentTypeNameTo = $input->getArgument('contentTypeNameTo'); $elasticsearchIndex = $input->getArgument('elasticsearchIndex'); if (null !== $input->getArgument('mode') && ($input->getArgument('mode')[0] == "M" || $input->getArgument('mode')[0] == "m")) { $mode = "merge"; } else { $mode = "earse"; } /** @var \AppBundle\Repository\ContentTypeRepository $contentTypeRepository */ $contentTypeRepository = $em->getRepository('AppBundle:ContentType'); /** @var \AppBundle\Entity\ContentType $contentTypeTo */ $contentTypeTo = $contentTypeRepository->findOneBy(array("name" => $contentTypeNameTo, 'deleted' => false)); if (!$contentTypeTo) { $output->writeln("<error>Content type " . $contentTypeNameTo . " not found</error>"); exit; } $output->writeln("Start migration of " . $contentTypeTo->getPluralName()); if ($contentTypeTo->getDirty()) { $output->writeln("<error>Content type \"" . $contentTypeNameTo . "\" is dirty. Please clean it first</error>"); exit; } if (!$input->getOption('force') && strcmp($contentTypeTo->getEnvironment()->getAlias(), $elasticsearchIndex) === 0 && strcmp($contentTypeNameFrom, $contentTypeNameTo) === 0) { $output->writeln("<error>You can not import a content type on himself</error>"); exit; } //Delete ContentType if erase if ($mode == "erase") { /** @var RevisionRepository $repository */ $repository = $em->getRepository('AppBundle:Revision'); $repository->deleteRevisions(); $repository->clear(); } $arrayElasticsearchIndex = $this->client->search(['index' => $elasticsearchIndex, 'type' => $contentTypeNameFrom, 'size' => 1]); $total = $arrayElasticsearchIndex["hits"]["total"]; // create a new progress bar $progress = new ProgressBar($output, $total); // start and displays the progress bar $progress->start(); for ($from = 0; $from < $total; $from = $from + 50) { $arrayElasticsearchIndex = $this->client->search(['index' => $elasticsearchIndex, 'type' => $contentTypeNameFrom, 'size' => 50, 'from' => $from, 'preference' => '_primary']); // $output->writeln("\nMigrating " . ($from+1) . " / " . $total ); /** @var RevisionRepository $repository */ $repository = $em->getRepository('AppBundle:Revision'); foreach ($arrayElasticsearchIndex["hits"]["hits"] as $index => $value) { try { $now = new \DateTime(); $until = $now->add(new \DateInterval("PT5M")); //+5 minutes $newRevision = new Revision(); $newRevision->setContentType($contentTypeTo); $newRevision->addEnvironment($contentTypeTo->getEnvironment()); $newRevision->setOuuid($value['_id']); $newRevision->setStartTime($now); $newRevision->setEndTime(null); $newRevision->setDeleted(0); $newRevision->setDraft(1); $newRevision->setLockBy('SYSTEM_MIGRATE'); $newRevision->setLockUntil($until); $currentRevision = $repository->getCurrentRevision($contentTypeTo, $value['_id']); if ($currentRevision) { //If there is a current revision, datas in fields that are protected against migration must not be overridden //So we load the datas from the current revision into the next revision $newRevision->setRawData($currentRevision->getRawData()); //We build the new revision object $this->dataService->loadDataStructure($newRevision); //We update the new revision object with the new datas. Here, the protected fields are not overridden. $newRevision->getDataField()->updateDataValue($value['_source'], true); //isMigrate=true //We serialize the new object $objectArray = $this->mapping->dataFieldToArray($newRevision->getDataField()); $newRevision->setRawData($objectArray); } else { if ($input->getOption('strip')) { $newRevision->setRawData([]); $this->dataService->loadDataStructure($newRevision); $newRevision->getDataField()->updateDataValue($value['_source'], true); //We serialize the new object $objectArray = $this->mapping->dataFieldToArray($newRevision->getDataField()); $newRevision->setRawData($objectArray); } else { $newRevision->setRawData($value['_source']); $objectArray = $value['_source']; } } $this->client->index(['index' => $contentTypeTo->getEnvironment()->getAlias(), 'type' => $contentTypeNameTo, 'id' => $value['_id'], 'body' => $objectArray]); //TODO: Test if client->index OK $em->persist($newRevision); $em->flush(); $repository->finaliseRevision($contentTypeTo, $value['_id'], $now); //hot fix query: insert into `environment_revision` select id, 1 from `revision` where `end_time` is null; $repository->publishRevision($newRevision); } catch (NotLockedException $e) { $output->writeln("<error>'.{$e}.'</error>"); } // advance the progress bar 1 unit $progress->advance(); } $repository->clear(); } // ensure that the progress bar is at 100% $progress->finish(); $output->writeln(""); $output->writeln("Migration done"); }
public function unpublish(Revision $revision, Environment $environment) { if (!$this->authorizationChecker->isGranted($revision->getContentType()->getEditRole())) { $this->session->getFlashBag()->add('warning', 'You are not allowed to unpublish the object ' . $revision); return; } $user = $this->userService->getCurrentUser(); if (!empty($environment->getCircles() && !$this->authorizationChecker->isGranted('ROLE_ADMIN') && empty(array_intersect($environment->getCircles(), $user->getCircles())))) { $this->session->getFlashBag()->add('warning', 'You are not allowed to unpublish from the environment ' . $environment); return; } if ($revision->getContentType()->getEnvironment() == $environment) { $this->session->getFlashBag()->add('warning', 'You can\'t unpublish from the default environment of the content type ' . $revision->getContentType()); return; } $this->dataService->lockRevision($revision, $environment); $revision->removeEnvironment($environment); try { $status = $this->client->delete(['id' => $revision->getOuuid(), 'index' => $environment->getAlias(), 'type' => $revision->getContentType()->getName()]); $this->session->getFlashBag()->add('notice', 'The object ' . $revision . ' has been unpublished from environment ' . $environment->getName()); } catch (\Exception $e) { if (!$revision->getDeleted()) { $this->session->getFlashBag()->add('warning', 'The object ' . $revision . ' was already unpublished from environment ' . $environment->getName()); } } $em = $this->doctrine->getManager(); $em->persist($revision); $em->flush(); $this->auditService->auditLog('PublishService:unpublish', $revision->getRawData(), $environment->getName()); }
public function deleteRevision(Revision $revision) { $qb = $this->createQueryBuilder('r')->update()->set('r.delete', 1)->where('r.id = ?1')->setParameter(1, $revision->getId()); return $qb->getQuery()->execute(); }
public function __construct(Revision $revision) { $this->revision = $revision; $message = "Update on a not locked object " . $revision->getContentType()->getName() . ":" . $revision->getOuuid() . ' #' . $revision->getId(); parent::__construct($message, 0, null); }
public function removeCriteria($filters, Revision $revision, $criteriaField) { $rawData = $revision->getRawData(); if (!isset($rawData[$criteriaField])) { $rawData[$criteriaField] = []; } $criteriaFieldType = $revision->getContentType()->getFieldType()->__get('ems_' . $criteriaField); $multipleField = $this->getMultipleField($criteriaFieldType); $found = false; foreach ($rawData[$criteriaField] as $index => $criteriaSet) { $found = true; foreach ($filters as $criterion => $value) { if ($criterion != $multipleField && $value != $criteriaSet[$criterion]) { $found = false; break; } } if ($found) { if ($multipleField) { $indexKey = array_search($filters[$multipleField], $criteriaSet[$multipleField]); if ($indexKey === FALSE) { $this->addFlash('notice', 'Criteria not found in multiple key'); } else { unset($rawData[$criteriaField][$index][$multipleField][$indexKey]); $rawData[$criteriaField][$index][$multipleField] = array_values($rawData[$criteriaField][$index][$multipleField]); if (count($rawData[$criteriaField][$index][$multipleField]) == 0) { unset($rawData[$criteriaField][$index]); $rawData[$criteriaField] = array_values($rawData[$criteriaField]); } if (!$revision->getDraft()) { $revision = $this->dataService->initNewDraft($revision->getContentType()->getName(), $revision->getOuuid(), $revision); } $revision->setRawData($rawData); $this->addFlash('notice', '<b>Remove</b> ' . $multipleField . ' with value ' . $filters[$multipleField] . ' from ' . $revision); return $revision; } } else { unset($rawData[$criteriaField][$index]); $rawData[$criteriaField][$index] = array_values($rawData[$criteriaField][$index]); if (!$revision->getDraft()) { $revision = $this->dataService->initNewDraft($revision->getContentType()->getName(), $revision->getOuuid(), $revision); } $revision->setRawData($rawData); $this->addFlash('notice', '<b>Remove</b> from ' . $revision); return $revision; } break; } } if (!$found) { $this->addFlash('notice', 'Criteria not found for ' . $revision); } return false; }
public function replaceData(Revision $revision, array $rawData, $replaceOrMerge = "replace") { if (!$revision->getDraft()) { $em = $this->doctrine->getManager(); $this->lockRevision($revision, false, false); $now = new \DateTime(); $newDraft = new Revision($revision); if ($replaceOrMerge === "replace") { $newDraft->setRawData($rawData); } elseif ($replaceOrMerge === "merge") { $newRawData = array_merge($revision->getRawData(), $rawData); $newDraft->setRawData($newRawData); } else { $this->session->getFlashBag()->add('error', 'The revision ' . $revision . ' has not been replaced or replaced'); return $revision; } $newDraft->setStartTime($now); $revision->setEndTime($now); $this->lockRevision($newDraft, false, false); $em->persist($revision); $em->persist($newDraft); $em->flush(); return $newDraft; } else { $this->session->getFlashBag()->add('error', 'The revision ' . $revision . ' is not a finalize version'); } return $revision; }