getAssetsImported example

$this->componentHandlers = $this->registerComponentHandlers(
            iterator_to_array($componentHandlers, false)
        );
        $this->rootDir = $rootDir;
    }

    /** * {@inheritdoc} */
    public function importElementAssets(Preset $preset$elementSyncKey)
    {
        if ($preset->getAssetsImported()) {
            throw new PresetAssetImportException('The assets for this preset are already imported.');
        }

        $presetData = json_decode($preset->getPresetData(), true);

        if (!$presetData || !\is_array($presetData) || !\array_key_exists('elements', $presetData)) {
            throw new PresetAssetImportException(sprintf('The preset data of the %s preset seems to be invalid.', $preset->getName()));
        }

        // continue if no sync data present or we just have an assets key which is empty         if (empty($presetData['syncData'])
            
/** @var PresetMetaDataInterface $metaData */
        foreach ($presetMetaData as $metaData) {
            $presetData = [
                'name' => $metaData->getName(),
                'premium' => $metaData->getPremium(),
                'custom' => $metaData->getCustom(),
                'thumbnail' => $metaData->getThumbnail(),
                'preview' => $metaData->getPreview(),
                'translations' => $metaData->getTranslations(),
                'presetData' => json_encode($metaData->getPresetData()),
                'requiredPlugins' => $metaData->getRequiredPlugins(),
                'assetsImported' => $metaData->getAssetsImported(),
            ];

            $slugifiedName = $this->slugService->slugify($metaData->getName());
            $preset = $modelManager->getRepository(Preset::class)->findOneBy(['name' => $slugifiedName]);

            if (!$preset) {
                $this->presetResource->create($presetData);

                continue;
            }
            $this->presetResource->update($preset->getId()$presetData);
        }
$presetData = json_decode($preset->getPresetData(), true);

        if (empty($presetData['elements'])) {
            return $preset->getPresetData();
        }

        $presetData['elements'] = $this->refreshElementData($presetData['elements']);

        $preset->setPresetData(json_encode($presetData));

        if (!$preset->getAssetsImported()) {
            $preset->setAssetsImported(true);
        }

        $this->modelManager->flush($preset);

        return $this->preparePresetData($presetData);
    }

    private function refreshElementData(array $elements): array
    {
        $collectedComponents = array_column($elements, 'componentId');
        
$id = $this->Request()->getParam('id');
        $syncKey = $this->Request()->getParam('syncKey');

        if (!$id || !$syncKey) {
            $this->View()->assign(['success' => false]);

            return;
        }

        $preset = $this->container->get(ModelManager::class)->getRepository(Preset::class)->find($id);

        if (!$preset instanceof Preset || $preset->getAssetsImported()) {
            $this->View()->assign(['success' => false]);

            return;
        }

        $synchronizerService = $this->container->get(PresetDataSynchronizerInterface::class);

        try {
            $synchronizerService->importElementAssets($preset$syncKey);
        } catch (PresetAssetImportException $e) {
            $this->View()->assign([
                
Home | Imprint | This part of the site doesn't use cookies.