Skip to content

Commit

Permalink
🎨 tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
carbontwelve committed Nov 23, 2017
1 parent 49b9b55 commit 6e87308
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 42 deletions.
21 changes: 14 additions & 7 deletions src/Entities/ContentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,44 @@ class ContentType
{
/**
* @var int
* @Id @Column(type="integer") @GeneratedValue */
* @Id @Column(type="integer") @GeneratedValue
*/
private $id;

/**
* @var Environment
* @ManyToOne(targetEntity="Environment") */
* @ManyToOne(targetEntity="Environment")
*/
private $environment;

/**
* @var string
* @Column(type="string") */
* @Column(type="string")
*/
private $name;

/**
* @var string
* @Column(type="string") */
* @Column(type="string")
*/
private $path;

/**
* @var string
* @Column(type="string") */
* @Column(type="string")
*/
private $template;

/**
* @var string
* @Column(type="string") */
* @Column(type="string")
*/
private $permalink;

/**
* @var bool
* @Column(type="boolean") */
* @Column(type="boolean")
*/
private $enabled;

/**
Expand Down
6 changes: 4 additions & 2 deletions src/Entities/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public function getContentTypes()
return $this->contentTypes;
}

public function addContentType(ContentType $contentType) {
public function addContentType(ContentType $contentType)
{
$this->contentTypes[] = $contentType;
}

Expand All @@ -52,7 +53,8 @@ public function getFiles()
return $this->files;
}

public function addFile(File $file) {
public function addFile(File $file)
{
$this->files[] = $file;
}
}
3 changes: 2 additions & 1 deletion src/Entities/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ public function setEnvironment(Environment $environment)
$this->environment = $environment;
}

public function addFrontMatter(FrontMatter $frontMatter) {
public function addFrontMatter(FrontMatter $frontMatter)
{
if ($this->frontMatter->contains($frontMatter)) {
return;
}
Expand Down
9 changes: 6 additions & 3 deletions src/Entities/FrontMatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@ class FrontMatter
{
/**
* @var int
* @Id @Column(type="integer") @GeneratedValue */
* @Id @Column(type="integer") @GeneratedValue
*/
private $id;

/**
* @var string
* @Column(type="string") */
* @Column(type="string")
*/
private $name;

/**
* @var string
* @Column(type="string") */
* @Column(type="string")
*/
private $value;

/** @ManyToOne(targetEntity="File") */
Expand Down
9 changes: 6 additions & 3 deletions src/Entities/Taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ class Taxonomy
/**
* @var int
*
* @Id @Column(type="integer") @GeneratedValue */
* @Id @Column(type="integer") @GeneratedValue
*/
private $id;

/**
* @var string
*
* @Column(type="string") */
* @Column(type="string")
*/
private $name;


Expand Down Expand Up @@ -74,7 +76,8 @@ public function getContentType()
return $this->contentType;
}

public function setContentType(ContentType $contentType) {
public function setContentType(ContentType $contentType)
{
$this->contentType = $contentType;
}

Expand Down
12 changes: 5 additions & 7 deletions src/Exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,18 @@

use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use PDO;
use Symfony\Component\Console\Output\OutputInterface;
use Tapestry\Entities\Collections\FlatCollection;
use Tapestry\Entities\Project;
use Doctrine\DBAL\Connection;
use Tapestry\Modules\ContentTypes\ContentTypeFactory;
use Tapestry\Tapestry;
use TapestryCloud\Database\Entities\ContentType;
use TapestryCloud\Database\Entities\Environment;
use TapestryCloud\Database\Entities\File;
use TapestryCloud\Database\Synchronizes\ContentTypes;
use TapestryCloud\Database\Synchronizes\Files;
use TapestryCloud\Database\Hydrators\File as FileHydrator;

class Exporter {
class Exporter
{
/**
* @var EntityManagerInterface|EntityManager
*/
Expand All @@ -40,7 +37,8 @@ public function __construct(EntityManagerInterface $entityManager, Tapestry $tap

}

public function export(Project $project) {
public function export(Project $project)
{

$this->output->writeln('[$] Syncing with database.');

Expand All @@ -53,7 +51,7 @@ public function export(Project $project) {
/** @var array $cmdOptions */
$cmdOptions = $project->get('cmd_options');

if (! $environment = $this->entityManager->getRepository(Environment::class)->findOneBy(['name' => $cmdOptions['env']])) {
if (!$environment = $this->entityManager->getRepository(Environment::class)->findOneBy(['name' => $cmdOptions['env']])) {
$environment = new Environment();
$environment->setName($cmdOptions['env']);
$this->entityManager->persist($environment);
Expand Down
6 changes: 3 additions & 3 deletions src/Hydrators/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class File extends Hydrator
* @param \Tapestry\Entities\File $file
* @param Environment|null $environment
*/
public function hydrate(Model $model, \Tapestry\Entities\File $file, Environment $environment = null)
public function hydrate(Model $model, \Tapestry\Entities\File $file, Environment $environment = null)
{
$model->setUid($file->getUid());
$model->setLastModified($file->getLastModified());
Expand All @@ -27,10 +27,10 @@ public function hydrate(Model $model, \Tapestry\Entities\File $file, Environmen
$model->setPath($file->getPath());
$model->setToCopy($file->isToCopy());

if (! $file->isToCopy()) {
if (!$file->isToCopy()) {
$frontMatter = new TapestryFrontMatter($file->getFileContent());
$model->setContent($frontMatter->getContent());
foreach($frontMatter->getData() as $key => $value) {
foreach ($frontMatter->getData() as $key => $value) {
$fmRecord = new FrontMatter();
$fmRecord->setName($key);
$fmRecord->setValue(json_encode($value));
Expand Down
12 changes: 5 additions & 7 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

namespace TapestryCloud\Database;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;
use Doctrine\ORM\EntityManager;
Expand All @@ -19,6 +20,7 @@ class ServiceProvider extends AbstractServiceProvider implements BootableService
EntityManagerInterface::class,
Connection::class
];

/**
* Use the register method to register items with the container via the
* protected $this->container property or the `getContainer` method
Expand All @@ -29,13 +31,13 @@ class ServiceProvider extends AbstractServiceProvider implements BootableService
public function register()
{

$this->getContainer()->add(Connection::class, function() {
$this->getContainer()->add(Connection::class, function () {
/** @var Configuration $configuration */
$configuration = $this->getContainer()->get(Configuration::class);
return DriverManager::getConnection($configuration->get('plugins.database', []), new \Doctrine\DBAL\Configuration());
});

$this->getContainer()->add(EntityManagerInterface::class, function() {
$this->getContainer()->add(EntityManagerInterface::class, function () {
/** @var Configuration $configuration */
$configuration = $this->getContainer()->get(Configuration::class);

Expand All @@ -49,12 +51,8 @@ public function register()
)
);
});

// $this->getContainer()->add(Exporter::class, function() {
//
// return new Exporter();
// });
}

/**
* Method will be invoked on registration of a service provider implementing
* this interface. Provides ability for eager loading of Service Providers.
Expand Down
18 changes: 10 additions & 8 deletions src/Synchronizes/ContentTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ public function __construct(EntityManagerInterface $em)
$this->em = $em;
}

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()])){
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()])) {
// INSERT
$record = new ContentType();
$record->hydrate($contentType, $environment);
Expand All @@ -49,9 +50,10 @@ public function sync(ContentTypeFactory $contentTypeFactory, Environment $enviro
* @param TapestryTaxonomy[] $taxonomies
* @param Environment $environment
*/
private function syncTaxonomyToContentType(ContentType $contentType, array $taxonomies, Environment $environment) {
private function syncTaxonomyToContentType(ContentType $contentType, array $taxonomies, Environment $environment)
{
/** @var TapestryTaxonomy $taxonomy */
foreach($taxonomies as $taxonomy) {
foreach ($taxonomies as $taxonomy) {
if (!$record = $this->em->getRepository(Taxonomy::class)->findOneBy(['name' => $taxonomy->getName()])) {
$record = new Taxonomy();
$record->hydrate($taxonomy);
Expand All @@ -64,7 +66,7 @@ private function syncTaxonomyToContentType(ContentType $contentType, array $taxo
}

foreach ($taxonomy->getFileList() as $classification => $files) {
if (! $classificationRecord = $this->em->getRepository(Classification::class)->findOneBy(['name' => $classification])){
if (!$classificationRecord = $this->em->getRepository(Classification::class)->findOneBy(['name' => $classification])) {
$classificationRecord = new Classification();
$classificationRecord->setName($classification);
$this->em->persist($classificationRecord);
Expand All @@ -73,9 +75,9 @@ private function syncTaxonomyToContentType(ContentType $contentType, array $taxo
$classificationRecord->addTaxonomy($record);
$this->em->flush();

foreach(array_keys($files) as $filename) {
foreach (array_keys($files) as $filename) {
/** @var File $file */
if ($file = $this->em->getRepository(File::class)->findOneBy(['uid' => $filename, 'environment' => $environment->getId()])){
if ($file = $this->em->getRepository(File::class)->findOneBy(['uid' => $filename, 'environment' => $environment->getId()])) {
$file->addClassification($classificationRecord);
$this->em->persist($file);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Synchronizes/Files.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public function __construct(EntityManagerInterface $em, FileHydrator $fileHydrat
$this->fileHydrator = $fileHydrator;
}

public function sync(FlatCollection $files, Environment $environment) {
public function sync(FlatCollection $files, Environment $environment)
{

/** @var TapestryFile $file */
foreach ($files as $file) {
Expand Down

0 comments on commit 6e87308

Please sign in to comment.