public function updateMetaData(File $file) { $this->pdo->beginTransaction(); try { $query = $this->executeSql(' UPDATE files SET name = :name, path = :path, mime_type = :mime_type WHERE file_uuid = :file_uuid ', ['file_uuid' => $file->getUuid()->getBytes(), 'name' => $file->getName()->toString(), 'path' => $file->getPath()->toString(), 'mime_type' => $file->getMimeType()->toString()]); // When at least one of the fields changes, the rowCount will be 1 and an update occurred if ($query->rowCount() === 1) { $this->objectRepository->update(File::TYPE, $file->getUuid()); $file->metaDataSetUpdateTimestamp(new \DateTimeImmutable()); } $this->pdo->commit(); } catch (\Throwable $exception) { $this->pdo->rollBack(); throw $exception; } }
public function it_can_update_a_files_content(File $file) { $uuid = Uuid::uuid4(); $stream = tmpfile(); $file->getUuid()->willReturn($uuid); $file->getStream()->willReturn($stream); $file->metaDataSetUpdateTimestamp(new Argument\Token\TypeToken(\DateTimeInterface::class))->shouldBeCalled(); $this->fileSystem->putStream($uuid->toString(), $stream)->willReturn(true); $this->objectRepository->update(File::TYPE, $uuid)->shouldBeCalled(); $this->updateContent($file); // cleanup fclose($stream); }