Skip to content

Commit

Permalink
Merge branch 'v1-develop' into v1
Browse files Browse the repository at this point in the history
  • Loading branch information
hostep committed Jun 11, 2020
2 parents bfdc12f + 1841b28 commit a6e5876
Show file tree
Hide file tree
Showing 24 changed files with 4,123 additions and 3,797 deletions.
11 changes: 11 additions & 0 deletions Block/Adminhtml/Metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ class Metadata extends Template
{
private $metaStorage;

/**
* @param array<mixed> $data
*/
public function __construct(
BackendBlockContext $context,
MetaStorage $metaStorage,
Expand All @@ -23,6 +26,9 @@ public function __construct(
$this->metaStorage = $metaStorage;
}

/**
* @return array<string, mixed>
*/
public function getMetadata()
{
$storageIdentifier = $this->getStorageIdentifier();
Expand All @@ -36,6 +42,11 @@ public function getMetadata()
return $metaData;
}

/**
* @param array<string, mixed> $metaData
*
* @return array<string, mixed>
*/
private function format(array $metaData): array
{
$formatted = [];
Expand Down
19 changes: 16 additions & 3 deletions Checker/Catalog/Category/UrlPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class UrlPath
private $categoryCollectionFactory;
private $attributeScopeOverriddenValueFactory;

/** @var array<string, string> */
private $calculatedUrlPathPerCategoryAndStoreId;

public function __construct(
Expand All @@ -38,13 +39,19 @@ public function __construct(
$this->attributeScopeOverriddenValueFactory = $attributeScopeOverriddenValueFactory;
}

/**
* @return array<array<string, mixed>>
*/
public function execute(): array
{
$categoryData = $this->checkForIncorrectUrlPathAttributeValues();

return $categoryData;
}

/**
* @return array<array<string, mixed>>
*/
public function checkForIncorrectUrlPathAttributeValues(): array
{
$problems = [];
Expand Down Expand Up @@ -81,7 +88,10 @@ public function checkForIncorrectUrlPathAttributeValues(): array
return $problems;
}

private function getAllVisibleCategoriesWithStoreId($storeId): CategoryCollection
/**
* @return CategoryCollection<Category>
*/
private function getAllVisibleCategoriesWithStoreId(int $storeId): CategoryCollection
{
$categories = $this->categoryCollectionFactory->create()
->addAttributeToSelect('name')
Expand Down Expand Up @@ -132,9 +142,9 @@ private function fetchAllCategoriesWithUrlPathCalculatedByUrlKey()
foreach ($allCategories as $category) {
$categoryId = (int) $category->getId();

$path = $category->getPath();
$path = $category->getPath() ?: '';
foreach ($invisibleRootIds as $rootId) {
$path = preg_replace('#^' . preg_quote($rootId) . self::URL_PATH_SEPARATOR . '#', '', $path);
$path = preg_replace('#^' . preg_quote($rootId) . self::URL_PATH_SEPARATOR . '#', '', $path) ?: '';
}

$tempCatData[$categoryId] = [
Expand Down Expand Up @@ -164,6 +174,9 @@ private function fetchAllCategoriesWithUrlPathCalculatedByUrlKey()
}
}

/**
* @return array<string>
*/
private function getAllInvisibleRootIds(): array
{
$categoryIds = $this->categoryCollectionFactory->create()
Expand Down
3 changes: 3 additions & 0 deletions Checker/Catalog/Product/UrlKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public function __construct(
$this->progress = $progress;
}

/**
* @return array<array<string, mixed>>
*/
public function execute(): array
{
$productData = array_merge(
Expand Down
17 changes: 17 additions & 0 deletions Checker/Catalog/Product/UrlKey/DuplicateUrlKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Baldwin\UrlDataIntegrityChecker\Util\Stores as StoresUtil;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Model\Attribute\ScopeOverriddenValueFactory as AttributeScopeOverriddenValueFactory;
use Magento\Catalog\Model\Product as ProductModel;
use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory;
use Magento\Store\Model\Store;
Expand Down Expand Up @@ -37,8 +38,15 @@ public function __construct(
$this->progress = $progress;
$this->productCollectionFactory = $productCollectionFactory;
$this->attributeScopeOverriddenValueFactory = $attributeScopeOverriddenValueFactory;

$this->progressIndex = 0;
$this->cachedProductUrlKeyData = [];
$this->cachedProductSkusByIds = [];
}

/**
* @return array<array<string, mixed>>
*/
public function execute(): array
{
$this->cachedProductUrlKeyData = [];
Expand All @@ -49,6 +57,9 @@ public function execute(): array
return $productData;
}

/**
* @return array<array<string, mixed>>
*/
private function checkForDuplicatedUrlKeyAttributeValues(): array
{
$this->progress->initProgressBar(
Expand Down Expand Up @@ -95,6 +106,9 @@ private function checkForDuplicatedUrlKeyAttributeValues(): array
return $productsWithProblems;
}

/**
* @param ProductCollection<ProductModel> $collection
*/
private function storeProductUrlKeyData(int $storeId, ProductCollection $collection)
{
foreach ($collection as $product) {
Expand All @@ -121,6 +135,9 @@ private function storeProductUrlKeyData(int $storeId, ProductCollection $collect
}
}

/**
* @return array<array<string, mixed>>
*/
private function getProductsWithDuplicatedUrlKeyProblems(): array
{
$problems = [];
Expand Down
14 changes: 14 additions & 0 deletions Checker/Catalog/Product/UrlKey/EmptyUrlKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Baldwin\UrlDataIntegrityChecker\Util\Stores as StoresUtil;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Model\Attribute\ScopeOverriddenValueFactory as AttributeScopeOverriddenValueFactory;
use Magento\Catalog\Model\Product as ProductModel;
use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory;
use Magento\Store\Model\Store;
Expand All @@ -33,15 +34,23 @@ public function __construct(
$this->progress = $progress;
$this->productCollectionFactory = $productCollectionFactory;
$this->attributeScopeOverriddenValueFactory = $attributeScopeOverriddenValueFactory;

$this->progressIndex = 0;
}

/**
* @return array<array<string, mixed>>
*/
public function execute(): array
{
$productData = $this->checkForEmptyUrlKeyAttributeValues();

return $productData;
}

/**
* @return array<array<string, mixed>>
*/
private function checkForEmptyUrlKeyAttributeValues(): array
{
$productsWithProblems = [];
Expand Down Expand Up @@ -96,6 +105,11 @@ private function checkForEmptyUrlKeyAttributeValues(): array
return $productsWithProblems;
}

/**
* @param ProductCollection<ProductModel> $collection
*
* @return array<array<string, mixed>>
*/
private function getProductsWithProblems(int $storeId, ProductCollection $collection): array
{
$problems = [];
Expand Down
12 changes: 12 additions & 0 deletions Checker/Catalog/Product/UrlPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Baldwin\UrlDataIntegrityChecker\Util\Stores as StoresUtil;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Model\Attribute\ScopeOverriddenValueFactory as AttributeScopeOverriddenValueFactory;
use Magento\Catalog\Model\Product as ProductModel;
use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory;
use Magento\Store\Model\Store;
Expand All @@ -33,13 +34,19 @@ public function __construct(
$this->attributeScopeOverriddenValueFactory = $attributeScopeOverriddenValueFactory;
}

/**
* @return array<array<string, mixed>>
*/
public function execute(): array
{
$productData = $this->checkForNonEmptyUrlPathAttributeValues();

return $productData;
}

/**
* @return array<array<string, mixed>>
*/
private function checkForNonEmptyUrlPathAttributeValues(): array
{
$productsWithProblems = [];
Expand Down Expand Up @@ -67,6 +74,11 @@ private function checkForNonEmptyUrlPathAttributeValues(): array
return $productsWithProblems;
}

/**
* @param ProductCollection<ProductModel> $collection
*
* @return array<array<string, mixed>>
*/
private function getProductsWithProblems(int $storeId, ProductCollection $collection): array
{
$problems = [];
Expand Down
3 changes: 3 additions & 0 deletions Console/CategoryResultOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

class CategoryResultOutput
{
/**
* @param array<array<string, mixed>> $categoryData
*/
public function outputResult(array $categoryData, OutputInterface $output): int
{
if (empty($categoryData)) {
Expand Down
3 changes: 3 additions & 0 deletions Console/ProductResultOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

class ProductResultOutput
{
/**
* @param array<array<string, mixed>> $productData
*/
public function outputResult(array $productData, OutputInterface $output): int
{
if (empty($productData)) {
Expand Down
16 changes: 15 additions & 1 deletion Console/Progress.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,21 @@

class Progress
{
/** @var ProgressBar */
private $progressBar;

/** @var OutputInterface */
private $output;

private $sizeByIndex;
private $format;

public function __construct()
{
$this->sizeByIndex = [];
$this->format = '';
}

public function setOutput(OutputInterface $output)
{
$this->output = $output;
Expand Down Expand Up @@ -60,6 +70,10 @@ public function setMessage(string $message)
}
}

/**
* @psalm-suppress ReservedWord
* When we remove PHP 7.0 support from the composer.json file, we can remove this suppress line
*/
public function finish()
{
if ($this->canOutput()) {
Expand All @@ -75,7 +89,7 @@ private function canOutput(): bool
private function updateMaxSteps()
{
if ($this->canOutput()) {
$newMaxStepsValue = array_sum($this->sizeByIndex);
$newMaxStepsValue = (int) array_sum($this->sizeByIndex);

// ugly solution for the fact that the setMaxSteps method only became
// publicly accesible in symfony/console > 4.1.0
Expand Down
8 changes: 6 additions & 2 deletions Cron/ScheduleJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Baldwin\UrlDataIntegrityChecker\Cron;

use Magento\Cron\Model\ResourceModel\Schedule\Collection as CronScheduleCollection;
use Magento\Cron\Model\Schedule;
use Magento\Cron\Model\Schedule as CronScheduleModel;
use Magento\Framework\App\ProductMetadataInterface;
use Magento\Framework\Stdlib\DateTime\DateTime;
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
Expand All @@ -17,6 +17,9 @@ class ScheduleJob
private $timezone;
private $cronScheduleCollection;

/**
* @param CronScheduleCollection<CronScheduleModel> $cronScheduleCollection
*/
public function __construct(
ProductMetadataInterface $productMetadata,
DateTime $dateTime,
Expand All @@ -34,10 +37,11 @@ public function schedule(string $jobCode): bool
$createdAtTime = $this->getCronTimestamp();
$scheduledAtTime = $createdAtTime + (60 - ($createdAtTime % 60)); // set scheduledAtTime to next minute

/** @var CronScheduleModel */
$schedule = $this->cronScheduleCollection->getNewEmptyItem();
$schedule
->setJobCode($jobCode)
->setStatus(Schedule::STATUS_PENDING)
->setStatus(CronScheduleModel::STATUS_PENDING)
->setCreatedAt(strftime('%Y-%m-%d %H:%M:%S', $createdAtTime))
->setScheduledAt(strftime('%Y-%m-%d %H:%M', $scheduledAtTime))
->save();
Expand Down
12 changes: 11 additions & 1 deletion Model/ResourceModel/Catalog/Category/UrlPathCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Magento\Framework\Api\SearchCriteriaInterface;
use Magento\Framework\Data\Collection as DataCollection;
use Magento\Framework\Data\Collection\EntityFactoryInterface;
use Magento\Framework\DataObject;
use Magento\Framework\Exception\LocalizedException;

class UrlPathCollection extends DataCollection implements SearchResultInterface
Expand All @@ -27,6 +28,12 @@ public function __construct(
$this->storage = $storage;
}

/**
* @param bool $printQuery
* @param bool $logQuery
*
* @return UrlPathCollection<DataObject>
*/
public function loadData($printQuery = false, $logQuery = false)
{
if (!$this->isLoaded()) {
Expand Down Expand Up @@ -61,7 +68,10 @@ public function loadData($printQuery = false, $logQuery = false)
return $this;
}

public function createDataObject(array $arguments = [])
/**
* @param array<string, mixed> $arguments
*/
public function createDataObject(array $arguments = []): DataObject
{
$obj = $this->_entityFactory->create($this->_itemObjectClass, ['data' => $arguments]);

Expand Down
Loading

0 comments on commit a6e5876

Please sign in to comment.