/**
  * Registers the bundle modules
  */
 public function __construct()
 {
     PlentymarketsUtils::registerBundleModules();
 }
    /**
     * Prunes the item bundles
     */
    protected function pruneItemBundles()
    {
        // Register the modules
        PlentymarketsUtils::registerBundleModules();
        // Create a temporary table
        Shopware()->Db()->exec('
			CREATE TEMPORARY TABLE IF NOT EXISTS plenty_cleanup_item_bundle
				(bundleId INT UNSIGNED, INDEX (bundleId))
				ENGINE = MEMORY;
		');
        // Get all bundles - regardless of store ids
        $Request_GetItemBundles = new PlentySoapRequest_GetItemBundles();
        $Request_GetItemBundles->LastUpdate = 0;
        $Request_GetItemBundles->Page = 0;
        do {
            /** @var PlentySoapResponse_GetItemBundles $Response_GetItemsBase */
            $Response_GetItemBundles = PlentymarketsSoapClient::getInstance()->GetItemBundles($Request_GetItemBundles);
            // Call failed
            if (is_null($Response_GetItemBundles) || !property_exists($Response_GetItemBundles, 'ItemBundles')) {
                // Log
                PlentymarketsLogger::getInstance()->error('Cleanup:Item:Bundle', 'Aborting. GetItemBundles apparently failed');
                // Delete the temporary table
                Shopware()->Db()->exec('
					DROP TEMPORARY TABLE plenty_cleanup_item_bundle
				');
                return;
            }
            $bundleIds = array();
            // Collect the bundle head ids
            foreach ($Response_GetItemBundles->ItemBundles->item as $bundle) {
                /** @var PlentySoapObject_Bundle $bundle */
                $plentyBundleHeadSku = explode('-', $bundle->SKU);
                $plentyBundleHeadId = (int) $plentyBundleHeadSku[0];
                $bundleIds[] = $plentyBundleHeadId;
            }
            if (empty($bundleIds)) {
                break;
            }
            // Build the sql statement
            $bundleIdsSql = implode(', ', array_map(function ($itemId) {
                return sprintf('(%u)', $itemId);
            }, $bundleIds));
            // Fill the table
            Shopware()->Db()->exec('
				INSERT IGNORE INTO plenty_cleanup_item_bundle VALUES ' . $bundleIdsSql . '
			');
        } while (++$Request_GetItemBundles->Page < $Response_GetItemBundles->Pages);
        // Get all shopware bundles which are no longer in plentymarkets
        $bundles = Shopware()->Db()->fetchAll('
			SELECT
					id
				FROM s_articles_bundles
				WHERE
					id NOT IN (
						SELECT pmi.shopwareID
							FROM plenty_cleanup_item_bundle pci
							LEFT JOIN plenty_mapping_item_bundle pmi ON pmi.plentyID = pci.bundleId
							WHERE pmi.shopwareID IS NOT NULL
					)
		');
        // And delete them
        foreach ($bundles as $bundle) {
            /** @var Shopware\CustomModels\Bundle\Bundle $bundle */
            $bundle = Shopware()->Models()->find('Shopware\\CustomModels\\Bundle\\Bundle', $bundle['id']);
            Shopware()->Models()->remove($bundle);
            // Log
            PyLog()->message('Cleanup:Item:Bundle', 'The item bundle »' . $bundle->getName() . '« with the number »' . $bundle->getNumber() . '« has been deleted');
        }
        Shopware()->Models()->flush();
        Shopware()->Db()->delete('plenty_mapping_item_bundle', 'shopwareID NOT IN (SELECT id FROM s_articles_bundles)');
    }