Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add created and updated timestamps to node translations #16

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions src/Kunstmaan/NodeBundle/AdminList/NodeAdminListConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand All @@ -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');
}

Expand Down Expand Up @@ -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);
}

}
9 changes: 9 additions & 0 deletions src/Kunstmaan/NodeBundle/Changelog.md
Original file line number Diff line number Diff line change
@@ -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)
50 changes: 50 additions & 0 deletions src/Kunstmaan/NodeBundle/Command/FixTimestampsCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Kunstmaan\NodeBundle\Command;

use Doctrine\DBAL\DBALException;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class FixTimestampsCommand extends ContainerAwareCommand
{

/**
* {@inheritdoc}
*/
protected function configure()
{
parent::configure();

$this->setName('kuma:nodes:fix-timestamps')
->setDescription('Update timestamps for all node translations.')
->setHelp("The <info>kuma:nodes:fix-timestamps</info> 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 = <<<SQL
update kuma_node_translations nt
set nt.created=(select MIN(created) from kuma_node_versions nv where nv.node_translation_id=nt.id AND nv.type='public'),
nt.updated=(select MAX(updated) from kuma_node_versions nv where nv.node_translation_id=nt.id AND nv.type='public')
SQL;

$db->exec($sql);
$db->commit();
$output->writeln('Updated all node translation timestamps');
} catch (DBALException $e) {
$db->rollBack();
$output->writeln('<error>An error occured while updating the node translation timestamps</error>');
$output->writeln('<error>' . $e->getMessage() . '</error>');
}
}
}
5 changes: 4 additions & 1 deletion src/Kunstmaan/NodeBundle/Controller/NodeAdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
81 changes: 55 additions & 26 deletions src/Kunstmaan/NodeBundle/Entity/NodeTranslation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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;
}
}
Loading