From f0c73989ae2ee2ba79be21705c83e508bcb72bf3 Mon Sep 17 00:00:00 2001 From: Pieter Hoste Date: Mon, 24 Apr 2023 15:21:34 +0200 Subject: [PATCH 1/2] Remove obsolete ResourceModel\Product dependency and reworked DateTime to DateTimeFactory. Both of these caused unnecessary connections to be made to the database when executing bin/magento commands. --- .../Model/ResourceModel/GetEntityContent.php | 11 +---------- .../Model/SynchronizeFiles.php | 14 +++++++------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/app/code/Magento/MediaContentCatalog/Model/ResourceModel/GetEntityContent.php b/app/code/Magento/MediaContentCatalog/Model/ResourceModel/GetEntityContent.php index c3766484ce4f1..9136f24549289 100644 --- a/app/code/Magento/MediaContentCatalog/Model/ResourceModel/GetEntityContent.php +++ b/app/code/Magento/MediaContentCatalog/Model/ResourceModel/GetEntityContent.php @@ -7,7 +7,6 @@ namespace Magento\MediaContentCatalog\Model\ResourceModel; -use Magento\Catalog\Model\ResourceModel\Product; use Magento\Framework\App\ResourceConnection; use Magento\MediaContentApi\Model\GetEntityContentsInterface; use Magento\MediaContentApi\Api\Data\ContentIdentityInterface; @@ -23,11 +22,6 @@ class GetEntityContent implements GetEntityContentsInterface */ private $config; - /** - * @var Product - */ - private $productResource; - /** * @var ResourceConnection */ @@ -36,15 +30,12 @@ class GetEntityContent implements GetEntityContentsInterface /** * @param Config $config * @param ResourceConnection $resourceConnection - * @param Product $productResource */ public function __construct( Config $config, - ResourceConnection $resourceConnection, - Product $productResource + ResourceConnection $resourceConnection ) { $this->config = $config; - $this->productResource = $productResource; $this->resourceConnection = $resourceConnection; } diff --git a/app/code/Magento/MediaGallerySynchronization/Model/SynchronizeFiles.php b/app/code/Magento/MediaGallerySynchronization/Model/SynchronizeFiles.php index eebb172e48202..01465eb2b27aa 100644 --- a/app/code/Magento/MediaGallerySynchronization/Model/SynchronizeFiles.php +++ b/app/code/Magento/MediaGallerySynchronization/Model/SynchronizeFiles.php @@ -12,7 +12,7 @@ use Magento\Framework\Filesystem; use Magento\Framework\Filesystem\Directory\ReadInterface; use Magento\Framework\Filesystem\Driver\File; -use Magento\Framework\Stdlib\DateTime\DateTime; +use Magento\Framework\Stdlib\DateTime\DateTimeFactory; use Magento\MediaGalleryApi\Api\GetAssetsByPathsInterface; use Magento\MediaGallerySynchronizationApi\Model\ImportFilesInterface; use Magento\MediaGallerySynchronizationApi\Api\SynchronizeFilesInterface; @@ -60,14 +60,14 @@ class SynchronizeFiles implements SynchronizeFilesInterface private $importFiles; /** - * @var DateTime + * @var DateTimeFactory */ - private $date; + private $dateFactory; /** * @param File $driver * @param Filesystem $filesystem - * @param DateTime $date + * @param DateTime $dateFactory * @param LoggerInterface $log * @param GetFileInfo $getFileInfo * @param GetAssetsByPathsInterface $getAssetsByPaths @@ -76,7 +76,7 @@ class SynchronizeFiles implements SynchronizeFilesInterface public function __construct( File $driver, Filesystem $filesystem, - DateTime $date, + DateTimeFactory $dateFactory, LoggerInterface $log, GetFileInfo $getFileInfo, GetAssetsByPathsInterface $getAssetsByPaths, @@ -84,7 +84,7 @@ public function __construct( ) { $this->driver = $driver; $this->filesystem = $filesystem; - $this->date = $date; + $this->dateFactory = $dateFactory; $this->log = $log; $this->getFileInfo = $getFileInfo; $this->getAssetsByPaths = $getAssetsByPaths; @@ -148,7 +148,7 @@ private function getPathsToUpdate(array $paths): array */ private function getFileModificationTime(string $path): string { - return $this->date->gmtDate( + return $this->dateFactory->create()->gmtDate( self::DATE_FORMAT, $this->getFileInfo->execute($this->getMediaDirectory()->getAbsolutePath($path))->getMTime() ); From 6499d91eb64753fc23158d97cc93fda03667d32d Mon Sep 17 00:00:00 2001 From: Ihor Sviziev Date: Wed, 26 Apr 2023 14:19:14 +0300 Subject: [PATCH 2/2] Fix for running bin/magento without proper database connection (removes db connection attempts from DI constructors) Fix typo Co-authored-by: Dan Wallis --- .../MediaGallerySynchronization/Model/SynchronizeFiles.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/MediaGallerySynchronization/Model/SynchronizeFiles.php b/app/code/Magento/MediaGallerySynchronization/Model/SynchronizeFiles.php index 01465eb2b27aa..231b7e92f065e 100644 --- a/app/code/Magento/MediaGallerySynchronization/Model/SynchronizeFiles.php +++ b/app/code/Magento/MediaGallerySynchronization/Model/SynchronizeFiles.php @@ -67,7 +67,7 @@ class SynchronizeFiles implements SynchronizeFilesInterface /** * @param File $driver * @param Filesystem $filesystem - * @param DateTime $dateFactory + * @param DateTimeFactory $dateFactory * @param LoggerInterface $log * @param GetFileInfo $getFileInfo * @param GetAssetsByPathsInterface $getAssetsByPaths