public function saveentry() { $collection = $this->param("collection", null); $entry = $this->param("entry", null); if ($collection && $entry) { $entry["modified"] = time(); $entry["_uid"] = @$this->user["_id"]; $col = "collection" . $collection["_id"]; // Check for uniqueeness of fields set as unique foreach ($collection["fields"] as $fieldDefinition) { $slugName = $fieldDefinition["name"] . "_slug"; if (!empty($fieldDefinition["slug"]) && !empty($fieldDefinition["unique"]) && isset($entry[$slugName])) { $collision = $this->app->db->findOne("collections/{$col}", [$slugName => $entry[$slugName]]); if (!$collision) { continue; } // New and colliding or other entry if (!isset($entry["_id"]) || $entry["_id"] != $collision["_id"]) { $this->app->response->status = 409; return sprintf($this->app->helper("i18n")->get("There is already an entry in this collection with this slug for field '%s'."), $fieldDefinition["label"]); } } } if (!isset($entry["_id"])) { $entry["created"] = $entry["modified"]; } else { if ($this->param("createversion", null)) { $id = $entry["_id"]; $colid = $collection["_id"]; $this->app->helper("versions")->add("coentry:{$colid}-{$id}", $entry); } } $this->app->db->save("collections/{$col}", $entry); } return $entry ? json_encode($entry) : '{}'; }