Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DsServiceBundle] add ServiceLoadDataExtesion #57

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Ds/Bundle/ServiceBundle/.idea/ServiceBundle.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions src/Ds/Bundle/ServiceBundle/.idea/deployment.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions src/Ds/Bundle/ServiceBundle/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/Ds/Bundle/ServiceBundle/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

410 changes: 410 additions & 0 deletions src/Ds/Bundle/ServiceBundle/.idea/workspace.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
<?php

namespace Ds\Bundle\ServiceBundle\Migration\Extension;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Persistence\ObjectManager;
use Oro\Bundle\LocaleBundle\Entity\LocalizedFallbackValue;
use Symfony\Component\Yaml\Yaml;
use Ds\Bundle\ServiceBpmBundle\Entity\ServiceBpm;
use Oro\Bundle\LocaleBundle\Entity\Repository\LocalizationRepository;

/**
* Class ServiceExtension
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update documentation with correct class name.

*/
class ServiceBpmExtension
{
/**
* @var \Oro\Bundle\LocaleBundle\Entity\Repository\LocalizationRepository;
*/
protected $localizationRepository;

/**
* Constructor
*
* @param \Oro\Bundle\LocaleBundle\Entity\Repository\LocalizationRepository $localizationRepository
*/
public function __construct(LocalizationRepository $localizationRepository)
{
$this->localizationRepository = $localizationRepository;
}

/**
* Import resource
*
* @param string $resource
* @param \Doctrine\Common\Persistence\ObjectManager $objectManager
*/
public function import($resource, ObjectManager $objectManager)
{
$data = Yaml::parse(file_get_contents($resource));

foreach ($data['services'] as $item) {
if (array_key_exists('prototype', $data)) {
$item += $data['prototype'];
}
$serviceBpm = new ServiceBpm();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space missing after if condition.


#region TITLES
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Titles, Descriptions, Buttons and Presentations block could be refactored into one common block using some kind of loop.

//Set default Locale value
$localized = new LocalizedFallbackValue();
$localized->setText($item['titles']['0']['text']);
$titles = new ArrayCollection([$localized]);

//Set all others location in .yml file
foreach ($item['titles'] as $localeValue) {
//If location for title exists in .yml file
if ($localeValue['localization']) {
$locale = $localeValue['localization'];
$localization = $this->localizationRepository->findOneBy([ 'formattingCode' => $locale ]);
if ($localization) {
$localized = new LocalizedFallbackValue();
$localized->setText($localeValue['text']);
$localized->setLocalization($localization);
$titles->add($localized);
}
}
}
$serviceBpm->setTitles($titles);
#endregion Titles

#region DESCRIPTIONS
//Set default Locale value
$localized = new LocalizedFallbackValue();
$localized->setText($item['descriptions']['0']['text']);
$descriptions = new ArrayCollection([$localized]);

//Set all others location in .yml file
foreach ($item['descriptions'] as $localeValue) {
//If location for title exists in .yml file
if ($localeValue['localization']) {
$locale = $localeValue['localization'];
$localization = $this->localizationRepository->findOneBy([ 'formattingCode' => $locale ]);
if ($localization) {
$localized = new LocalizedFallbackValue();
$localized->setText($localeValue['text']);
$localized->setLocalization($localization);
$descriptions->add($localized);
}
}
}
$serviceBpm->setDescriptions($descriptions);
#endregion DESCRIPTIONS

$serviceBpm->setIcon($item['icon']);

#region BUTTONS
//Set default Locale value
$localized = new LocalizedFallbackValue();
$localized->setText($item['buttons']['0']['text']);
$buttons = new ArrayCollection([$localized]);

//Set all others location in .yml file
foreach ($item['buttons'] as $localeValue) {
//If location for title exists in .yml file
if ($localeValue['localization']) {
$locale = $localeValue['localization'];
$localization = $this->localizationRepository->findOneBy([ 'formattingCode' => $locale ]);
if ($localization) {
$localized = new LocalizedFallbackValue();
$localized->setText($localeValue['text']);
$localized->setLocalization($localization);
$buttons->add($localized);
}
}
}
$serviceBpm->setButtons($buttons);
#endregion BUTTONS

#region PRESENTATIONS
//Set default Locale value
$localized = new LocalizedFallbackValue();
$localized->setText($item['descriptions']['0']['text']);
$presentations = new ArrayCollection([$localized]);

//Set all others location in .yml file
foreach ($item['presentations'] as $localeValue) {
//If location for title exists in .yml file
if ($localeValue['localization']) {
$locale = $localeValue['localization'];
$localization = $this->localizationRepository->findOneBy([ 'formattingCode' => $locale ]);
if ($localization) {
$localized = new LocalizedFallbackValue();
$localized->setText($localeValue['text']);
$localized->setLocalization($localization);
$presentations->add($localized);
}
}
}
$serviceBpm->setPresentations($presentations);
#endregion PRESENTATIONS

$serviceBpm->setSlug($item['slug']);

#region OWNER
$owner = $objectManager
->getRepository('OroOrganizationBundle:BusinessUnit')
->findOneBy([ 'name' => $item['owner'] ]);

if (!$owner) {
throw new RuntimeException('Business unit does not exist.');
}

$serviceBpm->setOwner($owner);
#endregion OWNER

#region ORGANIZATION
$organization = $objectManager
->getRepository('OroOrganizationBundle:Organization')
->findOneBy([ 'name' => $item['organization'] ]);

if (!$organization) {
throw new RuntimeException('Organization does not exist.');
}

$serviceBpm->setOrganization($organization);
#endregion ORGANIZATION

$serviceBpm->setBpm($item['bpm']);

$serviceBpm->setBpmId($item['bpmId']);

$objectManager->persist($serviceBpm);
$objectManager->flush();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Ds\Bundle\ServiceBundle\Migration\Extension;

/**
* Interface ServiceBpmExtensionAwareInterface
*/
interface ServiceBpmExtensionAwareInterface
{
/**
* Sets the service Bpm extension
*
* @param \Ds\Bundle\ServiceBundle\Migration\Extension\ServiceBpmExtension $serviceBpmExtension
*/
public function setServiceBpmExtension(ServiceBpmExtension $serviceBpmExtension);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Ds\Bundle\ServiceBundle\Migration\Extension;

/**
* Trait ServiceBpmExtensionAwareTrait
*/
trait ServiceBpmExtensionAwareTrait
{
/**
* @var \Ds\Bundle\ServiceBundle\Migration\Extension\ServiceBpmExtension
*/
protected $serviceBpmExtension; # region accessors

/**
* Sets the service Bpm extension
*
* @param \Ds\Bundle\ServiceBundle\Migration\Extension\ServiceBpmExtension $serviceBpmExtension
*/
public function setServiceBpmExtension(ServiceBpmExtension $serviceBpmExtension)
{
$this->serviceBpmExtension = $serviceBpmExtension;
}

# endregion
}
Loading