-
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.
🎨 updated project structure and tidied code execution order
- Loading branch information
1 parent
0bc4888
commit 146969c
Showing
12 changed files
with
292 additions
and
50 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
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,29 @@ | ||
<?php | ||
|
||
namespace TapestryCloud\Database\Hydrators; | ||
|
||
use TapestryCloud\Database\Entities\Environment; | ||
use TapestryCloud\Database\Entities\ContentType as Model; | ||
|
||
class ContentType extends Hydrator | ||
{ | ||
/** | ||
* ContentType Hydration. | ||
* | ||
* @param Model $model | ||
* @param \Tapestry\Entities\ContentType $contentType | ||
* @param Environment|null $environment | ||
*/ | ||
public function hydrate(Model $model, \Tapestry\Entities\ContentType $contentType, Environment $environment = null) | ||
{ | ||
$model->setName($contentType->getName()); | ||
$model->setPath($contentType->getPath()); | ||
$model->setTemplate($contentType->getTemplate()); | ||
$model->setPermalink($contentType->getPermalink()); | ||
$model->setEnabled($contentType->isEnabled()); | ||
|
||
if (!is_null($environment)) { | ||
$model->setEnvironment($environment); | ||
} | ||
} | ||
} |
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,19 @@ | ||
<?php | ||
|
||
namespace TapestryCloud\Database\Hydrators; | ||
|
||
use TapestryCloud\Database\Entities\Taxonomy as Model; | ||
|
||
class Taxonomy extends Hydrator | ||
{ | ||
/** | ||
* Taxonomy Hydration. | ||
* | ||
* @param Model $model | ||
* @param \Tapestry\Entities\Taxonomy $taxonomy | ||
*/ | ||
public function hydrate(Model $model, \Tapestry\Entities\Taxonomy $taxonomy) | ||
{ | ||
$model->setName($taxonomy->getName()); | ||
} | ||
} |
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,60 @@ | ||
<?php | ||
|
||
namespace TapestryCloud\Database\Synchronizes; | ||
|
||
use Doctrine\ORM\EntityManagerInterface; | ||
use Tapestry\Entities\Taxonomy as TapestryTaxonomy; | ||
use Tapestry\Modules\ContentTypes\ContentTypeFactory; | ||
use TapestryCloud\Database\Entities\Classification; | ||
use TapestryCloud\Database\Entities\ContentType; | ||
use TapestryCloud\Database\Entities\Environment; | ||
use TapestryCloud\Database\Entities\File; | ||
use TapestryCloud\Database\Entities\Taxonomy; | ||
use TapestryCloud\Database\Hydrators\ContentType as ContentTypeHydrator; | ||
use TapestryCloud\Database\Hydrators\Taxonomy as TaxonomyHydrator; | ||
|
||
class ContentTypeSync | ||
{ | ||
/** | ||
* @var EntityManagerInterface | ||
*/ | ||
private $em; | ||
|
||
/** | ||
* @var ContentTypeHydrator | ||
*/ | ||
private $contentTypeHydrator; | ||
/** | ||
* @var TaxonomyHydrator | ||
*/ | ||
private $taxonomyHydrator; | ||
|
||
/** | ||
* ContentTypes constructor. | ||
* @param EntityManagerInterface $em | ||
* @param ContentTypeHydrator $contentTypeHydrator | ||
* @param TaxonomyHydrator $taxonomyHydrator | ||
*/ | ||
public function __construct( | ||
EntityManagerInterface $em, | ||
ContentTypeHydrator $contentTypeHydrator, | ||
TaxonomyHydrator $taxonomyHydrator | ||
){ | ||
$this->em = $em; | ||
$this->contentTypeHydrator = $contentTypeHydrator; | ||
$this->taxonomyHydrator = $taxonomyHydrator; | ||
} | ||
|
||
public function sync(ContentTypeFactory $contentTypeFactory, Environment $environment) | ||
{ | ||
foreach ($contentTypeFactory->all() as $contentType) { | ||
if (!$record = $this->em->getRepository(ContentType::class)->findOneBy(['name' => $contentType->getName(), 'environment' => $environment->getId()])) { | ||
$record = new ContentType(); | ||
} | ||
|
||
$this->contentTypeHydrator->hydrate($record, $contentType, $environment); | ||
$this->em->persist($record); | ||
} | ||
$this->em->flush(); | ||
} | ||
} |
Oops, something went wrong.