Skip to content

Commit

Permalink
Merge pull request #108 from symfony-cmf/adjust-page-document
Browse files Browse the repository at this point in the history
have additionalInfoBlock and remove createDate from page
  • Loading branch information
lsmith77 committed Apr 16, 2014
2 parents 21958e3 + 75922a8 commit 544488c
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 38 deletions.
8 changes: 3 additions & 5 deletions Admin/PageAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ protected function configureListFields(ListMapper $listMapper)
->addIdentifier('title', 'text')
->add('label', 'text')
->add('name', 'text')
->add('createDate', 'date')
;
}

Expand All @@ -60,7 +59,6 @@ protected function configureFormFields(FormMapper $formMapper)
->add('label', null, array('required' => false))
->add('title')
->add('body', 'textarea')
->add('createDate')
->end()
->with('form.group_advanced', array(
'translation_domain' => 'CmfRoutingBundle',
Expand Down Expand Up @@ -112,7 +110,7 @@ protected function ensureOrderByDate($page)
$itemsByDate = array();
/** @var $item Page */
foreach ($items as $item) {
$itemsByDate[$item->getDate()->format('U')][$item->getCreateDate()->format('U')][] = $item;
$itemsByDate[$item->getDate()->format('U')][$item->getPublishStartDate()->format('U')][] = $item;
}

if ('asc' == $this->sortOrder) {
Expand All @@ -127,8 +125,8 @@ protected function ensureOrderByDate($page)
} else {
krsort($itemsForDate);
}
foreach ($itemsForDate as $itemsForCreateDate) {
foreach ($itemsForCreateDate as $item) {
foreach ($itemsForDate as $itemsForPublishDate) {
foreach ($itemsForPublishDate as $item) {
$sortedItems[$item->getName()] = $item;
}
}
Expand Down
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ Changelog
1.1.0-RC2
---------

* **2014-04-15**: Page now also provides the additionalInfoBlock child. Removed
the createDate as its redundant with the publishStartDate.

* **2014-04-11**: drop Symfony 2.2 compatibility

1.1.0-RC1
---------

* **2014-04-01**: Refactored the RoutingBundle to provide all routing
features needed by SimpleCmsBundle.
* If you where only using the SimpleCmsBundle you now need to activate
the dynamic router. SimpleCmsBundle automatically does this for you.
* The dynamic router of RoutingBundle needs to be active. The
SimpleCmsBundle automatically does this for you.
* The configuration for document to route/template now all happens under
cmf_routing.dynamic and the route enhancers also apply to simplecms Pages.
You can configure additional base paths where to look for routes in the
Expand Down
57 changes: 32 additions & 25 deletions Doctrine/Phpcr/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use LogicException;
use Knp\Menu\NodeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Sonata\BlockBundle\Model\BlockInterface;
use Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishTimePeriodInterface;
use Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishableInterface;
use Symfony\Cmf\Bundle\CoreBundle\Translatable\TranslatableInterface;
Expand Down Expand Up @@ -114,9 +115,12 @@ class Page extends Route implements
protected $body;

/**
* @var \DateTime
* This will usually be a ContainerBlock but can be any block that will be
* rendered in the additionalInfoBlock area.
*
* @var BlockInterface
*/
protected $createDate;
protected $additionalInfoBlock;

/**
* @var \DateTime
Expand Down Expand Up @@ -144,13 +148,6 @@ class Page extends Route implements
*/
protected $extras = array();

public function __construct(array $options = array())
{
parent::__construct($options);

$this->createDate = new \DateTime();
}

/**
* @deprecated use getOption('add_locale_pattern') instead
*/
Expand Down Expand Up @@ -192,12 +189,25 @@ public function setLocale($locale)
}

/**
* Get the "date" of this page, which is the publishStartDate if set,
* otherwise the createDate.
* @deprecated Since 1.1 we only have the publish start date
*
* This method is kept for BC but will return the result of getDate().
*
* @return \DateTime
*/
public function getCreateDate()
{
return $this->getDate();
}

/**
* Get the "date" of this page, which is the publishStartDate.
*
* @return \DateTime
*/
public function getDate()
{
return $this->publishStartDate ? $this->publishStartDate : $this->createDate;
return $this->getPublishStartDate();
}

/**
Expand Down Expand Up @@ -251,7 +261,7 @@ public function setPublishable($publishable)
/**
* Get extras - a flat key-value hashmap
*
* @return array with only string values
* @return array hashmap with only string values
*/
public function getExtras()
{
Expand Down Expand Up @@ -434,26 +444,23 @@ public function getBody()
}

/**
* Get the creation date
*
* @return \DateTime
* @return BlockInterface
*/
public function getCreateDate()
public function getAdditionalInfoBlock()
{
return $this->createDate;
return $this->additionalInfoBlock;
}

/**
* Overwrite the creation date manually
*
* On creation of a Page, the createDate is automatically set to the
* current time.
* Set the additional info block for this content. Usually you want this to
* be a container block in order to be able to add several blocks.
*
* @param \DateTime $createDate
* @param BlockInterface $block must be persistable through cascade by the
* persistence layer.
*/
public function setCreateDate(\DateTime $createDate = null)
public function setAdditionalInfoBlock($block)
{
$this->createDate = $createDate;
$this->additionalInfoBlock = $block;
}

/**
Expand Down
4 changes: 0 additions & 4 deletions Migrator/Phpcr/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,6 @@ public function migrate($path = '/', $depth = -1)
$page->setBody($data['body']);
}

if (isset($data['create_date'])) {
$page->setCreateDate(date_create_from_format('U', strtotime($data['create_date'])));
}

if (isset($data['publish_start_date'])) {
$page->setPublishStartDate(date_create_from_format('U', strtotime($data['publish_start_date'])));
}
Expand Down
4 changes: 3 additions & 1 deletion Resources/config/doctrine-phpcr/Page.phpcr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
<field name="title" type="string" translated="true"/>
<field name="label" type="string" translated="true" nullable="true"/>
<field name="body" type="string" translated="true" nullable="true"/>
<field name="createDate" type="date"/>
<child name="additionalInfoBlock">
<cascade><cascade-persist /></cascade>
</child>
<field name="publishable" type="boolean"/>
<field name="publishStartDate" type="date" nullable="true"/>
<field name="publishEndDate" type="date" nullable="true"/>
Expand Down
1 change: 0 additions & 1 deletion Tests/Functional/Doctrine/Phpcr/PageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public function testPage()
$page->setTitle('Page Title');
$page->setLabel('Page Label');
$page->setBody('This is body');
$page->setCreateDate(new \DateTime('2013-07-05'));
$page->setPublishable(false);
$page->setPublishStartDate(new \DateTime('2013-06-18'));
$page->setPublishEndDate(new \DateTime('2013-06-18'));
Expand Down
18 changes: 18 additions & 0 deletions UPGRADE-1.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
UPGRADE FROM 1.0 TO 1.1
=======================

Removed all custom routing service as RoutingBundle is now flexible enough.
* Move all routing configuration from cmf_simple_cms to cmf_routing.dynamic
* The configuration for locales is not needed anymore. Configuring it on the
cmf_routing is enough.
* The options for the format pattern, trailing slash and locale pattern are
now moved into the route "options" and the Page Document now takes an
array of options in the constructor instead of boolean flags.

The Page document has no `createDate` field anymore. Use the publishStartDate
for this purpose. If you where using the createDate and want to keep that
information, you can move it to the publishStartDate with the following query:

$ php app/console doctrine:phpcr:nodes:update \
--query="SELECT * FROM [nt:unstructured] WHERE [phpcr:class] = \"Symfony\\Cmf\\Bundle\\SimpleCmsBundle\\Doctrine\\Phpcr\\Page\"" \
--apply-closure="if (!\$node->getPublishStartDate()) \$node->setProperty('publishStartDate', \$node->getPropertyValue('createDate'));"

0 comments on commit 544488c

Please sign in to comment.