-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Update QR-Code after Node-Publish
- Update the QR-Code Image after a node was published - Update Commands - Use an own Model for the QR-Code BREAKING CHANGE: new structure and updated dependencies with breaking change
- Loading branch information
Showing
10 changed files
with
377 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
namespace NextBox\Neos\QrCode\Domain\Model; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
use Neos\Flow\Annotations as Flow; | ||
use Neos\Flow\ResourceManagement\PersistentResource; | ||
use NextBox\Neos\UrlShortener\Domain\Model\UrlShortener; | ||
|
||
/** | ||
* @Flow\Entity | ||
*/ | ||
class QrCode | ||
{ | ||
/** | ||
* @ORM\OneToOne(cascade={"all"}) | ||
* @var UrlShortener | ||
*/ | ||
protected UrlShortener $urlShortener; | ||
|
||
/** | ||
* @ORM\OneToOne(cascade={"all"}) | ||
* @var PersistentResource|null | ||
*/ | ||
protected ?PersistentResource $resource = null; | ||
|
||
|
||
/** | ||
* Getter for urlShortener | ||
* | ||
* @return UrlShortener | ||
*/ | ||
public function getUrlShortener(): UrlShortener | ||
{ | ||
return $this->urlShortener; | ||
} | ||
|
||
/** | ||
* Setter for urlShortener | ||
* | ||
* @param UrlShortener $urlShortener | ||
* @return QrCode | ||
*/ | ||
public function setUrlShortener(UrlShortener $urlShortener): QrCode | ||
{ | ||
$this->urlShortener = $urlShortener; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Getter for resource | ||
* | ||
* @return PersistentResource|null | ||
*/ | ||
public function getResource(): ?PersistentResource | ||
{ | ||
return $this->resource; | ||
} | ||
|
||
/** | ||
* Setter for resource | ||
* | ||
* @param PersistentResource|null $resource | ||
* @return QrCode | ||
*/ | ||
public function setResource(?PersistentResource $resource): QrCode | ||
{ | ||
$this->resource = $resource; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace NextBox\Neos\QrCode\Domain\Repository; | ||
|
||
use Neos\Flow\Annotations as Flow; | ||
use Neos\Flow\Persistence\Repository; | ||
use NextBox\Neos\QrCode\Domain\Model\QrCode; | ||
use NextBox\Neos\UrlShortener\Domain\Model\UrlShortener; | ||
|
||
/** | ||
* @Flow\Scope("singleton") | ||
* | ||
* @method QrCode|null findOneByUrlShortener(UrlShortener $urlShortener) | ||
*/ | ||
class QrCodeRepository extends Repository | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
namespace NextBox\Neos\QrCode\Services; | ||
|
||
use Neos\ContentRepository\Domain\Model\NodeInterface; | ||
use Neos\Flow\Annotations as Flow; | ||
use NextBox\Neos\QrCode\Domain\Model\QrCode; | ||
use NextBox\Neos\QrCode\Domain\Repository\QrCodeRepository; | ||
use NextBox\Neos\UrlShortener\Domain\Model\UrlShortener; | ||
|
||
/** | ||
* @Flow\Scope("singleton") | ||
*/ | ||
class BackendService extends \NextBox\Neos\UrlShortener\Services\BackendService | ||
{ | ||
/** | ||
* @Flow\Inject | ||
* @var QrCodeService | ||
*/ | ||
protected $qrCodeService; | ||
|
||
/** | ||
* @Flow\Inject | ||
* @var QrCodeRepository | ||
*/ | ||
protected $qrCodeRepository; | ||
|
||
/** | ||
* @Flow\InjectConfiguration(path="shortTypes", package="NextBox.Neos.UrlShortener") | ||
* @var array | ||
*/ | ||
protected array $typeSettings; | ||
|
||
/** | ||
* Loop to update the short identifier or create a new entry | ||
* | ||
* @param NodeInterface $node | ||
* @return void | ||
*/ | ||
public function updateNode(NodeInterface $node): void | ||
{ | ||
foreach ($this->typeSettings as $shortType => $setting) { | ||
$nodeTypeName = $setting['nodeType']; | ||
$propertyName = $setting['property']; | ||
|
||
$this->handleQrCode($node, $shortType, $nodeTypeName, $propertyName); | ||
} | ||
} | ||
|
||
/** | ||
* Update the short identifier or create a new entry | ||
* | ||
* @param NodeInterface $node | ||
* @param string $shortType | ||
* @param string $nodeTypeName | ||
* @param string $propertyName | ||
* @return UrlShortener|null | ||
*/ | ||
protected function handleQrCode(NodeInterface $node, string $shortType, string $nodeTypeName, string $propertyName): ?QrCode | ||
{ | ||
$urlShortener = $this->handleUrlShortener($node, $shortType, $nodeTypeName, $propertyName); | ||
|
||
if (!$urlShortener instanceof UrlShortener) { | ||
return null; | ||
} | ||
|
||
$qrCode = $this->qrCodeService->getQrCodeOfUrlShortener($urlShortener); | ||
$this->qrCodeService->deleteQrCodeResource($qrCode); | ||
|
||
$resource = $this->qrCodeService->createFileForUrlShortener($urlShortener); | ||
$qrCode->setResource($resource); | ||
|
||
$this->qrCodeRepository->update($qrCode); | ||
|
||
return $qrCode; | ||
} | ||
} |
Oops, something went wrong.