-
Notifications
You must be signed in to change notification settings - Fork 7
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
4b8ed55
8e8d0a5
666b064
63d7df2
37cf646
5a0bbac
0c78128
13e8385
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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.
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.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 | ||
*/ | ||
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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Space missing after if condition. |
||
|
||
#region TITLES | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} |
There was a problem hiding this comment.
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.