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

[WIP][GeneratorBundle] Commands to generate new website skeleton and default pageparts #2512

Open
wants to merge 16 commits into
base: 6.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@
"kunstmaan/sensio-generator-bundle": "^3.2",
"doctrine/collections": "^1.6",
"symfony/deprecation-contracts": "^2.5|^3.0",
"pagerfanta/doctrine-dbal-adapter": "^2.7"
"pagerfanta/doctrine-dbal-adapter": "^2.7",
"symfony/maker-bundle": "^1.11"
},
"require-dev": {
"symfony/error-handler": "^4.4|^5.3",
Expand Down

Large diffs are not rendered by default.

63 changes: 61 additions & 2 deletions src/Kunstmaan/AdminBundle/Resources/ui/js/_pagepart-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,18 @@ kunstmaanbundles.pagepartEditor = function (window) {
}

var $targetContainer = $select.closest('.js-pp-container'),
requestUrl = $select.data('url');
requestUrl = $select.data('url'),
spacerPagePart = $('body').data('spacer-pp');

// Get necessary data
var pageClassName = $targetContainer.data('pageclassname'),
pageId = $targetContainer.data('pageid'),
context = $targetContainer.data('context'),
ppType = $select.val();

const allowAutoSpacer = $targetContainer.parent().parent().hasClass('js-auto-spacer');
var spacerAdded = false;

// Set Loading
kunstmaanbundles.appLoading.addLoading();

Expand All @@ -100,6 +104,7 @@ kunstmaanbundles.pagepartEditor = function (window) {
// Create a temporary node of the new PP
var $temp = $('<div>');
$temp.append(data);
const ppScope = $temp[0].lastElementChild.dataset.scope;

// Check if some javascript needs to be reinitialised for this PP
reInit($temp);
Expand All @@ -116,6 +121,13 @@ kunstmaanbundles.pagepartEditor = function (window) {
// Reset ajax-modals
kunstmaanbundles.ajaxModal.resetAjaxModals();

events.add.push(function() {
if (allowAutoSpacer && ppScope !== spacerPagePart.replace('\\', '') && !spacerAdded) {
addSpacer(requestUrl, pageClassName, pageId, context, spacerPagePart, $select);
spacerAdded = true;
}
});

executeEvent('add');
}
});
Expand All @@ -127,14 +139,18 @@ kunstmaanbundles.pagepartEditor = function (window) {
// Add
addPagePartExtended = function ($select) {
var $targetContainer = target.closest('.js-pp-container'),
requestUrl = target.data('url');
requestUrl = target.data('url'),
spacerPagePart = $('body').data('spacer-pp');

// Get necessary data
var pageClassName = $targetContainer.data('pageclassname'),
pageId = $targetContainer.data('pageid'),
context = $targetContainer.data('context'),
ppType = $select.data('pagepartclass');

const allowAutoSpacer = $targetContainer.parent().parent().hasClass('js-auto-spacer');
var spacerAdded = false;

// Set Loading
kunstmaanbundles.appLoading.addLoading();

Expand All @@ -161,6 +177,7 @@ kunstmaanbundles.pagepartEditor = function (window) {
// Create a temporary node of the new PP
var $temp = $('<div>');
$temp.append(data);
const ppScope = $temp[0].lastElementChild.dataset.scope;

// Check if some javascript needs to be reinitialised for this PP
reInit($temp);
Expand All @@ -177,13 +194,55 @@ kunstmaanbundles.pagepartEditor = function (window) {
// Reset ajax-modals
kunstmaanbundles.ajaxModal.resetAjaxModals();

events.add.push(function() {
if (allowAutoSpacer && ppScope !== spacerPagePart.replace('\\', '') && !spacerAdded) {
addSpacer(requestUrl, pageClassName, pageId, context, spacerPagePart, target);
spacerAdded = true;
}
});

executeEvent('add');
}
});

$('#' + $select.data('pagepartmodalname')).modal('hide');
};

addSpacer = function addSpacer(requestUrl, pageClassName, pageId, context, spacerPagePart, $select) {
$.ajax({
url: requestUrl,
data: {
'pageclassname': pageClassName,
'pageid': pageId,
'context': context,
'type': spacerPagePart,
},
async: true,
success: function (data) {
// Add PP
const elem = $select.closest('.js-sortable-item').after(data);

// Create a temporary node of the new PP
const $temp = $('<div>');
$temp.append(data);

// Check if some javascript needs to be reinitialised for this PP
reInit($temp);

// Remove Loading
kunstmaanbundles.appLoading.removeLoading();

// Enable leave-page modal
kunstmaanbundles.checkIfEdited.edited();

// Reinit custom selects
kunstmaanbundles.advancedSelect.init();

// Reset ajax-modals
kunstmaanbundles.ajaxModal.resetAjaxModals();
},
});
};

// Edit
editPagePart = function ($btn) {
Expand Down
31 changes: 27 additions & 4 deletions src/Kunstmaan/GeneratorBundle/Command/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Process\Process;

/**
Expand Down Expand Up @@ -57,6 +58,8 @@ protected function configure()
new InputOption('namespace', '', InputOption::VALUE_OPTIONAL, 'The namespace of the bundle to create (only for SF3)'),
new InputOption('dir', '', InputOption::VALUE_OPTIONAL, 'The directory where to create the bundle (only for SF3)'),
new InputOption('bundle-name', '', InputOption::VALUE_OPTIONAL, 'The optional bundle name (only for SF3)'),
new InputOption('new-cms-skeleton', '', InputOption::VALUE_NONE, 'Use the new cms skeleton and default pageparts'),
new InputOption('prefix', '', InputOption::VALUE_REQUIRED, 'The prefix to be used in the table name of the generated entities', ''),
]
)
);
Expand All @@ -83,14 +86,26 @@ protected function interact(InputInterface $input, OutputInterface $output)
$outputStyle->writeln('<info>Installing KunstmaanCms...</info>');
$outputStyle->writeln($this->getKunstmaanLogo());

if (Kernel::VERSION_ID < 40000 && $input->getOption('new-cms-skeleton')) {
$output->writeln('<error>The new cms skeleton and default pageparts are not supported on Symfony 3</error>');
$this->shouldStop = true;

return;
}

if (true !== $input->getOption('db-installed')) {
$this->shouldStop = !$this->assistant->askConfirmation('We need access to your database. Are the database credentials setup properly? (y/n)', 'y');
if ($this->shouldStop) {
return;
}
}

if (null === $input->getOption('demosite')) {
if ($input->getOption('demosite') && $input->getOption('new-cms-skeleton')) {
$this->assistant->writeSection('The demosite option is not available together with the new cms skeleton and default pageparts. Ignoring the demosite option..', 'bg=yellow;fg=black;options=bold');
$input->setOption('demosite', 'No');
}

if (null === $input->getOption('demosite') && false === $input->getOption('new-cms-skeleton')) {
$demoSiteOption = $this->assistant->askConfirmation('Do you want to create a "demosite"? (y/n)', 'n', '?', false);
$input->setOption('demosite', $demoSiteOption === true ? 'Yes' : 'No');
}
Expand Down Expand Up @@ -119,7 +134,9 @@ protected function execute(InputInterface $input, OutputInterface $output)

$this->initAssistant($input, $output);

$defaultSiteOptions = [];
$defaultSiteOptions = [
'--prefix' => $input->getOption('prefix'),
];
$defaultSiteOptions['--browsersync'] = 'https://myproject.dev';
if ($input->getOption('demosite') === 'Yes') {
$defaultSiteOptions['--articleoverviewpageparent'] = 'HomePage';
Expand All @@ -132,8 +149,14 @@ protected function execute(InputInterface $input, OutputInterface $output)

$this->executeCommand($output, 'kuma:generate:config');

if ($input->getOption('new-cms-skeleton')) {
$this->executeCommand($output, 'make:website-skeleton', $defaultSiteOptions);
$this->executeCommand($output, 'make:default-pageparts', $defaultSiteOptions);
} else {
$this->executeCommand($output, 'kuma:generate:default-site', $defaultSiteOptions);
}

$this
->executeCommand($output, 'kuma:generate:default-site', $defaultSiteOptions)
->executeCommand($output, 'doctrine:database:create')
->executeCommand($output, 'doctrine:schema:drop', ['--force' => true])
->executeCommand($output, 'doctrine:schema:create')
Expand All @@ -153,7 +176,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

protected function executeCommand(OutputInterface $output, $command, array $options = [], $separateProcess = false)
{
$options = array_merge(['--no-debug' => true], $options);
$options = array_merge(['--no-debug' => true, 'command' => $command], $options);

++$this->commandSteps;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ public function load(array $configs, ContainerBuilder $container)
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');
$loader->load('maker.yml');
}
}
19 changes: 19 additions & 0 deletions src/Kunstmaan/GeneratorBundle/Helper/DoctrineHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Kunstmaan\GeneratorBundle\Helper;


use Doctrine\Inflector\Inflector;
use Doctrine\Inflector\InflectorFactory;

/**
* @internal
*/
final class DoctrineHelper
{
public static function convertToTableName(string $className): string
{
$inflector = InflectorFactory::create()->build();
return $inflector->tableize($inflector->pluralize($className));
}
}
16 changes: 16 additions & 0 deletions src/Kunstmaan/GeneratorBundle/Helper/SymfonyVersionChecker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Kunstmaan\GeneratorBundle\Helper;

use Symfony\Component\HttpKernel\Kernel;

/**
* @internal
*/
final class SymfonyVersionChecker
{
public static function isSymfony4()
{
return Kernel::VERSION_ID >= 40000;
}
}