/** * Save the current item to the database. * * This will either create or update an existing item, using the Mongo upsert * functionality. It also sets time created (if new) and time updated. * * @param string|int $safe * Whether to conduct a safe upsert or not. * - Database::WRITE_SAFE: Safe. Returns status (default) * - Database::WRITE_UNSAFE: Not safe. Does not return status. * * @return array * Result of the Upsert */ public function save($safe = BaseQuery::WRITE_UNSAFE) { // Load a database. $this->invokeDatabaseConnection(); $this->vultan->useCollection($this->collection); // Set defaults. $this->setDefaultProperties(); $identifier = $this->getId(); if (!empty($identifier)) { return $this->vultan->upsert($this, array(), $safe); } else { return $this->vultan->insert($this, $safe); } }