/** * updates the TemplateSnippet of the given id and website id. * if snippet exists only at filesystem, create the snippet in db. * * @param TemplateSnippetSource $snippetSource * @param \Cms\Data\TemplateSnippet $snippet * * @return DataTemplateSnippet */ public function update(TemplateSnippetSource $snippetSource, DataTemplateSnippet $snippet) { $snippetId = $snippet->getId(); $existsAtFilesystem = $this->daoFilesystem->existsSnippet($snippetSource, $snippetId); $existsAtDoctrine = $this->daoDoctrine->existsSnippet($snippetSource, $snippetId); if ($existsAtFilesystem && !$existsAtDoctrine) { return $this->daoDoctrine->create($snippetSource, $snippet); } return $this->daoDoctrine->update($snippetSource, $snippet); }
/** * @param string $websiteId * @param string $id * @param SourceItem $sourceItem * @param \stdClass $manifest * @param string $lastUpdate * @param string $previewImageUrl * * @return DataTemplateSnippet */ protected function loadDataObject($websiteId, $id, SourceItem $sourceItem, \stdClass $manifest, $lastUpdate, $previewImageUrl) { $snippet = new DataTemplateSnippet(); $snippet->setWebsiteid($websiteId); $snippet->setId($id); $snippet->setReadonly($sourceItem->isReadonly()); $snippet->setSourceType($sourceItem->getType()); $snippet->setLastupdate($lastUpdate); if (!empty($previewImageUrl)) { $snippet->setPreviewImageUrl($previewImageUrl); } if (property_exists($manifest, 'name')) { $snippet->setName($manifest->name); } if (property_exists($manifest, 'description')) { $snippet->setDescription($manifest->description); } if (property_exists($manifest, 'category')) { $snippet->setCategory($manifest->category); } if (property_exists($manifest, 'content')) { $snippet->setContent($manifest->content); } if (property_exists($manifest, 'baseLayout')) { $snippet->setBaseLayout($manifest->baseLayout); } if (property_exists($manifest, 'pageTypes') && is_array($manifest->pageTypes)) { $snippet->setPageTypes($manifest->pageTypes); } return $snippet; }
/** * @param \Cms\Data\TemplateSnippet $data */ protected function setValuesFromData(TemplateSnippetData $data) { $this->setWebsiteId($data->getWebsiteId()); $this->setId($data->getId()); $this->setName($data->getName()); $this->setDescription($data->getDescription()); $this->setCategory($data->getCategory()); $this->setContent($data->getContent()); $this->setReadonly($data->isReadonly()); $this->setSourceType($data->getSourceType()); $this->setOverwritten($data->isOverwritten()); $this->setBaseLayout($data->isBaseLayout()); $this->setPageTypes($data->getPageTypes()); $this->setPreviewImageUrl($data->getPreviewImageUrl()); }
/** * @param \Cms\Data\TemplateSnippet * @param array $attributes */ protected function setAttributesToTemplateSnippet(DataTemplateSnippet $snippet, array $attributes) { if (isset($attributes['name'])) { $snippet->setName($attributes['name']); } if (isset($attributes['description'])) { $snippet->setDescription($attributes['description']); } if (isset($attributes['category'])) { $snippet->setCategory($attributes['category']); } if (isset($attributes['content'])) { $contentString = is_array($attributes['content']) ? \Zend_Json::encode($attributes['content']) : $attributes['content']; $snippet->setContent($contentString); } }
/** * set the TemplateSnippet attributes (if they are exists in the attributes array) * * @param \Orm\Entity\TemplateSnippet $snippetOrm * @param \Cms\Data\TemplateSnippet $snippet */ protected function setAttributesToOrm(OrmTemplateSnippet $snippetOrm, DataTemplateSnippet $snippet) { $snippetOrm->setName($snippet->getName()); $snippetOrm->setDescription($snippet->getDescription()); $snippetOrm->setCategory($snippet->getCategory()); $snippetOrm->setContent($snippet->getContent()); }
/** * @test * @group small * @group dev * @group library */ public function test_updateThrowNotExistsExceptionAsExpected() { // ARRANGE $dao = $this->getFilesystemDao(); $websiteId = 'WEBSITE-ID'; $snippetId = 'SNIPPET-ID-NOT-EXISTS'; $sourceItems = $this->getSourceItemsFromDirectory($this->getBaseDirectory('snippets'), '/url/to/templateSnippet', SourceItem::SOURCE_REPOSITORY, true); $source = $this->getTemplateSnippetSource($websiteId, $sourceItems); $expectedExceptionData = array('id' => $snippetId, 'websiteid' => $websiteId); $snippet = new DataTemplateSnippet(); $snippet->setId($snippetId); // ACT try { $dao->update($source, $snippet); $actualException = null; } catch (CmsException $actualException) { } // ASSERT $this->assertInstanceOf('\\Cms\\Exception', $actualException); $this->assertEquals(1602, $actualException->getCode()); $actualExceptionData = $actualException->getData(); $this->assertEquals($expectedExceptionData, $actualExceptionData); }
/** * @param string $count * @param string $suffix * @param array $attributes * * @return \Cms\Data\TemplateSnippet[] */ protected function createDataSnippets($count, $suffix, $attributes = array()) { $snippets = array(); for ($i = 1; $i <= $count; $i++) { $snippet = new DataTemplateSnippet(); if (array_key_exists('websiteid', $attributes)) { $snippet->setWebsiteid($attributes['websiteid']); } if (array_key_exists('id', $attributes)) { $snippet->setId($attributes['id']); } else { $snippet->setNewGeneratedId(); } if (array_key_exists('name', $attributes)) { $snippet->setName($attributes['name']); } else { $snippet->setName(sprintf('name_%04d%s', $i, $suffix)); } if (array_key_exists('description', $attributes)) { $snippet->setDescription($attributes['description']); } else { $snippet->setDescription(sprintf('description_%04d%s', $i, $suffix)); } if (array_key_exists('category', $attributes)) { $snippet->setCategory($attributes['category']); } else { $snippet->setCategory(sprintf('category_%04d%s', $i, $suffix)); } if (array_key_exists('content', $attributes)) { $snippet->setContent($attributes['content']); } else { $snippet->setCategory(json_encode(array(array('attribute' => sprintf('content_%04d%s', $i, $suffix))))); } if (array_key_exists('readonly', $attributes)) { $snippet->setReadonly($attributes['readonly']); } else { $snippet->setReadonly(false); } if (array_key_exists('sourcetype', $attributes)) { $snippet->setSourceType($attributes['sourcetype']); } else { $snippet->setSourceType($snippet::SOURCE_LOCAL); } if (array_key_exists('overwritten', $attributes)) { $snippet->setOverwritten($attributes['overwritten']); } else { $snippet->setOverwritten(false); } if (array_key_exists('lastupdate', $attributes)) { $snippet->setLastupdate($attributes['lastupdate']); } else { $snippet->setLastupdate(time()); } $snippets[] = $snippet; } return $snippets; }
/** * @param Data\TemplateSnippet $templateSnippet * @return string */ private function getTemplateSnippetJson(Data\TemplateSnippet $templateSnippet) { $templateSnippetColumnsAndValues = $templateSnippet->getExportColumnsAndValues(); $templateSnippetJson = json_encode($templateSnippetColumnsAndValues); $this->extendingColorIds($templateSnippet->getWebsiteid(), $templateSnippetJson); return $templateSnippetJson; }