Skip to content
This repository was archived by the owner on Dec 11, 2022. It is now read-only.

Commit c6fc7e5

Browse files
committed
Fixed problem with cdate and mdate on new property protection.
1 parent 3dbb009 commit c6fc7e5

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

examples/employee/Employee.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Employee extends Entity {
1919
const etype = 'employee';
2020
protected $protectedTags = array('employee');
2121
protected $whitelistTags = array('boss', 'bigcheese');
22-
protected $whitelistData = array('name', 'id', 'title', 'department', 'subordinates', 'salary', 'current', 'start_date', 'end_date', 'phone');
22+
protected $whitelistData = array('name', 'id', 'title', 'department', 'subordinates', 'salary', 'current', 'start_date', 'end_date', 'phone', 'manager');
2323

2424
public function __construct($id = 0) {
2525
$this->addTag('employee');

src/Entity.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,9 @@ public function jsonSerialize() {
566566
}
567567

568568
public function jsonAcceptTags($tags) {
569+
if ($this->isASleepingReference)
570+
$this->referenceWake();
571+
569572
$currentTags = $this->getTags();
570573
$protectedTags = array_intersect($this->protectedTags, $currentTags);
571574
$tags = array_diff($tags, $this->protectedTags);
@@ -579,6 +582,9 @@ public function jsonAcceptTags($tags) {
579582
}
580583

581584
public function jsonAcceptData($data) {
585+
if ($this->isASleepingReference)
586+
$this->referenceWake();
587+
582588
foreach ($this->objectData as $var) {
583589
if (isset($data[$var]) && (array) $data[$var] === $data) {
584590
$data[$var] = (object) $data[$var];
@@ -587,15 +593,15 @@ public function jsonAcceptData($data) {
587593

588594
$privateData = array();
589595
foreach ($this->privateData as $var) {
590-
if (key_exists($var, $this->data) || key_exists($var, $this->sdata) || $var === 'cdate' || $var === 'mdate')
596+
if (key_exists($var, $this->data) || key_exists($var, $this->sdata))
591597
$privateData[$var] = $this->$var;
592598
if (key_exists($var, $data))
593599
unset($data[$var]);
594600
}
595601

596602
$protectedData = array();
597603
foreach ($this->protectedData as $var) {
598-
if (key_exists($var, $this->data) || key_exists($var, $this->sdata) || $var === 'cdate' || $var === 'mdate')
604+
if (key_exists($var, $this->data) || key_exists($var, $this->sdata))
599605
$protectedData[$var] = $this->$var;
600606
if (key_exists($var, $data))
601607
unset($data[$var]);
@@ -610,14 +616,11 @@ public function jsonAcceptData($data) {
610616

611617
$data = array_merge($data, $protectedData, $privateData);
612618

613-
if (isset($data['cdate'])) {
614-
$this->cdate = $data['cdate'];
615-
unset($data['cdate']);
616-
}
617-
if (isset($data['mdate'])) {
618-
$this->mdate = $data['mdate'];
619-
unset($data['mdate']);
620-
}
619+
if (!isset($data['cdate']))
620+
$data['cdate'] = $this->cdate;
621+
if (!isset($data['mdate']))
622+
$data['mdate'] = $this->mdate;
623+
621624
$this->putData($data);
622625
}
623626

src/Interfaces.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,10 +420,11 @@ public function save();
420420
* even after deletion. It's the job of the entity manager to make sure no two
421421
* entities ever have the same GUID.
422422
*
423-
* Tags are used to classify entities. Though not strictly necessary, it is
424-
* *HIGHLY RECOMMENDED* to give every entity your component creates a tag
425-
* indentical to your component's name, such as 'com_xmlparser'. You don't want
426-
* to accidentally get another component's entities.
423+
* Tags are used to classify entities. Where an etype is used to separate data
424+
* by table, tags are used to separate entities within a table. You can define
425+
* specific tags to be protected, meaning they cannot be added/removed on the
426+
* frontend. It can be useful to allow user defined tags, such as for a blog
427+
* post.
427428
*
428429
* Simply calling delete() will not unset the entity. It will still take up
429430
* memory. Likewise, simply calling unset will not delete the entity from

0 commit comments

Comments
 (0)