Skip to content

Commit

Permalink
add publishing (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz authored and chirimoya committed Jul 19, 2016
1 parent 482699d commit 339234b
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 49 deletions.
20 changes: 20 additions & 0 deletions Controller/ArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,12 @@ public function getAction($uuid, Request $request)
*/
public function postAction(Request $request)
{
$action = $request->get('action');
$document = $this->getDocumentManager()->create(self::DOCUMENT_TYPE);
$locale = $this->getRequestParameter($request, 'locale', true);

$this->persistDocument($request->request->all(), $document, $locale);
$this->handleActionParameter($action, $document, $locale);
$this->getDocumentManager()->flush();

return $this->handleView(
Expand All @@ -183,6 +185,7 @@ public function postAction(Request $request)
public function putAction(Request $request, $uuid)
{
$locale = $this->getRequestParameter($request, 'locale', true);
$action = $request->get('action');

$document = $this->getDocumentManager()->find(
$uuid,
Expand All @@ -196,6 +199,7 @@ public function putAction(Request $request, $uuid)
$this->get('sulu_hash.request_hash_checker')->checkHash($request, $document, $document->getUuid());

$this->persistDocument($request->request->all(), $document, $locale);
$this->handleActionParameter($action, $document, $locale);
$this->getDocumentManager()->flush();

return $this->handleView(
Expand Down Expand Up @@ -288,4 +292,20 @@ protected function getDocumentManager()
{
return $this->get('sulu_document_manager.document_manager');
}

/**
* Delegates actions by given actionParameter, which can be retrieved from the request.
*
* @param string $actionParameter
* @param object $document
* @param string $locale
*/
private function handleActionParameter($actionParameter, $document, $locale)
{
switch ($actionParameter) {
case 'publish':
$this->getDocumentManager()->publish($document, $locale);
break;
}
}
}
42 changes: 41 additions & 1 deletion Document/ArticleDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Sulu\Component\Content\Document\Behavior\LocalizedAuditableBehavior;
use Sulu\Component\Content\Document\Behavior\LocalizedStructureBehavior;
use Sulu\Component\Content\Document\Behavior\StructureBehavior;
use Sulu\Component\Content\Document\Behavior\WorkflowStageBehavior;
use Sulu\Component\Content\Document\Extension\ExtensionContainer;
use Sulu\Component\Content\Document\Structure\Structure;
use Sulu\Component\Content\Document\Structure\StructureInterface;
Expand All @@ -41,7 +42,8 @@ class ArticleDocument implements
LocalizedAuditableBehavior,
DateShardingBehavior,
RoutableInterface,
ExtensionBehavior
ExtensionBehavior,
WorkflowStageBehavior
{
/**
* @var string
Expand Down Expand Up @@ -125,6 +127,20 @@ class ArticleDocument implements
*/
protected $extensions;

/**
* Workflow Stage currently Test or Published.
*
* @var int
*/
protected $workflowStage;

/**
* Is Document is published.
*
* @var bool
*/
protected $published;

public function __construct()
{
$this->structure = new Structure();
Expand Down Expand Up @@ -359,4 +375,28 @@ public function setExtension($name, $data)
{
$this->extensions[$name] = $data;
}

/**
* {@inheritdoc}
*/
public function getWorkflowStage()
{
return $this->workflowStage;
}

/**
* {@inheritdoc}
*/
public function setWorkflowStage($workflowStage)
{
$this->workflowStage = $workflowStage;
}

/**
* {@inheritdoc}
*/
public function getPublished()
{
return $this->published;
}
}
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ Install bundle over composer:
composer require sulu/article-bundle
```

Add bundle to AbstractKernel:

```php
new Sulu\Bundle\ArticleBundle\SuluArticleBundle(),
new ONGR\ElasticsearchBundle\ONGRElasticsearchBundle(),
```

Create required phpcr nodes:

```bash
Expand All @@ -16,7 +23,7 @@ app/console sulu:document:init

Configure the bundle:

```
```yml
sulu_route:
mappings:
Sulu\Bundle\ArticleBundle\Document\ArticleDocument:
Expand All @@ -35,6 +42,6 @@ ongr_elasticsearch:

Create elasticsearch index:

```
```bash
bin/console ongr:es:index:create
```
1 change: 1 addition & 0 deletions Resources/config/serializer/Document.ArticleDocument.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<property name="created" type="DateTime" groups="defaultPage"/>
<property name="changed" type="DateTime" groups="defaultPage"/>

<property name="published" type="DateTime" groups="defaultPage,smallPage"/>
<property name="extensions" type="Sulu\Component\Content\Document\Extension\ExtensionContainer" serialized-name="ext" groups="defaultPage,preview"/>
</class>
</serializer>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 339234b

Please sign in to comment.