JamesMoss\Flywheel\Repository::update PHP Method

update() public method

Store a Document in the repository, but only if it already exists. The document must have an ID.
public update ( JamesMoss\Flywheel\DocumentInterface $document ) : boolean
$document JamesMoss\Flywheel\DocumentInterface The document to store
return boolean True if stored, otherwise false
    public function update(DocumentInterface $document)
    {
        if (!$document->getId()) {
            return false;
        }
        $oldPath = $this->getPathForDocument($document->getInitialId());
        if (!file_exists($oldPath)) {
            return false;
        }
        // If the ID has changed we need to delete the old document.
        if ($document->getId() !== $document->getInitialId()) {
            if (file_exists($oldPath)) {
                unlink($oldPath);
            }
        }
        return $this->store($document);
    }

Usage Example

 /**
  * @param EncryptedWallet $wallet
  * @throws \Exception
  */
 public function update(EncryptedWallet $wallet)
 {
     $walletDocument = $this->walletToDocument($wallet);
     if (!$this->repository->update($walletDocument)) {
         // TODO: custom exception
         throw new \Exception("Error updating wallet repository");
     }
 }
All Usage Examples Of JamesMoss\Flywheel\Repository::update