0

I am trying to override the below class file in my custom module.

Magento\Deploy\Service\DeployStaticContent.php

Vendor/Module/etc/di.xml

<?xml version="1.0" ?>
  <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
     <preference for="Magento\Deploy\Service\DeployStaticContent" 
   type="Vendor\Module\Deploy\Service\DeployStaticContent"/>    
   </config>

Vendor\Module\Deploy\Service\DeployStaticContent.php

 <?php

 namespace Vendor\Module\Deploy\Service;

 class DeployStaticContent extends \Magento\Deploy\Service\DeployStaticContent
 {

  public function deploy(array $options)
  {
    $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/test.log');
    $logger = new \Zend\Log\Logger();
    $logger->addWriter($writer);
    $logger->info('deployment start--');
    $version = !empty($options[Options::CONTENT_VERSION]) && is_string($options[Options::CONTENT_VERSION])
        ? $options[Options::CONTENT_VERSION]
        : (new \DateTime())->getTimestamp();
    $this->versionStorage->save($version);

    if ($this->isRefreshContentVersionOnly($options)) {
        $this->logger->warning("New content version: " . $version);
        return;
    }

    $queueOptions = [
        'logger' => $this->logger,
        'options' => $options,
        'maxProcesses' => $this->getProcessesAmount($options),
        'deployPackageService' => $this->objectManager->create(
            \Magento\Deploy\Service\DeployPackage::class,
            [
                'logger' => $this->logger
            ]
        )
    ];

    if (isset($options[Options::MAX_EXECUTION_TIME])) {
        $queueOptions['maxExecTime'] = (int)$options[Options::MAX_EXECUTION_TIME];
    }

    $deployStrategy = $this->deployStrategyFactory->create(
        $options[Options::STRATEGY],
        ['queue' => $this->queueFactory->create($queueOptions)]
    );

    $packages = $deployStrategy->deploy($options);

    if ($options[Options::NO_JAVASCRIPT] !== true) {
        $deployRjsConfig = $this->objectManager->create(
            DeployRequireJsConfig::class,
            ['logger' => $this->logger]
        );
        $deployI18n      = $this->objectManager->create(
            DeployTranslationsDictionary::class,
            ['logger' => $this->logger]
        );
        foreach ($packages as $package) {
            if (!$package->isVirtual()) {
                $deployRjsConfig->deploy($package->getArea(), $package->getTheme(), $package->getLocale());
                $deployI18n->deploy($package->getArea(), $package->getTheme(), $package->getLocale());
            }
        }
    }

    if ($options[Options::NO_JAVASCRIPT] !== true && $options[Options::NO_JS_BUNDLE] !== true) {
        $deployBundle = $this->objectManager->create(
            Bundle::class,
            ['logger' => $this->logger]
        );
        foreach ($packages as $package) {
            if (!$package->isVirtual()) {
                $deployBundle->deploy($package->getArea(), $package->getTheme(), $package->getLocale());
            }
        }
    }

    if ($options[Options::NO_HTML_MINIFY] !== true) {
        $this->objectManager->get(MinifyTemplates::class)->minifyTemplates();
      }
    
  }
}

This seems not working, can anyone help me with this, I want to write custom code after the static content deploy activity.

Thanks in Advance!!

1 Answer 1

0

Try doing the following changes:

     <preference 
       for="Magento\Deploy\Service\DeployStaticContent" 
       type="Vendor\Deploy\Service\DeployStaticContent"
     />

Module to be 'Deploy'.

Also replace you code from path

Vendor\Module\Deploy\Service\DeployStaticContent.php

to

Vendor\Deploy\Service\DeployStaticContent.php

Let me know if it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.