-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
59e2075
commit c2af967
Showing
10 changed files
with
786 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?php | ||
|
||
namespace Notamedia\ConsoleJedi\Iblock\Command; | ||
|
||
use Notamedia\ConsoleJedi\Application\Command\BitrixCommand; | ||
use Notamedia\ConsoleJedi\Iblock\Exception\IblockException; | ||
use Notamedia\ConsoleJedi\Iblock\Exporter; | ||
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\Helper\FormatterHelper; | ||
use Bitrix\Main\Loader; | ||
|
||
/** | ||
* Command export information block(s) in xml file(s) | ||
*/ | ||
class ExportCommand extends BitrixCommand | ||
{ | ||
use MigrationCommandTrait; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('iblock:export') | ||
->setDescription('Export information block(s) to xml') | ||
->addArgument( | ||
'type', | ||
InputArgument::REQUIRED, | ||
'Information block type' | ||
) | ||
->addArgument( | ||
'code', | ||
InputArgument::REQUIRED, | ||
'Information block code' | ||
) | ||
->addArgument( | ||
'dir', | ||
InputArgument::OPTIONAL, | ||
'Directory to export' | ||
) | ||
->addOption( | ||
'sections', | ||
's', | ||
InputOption::VALUE_OPTIONAL, | ||
'Export sections [ "active", "all", "none" ]', | ||
'none' | ||
) | ||
->addOption( | ||
'elements', | ||
'e', | ||
InputOption::VALUE_OPTIONAL, | ||
'Export elements [ "active", "all", "none" ]', | ||
'none' | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function initialize(InputInterface $input, OutputInterface $output) | ||
{ | ||
Loader::includeModule('iblock'); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function interact(InputInterface $input, OutputInterface $output) | ||
{ | ||
$this->setDir($input); | ||
$this->setIblocks($input); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$formatter = new FormatterHelper(); | ||
|
||
if (count($this->errors) > 0) { | ||
$output->writeln($formatter->formatBlock($this->errors, 'error')); | ||
return false; | ||
} | ||
|
||
$exporter = new Exporter(); | ||
$exporter | ||
->setSections($input->getOption('sections')) | ||
->setElements($input->getOption('elements')); | ||
|
||
foreach ($this->iblocks as $iblock) { | ||
|
||
try { | ||
$xml_id = \CIBlockCMLExport::GetIBlockXML_ID($iblock['ID']); | ||
$path = implode(DIRECTORY_SEPARATOR, [$this->dir, $xml_id]) . $this->extension; | ||
|
||
$exporter | ||
->setPath($path) | ||
->setId($iblock['ID']) | ||
->execute(); | ||
|
||
$output->writeln(sprintf('<info>%s</info> iblock %s %s', 'success', $iblock['CODE'], $path)); | ||
|
||
} catch (IblockException $e) { | ||
$output->writeln(sprintf('<error>%s</error> iblock %s', 'fail', $iblock['CODE'])); | ||
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { | ||
$output->writeln($e->getMessage()); | ||
} | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<?php | ||
|
||
namespace Notamedia\ConsoleJedi\Iblock\Command; | ||
|
||
use Notamedia\ConsoleJedi\Application\Command\BitrixCommand; | ||
use Notamedia\ConsoleJedi\Iblock\Exception\IblockException; | ||
use Notamedia\ConsoleJedi\Iblock\Importer; | ||
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\Helper\FormatterHelper; | ||
use Bitrix\Main\Loader; | ||
|
||
/** | ||
* Command import information block(s) from xml file(s) | ||
*/ | ||
class ImportCommand extends BitrixCommand | ||
{ | ||
use MigrationCommandTrait; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('iblock:import') | ||
->setDescription('Import information block(s) from xml') | ||
->addArgument( | ||
'type', | ||
InputArgument::REQUIRED, | ||
'Information block type' | ||
) | ||
->addArgument( | ||
'sites', | ||
InputArgument::REQUIRED, | ||
'Sites to which the information block will be bound (if it is to be created)' | ||
) | ||
->addArgument( | ||
'dir', | ||
InputArgument::OPTIONAL, | ||
'Directory to import' | ||
) | ||
->addOption( | ||
'sections', | ||
's', | ||
InputOption::VALUE_OPTIONAL, | ||
'If an existing section is no longer in the source file [ leave: "N", deactivate: "A", delete: "D" ]', | ||
'A' | ||
) | ||
->addOption( | ||
'elements', | ||
'e', | ||
InputOption::VALUE_OPTIONAL, | ||
'If an existing element is no longer in the source file [ leave: "N", deactivate: "A", delete: "D" ]', | ||
'A' | ||
); | ||
|
||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function initialize(InputInterface $input, OutputInterface $output) | ||
{ | ||
Loader::includeModule('iblock'); | ||
} | ||
|
||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function interact(InputInterface $input, OutputInterface $output) | ||
{ | ||
$this->setDir($input); | ||
$this->setType($input); | ||
$this->setSites($input); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$formatter = new FormatterHelper(); | ||
|
||
if (count($this->errors) > 0) { | ||
$output->writeln($formatter->formatBlock($this->errors, 'error')); | ||
return false; | ||
} | ||
|
||
$importer = new Importer(); | ||
$importer | ||
->setType($this->type) | ||
->setSites($this->sites) | ||
->setActionSection($input->getOption('sections')) | ||
->setActionElement($input->getOption('elements'));; | ||
|
||
foreach (glob(implode(DIRECTORY_SEPARATOR . '*', [$this->dir, $this->extension])) as $file) { | ||
|
||
try { | ||
$importer | ||
->setPath($file) | ||
->execute(); | ||
|
||
$output->writeln(sprintf('<info>%s</info> file %s', 'success', $file)); | ||
|
||
} catch (IblockException $e) { | ||
$output->writeln(sprintf('<error>%s</error> file %s', 'fail', $file)); | ||
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { | ||
$output->writeln($e->getMessage()); | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.