Skip to content

Commit

Permalink
feature [CoreBundle] [DoctrineORMBundle] Add created / updated fields…
Browse files Browse the repository at this point in the history
… to content and user
  • Loading branch information
Franz Wilding committed Dec 19, 2019
1 parent feaeed3 commit 5c16c53
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 3 deletions.
48 changes: 48 additions & 0 deletions Content/BaseContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ abstract class BaseContent implements ContentInterface
*/
protected $deleted = null;

/**
* @var DateTime
*/
protected $created;

/**
* @var DateTime
*/
protected $updated;

/**
* Content constructor.
*
Expand All @@ -41,6 +51,8 @@ abstract class BaseContent implements ContentInterface
public function __construct(string $type)
{
$this->type = $type;
$this->created = new DateTime('now');
$this->updated = new DateTime('now');
}

/**
Expand Down Expand Up @@ -111,4 +123,40 @@ public function getDeleted(): ?DateTime
{
return $this->deleted;
}

/**
* @return DateTime
*/
public function getCreated(): DateTime
{
return $this->created;
}

/**
* @param DateTime $created
* @return self
*/
public function setCreated(DateTime $created): ContentInterface
{
$this->created = $created;
return $this;
}

/**
* @return DateTime
*/
public function getUpdated(): DateTime
{
return $this->updated;
}

/**
* @param DateTime $updated
* @return self
*/
public function setUpdated(DateTime $updated): ContentInterface
{
$this->updated = $updated;
return $this;
}
}
10 changes: 10 additions & 0 deletions Content/ContentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ public function getData() : array;
*/
public function getFieldData(string $fieldName) : ?FieldData;

/**
* @return DateTime
*/
public function getCreated() : DateTime;

/**
* @return DateTime
*/
public function getUpdated() : DateTime;

/**
* @return DateTime|null
*/
Expand Down
3 changes: 2 additions & 1 deletion Content/ContentManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,11 @@ public function revert(Domain $domain, ContentInterface $content, int $version)
* @param ContentInterface $content
* @param int $limit
* @param int $offset
* @param array $orderBy
*
* @return ContentRevisionInterface[]
*/
public function revisions(Domain $domain, ContentInterface $content, int $limit = 20, int $offset = 0) : array;
public function revisions(Domain $domain, ContentInterface $content, int $limit = 20, int $offset = 0, array $orderBy = ['version' => 'DESC']) : array;

/**
* Mark a content item as deleted (without persisting it).
Expand Down
21 changes: 21 additions & 0 deletions GraphQL/Resolver/Field/ContentMetaResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,29 @@ public function resolve($value, $args, $context, ResolveInfo $info) {
return $value->getId();

case 'deleted':

if(!$this->security->isGranted(ContentVoter::UPDATE, $value)) {
throw new ContentAccessDeniedException(sprintf('You need %s permission to see if this content is deleted.', ContentVoter::UPDATE));
}

return $value->getDeleted();

case 'created':

if(!$this->security->isGranted(ContentVoter::UPDATE, $value)) {
throw new ContentAccessDeniedException(sprintf('You need %s permission to see the creation date of this content.', ContentVoter::UPDATE));
}

return $value->getCreated();

case 'updated':

if(!$this->security->isGranted(ContentVoter::UPDATE, $value)) {
throw new ContentAccessDeniedException(sprintf('You need %s permission to see the update date of this content.', ContentVoter::UPDATE));
}

return $value->getUpdated();

case 'permissions':
$permissions = [];
foreach(ContentVoter::ENTITY_PERMISSIONS as $permission) {
Expand Down
2 changes: 1 addition & 1 deletion Query/ContentCriteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class ContentCriteria extends Criteria
{
const BASE_FIELDS = ['id', 'deleted'];
const BASE_FIELDS = ['id', 'created', 'updated', 'deleted'];

const NCONTAINS = 'NCONTAINS';

Expand Down
2 changes: 2 additions & 0 deletions Resources/GraphQL/Schema/unite-cms.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ type UniteContentMeta {
id: ID
version: Int!
revisions: [UniteContentRevision!]
created: DateTime!
updated: DateTime
deleted: DateTime
permissions: UniteContentEntityPermissions!
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/Mock/TestContentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function recover(Domain $domain, ContentInterface $content): ContentInter
/**
* {@inheritDoc}
*/
public function revisions(Domain $domain, ContentInterface $content, int $limit = 20, int $offset = 0): array {
public function revisions(Domain $domain, ContentInterface $content, int $limit = 20, int $offset = 0, array $orderBy = ['version' => 'DESC']): array {
return [];
}

Expand Down

0 comments on commit 5c16c53

Please sign in to comment.