executeUpdate example

use Shopware\Bundle\PluginInstallerBundle\Service\PluginLicenceService;
use Shopware\Bundle\PluginInstallerBundle\Struct\AccessTokenStruct;

class Shopware_Controllers_Backend_UpdateWizard extends Shopware_Controllers_Backend_ExtJs
{
    public function indexAction()
    {
        /** @var Connection $connection */
        $connection = $this->get(\Doctrine\DBAL\Connection::class);
        $sql = "INSERT IGNORE INTO `s_core_config_elements` (`id`, `form_id`, `name`, `value`, `label`, `description`, `type`, `required`, `position`, `scope`) VALUES (NULL, '0', 'updateWizardStarted', 'b:1;', '', '', 'checkbox', '0', '0', '1');";
        $connection->executeUpdate($sql);

        Shopware()->Container()->get(\Shopware\Components\CacheManager::class)->clearConfigCache();
    }

    public function updateAction()
    {
        $pluginCheck = new \ShopwarePlugins\SwagUpdate\Components\PluginCheck($this->container);

        /** @var PluginLicenceService $licenceService */
        $licenceService = $this->get(\Shopware\Bundle\PluginInstallerBundle\Service\PluginLicenceService::class);

        
$this->View()->assign(['success' => true, 'data' => $products, 'total' => $total]);
    }

    /** * @return void */
    public function removeSelectedProductAction()
    {
        $streamId = $this->Request()->getParam('streamId');
        $productId = $this->Request()->getParam('articleId');

        Shopware()->Container()->get(Connection::class)->executeUpdate(
            'DELETE FROM s_product_streams_selection WHERE stream_id = :streamId AND article_id = :articleId',
            [':streamId' => $streamId, ':articleId' => $productId]
        );

        $this->View()->assign('success', true);
    }

    /** * @return void */
    public function addSelectedProductAction()
    {


        return $this->manager;
    }

    /** * @param int $filterSetId */
    private function removeSetRelationsFromProducts($filterSetId)
    {
        $sql = 'UPDATE s_articles SET filtergroupID = null WHERE filtergroupID = ?';
        $this->get(\Doctrine\DBAL\Connection::class)->executeUpdate($sql[$filterSetId]);
    }
}
->setDescription('Remove backlog entries that are already synchronized.')
        ;
    }

    /** * {@inheritdoc} */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $lastId = $this->container->get(\Shopware\Bundle\ESIndexingBundle\BacklogReader::class)->getLastBacklogId();

        $this->container->get(\Doctrine\DBAL\Connection::class)->executeUpdate('DELETE FROM s_es_backlog WHERE id <= :id', [':id' => $lastId]);

        return 0;
    }
}
$threshold = (new DateTime())
            ->modify(sprintf('-%d months', $months))
            ->format('Y-m-d H:i:s');

        $query = <<<'SQL' DELETE u FROM `s_user` u LEFT JOIN `s_order` o ON o.`userID` = u.`id` AND o.`status` <> -1 WHERE u.`accountmode` = 1 AND u.`firstlogin` < :threshold AND o.`id` IS NULL SQL;
        $this->connection->executeUpdate($query['threshold' => $threshold]);
    }

    /** * {@inheritdoc} */
    public function cleanupCanceledOrders($months)
    {
        $threshold = (new DateTime())
            ->modify(sprintf('-%d months', $months))
            ->format('Y-m-d H:i:s');

        

    public function updateTimestamp($shopId$timestamp)
    {
        $sql = <<<'sql' INSERT INTO s_core_config_values (`element_id`, `shop_id`, `value`) VALUES ( (SELECT id FROM s_core_config_elements WHERE `name` LIKE 'assetTimestamp' LIMIT 1), :shopId, :value ) ON DUPLICATE KEY UPDATE s_core_config_values.value = :value; sql;

        $this->connection->executeUpdate(
            $sql,
            [
                'value' => serialize($timestamp),
                'shopId' => $shopId,
            ]
        );
    }
}

        });
    }

    /** * @deprecated in 5.6, will be removed in 5.8 without replacement */
    public function clearIndex()
    {
        trigger_error(sprintf('%s:%s is deprecated since Shopware 5.6 and will be removed with 5.8. Will be removed without replacement.', __CLASS__, __METHOD__), E_USER_DEPRECATED);

        $this->connection->executeUpdate('DELETE FROM s_customer_search_index');
    }

    public function cleanupIndex()
    {
        $this->connection->executeUpdate(' DELETE search_index FROM s_customer_search_index search_index LEFT JOIN s_user customer ON customer.id = search_index.id WHERE customer.id IS NULL ');
    }

    
/** * @return void */
    public function addCustomerToStreamAction()
    {
        $streamId = (int) $this->Request()->getParam('streamId');
        $customerId = (int) $this->Request()->getParam('customerId');
        $connection = $this->container->get(Connection::class);

        try {
            $connection->executeUpdate(
                'INSERT INTO s_customer_streams_mapping (stream_id, customer_id) VALUES (:streamId, :customerId)',
                [':streamId' => $streamId, ':customerId' => $customerId]
            );
            $this->View()->assign('success', true);
        } catch (Exception $e) {
            $this->View()->assign('success', false);
        }
    }

    /** * @return void */
return [
            'Shopware_CronJob_CleanupSignatures' => 'cleanup',
        ];
    }

    public function cleanup()
    {
        $date = (new DateTime())
            ->sub(new DateInterval('P10D'))
            ->format('Y-m-d');

        $this->connection->executeUpdate(
            'DELETE FROM ' . BasketPersister::DBAL_TABLE . ' WHERE created_at < :createdAt',
            [':createdAt' => $date]
        );

        return true;
    }
}

    public function resetColumn($table$column)
    {
        $this->validate($table$column);

        if (!$this->tableMapping->isTableColumn($table$column)) {
            throw new Exception(sprintf('Provided column %s does not exist in table %s', $column$table));
        }

        $sql = sprintf('UPDATE `%s` SET `%s` = NULL', $table$column);
        $this->connection->executeUpdate($sql);
    }

    /** * @param string $table * @param string $name * * @throws Exception */
    private function validate($table$name)
    {
        if (!$table) {
            


    /** * Delete products from comparision chart * * @param int $articleId Unique product id - refers to s_articles.id */
    public function sDeleteComparison($articleId)
    {
        $productId = (int) $articleId;
        if ($productId) {
            $this->db->executeUpdate(
                'DELETE FROM s_order_comparisons WHERE sessionID=? AND articleID=?',
                [$this->session->offsetGet('sessionId')$productId]
            );
        }
    }

    /** * Delete all products from comparision chart */
    public function sDeleteComparisons()
    {
        

    public function increment($name)
    {
        $this->connection->beginTransaction();
        try {
            $number = $this->connection->fetchColumn('SELECT number FROM s_order_number WHERE name = ? FOR UPDATE', [$name]);

            if ($number === false) {
                throw new RuntimeException(sprintf('Number range with name "%s" does not exist.', $name));
            }

            $this->connection->executeUpdate('UPDATE s_order_number SET number = number + 1 WHERE name = ?', [$name]);
            ++$number;
            $this->connection->commit();
        } catch (Exception $e) {
            $this->connection->rollBack();
            throw $e;
        }

        return $number;
    }
}
public function deleteResource($resourceName)
    {
        $repository = $this->em->getRepository(UserResource::class);

        /** @var UserResource|null $resource */
        $resource = $repository->findOneBy(['name' => $resourceName]);
        if ($resource === null) {
            return false;
        }

        // The mapping table s_core_acl_roles must be cleared manually.         $this->em->getConnection()->executeUpdate(
            'DELETE FROM s_core_acl_roles WHERE resourceID = ?',
            [$resource->getId()]
        );

        foreach ($resource->getPrivileges() as $privilege) {
            $this->em->remove($privilege);
        }
        // The privileges will be removed automatically         $this->em->remove($resource);
        $this->em->flush();

        
return $thumbnails;
    }

    private function updateMedia(array $data): array
    {
        $imageSize = getimagesizefromstring((string) $this->mediaService->read($data['__media_path']));
        if (!\is_array($imageSize)) {
            throw new RuntimeException(sprintf('Could not get image size from "%s"', $data['__media_path']));
        }
        [$width$height] = $imageSize;
        $this->connection->executeUpdate(
            'UPDATE s_media SET width = :width, height = :height WHERE id = :id',
            [
                ':width' => $width,
                ':height' => $height,
                ':id' => $data['__media_id'],
            ]
        );

        $data['__media_width'] = $width;
        $data['__media_height'] = $height;

        
if ($this->config['sVOTEUNLOCK']) {
            $active = 0;
        } else {
            $active = 1;
        }

        if (!empty($this->session['sArticleCommentInserts'][$article])) {
            $sql = ' DELETE FROM s_articles_vote WHERE id=? ';
            $this->db->executeUpdate($sql[
                $this->session['sArticleCommentInserts'][$article],
            ]);
        }

        $date = date('Y-m-d H:i:s');

        $container = Shopware()->Container();
        $shopId = null;
        if ($container->initialized('shop')) {
            $shopId = $container->get('shop')->getId();
        }

        
Home | Imprint | This part of the site doesn't use cookies.