Process abandoned carts for automation program enrolment

@param \Magento\Store\Api\Data\StoreInterface $store

@return void
@throws \Exception
975807
private function processAbandonedCartsProgramEnrolmentAutomation($store)
    {
        $storeId = $store->getId();
        $programId = $this->helper->getScopeConfig()->getValue(
            \Dotdigitalgroup\Email\Helper\Config::XML_PATH_LOSTBASKET_ENROL_TO_PROGRAM_ID,
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
            $storeId
        );

        if (empty($programId) || $programId === "0") {
            return;
        }

        $updated = $this->interval->getAbandonedCartProgramEnrolmentWindow($storeId);

        $quoteCollection = $this->getStoreQuotesForGuestsAndCustomers($storeId, $updated);

        foreach ($quoteCollection as $quote) {
            $this->saver->save($quote, $store, $programId);
            $this->cartInsight->send($quote, $storeId);
        }
    }
1006175
final public function process(BuildInterface $build)
    {
        if (($status = $this->build($build)) === true) {
            $build->setStatus(BuildInterface::PASSED);
        } elseif ($status == -1) {
            $build->setStatus(BuildInterface::STOPPED);
        } else {
            $build->setStatus(BuildInterface::FAILED);
        }
    }
577522
public function restore($identifier)
    {
        if( ! $this->storedCartWithIdentifierExists($identifier)) {
            return;
        }

        $stored = $this->getConnection()->table($this->getTableName())
            ->where('identifier', $identifier)->first();

        $storedContent = unserialize($stored->content);

        $currentInstance = $this->currentInstance();

        $this->instance($stored->instance);

        $content = $this->getContent();

        foreach ($storedContent as $cartItem) {
            $content->put($cartItem->rowId, $cartItem);
        }

        $this->events->fire('cart.restored');

        $this->session->put($this->instance, $content);

        $this->instance($currentInstance);

        $this->getConnection()->table($this->getTableName())
            ->where('identifier', $identifier)->delete();
    }
764718
public function performAddStoreFilter($store, $withAdmin = true)
    {
        if ($store instanceof Store) {
            $store = [$store->getId()];
        }

        if (!is_array($store)) {
            $store = [$store];
        }

        if ($withAdmin) {
            $store[] = Store::DEFAULT_STORE_ID;
        }

        $this->addFilter('store', ['in' => $store], 'public');
    }
55355
public function execute(DataSetInterface $dataSet): void
    {
        $shoppingListItemEntity = $this->createShoppingListItemQuery()
            ->filterByFkShoppingList($dataSet[ShoppingListItemDataSetInterface::ID_SHOPPING_LIST])
            ->filterBySku($dataSet[ShoppingListItemDataSetInterface::COLUMN_PRODUCT_SKU])
            ->findOneOrCreate();

        $shoppingListItemEntity
            ->setQuantity($dataSet[ShoppingListItemDataSetInterface::COLUMN_QUANTITY])
            ->save();
    }
150534
final public function process(BuildInterface $build)
    {
        $result = $this->checkModified($build);
        $this->frame->addResult($result);
    }
1219860
private function checkProductsAvailability(OrderInterface $cart)
    {
        // no check needed
        if ($cart->getItems()->isEmpty()) {
            return true;
        }

        $containsInvalidProducts = false;
        /** @var \Sulu\Bundle\Sales\CoreBundle\Entity\ItemInterface $item */
        foreach ($cart->getItems() as $item) {
            if (!$item->getProduct() ||
                !$item->getProduct()->isValidShopProduct()
            ) {
                $containsInvalidProducts = true;
                $cart->removeItem($item);
                $this->em->remove($item);
            }
        }
        // persist new cart
        if ($containsInvalidProducts) {
            $this->em->flush();
        }

        return !$containsInvalidProducts;
    }
810489
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $io = new SymfonyStyle($input, $output);
        $context = Context::createDefaultContext();
        $plugins = $this->prepareExecution(self::LIFECYCLE_METHOD, $io, $input, $context);

        $keepUserData = (bool) $input->getOption('keep-user-data');

        $uninstalledPluginCount = 0;
        /** @var PluginEntity $plugin */
        foreach ($plugins as $plugin) {
            if ($plugin->getInstalledAt() === null) {
                $io->note(sprintf('Plugin "%s" is not installed. Skipping.', $plugin->getName()));

                continue;
            }

            $this->pluginLifecycleService->uninstallPlugin($plugin, $context, $keepUserData);
            ++$uninstalledPluginCount;

            $io->text(sprintf('Plugin "%s" has been uninstalled successfully.', $plugin->getName()));
        }

        if ($uninstalledPluginCount !== 0) {
            $io->success(sprintf('Uninstalled %d plugins.', $uninstalledPluginCount));
        }
    }
1145461
public function isStoreSelected(\Magento\Store\Model\Store $store)
    {
        return $this->getStoreId() !== null && (int) $this->getStoreId() === (int) $store->getId();
    }
916807
protected function doesResourceExist(StoreInterface $store, $resourceType, $resourceId)
    {
        $identifier = ResourceIdentifier::create($resourceType, $resourceId);

        return $store->exists($identifier);
    }
970830
public function rollback(ContainerInterface $container): void
    {
        foreach ($this->getRollbacks($container) as $class) {
            assert(is_string($class));
            $this->getIO()->writeInfo("Starting rollback for `$class`..." . PHP_EOL, IoInterface::VERBOSITY_VERBOSE);
            if (($migration = $this->createMigration($class, $container)) !== null) {
                $migration->init($container)->rollback();
                $this->getIO()->writeInfo("Rollback finished for `$class`." . PHP_EOL, IoInterface::VERBOSITY_NORMAL);
            }
        }

        $manager = $this->getConnection($container)->getSchemaManager();
        if ($manager->tablesExist([static::MIGRATIONS_TABLE]) === true) {
            $manager->dropTable(static::MIGRATIONS_TABLE);
        }
        if ($manager->tablesExist([static::SEEDS_TABLE]) === true) {
            $manager->dropTable(static::SEEDS_TABLE);
        }
    }
149121
public function execute(StorageInterface $storage, Operations $operations)
    {
        foreach ($operations->getOperations() as $operation) {
            if ($operation instanceof AddDocumentOperation) {
                $document = $operation->getDocument();
                $event = new DocumentEvent($document);
                if ($this->eventDispatcher->dispatch(IndexerEvents::BEFORE_STORAGE_ADD_DOCUMENT, $event)
                    ->isPropagationStopped()
                ) {
                    continue;
                }

                $storage->addDocument($document);

                $event = new DocumentEvent($document);
                $this->eventDispatcher->dispatch(IndexerEvents::STORAGE_ADD_DOCUMENT, $event);
            } elseif ($operation instanceof AddIdentityOperation) {
                throw new InvalidArgumentException('Add identity command not supported by run().');
            } elseif ($operation instanceof UpdateDocumentOperation) {
                $document = $operation->getDocument();
                $event = new DocumentEvent($document);
                if ($this->eventDispatcher->dispatch(IndexerEvents::BEFORE_STORAGE_UPDATE_DOCUMENT, $event)->isPropagationStopped()) {
                    continue;
                }

                $storage->updateDocument($document);

                $event = new DocumentEvent($document);
                $this->eventDispatcher->dispatch(IndexerEvents::STORAGE_UPDATE_DOCUMENT, $event);
            } elseif ($operation instanceof UpdateIdentityOperation) {
                throw new InvalidArgumentException('Update identity command not supported by run().');
            } elseif ($operation instanceof DeleteDocumentOperation) {
                $storage->deleteDocument($operation->getDocument());
            } elseif ($operation instanceof DeleteIdentityOperation) {
                $storage->delete($operation->getIdentity());
            } elseif ($operation instanceof DeleteTypeOperation) {
                $storage->deleteType($operation->getType());
            } elseif ($operation instanceof DeleteAllOperation) {
                $storage->deleteAll();
            } elseif ($operation instanceof FlushOperation) {
                if ($storage instanceof Flushable) {
                    $storage->flush();
                }
            } elseif ($operation instanceof OptimizeOperation) {
                if ($storage instanceof Optimizable) {
                    $storage->optimize();
                }
            } elseif ($operation instanceof CommitOperation) {
                if ($storage instanceof Commitable) {
                    $storage->commit();
                }
            } elseif ($operation instanceof RollbackOperation) {
                if ($storage instanceof Rollbackable) {
                    $storage->rollback();
                }
            }
        }

        return true;
    }
8602
private function setTenant(?TenantInterface $tenant, ?TokenStorageInterface $tokenStorage): void
    {
        if ($tenant !== null) {
            $this->tenant = $tenant;
        } elseif ($tokenStorage !== null) {
            $token = $tokenStorage->getToken();

            if ($token !== null) {
                $tenant = $token->getUser();

                if ($tenant instanceof TenantInterface) {
                    $this->tenant = $tenant;
                }
            }
        } else {
            throw new \RuntimeException('Can\'t get tenant');
        }
    }
145806
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->input = $input;
        $this->setOutput($output);
        //
        if ($this->database && config('components.database')) {
            Database::ini();
        } elseif ($this->database && !config('components.database')) {
            exception(LogicException::class, 'The database surface is disabled');
        }
        //
        $this->handle();
    }
394399
protected function process()
    {

        // prepare the store view code
        $this->prepareStoreViewCode($this->getRow());

        // load the store view code
        $storeViewCode = $this->getStoreViewCode(StoreViewCodes::ADMIN);

        // check if we're in default store
        if (!$this->isDefaultStore($storeViewCode)) {
            // prepare and initialize the bundle selection price
            $productBundleSelectionPrice = $this->initializeBundleSelectionPrice($this->prepareAttributes());

            // persist the bundle selection price
            $this->persistProductBundleSelectionPrice($productBundleSelectionPrice);
        }
    }
627353
public function _after(\Codeception\TestInterface $test)
    {
        if ($this->applicationUsesDatabase()) {
            $db = $this->app['db'];

            if ($db instanceof \Illuminate\Database\DatabaseManager) {
                if ($this->config['cleanup']) {
                    $db->rollback();
                    $this->debugSection('Database', 'Transaction cancelled; all changes reverted.');
                }

                /**
                 * Close all DB connections in order to prevent "Too many connections" issue
                 *
                 * @var \Illuminate\Database\Connection $connection
                 */
                foreach ($db->getConnections() as $connection) {
                    $connection->disconnect();
                }
            }

            // Remove references to Faker in factories to prevent memory leak
            unset($this->app[\Faker\Generator::class]);
            unset($this->app[\Illuminate\Database\Eloquent\Factory::class]);
        }
    }
147269
public function loadCartShippingAmount(CartInterface $cart)
    {
        $shippingMethodId = $cart->getShippingMethod();

        if (empty($shippingMethodId)) {
            return;
        }

        $shippingMethod = $this
            ->shippingWrapper
            ->getOneById($cart, $shippingMethodId);

        if ($shippingMethod instanceof ShippingMethod) {
            $cart->setShippingAmount(
                $shippingMethod->getPrice()
            );
        }
    }