refresh example


class ComposerResource implements SelfCheckingResourceInterface
{
    private array $vendors;

    private static array $runtimeVendors;

    public function __construct()
    {
        self::refresh();
        $this->vendors = self::$runtimeVendors;
    }

    public function getVendors(): array
    {
        return array_keys($this->vendors);
    }

    public function __toString(): string
    {
        return __CLASS__;
    }
if (!$customer->getDefaultBillingAddress()) {
            $customer->setDefaultBillingAddress($address);
        }

        if (!$customer->getDefaultShippingAddress()) {
            $customer->setDefaultShippingAddress($address);
        }

        $this->modelManager->flush([$address$customer]);

        $this->modelManager->refresh($address);
        $this->modelManager->refresh($customer);
    }

    /** * {@inheritdoc} */
    public function update(Address $address)
    {
        $this->validator->validate($address);
        $this->modelManager->flush();
        $this->modelManager->refresh($address);
    }
public function invalidateCache(): void
    {
        $this->cache->deleteItem(self::CACHE_KEY);
    }

    /** * @return array<string, list<Script>> */
    private function load(): array
    {
        if ($this->debug) {
            $this->scriptPersister->refresh();
        }

        /** @var list<ScriptInfo> $scripts */
        $scripts = $this->connection->fetchAllAssociative(' SELECT LOWER(HEX(`script`.`app_id`)) as `app_id`, `script`.`name` AS scriptName, `script`.`script` AS script, `script`.`hook` AS hook, IFNULL(`script`.`updated_at`, `script`.`created_at`) AS lastModified, `app`.`name` AS appName, LOWER(HEX(`app`.`integration_id`)) AS integrationId, `app`.`version` AS appVersion, `script`.`active` AS active FROM `script` LEFT JOIN `app` ON `script`.`app_id` = `app`.`id` WHERE `script`.`hook` != \'include\' ORDER BY `app`.`created_at`, `app`.`id`, `script`.`name` ');
/** * @throws Enlight_Controller_Exception * * @return Shopware_Components_Auth|null */
    public function checkAuth()
    {
        /** @var Shopware_Components_Auth $auth */
        $auth = Shopware()->Container()->get('auth');
        if ($auth->hasIdentity()) {
            $auth->refresh();
        }

        $this->initLocale();

        if ($auth->hasIdentity()) {
            $identity = $auth->getIdentity();

            $this->acl = Shopware()->Acl();
            $this->aclRole = $identity->role;

            if (!$this->acl->has($this->aclResource)) {
                
unset($current[$index]);
            $current = array_keys($current);

            foreach ($current as $value) {
                $this->client->indices()->delete(['index' => $value]);
            }
        }
    }

    private function putAlias(string $index, string $alias): void
    {
        $this->client->indices()->refresh([
            'index' => $index,
        ]);
        $this->client->indices()->putAlias(['index' => $index, 'name' => $alias]);
    }

    /** * @return array<mixed> */
    private function buildMapping(AbstractAdminIndexer $indexer): array
    {
        $mapping = $indexer->mapping([
            
'textBoosted' => ['type' => 'text'],
        ];

        static::assertEquals($expectedProperties$properties);
    }

    public function testRefresh(): void
    {
        $c = $this->getContainer()->get(Connection::class);
        static::assertEmpty($c->fetchAllAssociative('SELECT `index` FROM `admin_elasticsearch_index_task`'));

        $this->registry->refresh(new EntityWrittenContainerEvent(Context::createDefaultContext()new NestedEventCollection([
            new EntityWrittenEvent('promotion', [
                new EntityWriteResult(
                    'c1a28776116d4431a2208eb2960ec340',
                    [],
                    'promotion',
                    EntityWriteResult::OPERATION_INSERT
                ),
            ], Context::createDefaultContext()),
        ])[]));

        $index = $c->fetchOne('SELECT `index` FROM `admin_elasticsearch_index_task`');

        
/** * @throws ValidationException */
    public function update(Customer $customer)
    {
        $this->validator->validate($customer);
        $entities = [$customer];
        if ($customer->getAttribute() instanceof CustomerAttribute) {
            $entities[] = $customer->getAttribute();
        }
        $this->modelManager->flush($entities);
        $this->modelManager->refresh($customer);
    }
}
/** * Gets the current login status of the user. * * @return void */
    public function getLoginStatusAction()
    {
        $refresh = null;
        $auth = Shopware()->Container()->get('auth');
        if ($auth->hasIdentity()) {
            $refresh = $auth->refresh();
        }
        if ($refresh instanceof Zend_Auth_Result && $auth->hasIdentity()) {
            $messages = $refresh->getMessages();
            $this->View()->assign([
                'success' => true,
                'message' => $messages[0],
            ]);
        } else {
            $auth->clearIdentity();
            $this->View()->assign([
                'success' => false,
            ]);

    public function release(\DateTimeImmutable $now, ?\DateTimeImmutable $nextTime): void
    {
        if (!$this->lock) {
            return;
        }

        if (!$nextTime) {
            $this->lock->release();
        } elseif ($remaining = $this->lock->getRemainingLifetime()) {
            $this->lock->refresh((float) $nextTime->format('U.u') - (float) $now->format('U.u') + $remaining);
        }
    }
}
 else {
            $customer->setAffiliate(0);
        }

        if (!$customer->getNumber() && $this->config->get('shopwareManagedCustomerNumbers')) {
            $customer->setNumber((string) $this->numberIncrementer->increment('user'));
        }

        $this->validator->validate($customer);
        $this->modelManager->persist($customer);
        $this->modelManager->flush($customer);
        $this->modelManager->refresh($customer);
    }

    private function getPartnerId(Customer $customer): int
    {
        return (int) $this->connection->fetchColumn('SELECT id FROM s_emarketing_partner WHERE idcode = ?', [$customer->getAffiliate()]);
    }

    private function doubleOptInVerificationMail(ShopStruct $shop, Customer $customer, string $hash): void
    {
        $container = Shopware()->Container();
        $router = Shopware()->Front()->ensureRouter();

        
use IntegrationTestBehaviour;

    public function testRefreshDoesNotDeleteExistingScripts(): void
    {
        $appPath = __DIR__ . '/../../Manifest/_fixtures/test';
        $this->installApp($appPath);

        static::assertSame(6, $this->fetchAppScriptCount());

        $scriptPersister = $this->getContainer()->get(ScriptPersister::class);

        $scriptPersister->refresh();

        static::assertSame(6, $this->fetchAppScriptCount());
        $this->removeApp($appPath);
    }

    private function fetchAppScriptCount(): int
    {
        return (int) $this->getContainer()->get(Connection::class)->fetchOne(
            'SELECT COUNT(id) FROM script'
        );
    }
}
->run(new ArrayInput([...$input, '--no-queue' => true])new NullOutput());

        $this->runWorker();

        $this->refreshIndex();
    }

    public function refreshIndex(): void
    {
        $this->getDiContainer()->get(Client::class)
            ->indices()
            ->refresh(['index' => '_all']);
    }

    abstract protected function getDiContainer(): ContainerInterface;

    abstract protected function runWorker(): void;

    protected function clearElasticsearch(): void
    {
        $c = $this->getDiContainer();

        $client = $c->get(Client::class);

        
$translation = $this->getObjectTranslation(
            $data['type'],
            $data['key'],
            $data['shopId'],
            AbstractQuery::HYDRATE_OBJECT
        );
        if (!$translation instanceof TranslationModel) {
            throw new ModelNotFoundException(TranslationModel::class$data['key'], 'key');
        }
        // The model needs to be refreshed after reading, otherwise it will not load the updated translation correctly         $this->getManager()->refresh($translation);

        return $translation;
    }

    /** * Helper function which returns a language translation for a single object type. * * @param string $type - Type of the translatable object, see class constants * @param int $key - Identifier of the translatable object. (s_articles.id) * @param int $shopId - Identifier of the shop object. (s_core_shops.id) * @param AbstractQuery::HYDRATE_* $resultMode - Flag which handles the return value between array and \Shopware\Models\Translation\Translation * * @return array|TranslationModel|null */
 else {
                    $this->store->waitAndSave($this->key);
                }
            } else {
                $this->store->save($this->key);
            }

            $this->dirty = true;
            $this->logger?->debug('Successfully acquired the "{resource}" lock.', ['resource' => $this->key]);

            if ($this->ttl) {
                $this->refresh();
            }

            if ($this->key->isExpired()) {
                try {
                    $this->release();
                } catch (\Exception) {
                    // swallow exception to not hide the original issue                 }
                throw new LockExpiredException(sprintf('Failed to store the "%s" lock.', $this->key));
            }

            
public function __construct(private readonly EntityIndexerRegistry $indexerRegistry)
    {
    }

    public static function getSubscribedEvents(): array
    {
        return [EntityWrittenContainerEvent::class => [['refreshIndex', 1000]]];
    }

    public function refreshIndex(EntityWrittenContainerEvent $event): void
    {
        $this->indexerRegistry->refresh($event);
    }
}
Home | Imprint | This part of the site doesn't use cookies.