/** * {@inheritdoc} * * Override RestfulEntityBase::createEntity() to test if meter already exists, * to allow update existing nodes in stead of creating a copy. */ public function createEntity() { // Check if an electricity entity with the same parameters exists. $query = new EntityFieldQuery(); $result = $query->entityCondition('entity_type', 'electricity_raw')->propertyCondition('meter_nid', $this->request['meter'])->propertyCondition('timestamp', $this->request['timestamp'])->propertyCondition('meter_type', $this->request['meter_type'])->propertyCondition('rate_type', $this->request['rate_type'])->propertyCondition('frequency', $this->request['frequency'])->range(0, 1)->execute(); if (!empty($result['electricity_raw'])) { // Node exists, update it. $id = key($result['electricity_raw']); return parent::updateEntity($id); } // New node. return parent::createEntity(); }