Skip to content

Commit

Permalink
Merge pull request #13 from jorisros/master
Browse files Browse the repository at this point in the history
Translate the bundle from Pimcore 4 to Pimcore 5
  • Loading branch information
jorisros authored Jan 8, 2018
2 parents 4ccbaa1 + 5ba3393 commit dd36d65
Show file tree
Hide file tree
Showing 24 changed files with 131 additions and 162 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Fixtures\Alice\Persister;
namespace FixtureBundle\Alice\Persister;

use Nelmio\Alice\PersisterInterface;
use Pimcore\Model\Asset;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php


namespace Fixtures\Alice\Processor;
namespace FixtureBundle\Alice\Processor;


use Nelmio\Alice\ProcessorInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Time: 7:09
*/

namespace Fixtures\Alice\Processor;
namespace FixtureBundle\Alice\Processor;


use Nelmio\Alice\ProcessorInterface;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php


namespace Fixtures\Alice\Processor;
namespace FixtureBundle\Alice\Processor;


use Nelmio\Alice\ProcessorInterface;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php


namespace Fixtures\Alice\Processor;
namespace FixtureBundle\Alice\Processor;


use Nelmio\Alice\ProcessorInterface;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php


namespace Fixtures\Alice\Providers;
namespace FixtureBundle\Alice\Providers;


class Assets
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php


namespace Fixtures\Alice\Providers;
namespace FixtureBundle\Alice\Providers;

use Pimcore\Model\Object\Product;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Time: 17:25
*/

namespace Fixtures\Alice\Providers;
namespace FixtureBundle\Alice\Providers;


class DateTime {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php


namespace Fixtures\Alice\Providers;
namespace FixtureBundle\Alice\Providers;

use Pimcore\File;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php


namespace Fixtures\Alice\Providers;
namespace FixtureBundle\Alice\Providers;

use Exception;
use Faker\Provider\Base;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
<?php
namespace Fixtures\Console\Command;

use Fixtures\FixtureLoader;
use Fixtures\Generator;
use Fixtures\Repository\FolderRepository;
use Nelmio\Alice\Fixtures;
namespace FixtureBundle\Command;

use FixtureBundle\Repository\FolderRepository;
use FixtureBundle\Service\FixtureLoader;
use FixtureBundle\Service\Generator;
use Pimcore\Console\AbstractCommand;
use Pimcore\Model\Element\AbstractElement;
use Pimcore\Model\Object\AbstractObject;
use Pimcore\Model\Object\Folder;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ChoiceQuestion;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Console\Question\Question;
use Symfony\Component\Validator\Constraints\Choice;

class GenerateFixturesCommand extends AbstractCommand
{
Expand Down Expand Up @@ -41,7 +47,6 @@ protected function execute(InputInterface $input, OutputInterface $output)

$rootFolder = $helper->ask($input, $output, $folderRootQuestion);


$filenameQuestion = new Question('<info>Choose filename: </info>', 'test');
$levelsQuestion = new Question('<info>Choose max levels deep (100): </info>', 100);

Expand All @@ -50,11 +55,11 @@ protected function execute(InputInterface $input, OutputInterface $output)

$output->writeln(
['<info>',
'You chose: ',
'Root folder: <comment>' . $rootFolder . '</comment>',
'Filename: <comment>' . $filename . '</comment>',
'Max level deep: <comment>' . $levels . '</comment>',
'</info>'
'You chose: ',
'Root folder: <comment>' . $rootFolder . '</comment>',
'Filename: <comment>' . $filename . '</comment>',
'Max level deep: <comment>' . $levels . '</comment>',
'</info>'
]);

$confirmationQuestion = new ConfirmationQuestion(
Expand All @@ -64,6 +69,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (!$helper->ask($input, $output, $confirmationQuestion)) {
return;
}

foreach (glob(FixtureLoader::FIXTURE_FOLDER . '_generated' . DIRECTORY_SEPARATOR . '*.yml') as $file){
unlink($file);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,48 +1,40 @@
<?php
namespace Fixtures\Console\Command;

use Fixtures\FixtureLoader;
use Nelmio\Alice\Fixtures;
use Pimcore\Config;
namespace FixtureBundle\Command;

use FixtureBundle\Service\FixtureLoader;
use Pimcore\Console\AbstractCommand;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class LoadFixturesCommand extends AbstractCommand
{

protected function configure()
{
$this->setName('fixtures:load')
$this
->setName('fixtures:load')
->setDescription('Imports yml fixtures')
->addOption('with-cache', 'c', InputArgument::OPTIONAL, 'Calculates the fingerprint of fixtures and if matches with load sql file instead of looping throw fixtures', false)
->addOption('omit-validation', 'ov', InputArgument::OPTIONAL, 'Omits object validation', true)
->addOption('check-path-exists', 'cpe', InputArgument::OPTIONAL, 'If true it will check if the path already exists and if yes then it will update the values', false)
->addOption('files', 'f', InputArgument::OPTIONAL, 'Comma separated files located at "' . FixtureLoader::FIXTURE_FOLDER . '"');
;
}

/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int|void
* @throws \Symfony\Component\Console\Exception\InvalidArgumentException
*/
protected function execute(InputInterface $input, OutputInterface $output)
{

// Currently we have calculated fields without any class attached
$this->disableLogging();
$withCache = $input->getOption('with-cache');
$omitValidation = $input->getOption('omit-validation');
$checkPathExists = $input->getOption('check-path-exists');
$files = $input->getOption('files') ? explode(',', $input->getOption('files')) : null;
$fixtureFiles = FixtureLoader::getFixturesFiles($files);
$fingerPrintFilePath = PIMCORE_TEMPORARY_DIRECTORY . '/pimcore_fixtures_cache_' . $this->getSha1FromFixtures($fixtureFiles). '.sql';


if ($withCache === false || file_exists($fingerPrintFilePath) === false) {
$steps = $withCache ? count($fixtureFiles) + 1 : count($fixtureFiles);
$progress = new ProgressBar($output, $steps);
Expand Down Expand Up @@ -77,9 +69,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
}

$output->writeln(' <info>Done!</info>');
}


private function getSha1FromFixtures($fixtureFiles)
{
$sha1sFromContent = '';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
<?php
namespace Fixtures\Console\Command;

use Fixtures\FixtureLoader;
use Fixtures\Generator;
use Fixtures\Rearrange;
use Fixtures\Repository\FolderRepository;
use Nelmio\Alice\Fixtures;
namespace FixtureBundle\Command;

use Pimcore\Console\AbstractCommand;
use Pimcore\Model\Object\Folder;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ChoiceQuestion;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Console\Question\Question;

class RearrangeFixturesCommand extends AbstractCommand
{

protected function configure()
{
$this->setName('fixtures:rearrange')
Expand All @@ -37,6 +31,4 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln('<info>Done. Your fixtures are at: "' . FixtureLoader::FIXTURE_FOLDER . '".</info>');

}


}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
namespace Fixtures\Console\Command;

namespace FixtureBundle\Command;

use Nelmio\Alice\Fixtures;
use Pimcore\Console\AbstractCommand;
Expand All @@ -8,7 +9,9 @@
use Pimcore\Model\Element\ElementInterface;
use Pimcore\Model\Element\Service;
use Pimcore\Model\Object\AbstractObject;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -108,11 +111,11 @@ protected function askForConfirmation(OutputInterface $output, $type, $path, $on
{
$output->writeln(
['<info>',
'Are you sure you want to continue: ',
'Type: <comment>' . $type . '</comment>',
'Path: <comment>' . $path . '</comment>',
'Only children: <comment>' . $onlyChildren . '</comment>',
'</info>'
'Are you sure you want to continue: ',
'Type: <comment>' . $type . '</comment>',
'Path: <comment>' . $path . '</comment>',
'Only children: <comment>' . $onlyChildren . '</comment>',
'</info>'
]);

$confirmationQuestion = new ConfirmationQuestion(
Expand Down
21 changes: 21 additions & 0 deletions FixtureBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* Created by PhpStorm.
* User: jorisros
* Date: 07/01/2018
* Time: 03:48
*/

namespace FixtureBundle;


use Pimcore\Extension\Bundle\AbstractPimcoreBundle;

class FixtureBundle extends AbstractPimcoreBundle
{
public function getJsPaths()
{
return [
];
}
}
24 changes: 17 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,28 @@ composer require --dev youwe/pimcore-fixtures
*This plugin is only for DEV, do NOT install on a production server*

### How to load fixtures
Make sure "PimcoreFixtures" is enabled in `/website/var/config/extensions.php`
Place your fixtures in `/website/var/plugins/PimcoreFixtures/fixtures` named "001_object_name.yml", "002_object_name.yml" etc.

You must enable the bundle as followed `php bin/console pimcore:bundle:enable FixtureBundle`. To check if the bundle is installed correctly `php bin/console pimcore:bundle:list`.
Place your fixtures in `/var/bundles/FixtureBundle/fixtures` named "001_object_name.yml", "002_object_name.yml" etc.

Example fixture for creating a folder
```yaml
# 001_folders.yml
# Object folders
Pimcore\Model\Object\Folder:
products_folder:
key: products
path: /
parentId: 1
```
Load them with:
#### Console
```sh
php pimcore/cli/console.php fixture:load --with-cache
php bin/console fixture:load --with-cache
```
Load individual files with --files comma separated files without yml extension:
#### Console
```sh
php pimcore/cli/console.php fixture:load --files filename1,filename2
php bin/console fixture:load --files filename1,filename2
```

#### Backend
Expand All @@ -39,13 +49,13 @@ Go to Extensions \ PimcoreFixtures \ plugin settings

#### Console
```sh
php pimcore/cli/console.php fixtures:generate
php bin/console fixtures:generate
```

### Delete object/assets/documents

```sh****
php pimcore/cli/console.php fixtures:delete-path -t object -p /products
php bin/console fixtures:delete-path -t object -p /products
```


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Time: 15:50
*/

namespace Fixtures\Repository;
namespace FixtureBundle\Repository;


use Pimcore\Model\Object;
Expand Down
Loading

0 comments on commit dd36d65

Please sign in to comment.