diff --git a/src/Kunstmaan/NodeBundle/AdminList/NodeAdminListConfigurator.php b/src/Kunstmaan/NodeBundle/AdminList/NodeAdminListConfigurator.php
index 8d5bbd95e5..aff194a89a 100644
--- a/src/Kunstmaan/NodeBundle/AdminList/NodeAdminListConfigurator.php
+++ b/src/Kunstmaan/NodeBundle/AdminList/NodeAdminListConfigurator.php
@@ -49,7 +49,10 @@ public function __construct(EntityManager $em, AclHelper $aclHelper, $locale, $p
*/
public function buildFilters()
{
- $this->addFilter('title', new StringFilterType('title'), 'Title')
+ $this
+ ->addFilter('title', new StringFilterType('title'), 'Title')
+ ->addFilter('created', new DateFilterType('created'), 'Created At')
+ ->addFilter('updated', new DateFilterType('updated'), 'Updated At')
->addFilter('online', new BooleanFilterType('online'), 'Online');
}
@@ -59,8 +62,8 @@ public function buildFilters()
public function buildFields()
{
$this->addField('title', 'Title', true, 'KunstmaanNodeBundle:Admin:title.html.twig')
- ->addField('created', 'Created At', false)
- ->addField('updated', 'Updated At', false)
+ ->addField('created', 'Created At', true)
+ ->addField('updated', 'Updated At', true)
->addField('online', 'Online', true, 'KunstmaanNodeBundle:Admin:online.html.twig');
}
@@ -159,12 +162,12 @@ public function adaptQueryBuilder(QueryBuilder $queryBuilder)
{
parent::adaptQueryBuilder($queryBuilder);
- $queryBuilder->innerJoin('b.node', 'n', 'WITH', 'b.node = n.id');
- $queryBuilder->innerJoin('b.nodeVersions', 'nv', 'WITH', 'b.publicNodeVersion = nv.id');
- $queryBuilder->andWhere('b.lang = :lang');
- $queryBuilder->andWhere('n.deleted = 0');
- $queryBuilder->addOrderBy("nv.updated", "DESC");
- $queryBuilder->setParameter('lang', $this->locale);
+ $queryBuilder
+ ->select('b,n')
+ ->innerJoin('b.node', 'n', 'WITH', 'b.node = n.id')
+ ->andWhere('b.lang = :lang')
+ ->andWhere('n.deleted = 0')
+ ->addOrderBy('b.updated', 'DESC')
+ ->setParameter('lang', $this->locale);
}
-
}
diff --git a/src/Kunstmaan/NodeBundle/Changelog.md b/src/Kunstmaan/NodeBundle/Changelog.md
index 860feb4d71..3655f4efb1 100644
--- a/src/Kunstmaan/NodeBundle/Changelog.md
+++ b/src/Kunstmaan/NodeBundle/Changelog.md
@@ -1,7 +1,16 @@
# Changelog
+### dev (2014-09-23)
+
+* Created and updated timestamps were added to node translations. The updated timestamp will only be modified when a
+change on the public version of a page is saved or a draft is published.
+
+* The kuma:nodes:fix-timestamps command was added to initialize the created and updated timestamps for existing sites.
+
### dev (2012-08-30)
+
* Support for ACL permissions instead of our own custom implementation.
### dev (2012-08-24)
+
* Added the functionality to configure the page action menus. (see Resources/doc/configurable_action_menu.md on how to use this)
diff --git a/src/Kunstmaan/NodeBundle/Command/FixTimestampsCommand.php b/src/Kunstmaan/NodeBundle/Command/FixTimestampsCommand.php
new file mode 100644
index 0000000000..5dbe4d5254
--- /dev/null
+++ b/src/Kunstmaan/NodeBundle/Command/FixTimestampsCommand.php
@@ -0,0 +1,50 @@
+setName('kuma:nodes:fix-timestamps')
+ ->setDescription('Update timestamps for all node translations.')
+ ->setHelp("The kuma:nodes:fix-timestamps will loop over all node translation entries and update the timestamps for the entries.");
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ $em = $this->getContainer()->get('doctrine.orm.entity_manager');
+
+ $db = $em->getConnection();
+ $db->beginTransaction();
+ try {
+ $sql = <<exec($sql);
+ $db->commit();
+ $output->writeln('Updated all node translation timestamps');
+ } catch (DBALException $e) {
+ $db->rollBack();
+ $output->writeln('An error occured while updating the node translation timestamps');
+ $output->writeln('' . $e->getMessage() . '');
+ }
+ }
+}
diff --git a/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php b/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php
index ee39b3aac7..afcd86d05f 100644
--- a/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php
+++ b/src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php
@@ -549,8 +549,11 @@ public function editAction($id, $subaction)
if ($isStructureNode) {
$nodeTranslation->setSlug('');
}
- $this->em->persist($nodeTranslation);
$nodeVersion->setUpdated(new DateTime());
+ if ($nodeVersion->getType() == 'public') {
+ $nodeTranslation->setUpdated($nodeVersion->getUpdated());
+ }
+ $this->em->persist($nodeTranslation);
$this->em->persist($nodeVersion);
$tabPane->persist($this->em);
$this->em->flush();
diff --git a/src/Kunstmaan/NodeBundle/Entity/NodeTranslation.php b/src/Kunstmaan/NodeBundle/Entity/NodeTranslation.php
index 22e161c4a6..cf0890e330 100644
--- a/src/Kunstmaan/NodeBundle/Entity/NodeTranslation.php
+++ b/src/Kunstmaan/NodeBundle/Entity/NodeTranslation.php
@@ -89,12 +89,28 @@ class NodeTranslation extends AbstractEntity
*/
protected $weight;
+ /**
+ * @var \DateTime
+ *
+ * @ORM\Column(type="datetime", nullable=true)
+ */
+ protected $created;
+
+ /**
+ * @var \DateTime
+ *
+ * @ORM\Column(type="datetime", nullable=true)
+ */
+ protected $updated;
+
/**
* contructor
*/
public function __construct()
{
$this->nodeVersions = new ArrayCollection();
+ $this->setCreated(new \DateTime());
+ $this->setUpdated(new \DateTime());
}
/**
@@ -356,32 +372,6 @@ public function getRef(EntityManager $em, $type = "public")
return null;
}
- /**
- * Returns the date the first node version was created
- *
- * @return \DateTime
- */
- public function getCreated()
- {
- $versions = $this->getNodeVersions();
- $firstVersion = $versions->first();
-
- return $firstVersion->getCreated();
- }
-
- /**
- * Returns the date the last node version was updated
- *
- * @return mixed
- */
- public function getUpdated()
- {
- $versions = $this->getNodeVersions();
- $lastVersion = $versions->last();
-
- return $lastVersion->getUpdated();
- }
-
/**
* @param string $url
*
@@ -422,4 +412,43 @@ public function getWeight()
return $this->weight;
}
+ /**
+ * @return \DateTime
+ */
+ public function getCreated()
+ {
+ return $this->created;
+ }
+
+ /**
+ * @param \DateTime $created
+ *
+ * @return NodeTranslation
+ */
+ public function setCreated($created)
+ {
+ $this->created = $created;
+
+ return $this;
+ }
+
+ /**
+ * @return \DateTime
+ */
+ public function getUpdated()
+ {
+ return $this->updated;
+ }
+
+ /**
+ * @param \DateTime $updated
+ *
+ * @return NodeTranslation
+ */
+ public function setUpdated($updated)
+ {
+ $this->updated = $updated;
+
+ return $this;
+ }
}
diff --git a/src/Kunstmaan/NodeBundle/Helper/NodeAdmin/NodeAdminPublisher.php b/src/Kunstmaan/NodeBundle/Helper/NodeAdmin/NodeAdminPublisher.php
index 238df7089f..e8342b4cb9 100644
--- a/src/Kunstmaan/NodeBundle/Helper/NodeAdmin/NodeAdminPublisher.php
+++ b/src/Kunstmaan/NodeBundle/Helper/NodeAdmin/NodeAdminPublisher.php
@@ -38,7 +38,9 @@ class NodeAdminPublisher
*/
private $eventDispatcher;
- /** @var CloneHelper */
+ /**
+ * @var CloneHelper
+ */
private $cloneHelper;
/**
@@ -46,12 +48,16 @@ class NodeAdminPublisher
* @param SecurityContextInterface $securityContext The security context
* @param EventDispatcherInterface $eventDispatcher The Event dispatcher
*/
- public function __construct(EntityManager $em, SecurityContextInterface $securityContext, EventDispatcherInterface $eventDispatcher, $cloneHelper)
- {
- $this->em = $em;
+ public function __construct(
+ EntityManager $em,
+ SecurityContextInterface $securityContext,
+ EventDispatcherInterface $eventDispatcher,
+ $cloneHelper
+ ) {
+ $this->em = $em;
$this->securityContext = $securityContext;
$this->eventDispatcher = $eventDispatcher;
- $this->cloneHelper = $cloneHelper;
+ $this->cloneHelper = $cloneHelper;
}
/**
@@ -63,7 +69,7 @@ public function __construct(EntityManager $em, SecurityContextInterface $securit
*/
public function publish(NodeTranslation $nodeTranslation, $user = null)
{
- if (false === $this->securityContext->isGranted(PermissionMap::PERMISSION_PUBLISH, $nodeTranslation->getNode())) {
+ if (false === $this->securityContext->isGranted(PermissionMap::PERMISSION_PUBLISH,$nodeTranslation->getNode())) {
throw new AccessDeniedException();
}
@@ -77,26 +83,32 @@ public function publish(NodeTranslation $nodeTranslation, $user = null)
if (!is_null($nodeVersion) && $nodeTranslation->isOnline()) {
$page = $nodeVersion->getRef($this->em);
/** @var $nodeVersion NodeVersion */
- $nodeVersion = $this->createPublicVersion($page, $nodeTranslation, $nodeVersion, $user);
+ $nodeVersion = $this->createPublicVersion($page, $nodeTranslation, $nodeVersion, $user);
$nodeTranslation = $nodeVersion->getNodeTranslation();
- }else {
+ } else {
$nodeVersion = $nodeTranslation->getPublicNodeVersion();
}
$page = $nodeVersion->getRef($this->em);
- $this->eventDispatcher->dispatch(Events::PRE_PUBLISH, new NodeEvent($node, $nodeTranslation, $nodeVersion, $page));
-
- $nodeTranslation->setOnline(true);
- $nodeTranslation->setPublicNodeVersion($nodeVersion);
-
+ $this->eventDispatcher->dispatch(
+ Events::PRE_PUBLISH,
+ new NodeEvent($node, $nodeTranslation, $nodeVersion, $page)
+ );
+ $nodeTranslation
+ ->setOnline(true)
+ ->setPublicNodeVersion($nodeVersion)
+ ->setUpdated(new \DateTime());
$this->em->persist($nodeTranslation);
$this->em->flush();
// Remove scheduled task
$this->unSchedulePublish($nodeTranslation);
- $this->eventDispatcher->dispatch(Events::POST_PUBLISH, new NodeEvent($node, $nodeTranslation, $nodeVersion, $page));
+ $this->eventDispatcher->dispatch(
+ Events::POST_PUBLISH,
+ new NodeEvent($node, $nodeTranslation, $nodeVersion, $page)
+ );
}
/**
@@ -115,13 +127,13 @@ public function publishLater(NodeTranslation $nodeTranslation, \DateTime $date)
//remove existing first
$this->unSchedulePublish($nodeTranslation);
- $user = $this->securityContext->getToken()->getUser();
+ $user = $this->securityContext->getToken()->getUser();
$queuedNodeTranslationAction = new QueuedNodeTranslationAction();
$queuedNodeTranslationAction
- ->setNodeTranslation($nodeTranslation)
- ->setAction(QueuedNodeTranslationAction::ACTION_PUBLISH)
- ->setUser($user)
- ->setDate($date);
+ ->setNodeTranslation($nodeTranslation)
+ ->setAction(QueuedNodeTranslationAction::ACTION_PUBLISH)
+ ->setUser($user)
+ ->setDate($date);
$this->em->persist($queuedNodeTranslationAction);
$this->em->flush();
}
@@ -133,25 +145,29 @@ public function publishLater(NodeTranslation $nodeTranslation, \DateTime $date)
*/
public function unPublish(NodeTranslation $nodeTranslation)
{
- if (false === $this->securityContext->isGranted(PermissionMap::PERMISSION_UNPUBLISH, $nodeTranslation->getNode())) {
+ if (false === $this->securityContext->isGranted(PermissionMap::PERMISSION_UNPUBLISH,$nodeTranslation->getNode())) {
throw new AccessDeniedException();
}
- $node = $nodeTranslation->getNode();
+ $node = $nodeTranslation->getNode();
$nodeVersion = $nodeTranslation->getPublicNodeVersion();
- $page = $nodeVersion->getRef($this->em);
-
- $this->eventDispatcher->dispatch(Events::PRE_UNPUBLISH, new NodeEvent($node, $nodeTranslation, $nodeVersion, $page));
+ $page = $nodeVersion->getRef($this->em);
+ $this->eventDispatcher->dispatch(
+ Events::PRE_UNPUBLISH,
+ new NodeEvent($node, $nodeTranslation, $nodeVersion, $page)
+ );
$nodeTranslation->setOnline(false);
-
$this->em->persist($nodeTranslation);
$this->em->flush();
// Remove scheduled task
$this->unSchedulePublish($nodeTranslation);
- $this->eventDispatcher->dispatch(Events::POST_UNPUBLISH, new NodeEvent($node, $nodeTranslation, $nodeVersion, $page));
+ $this->eventDispatcher->dispatch(
+ Events::POST_UNPUBLISH,
+ new NodeEvent($node, $nodeTranslation, $nodeVersion, $page)
+ );
}
/**
@@ -169,14 +185,13 @@ public function unPublishLater(NodeTranslation $nodeTranslation, \DateTime $date
//remove existing first
$this->unSchedulePublish($nodeTranslation);
-
- $user = $this->securityContext->getToken()->getUser();
+ $user = $this->securityContext->getToken()->getUser();
$queuedNodeTranslationAction = new QueuedNodeTranslationAction();
$queuedNodeTranslationAction
- ->setNodeTranslation($nodeTranslation)
- ->setAction(QueuedNodeTranslationAction::ACTION_UNPUBLISH)
- ->setUser($user)
- ->setDate($date);
+ ->setNodeTranslation($nodeTranslation)
+ ->setAction(QueuedNodeTranslationAction::ACTION_UNPUBLISH)
+ ->setUser($user)
+ ->setDate($date);
$this->em->persist($queuedNodeTranslationAction);
$this->em->flush();
}
@@ -187,7 +202,8 @@ public function unPublishLater(NodeTranslation $nodeTranslation, \DateTime $date
public function unSchedulePublish(NodeTranslation $nodeTranslation)
{
/* @var Node $node */
- $queuedNodeTranslationAction = $this->em->getRepository('KunstmaanNodeBundle:QueuedNodeTranslationAction')->findOneBy(array('nodeTranslation' => $nodeTranslation));
+ $queuedNodeTranslationAction = $this->em->getRepository('KunstmaanNodeBundle:QueuedNodeTranslationAction')
+ ->findOneBy(array('nodeTranslation' => $nodeTranslation));
if (!is_null($queuedNodeTranslationAction)) {
$this->em->remove($queuedNodeTranslationAction);
@@ -205,23 +221,38 @@ public function unSchedulePublish(NodeTranslation $nodeTranslation)
*
* @return mixed
*/
- public function createPublicVersion(HasNodeInterface $page, NodeTranslation $nodeTranslation, NodeVersion $nodeVersion, BaseUser $user)
- {
- $newPublicPage = $this->cloneHelper->deepCloneAndSave($page);
- $newNodeVersion = $this->em->getRepository('KunstmaanNodeBundle:NodeVersion')->createNodeVersionFor($newPublicPage, $nodeTranslation, $user, $nodeVersion);
-
- $newNodeVersion->setOwner($nodeVersion->getOwner());
- $newNodeVersion->setUpdated($nodeVersion->getUpdated());
- $newNodeVersion->setCreated($nodeVersion->getCreated());
- $nodeVersion->setOwner($user);
- $nodeVersion->setCreated(new \DateTime());
- $nodeVersion->setOrigin($newNodeVersion);
+ public function createPublicVersion(
+ HasNodeInterface $page,
+ NodeTranslation $nodeTranslation,
+ NodeVersion $nodeVersion,
+ BaseUser $user
+ ) {
+ $newPublicPage = $this->cloneHelper->deepCloneAndSave($page);
+ $newNodeVersion = $this->em->getRepository('KunstmaanNodeBundle:NodeVersion')->createNodeVersionFor(
+ $newPublicPage,
+ $nodeTranslation,
+ $user,
+ $nodeVersion
+ );
+
+ $newNodeVersion
+ ->setOwner($nodeVersion->getOwner())
+ ->setUpdated($nodeVersion->getUpdated())
+ ->setCreated($nodeVersion->getCreated());
+
+ $nodeVersion
+ ->setOwner($user)
+ ->setCreated(new \DateTime())
+ ->setOrigin($newNodeVersion);
$this->em->persist($newNodeVersion);
$this->em->persist($nodeVersion);
$this->em->persist($nodeTranslation);
$this->em->flush();
- $this->eventDispatcher->dispatch(Events::CREATE_PUBLIC_VERSION, new NodeEvent($nodeTranslation->getNode(), $nodeTranslation, $nodeVersion, $newPublicPage));
+ $this->eventDispatcher->dispatch(
+ Events::CREATE_PUBLIC_VERSION,
+ new NodeEvent($nodeTranslation->getNode(), $nodeTranslation, $nodeVersion, $newPublicPage)
+ );
return $newNodeVersion;
}