-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added command to convert old accordion blocks for new Thelia Blocks
- Loading branch information
Showing
1 changed file
with
91 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
namespace TheliaBlocks\Command; | ||
|
||
use Propel\Runtime\ActiveQuery\ModelCriteria; | ||
use Propel\Runtime\ActiveRecord\ActiveRecordInterface; | ||
use Symfony\Component\Console\Helper\ProgressBar; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
use Symfony\Component\Filesystem\Filesystem; | ||
use Symfony\Component\HttpFoundation\File\File; | ||
use Thelia\Command\ContainerAwareCommand; | ||
use Thelia\Model\ConfigQuery; | ||
use Thelia\Model\FolderImage; | ||
use Thelia\Model\LangQuery; | ||
use TheliaBlocks\Model\BlockGroupI18nQuery; | ||
|
||
class ValidateJsonContent extends ContainerAwareCommand | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
protected function configure(): void | ||
{ | ||
$this | ||
->setName('thelia_blocks:blocks:validate') | ||
->setDescription('Validate & update json_content structure'); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$jsonContents = BlockGroupI18nQuery::create()->find(); | ||
|
||
|
||
$output->writeln('<bg=blue>============================================================= </>'); | ||
$output->writeln("<fg=blue>Thelia blocks json_content validation started</>"); | ||
$progressBar = new ProgressBar($output, $jsonContents->count()); | ||
$progressBar->start(); | ||
|
||
foreach ($jsonContents as $jsonContent) { | ||
$content = $jsonContent->getJsonContent(); | ||
|
||
$decodedJson = json_decode($content, true); | ||
|
||
foreach ($decodedJson as $key => $value) { | ||
$output->writeln("-"); | ||
$output->writeln($value["type"]["id"]); | ||
|
||
if ($value["type"]["id"] === "blockAccordion") { | ||
$oldData = $decodedJson[$key]["data"]; | ||
|
||
$group = array_map(function ($item) { | ||
if (isset($item["group"])) { | ||
$item["content"] = []; | ||
$item["content"][] = $item["group"]; | ||
|
||
unset($item["group"]); | ||
|
||
$item["content"][0]["data"] = ["content" => [$item["content"][0]["data"]]]; | ||
} | ||
|
||
return $item; | ||
}, $oldData); | ||
|
||
$decodedJson[$key]["data"] = [ | ||
"title" => "", | ||
"group" => $group | ||
]; | ||
} | ||
} | ||
|
||
|
||
$jsonContent->setJsonContent(json_encode($decodedJson)); | ||
|
||
$jsonContent->save(); | ||
|
||
$progressBar->advance(); | ||
} | ||
|
||
$progressBar->finish(); | ||
$output->writeln(""); | ||
$output->writeln("<info>Thelia blocks json_content validation ended</info>"); | ||
$output->writeln('<bg=blue>============================================================= </>'); | ||
|
||
return 1; | ||
} | ||
} |