/** * Publish path * Create all needed Entities from JSON structure created by the Editor. * * @param \Innova\PathBundle\Entity\Path\Path $path * * @throws \Exception * * @return bool */ public function publish(Path $path) { // We need to publish all linked resources to have a full working Path // Start Publishing $this->start($path); // Store existing steps to remove steps which no longer exist $existingSteps = $path->getSteps()->toArray(); // Publish steps for this path $toProcess = !empty($this->pathStructure->steps) ? $this->pathStructure->steps : []; $publishedSteps = $this->publishSteps(0, null, $toProcess); // Clean steps to remove $this->cleanSteps($publishedSteps, $existingSteps); // Flush all created Entities in order to generate their IDs (needed to update the JSON structure of the Path) $this->om->flush(); // Mark Path as published and not modified $this->path->setPublished(true); $this->path->setModified(false); // Re encode updated structure and update Path // When the Path is published, the structure is built from generated Entities // So we want to do this now to inject Entities IDs into the JSON structure $updatedStructure = $this->path->getStructure(); $this->path->setStructure($updatedStructure); // Manage rights $this->manageRights(); // Persist data $this->om->persist($this->path); $this->om->flush(); // End Publishing $this->end(); return true; }
/** * Initialize a new Publishing * @param \Innova\PathBundle\Entity\Path\Path $path * @throws \Exception * @return \Innova\PathBundle\Manager\PublishingManager */ protected function start(Path $path) { // Get the path structure $pathStructure = $path->getStructure(); if (empty($pathStructure)) { throw new \Exception('Unable to find JSON structure of the path. Publication aborted.'); } // Decode structure $this->pathStructure = json_decode($pathStructure); $this->path = $path; $this->uniqId2step = array(); return $this; }
public function export(Workspace $workspace, array &$files, Path $path) { $data = []; // Get path data $pathData = []; $pathData['description'] = $path->getDescription(); $pathData['breadcrumbs'] = $path->hasBreadcrumbs(); $pathData['modified'] = $path->isModified(); $pathData['published'] = $path->isPublished(); $pathData['summaryDisplayed'] = $path->isSummaryDisplayed(); $pathData['completeBlockingCondition'] = $path->isCompleteBlockingCondition(); $pathData['manualProgressionAllowed'] = $path->isManualProgressionAllowed(); // Get path structure into a file (to replace resources ID with placeholders) $uid = uniqid() . '.txt'; $tmpPath = $this->ch->getParameter('tmp_dir') . DIRECTORY_SEPARATOR . $uid; $structure = $path->getStructure(); file_put_contents($tmpPath, $structure); $files[$uid] = $tmpPath; $pathData['structure'] = $uid; $data['path'] = $pathData; // Process Steps $data['steps'] = []; if ($path->isPublished()) { $stepsData = []; foreach ($path->getSteps() as $step) { $stepsData[] = $this->stepManager->export($step); } $data['steps'] = $stepsData; } return $data; }
/** * Edit existing path * @param \Innova\PathBundle\Entity\Path\Path $path * @return \Innova\PathBundle\Entity\Path\Path */ public function edit(Path $path) { // Check if JSON structure is built $structure = $path->getStructure(); if (empty($structure)) { // Initialize path structure $path->initializeStructure(); } // Set path as modified (= need publishing to be able to play path with new modifs) $path->setModified(true); $this->om->persist($path); // Update resource node if needed $resourceNode = $path->getResourceNode(); if ($path->getName() !== $resourceNode->getName()) { // Path name as changed => rename linked resource node $resourceNode->setName($path->getName()); $this->om->persist($resourceNode); } $this->om->flush(); return $path; }