Skip to content

Commit

Permalink
Add methods to refresh resource and location
Browse files Browse the repository at this point in the history
  • Loading branch information
RandyCupic committed Oct 15, 2023
1 parent f2a7935 commit 46eac9d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
22 changes: 22 additions & 0 deletions lib/API/Values/RemoteResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,4 +349,26 @@ public function getLocations(): Collection|array
{
return $this->locations;
}

public function refresh(self $remoteResource): self
{
$this
->setRemoteId($remoteResource->getRemoteId())
->setType($remoteResource->getType())
->setUrl($remoteResource->getUrl())
->setName($remoteResource->getName())
->setOriginalFilename($remoteResource->getOriginalFilename())
->setVersion($remoteResource->getVersion())
->setFolder($remoteResource->getFolder())
->setVisibility($remoteResource->getVisibility())
->setSize($remoteResource->getSize())
->setAltText($remoteResource->getAltText())
->setCaption($remoteResource->getCaption())
->setTags($remoteResource->getTags())
->setMd5($remoteResource->getMd5())
->setMetadata($remoteResource->getMetadata())
->setContext($remoteResource->getContext());

return $this;
}
}
8 changes: 8 additions & 0 deletions lib/API/Values/RemoteResourceLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,12 @@ public function setWatermarkText(?string $waterMarkText): self

return $this;
}

public function refresh(self $remoteResourceLocation): self
{
$this->remoteResource = $remoteResourceLocation->getRemoteResource();
$this->setSource($remoteResourceLocation->getSource());
$this->setCropSettings($remoteResourceLocation->getCropSettings());
$this->setWatermarkText($remoteResourceLocation->getWatermarkText());

Check failure on line 92 in lib/API/Values/RemoteResourceLocation.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Netgen\RemoteMedia\API\Values\RemoteResourceLocation::refresh() should return Netgen\RemoteMedia\API\Values\RemoteResourceLocation but return statement is missing.
}
}
11 changes: 2 additions & 9 deletions lib/Core/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,8 @@ public function store(RemoteResource $resource): RemoteResource
return $resource;
}

$existingResource
->setType($resource->getType())
->setUrl($resource->getUrl())
->setSize($resource->getSize())
->setAltText($resource->getAltText())
->setCaption($resource->getCaption())
->setTags($resource->getTags())
->setMetadata($resource->getMetadata())
->setUpdatedAt($this->dateTimeFactory->createCurrent());
$existingResource->refresh($resource);
$existingResource->setUpdatedAt($this->dateTimeFactory->createCurrent());

$this->entityManager->persist($existingResource);
$this->entityManager->flush();
Expand Down

0 comments on commit 46eac9d

Please sign in to comment.