/** * Renames the GridFS file with the specified ID. * * @param mixed $id File ID * @param string $newFilename New filename * * @throws FileNotFoundException */ public function rename($id, $newFilename) { $updateResult = $this->collectionWrapper->updateFilenameForId($id, $newFilename); if ($updateResult->getModifiedCount() === 1) { return; } /* If the update resulted in no modification, it's possible that the * file did not exist, in which case we must raise an error. Checking * the write result's matched count will be most efficient, but fall * back to a findOne operation if necessary (i.e. legacy writes). */ $found = $updateResult->getMatchedCount() !== null ? $updateResult->getMatchedCount() === 1 : $this->collectionWrapper->findFileById($id) !== null; if (!$found) { throw FileNotFoundException::byId($id, $this->getFilesNamespace()); } }