-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #299 in PLUG_OPEN/backend_swagimportexport from ne…
…xt to master * commit '0f459384dea3520959231635aa2c6d7eed16ec5f': (27 commits) PT-7190 - Change combo sorting PT-7254 - Catch database update failures PT-7151 - Extend profile description PT-7234 - Fix newsletter recipient export PT-7234 - Fix recipient import for known users PT-7190 - Fix category selection reset PT-7281 - Implemented default profile for orders PT-7192 - Improve import error messages for extended datasets PT-7239 - Ignore empty protpertyValues PT-7234 - Fix newsletter recipient import PT-7151 - Fix graduation price processing PT-7190 - Fix store reloading NTR - Fix component margin PT-7297 - Changed wording for profile editor PT-7190 - Filtering profile selection PT-7198 - Optimize profile editor ui PT-7063 - Fix update query PT-7063 - Fix profile updater PT-7286 - Fix column creation PT-7063 - Implement descriptions for default profiles ...
- Loading branch information
Showing
102 changed files
with
4,727 additions
and
1,063 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
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 |
---|---|---|
@@ -1,8 +1,15 @@ | ||
<?php | ||
/** | ||
* (c) shopware AG <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Shopware\Commands\SwagImportExport; | ||
|
||
use Shopware\Commands\ShopwareCommand; | ||
use Shopware\Components\Model\ModelManager; | ||
use Shopware\Components\SwagImportExport\Profile\Profile; | ||
use Shopware\Components\SwagImportExport\UploadPathProvider; | ||
use Shopware\CustomModels\ImportExport\Profile as ProfileEntity; | ||
|
@@ -16,10 +23,19 @@ | |
|
||
class ImportCommand extends ShopwareCommand | ||
{ | ||
/** @var string */ | ||
protected $profile; | ||
|
||
/** @var ProfileEntity */ | ||
protected $profileEntity; | ||
|
||
/** @var string */ | ||
protected $format; | ||
|
||
/** @var string */ | ||
protected $filePath; | ||
|
||
/** @var int */ | ||
protected $sessionId; | ||
|
||
/** | ||
|
@@ -46,9 +62,10 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
|
||
$this->start($output, $this->profileEntity, $this->filePath, $this->format); | ||
|
||
$profilesMapper = array('articles', 'articlesImages'); | ||
$profilesMapper = ['articles', 'articlesImages']; | ||
|
||
$uploadPathProvider = new UploadPathProvider(Shopware()->DocPath()); | ||
/** @var UploadPathProvider $uploadPathProvider */ | ||
$uploadPathProvider = $this->container->get('swag_import_export.upload_path_provider'); | ||
|
||
//loops the unprocessed data | ||
$pathInfo = pathinfo($this->filePath); | ||
|
@@ -80,29 +97,28 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
protected function start(OutputInterface $output, $profileModel, $file, $format) | ||
{ | ||
$helper = new CommandHelper( | ||
array( | ||
[ | ||
'profileEntity' => $profileModel, | ||
'filePath' => $file, | ||
'format' => $format, | ||
'username' => 'Commandline' | ||
) | ||
] | ||
); | ||
|
||
$output->writeln('<info>' . sprintf("Using profile: %s.", $profileModel->getName()) . '</info>'); | ||
$output->writeln('<info>' . sprintf("Using format: %s.", $format) . '</info>'); | ||
$output->writeln('<info>' . sprintf("Using file: %s.", $file) . '</info>'); | ||
|
||
$return = $helper->prepareImport(); | ||
$count = $return['count']; | ||
$preparationData = $helper->prepareImport(); | ||
$count = $preparationData['count']; | ||
$output->writeln('<info>' . sprintf("Total count: %d.", $count) . '</info>'); | ||
|
||
$return = $helper->importAction(); | ||
$position = $return['data']['position']; | ||
$output->writeln('<info>' . sprintf("Processed: %d.", $position) . '</info>'); | ||
$position = 0; | ||
|
||
while ($position < $count) { | ||
$return = $helper->importAction(); | ||
$position = $return['data']['position']; | ||
$data = $helper->importAction(); | ||
$this->container->get('models')->clear(); | ||
$position = $data['data']['position']; | ||
$output->writeln('<info>' . sprintf("Processed: %d.", $position) . '</info>'); | ||
} | ||
} | ||
|
@@ -119,24 +135,24 @@ protected function prepareImportInputValidation(InputInterface $input) | |
|
||
$parts = explode('.', $this->filePath); | ||
|
||
// get some service from container (formerly Shopware()->Bootstrap()->getResource()) | ||
/** @var ModelManager $em */ | ||
$em = $this->container->get('models'); | ||
|
||
/** @var Repository $profileRepository */ | ||
$profileRepository = $em->getRepository('Shopware\CustomModels\ImportExport\Profile'); | ||
$profileRepository = $em->getRepository(ProfileEntity::class); | ||
|
||
// if no profile is specified try to find it from the filename | ||
if ($this->profile === null) { | ||
foreach ($parts as $part) { | ||
$part = strtolower($part); | ||
$this->profileEntity = $profileRepository->findOneBy(array('name' => $part)); | ||
$this->profileEntity = $profileRepository->findOneBy(['name' => $part]); | ||
if ($this->profileEntity !== null) { | ||
$this->profile = $part; | ||
break; | ||
} | ||
} | ||
} else { | ||
$this->profileEntity = $profileRepository->findOneBy(array('name' => $this->profile)); | ||
$this->profileEntity = $profileRepository->findOneBy(['name' => $this->profile]); | ||
} | ||
|
||
// validate profile | ||
|
@@ -153,7 +169,7 @@ protected function prepareImportInputValidation(InputInterface $input) | |
$this->format = strtolower($this->format); | ||
|
||
// validate type | ||
if (!in_array($this->format, array('csv', 'xml'))) { | ||
if (!in_array($this->format, ['csv', 'xml'])) { | ||
throw new \Exception(sprintf('Invalid format: \'%s\'! Valid formats are: CSV and XML.', $this->format)); | ||
} | ||
|
||
|
Oops, something went wrong.