Small change to the timestamp

- Moved the timestamp generation for attributes and events that are
being saved and don't have one to Model->beforeValidate()
pull/217/head
iglocska 2013-06-07 10:24:03 +02:00
parent 58c00150ba
commit 7059eac08c
2 changed files with 20 additions and 5 deletions

View File

@ -426,7 +426,6 @@ class EventsController extends AppController {
// set these fields if the event is freshly created and not pushed from another instance.
// Moved out of if (!$fromXML), since we might get a restful event without the orgc/timestamp set
if (!isset ($data['Event']['timestamp'])) $data['Event']['timestamp'] = $date->getTimestamp();
if (!isset ($data['Event']['orgc'])) $data['Event']['orgc'] = $data['Event']['org'];
if ($fromXml) {
// FIXME FIXME chri: temporary workaround for unclear org, orgc, from
@ -522,7 +521,7 @@ class EventsController extends AppController {
$this->request->data['Event']['id'] = $existingEvent['Event']['id'];
if (isset($this->request->data['Event']['timestamp'])) {
if ($this->request->data['Event']['timestamp'] > $existingEvent['Event']['timestamp']) {
// Consider shadow attributes?
} else {
$saveEvent = false;
}
@ -1557,8 +1556,8 @@ class EventsController extends AppController {
//$saveEvent['Event']['id'] = $id;
$fieldList = array(
'Event' => array('published'),
'Attribute' => array('event_id', 'category', 'type', 'value', 'value1', 'value2', 'to_ids', 'uuid', 'private', 'cluster', 'communitie')
'Event' => array('published', 'timestamp'),
'Attribute' => array('event_id', 'category', 'type', 'value', 'value1', 'value2', 'to_ids', 'uuid', 'private', 'cluster', 'communitie', 'timestamp')
);
// Save it all
$saveResult = $this->Event->saveAssociated($saveEvent, array('validate' => true, 'fieldList' => $fieldList));

View File

@ -289,6 +289,16 @@ class Attribute extends AppModel {
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
'timestamp' => array(
'timestamp' => array(
'timestamp' => array('numeric'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
);
public function __construct($id = false, $table = null, $ds = null) {
@ -385,7 +395,6 @@ class Attribute extends AppModel {
$this->data['Attribute']['value2'] = '';
}
}
// update correlation... (only needed here if there's an update)
$this->__beforeSaveCorrelation($this->data['Attribute']);
// always return true after a beforeSave()
@ -486,6 +495,13 @@ class Attribute extends AppModel {
$this->data['Attribute']['uuid'] = String::uuid();
}
// generate timestamp if it doesn't exist
if (empty($this->data['Attribute']['timestamp'])) {
$date = new DateTime();
$this->data['Attribute']['timestamp'] = $date->getTimestamp();
}
// always return true, otherwise the object cannot be saved
return true;
}