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

Pim x #34

Open
wants to merge 8 commits into
base: master
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions changelog.md → CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.0.0]

Pimcore X Compatibility

## [2.0.0]

[BC] Switch to Elements Process-Manager

## [1.0.0]
6 changes: 3 additions & 3 deletions readme.md → README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ Enable the Bundle:

## Requirements

* Pimcore 6.3
* ProcessManager
* Pimcore 10 (X)
* [ProcessManager](https://github.com/elements-at/ProcessManager)

## Usage
Prepare a gridconfig that you want to export, open up ProcessManager, create a new Scheduled Export Executable.
Expand Down Expand Up @@ -86,7 +86,7 @@ Pimcore Scheduled Export source code is completely free and released under the
This module respects all Pimcore code quality rules and our own PHPCS and PHPMD rulesets.

## About Authors
![Divante-logo](http://divante.co/logo-HG.png "Divante")
![Divante-logo](https://www.divante.com/hubfs/raw_assets/public/Divante_March_2021/images/logo-new.svg "Divante")

We are a Software House from Europe, existing from 2008 and employing about 150 people. Our core competencies are built
around Magento, Pimcore and bespoke software projects (we love Symfony3, Node.js, Angular, React, Vue.js).
Expand Down
35 changes: 25 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,36 @@
"name": "Bruno Ramalho",
"email": "[email protected]",
"role": "Developer"
},
{
"name": "Michael Frank",
"email": "[email protected]",
"role": "Developer"
}
],
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"sort-packages": true,
"vendor-dir": "vendor",
"bin-dir": "vendor/bin/",
"optimize-autoloader": true,
"preferred-install": "dist",
"disable-tls": false,
"secure-http": true,
"allow-plugins": {
"ocramius/package-versions": true
}
},
"require": {
"pimcore/pimcore": ">=6.3",
"dpfaffenbauer/process-manager": "^2.0"
"ext-json": "*",
"php": ">=8.0",
"pimcore/pimcore": "^10.0 || ^11.0",
"elements/process-manager-bundle": "^4.0 || ^5.0"
},
"require-dev": {
"phpunit/phpunit": "^7.5",
"symfony/phpunit-bridge": "^4.2",
"divante-ltd/pimcore-coding-standards": "^0.1",
"phpmd/phpmd": "^2.6",
"sebastian/phpcpd": "^4.1",
"block8/php-docblock-checker": "^1.10",
"phploc/phploc": "^4.0.0",
"codeception/codeception": "^3.0"
"codeception/codeception": "^5.0",
"phpmd/phpmd": "^2.6"
},
"autoload": {
"psr-4": {
Expand Down
92 changes: 69 additions & 23 deletions src/ScheduledExportBundle/Command/ScheduledExportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,49 @@
* @copyright Copyright (c) 2017 Divante Ltd. (https://divante.co)
*/

declare(strict_types=1);

namespace Divante\ScheduledExportBundle\Command;

use Divante\ScheduledExportBundle\Export\Export;
use Carbon\Carbon;
use Elements\Bundle\ProcessManagerBundle\ExecutionTrait;
use Elements\Bundle\ProcessManagerBundle\MetaDataFile;
use Pimcore\Console\AbstractCommand;
use Pimcore\Model\DataObject\AbstractObject;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Pimcore\Serializer\Serializer;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Class ScheduledExportCommand
*
* @package Divante\ScheduledExportBundle\Command
*/
class ScheduledExportCommand extends ContainerAwareCommand
class ScheduledExportCommand extends AbstractCommand
{
use ExecutionTrait;

protected static $defaultName = 'scheduled-export:start';

private ContainerInterface $container;

public function __construct(ContainerInterface $container)
{
parent::__construct();

$this->container = $container;
}

/**
* {@inheritdoc}
*/
protected function configure()
protected function configure(): void
{
$this
->setName('scheduled-export:start')
->setName(self::$defaultName)
->setDescription('Run Scheduled Export.')
->setHelp(<<<EOT
The <info>%command.name%</info> runs export of object based on predefined grid config.
Expand Down Expand Up @@ -96,44 +114,72 @@ protected function configure()
'Divide file into parts with n lines'
)
->addOption(
'preserve_process',
'',
InputOption::VALUE_OPTIONAL,
'Don\'t delete process'
)->addOption(
'types',
'',
InputOption::VALUE_OPTIONAL,
'Set what types should be exported; e. g. "object,variant"; defaults to default list settings'
)->addOption(
)
->addOption(
'object-ids',
'',
InputOption::VALUE_OPTIONAL,
'Export only specified object ids'
)->addOption(
)
->addOption(
'add_utf_bom',
'',
InputOption::VALUE_OPTIONAL,
'Add BOM (Byte Order Mark)'
)
->addOption(
'monitoring-item-id',
null,
InputOption::VALUE_REQUIRED,
'Contains the monitoring item if executed via the Pimcore backend'
)
;
}

/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
self::initProcessManager($input->getOption('monitoring-item-id'), ['autoCreate' => true]);

$monitoringItem = self::getMonitoringItem();

$metDataFileObject = MetaDataFile::getById('sample-id');

$start = Carbon::now();
if (!empty($metDataFileObject->getData()['lastRun'])) {
$lastRun = Carbon::createFromTimestamp($metDataFileObject->getData()['lastRun']);
} else {
$lastRun = Carbon::now();
}

AbstractObject::setHideUnpublished(false);

$container = $this->getContainer();
$pimcoreSerializer = new Serializer();
$result = 0;
try {
$export = new Export(
$monitoringItem,
$this->container,
$pimcoreSerializer
);

$export = new Export(
$container,
$input,
$output
);
$export->execute();
} catch (\Exception $e) {
$result = 1;
$monitoringItem->getLogger()->error('Error on ScheduledExportCommand: ' . $e->getMessage());
$monitoringItem->setMessage($e->getMessage(), \Monolog\Logger::ERROR)->save();
$monitoringItem->getLogger()->debug($e->getTraceAsString());
$monitoringItem->setMessage($e->getTraceAsString(), \Monolog\Logger::ERROR)->save();
$monitoringItem->setHasCriticalError(true);
} finally {
$monitoringItem->getLogger()->debug('Last Run: ' . $lastRun->format(Carbon::DEFAULT_TO_STRING_FORMAT));
$metDataFileObject->setData(['lastRun' => $start->getTimestamp()])->save();
$monitoringItem->setMessage('Job finished')->setCompleted();
}

$export->export();
return $result;
}
}
43 changes: 26 additions & 17 deletions src/ScheduledExportBundle/Controller/GridConfigController.php
Original file line number Diff line number Diff line change
@@ -1,57 +1,66 @@
<?php

declare(strict_types=1);

namespace Divante\ScheduledExportBundle\Controller;

use Pimcore\Bundle\AdminBundle\Controller\AdminController;
use Exception;
use Pimcore\Bundle\AdminBundle\HttpFoundation\JsonResponse;
use Pimcore\Bundle\AdminBundle\Security\User\User;
use Pimcore\Controller\Traits\JsonHelperTrait;
use Pimcore\Controller\UserAwareController;
use Pimcore\Model\DataObject\ClassDefinition;
use Pimcore\Model\GridConfig;
use Pimcore\Model\User;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;

/**
* Class GridConfigController
*
* @Route("/admin/scheduled-export/grid-config")
*
* @package Divante\ScheduledExportBundle\Controller
*/
class GridConfigController extends AdminController
class GridConfigController extends UserAwareController
{
use JsonHelperTrait;

/** @var string True indicator for share globally */
const SHARE_GLOBALLY_TRUE = "1";
private const SHARE_GLOBALLY_TRUE = '1';

/**
* @param Request $request
* @return \Pimcore\Bundle\AdminBundle\HttpFoundation\JsonResponse
* @throws \Exception
* @return JsonResponse
* @throws Exception
*
* @Route("/admin/scheduled-export/grid-config/get-list")
* @Route("/get-list")
*/
public function getListAction(Request $request) : JsonResponse
{
$user = $this->getAdminUser();
$user = $this->getPimcoreUser();

$gridConfigs = new GridConfig\Listing();
$gridConfigs->setCondition("ownerId = ? or shareGlobally = ?", [$user->getId(), self::SHARE_GLOBALLY_TRUE]);
$gridConfigs->setCondition('ownerId = ? or shareGlobally = ?', [$user?->getId(), self::SHARE_GLOBALLY_TRUE]);
$gridConfigs->load();
$result = [];

$result = [];

/** @var GridConfig $gridConfig */
foreach ($gridConfigs->getGridConfigs() as $gridConfig) {
$classDefinition = ClassDefinition::getById($gridConfig->getClassId());
$user = \Pimcore\Model\User::getById($gridConfig->getOwnerId());
$user = User::getById($gridConfig->getOwnerId());
if ($user) {
$userName = $user->getName();
} else {
$userName = "unknown";
$userName = 'unknown';
}
$result[] = [
"id" => $gridConfig->getId(),
"name" => "[" . $gridConfig->getId() . "] " . $classDefinition->getName() . ": " .
$gridConfig->getName() . " (" . $userName . ")"
'id' => $gridConfig->getId(),
'name' => '[' . $gridConfig->getId() . '] ' .
($classDefinition !== null ? $classDefinition->getName() : 'no class found for ClassID: ' . $gridConfig->getClassId()) .
': ' . $gridConfig->getName() . ' (' . $userName . ')'
];
}

return $this->adminJson(["success" => true, "result" => $result]);
return $this->jsonResponse(['success' => true, 'result' => $result]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* @copyright Copyright (c) 2017 Divante Ltd. (https://divante.co)
*/

declare(strict_types=1);

namespace Divante\ScheduledExportBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
Expand All @@ -20,10 +22,10 @@ class Configuration implements ConfigurationInterface
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('divante_scheduled_export');
$treeBuilder = new TreeBuilder('divante_scheduled_export');
$rootNode = $treeBuilder->getRootNode();

// Here you should define the parameters that are allowed to
// configure your bundle. See the documentation linked above for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,36 @@
* @copyright Copyright (c) 2017 Divante Ltd. (https://divante.co)
*/

declare(strict_types=1);

namespace Divante\ScheduledExportBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension;
use Symfony\Component\DependencyInjection\Loader;

/**
* This is the class that loads and manages your bundle configuration.
*
* @link http://symfony.com/doc/current/cookbook/bundles/extension.html
*/
class DivanteScheduledExportExtension extends Extension
class DivanteScheduledExportExtension extends ConfigurableExtension implements PrependExtensionInterface
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
public function loadInternal(array $mergedConfig, ContainerBuilder $container): void
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$config = $this->processConfiguration($configuration, $mergedConfig);

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');
$loader->load('services.yaml');
}

public function prepend(ContainerBuilder $container): void
{
}
}
Loading