ver. 0.294: Code review complete — 96/96 classes, 27 fixes across all layers
Full codebase review of autoload/ directory (96 classes, ~1144 methods). Fixes: null safety (query/find guards), redundant DI bypass, undefined variables, missing globals, and Imagick WebP mime type bug in Helpers. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -769,31 +769,4 @@ class CategoryRepository
|
||||
return is_array($result) ? $result : [];
|
||||
}
|
||||
|
||||
public function subcategoriesLangCached(int $categoryId): array
|
||||
{
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "subcategories_lang:{$categoryId}";
|
||||
$cached = $cacheHandler->get($cacheKey);
|
||||
|
||||
if ($cached) {
|
||||
return unserialize($cached);
|
||||
}
|
||||
|
||||
$categories = $this->db->select('pp_shop_categories', '*', ['parent_id' => $categoryId]);
|
||||
if (!is_array($categories)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$result = [];
|
||||
foreach ($categories as $cat) {
|
||||
$lang = $this->db->get('pp_shop_categories_langs', '*', ['category_id' => $cat['id']]);
|
||||
if (is_array($lang)) {
|
||||
$result[] = $lang;
|
||||
}
|
||||
}
|
||||
|
||||
$cacheHandler->set($cacheKey, $result);
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -358,8 +358,9 @@ class ClientRepository
|
||||
|
||||
$orders = [];
|
||||
if (is_array($rows)) {
|
||||
$orderRepo = new \Domain\Order\OrderRepository($this->db);
|
||||
foreach ($rows as $row) {
|
||||
$orders[] = (new \Domain\Order\OrderRepository($this->db))->orderDetailsFrontend($row);
|
||||
$orders[] = $orderRepo->orderDetailsFrontend($row);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -248,10 +248,8 @@ class DictionariesRepository
|
||||
|
||||
private function clearCache(): void
|
||||
{
|
||||
if (class_exists('\S') && method_exists('\S', 'delete_dir')) {
|
||||
\Shared\Helpers\Helpers::delete_dir('../temp/');
|
||||
\Shared\Helpers\Helpers::delete_dir('../temp/dictionaries');
|
||||
}
|
||||
\Shared\Helpers\Helpers::delete_dir('../temp/');
|
||||
\Shared\Helpers\Helpers::delete_dir('../temp/dictionaries');
|
||||
}
|
||||
|
||||
private function cacheFetch(string $key)
|
||||
|
||||
@@ -28,7 +28,8 @@ class IntegrationsRepository
|
||||
public function getSettings( string $provider ): array
|
||||
{
|
||||
$table = $this->settingsTable( $provider );
|
||||
$results = $this->db->query( "SELECT * FROM $table" )->fetchAll( \PDO::FETCH_ASSOC );
|
||||
$stmt = $this->db->query( "SELECT * FROM $table" );
|
||||
$results = $stmt ? $stmt->fetchAll( \PDO::FETCH_ASSOC ) : [];
|
||||
$settings = [];
|
||||
foreach ( $results as $row )
|
||||
$settings[$row['name']] = $row['value'];
|
||||
@@ -535,8 +536,9 @@ class IntegrationsRepository
|
||||
|
||||
$response = curl_exec( $ch );
|
||||
if ( curl_errno( $ch ) ) {
|
||||
$error = curl_error( $ch );
|
||||
curl_close( $ch );
|
||||
return [ 'status' => 'error', 'msg' => 'Błąd cURL: ' . curl_error( $ch ) ];
|
||||
return [ 'status' => 'error', 'msg' => 'Błąd cURL: ' . $error ];
|
||||
}
|
||||
curl_close( $ch );
|
||||
|
||||
@@ -595,8 +597,8 @@ class IntegrationsRepository
|
||||
if ( !empty( $responseData['products'] ) ) {
|
||||
$this->db->update( 'pp_shop_products', [
|
||||
'apilo_product_id' => reset( $responseData['products'] ),
|
||||
'apilo_product_name' => $product->language['name'],
|
||||
], [ 'id' => $product->id ] );
|
||||
'apilo_product_name' => $product['language']['name'],
|
||||
], [ 'id' => $product['id'] ] );
|
||||
|
||||
return [ 'success' => true, 'message' => 'Produkt został dodany do magazynu APILO.' ];
|
||||
}
|
||||
|
||||
@@ -345,9 +345,10 @@ class LanguagesRepository
|
||||
return unserialize($objectData);
|
||||
}
|
||||
|
||||
$results = $this->db->query(
|
||||
$stmt = $this->db->query(
|
||||
'SELECT id FROM pp_langs WHERE status = 1 ORDER BY start DESC, o ASC LIMIT 1'
|
||||
)->fetchAll();
|
||||
);
|
||||
$results = $stmt ? $stmt->fetchAll() : [];
|
||||
|
||||
$defaultLanguage = $results[0][0] ?? 'pl';
|
||||
|
||||
|
||||
@@ -271,25 +271,27 @@ class LayoutsRepository
|
||||
$cacheHandler->delete($cacheKey);
|
||||
}
|
||||
|
||||
$layoutRows = $this->db->query(
|
||||
$stmt = $this->db->query(
|
||||
"SELECT pp_layouts.*
|
||||
FROM pp_layouts
|
||||
JOIN pp_shop_products ON pp_layouts.id = pp_shop_products.layout_id
|
||||
WHERE pp_shop_products.id = " . (int)$productId . "
|
||||
ORDER BY pp_layouts.id DESC"
|
||||
)->fetchAll(\PDO::FETCH_ASSOC);
|
||||
);
|
||||
$layoutRows = $stmt ? $stmt->fetchAll(\PDO::FETCH_ASSOC) : [];
|
||||
|
||||
if (is_array($layoutRows) && isset($layoutRows[0])) {
|
||||
$layout = $layoutRows[0];
|
||||
} else {
|
||||
$layoutRows = $this->db->query(
|
||||
$stmt2 = $this->db->query(
|
||||
"SELECT pp_layouts.*
|
||||
FROM pp_layouts
|
||||
JOIN pp_layouts_categories ON pp_layouts.id = pp_layouts_categories.layout_id
|
||||
JOIN pp_shop_products_categories ON pp_shop_products_categories.category_id = pp_layouts_categories.category_id
|
||||
WHERE pp_shop_products_categories.product_id = " . (int)$productId . "
|
||||
ORDER BY pp_shop_products_categories.o ASC, pp_layouts.id DESC"
|
||||
)->fetchAll(\PDO::FETCH_ASSOC);
|
||||
);
|
||||
$layoutRows = $stmt2 ? $stmt2->fetchAll(\PDO::FETCH_ASSOC) : [];
|
||||
|
||||
if (is_array($layoutRows) && isset($layoutRows[0])) {
|
||||
$layout = $layoutRows[0];
|
||||
@@ -348,13 +350,14 @@ class LayoutsRepository
|
||||
$cacheHandler->delete($cacheKey);
|
||||
}
|
||||
|
||||
$layoutRows = $this->db->query(
|
||||
$stmt = $this->db->query(
|
||||
"SELECT pp_layouts.*
|
||||
FROM pp_layouts
|
||||
JOIN pp_layouts_categories ON pp_layouts.id = pp_layouts_categories.layout_id
|
||||
WHERE pp_layouts_categories.category_id = " . (int)$categoryId . "
|
||||
ORDER BY pp_layouts.id DESC"
|
||||
)->fetchAll(\PDO::FETCH_ASSOC);
|
||||
);
|
||||
$layoutRows = $stmt ? $stmt->fetchAll(\PDO::FETCH_ASSOC) : [];
|
||||
|
||||
if (is_array($layoutRows) && isset($layoutRows[0])) {
|
||||
$layout = $layoutRows[0];
|
||||
|
||||
@@ -206,18 +206,21 @@ class OrderAdminService
|
||||
}
|
||||
|
||||
$query = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'pp_shop_orders' AND COLUMN_NAME != 'id'";
|
||||
$columns = $mdb->query($query)->fetchAll(\PDO::FETCH_COLUMN);
|
||||
$stmt = $mdb->query($query);
|
||||
$columns = $stmt ? $stmt->fetchAll(\PDO::FETCH_COLUMN) : [];
|
||||
$columnsList = implode(', ', $columns);
|
||||
$mdb->query('INSERT INTO pp_shop_orders (' . $columnsList . ') SELECT ' . $columnsList . ' FROM pp_shop_orders pso WHERE pso.id = ' . $orderId);
|
||||
$newOrderId = (int)$mdb->id();
|
||||
|
||||
$query = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'pp_shop_order_products' AND COLUMN_NAME != 'id' AND COLUMN_NAME != 'order_id'";
|
||||
$columns = $mdb->query($query)->fetchAll(\PDO::FETCH_COLUMN);
|
||||
$stmt2 = $mdb->query($query);
|
||||
$columns = $stmt2 ? $stmt2->fetchAll(\PDO::FETCH_COLUMN) : [];
|
||||
$columnsList = implode(', ', $columns);
|
||||
$mdb->query('INSERT INTO pp_shop_order_products (order_id, ' . $columnsList . ') SELECT ' . $newOrderId . ', ' . $columnsList . ' FROM pp_shop_order_products psop WHERE psop.order_id = ' . $orderId);
|
||||
|
||||
$query = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'pp_shop_order_statuses' AND COLUMN_NAME != 'id' AND COLUMN_NAME != 'order_id'";
|
||||
$columns = $mdb->query($query)->fetchAll(\PDO::FETCH_COLUMN);
|
||||
$stmt3 = $mdb->query($query);
|
||||
$columns = $stmt3 ? $stmt3->fetchAll(\PDO::FETCH_COLUMN) : [];
|
||||
$columnsList = implode(', ', $columns);
|
||||
$mdb->query('INSERT INTO pp_shop_order_statuses (order_id, ' . $columnsList . ') SELECT ' . $newOrderId . ', ' . $columnsList . ' FROM pp_shop_order_statuses psos WHERE psos.order_id = ' . $orderId);
|
||||
|
||||
|
||||
@@ -501,9 +501,10 @@ class OrderRepository
|
||||
{
|
||||
$date = date('Y-m');
|
||||
|
||||
$results = $this->db->query(
|
||||
$stmt = $this->db->query(
|
||||
'SELECT MAX( CONVERT( substring_index( substring_index( number, \'/\', -1 ), \' \', -1 ), UNSIGNED INTEGER) ) FROM pp_shop_orders WHERE date_order LIKE \'' . $date . '%\''
|
||||
)->fetchAll();
|
||||
);
|
||||
$results = $stmt ? $stmt->fetchAll() : [];
|
||||
|
||||
$nr = 0;
|
||||
if (is_array($results) && count($results)) {
|
||||
@@ -618,6 +619,7 @@ class OrderRepository
|
||||
$this->db->insert('pp_shop_order_statuses', ['order_id' => $order_id, 'status_id' => 0, 'mail' => 1]);
|
||||
|
||||
if (is_array($basket)) {
|
||||
$attributeRepo = new \Domain\Attribute\AttributeRepository($this->db);
|
||||
foreach ($basket as $basket_position) {
|
||||
$attributes = '';
|
||||
$product = $productRepo->findCached($basket_position['product-id'], $lang_id);
|
||||
@@ -625,7 +627,6 @@ class OrderRepository
|
||||
if (is_array($basket_position['attributes'])) {
|
||||
foreach ($basket_position['attributes'] as $row) {
|
||||
$row = explode('-', $row);
|
||||
$attributeRepo = new \Domain\Attribute\AttributeRepository($this->db);
|
||||
$attribute = $attributeRepo->frontAttributeDetails((int)$row[0], $lang_id);
|
||||
$value = $attributeRepo->frontValueDetails((int)$row[1], $lang_id);
|
||||
|
||||
@@ -641,7 +642,7 @@ class OrderRepository
|
||||
$product_custom_fields = '';
|
||||
if (is_array($basket_position['custom_fields'])) {
|
||||
foreach ($basket_position['custom_fields'] as $key => $val) {
|
||||
$custom_field = (new \Domain\Product\ProductRepository($this->db))->findCustomFieldCached($key);
|
||||
$custom_field = $productRepo->findCustomFieldCached($key);
|
||||
if ($product_custom_fields) {
|
||||
$product_custom_fields .= '<br>';
|
||||
}
|
||||
|
||||
@@ -1154,6 +1154,11 @@ class ProductRepository
|
||||
*/
|
||||
public function updateCustomLabel(int $productId, string $label, $value): bool
|
||||
{
|
||||
$allowed = ['0', '1', '2', '3', '4'];
|
||||
if (!in_array($label, $allowed, true)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->db->update( 'pp_shop_products', [
|
||||
'custom_label_' . $label => $value ? $value : null,
|
||||
], [ 'id' => $productId ] );
|
||||
@@ -1478,6 +1483,11 @@ class ProductRepository
|
||||
*/
|
||||
public function customLabelSuggestions(string $customLabel, string $labelType): array
|
||||
{
|
||||
$allowed = ['custom_label_0', 'custom_label_1', 'custom_label_2', 'custom_label_3', 'custom_label_4'];
|
||||
if (!in_array($labelType, $allowed, true)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$output = [];
|
||||
$results = $this->db->query(
|
||||
'SELECT DISTINCT ' . $labelType . ' AS label FROM pp_shop_products WHERE ' . $labelType . ' LIKE :custom_label LIMIT 10',
|
||||
@@ -1496,6 +1506,11 @@ class ProductRepository
|
||||
*/
|
||||
public function saveCustomLabel(int $productId, string $customLabel, string $labelType): bool
|
||||
{
|
||||
$allowed = ['custom_label_0', 'custom_label_1', 'custom_label_2', 'custom_label_3', 'custom_label_4'];
|
||||
if (!in_array($labelType, $allowed, true)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (bool) $this->db->update( 'pp_shop_products', [ $labelType => $customLabel ], [ 'id' => $productId ] );
|
||||
}
|
||||
|
||||
@@ -1525,6 +1540,7 @@ class ProductRepository
|
||||
global $lang_id;
|
||||
|
||||
$settings = ( new \Domain\Settings\SettingsRepository( $this->db ) )->allSettings( true );
|
||||
$this->transportRepoForXml = new \Domain\Transport\TransportRepository( $this->db );
|
||||
|
||||
$domainPrefix = 'https';
|
||||
$url = preg_replace( '#^(http(s)?://)?w{3}\.#', '$1', $_SERVER['SERVER_NAME'] );
|
||||
@@ -1715,7 +1731,7 @@ class ProductRepository
|
||||
$shippingNode->appendChild( $doc->createElement( 'g:country', 'PL' ) );
|
||||
$shippingNode->appendChild( $doc->createElement( 'g:service', '1 dzień roboczy' ) );
|
||||
$shippingNode->appendChild( $doc->createElement( 'g:price',
|
||||
( new \Domain\Transport\TransportRepository( $this->db ) )->lowestTransportPrice( (int) $product['wp'] ) . ' PLN'
|
||||
$this->transportRepoForXml->lowestTransportPrice( (int) $product['wp'] ) . ' PLN'
|
||||
) );
|
||||
}
|
||||
|
||||
@@ -2197,8 +2213,8 @@ class ProductRepository
|
||||
$product['categories'] = $this->db->select('pp_shop_products_categories', 'category_id', ['product_id' => $productId]);
|
||||
$product['products_related'] = $this->db->select('pp_shop_products_related', 'product_related_id', ['product_id' => $productId]);
|
||||
|
||||
$setId = $this->db->select('pp_shop_product_sets_products', 'set_id', ['product_id' => $productId]);
|
||||
$productsSets = $this->db->select('pp_shop_product_sets_products', 'product_id', ['set_id' => (int)$setId]);
|
||||
$setId = (int)($product['set_id'] ?? 0);
|
||||
$productsSets = $this->db->select('pp_shop_product_sets_products', 'product_id', ['set_id' => $setId]);
|
||||
$product['products_sets'] = is_array($productsSets) ? array_unique($productsSets) : [];
|
||||
|
||||
$attributes = $this->db->select('pp_shop_products_attributes', ['attribute_id', 'value_id'], ['product_id' => $productId]);
|
||||
@@ -2491,7 +2507,7 @@ class ProductRepository
|
||||
|
||||
public function searchProductsByNameCount(string $query, string $langId): int
|
||||
{
|
||||
$results = $this->db->query('SELECT COUNT(0) AS c FROM ( '
|
||||
$stmt = $this->db->query('SELECT COUNT(0) AS c FROM ( '
|
||||
. 'SELECT psp.id, '
|
||||
. '( CASE '
|
||||
. 'WHEN copy_from IS NULL THEN name '
|
||||
@@ -2505,14 +2521,15 @@ class ProductRepository
|
||||
. ') AS q1', [
|
||||
':query' => '%' . $query . '%',
|
||||
':lang_id' => $langId,
|
||||
])->fetchAll(\PDO::FETCH_ASSOC);
|
||||
]);
|
||||
$results = $stmt ? $stmt->fetchAll(\PDO::FETCH_ASSOC) : [];
|
||||
|
||||
return (int) ($results[0]['c'] ?? 0);
|
||||
}
|
||||
|
||||
public function getProductsIdByName(string $query, string $langId, int $limit, int $from): array
|
||||
{
|
||||
$results = $this->db->query('SELECT psp.id, '
|
||||
$stmt = $this->db->query('SELECT psp.id, '
|
||||
. '( CASE '
|
||||
. 'WHEN copy_from IS NULL THEN name '
|
||||
. 'WHEN copy_from IS NOT NULL THEN ( '
|
||||
@@ -2526,7 +2543,8 @@ class ProductRepository
|
||||
. 'LIMIT ' . (int) $from . ',' . (int) $limit, [
|
||||
':query' => '%' . $query . '%',
|
||||
':lang_id' => $langId,
|
||||
])->fetchAll(\PDO::FETCH_ASSOC);
|
||||
]);
|
||||
$results = $stmt ? $stmt->fetchAll(\PDO::FETCH_ASSOC) : [];
|
||||
|
||||
$output = [];
|
||||
if (is_array($results)) {
|
||||
@@ -2562,13 +2580,14 @@ class ProductRepository
|
||||
|
||||
public function searchProductByNameAjax(string $query, string $langId): array
|
||||
{
|
||||
$results = $this->db->query(
|
||||
$stmt = $this->db->query(
|
||||
'SELECT product_id FROM pp_shop_products_langs AS pspl '
|
||||
. 'INNER JOIN pp_shop_products AS psp ON psp.id = pspl.product_id '
|
||||
. 'WHERE status = 1 AND lang_id = :lang_id AND LOWER(name) LIKE :query '
|
||||
. 'ORDER BY visits DESC LIMIT 12',
|
||||
[':query' => '%' . $query . '%', ':lang_id' => $langId]
|
||||
)->fetchAll(\PDO::FETCH_ASSOC);
|
||||
);
|
||||
$results = $stmt ? $stmt->fetchAll(\PDO::FETCH_ASSOC) : [];
|
||||
|
||||
return is_array($results) ? $results : [];
|
||||
}
|
||||
|
||||
@@ -508,7 +508,7 @@ class PromotionRepository
|
||||
|
||||
foreach ( $basket as $key => $val )
|
||||
{
|
||||
$product_promotion = (new \Domain\Product\ProductRepository($this->db))->isProductOnPromotion( $val['product-id'] );
|
||||
$product_promotion = $productRepo->isProductOnPromotion( $val['product-id'] );
|
||||
|
||||
if ( !$product_promotion or $product_promotion and $promotion['include_product_promo'] )
|
||||
{
|
||||
@@ -538,7 +538,7 @@ class PromotionRepository
|
||||
{
|
||||
foreach ( $basket as $key => $val )
|
||||
{
|
||||
$product_promotion = (new \Domain\Product\ProductRepository($this->db))->isProductOnPromotion( $val['product-id'] );
|
||||
$product_promotion = $productRepo->isProductOnPromotion( $val['product-id'] );
|
||||
|
||||
if ( !$product_promotion or $product_promotion and $promotion['include_product_promo'] )
|
||||
{
|
||||
@@ -557,7 +557,7 @@ class PromotionRepository
|
||||
$cheapest_position = false;
|
||||
foreach ( $basket as $key => $val )
|
||||
{
|
||||
$price = (new \Domain\Product\ProductRepository($this->db))->getPrice( $val['product-id'] );
|
||||
$price = $productRepo->getPrice( $val['product-id'] );
|
||||
if ( !$cheapest_position or $cheapest_position['price'] > $price )
|
||||
{
|
||||
$cheapest_position['price'] = $price;
|
||||
@@ -586,7 +586,7 @@ class PromotionRepository
|
||||
|
||||
foreach ( $basket as $key => $val )
|
||||
{
|
||||
$product_promotion = (new \Domain\Product\ProductRepository($this->db))->isProductOnPromotion( $val['product-id'] );
|
||||
$product_promotion = $productRepo->isProductOnPromotion( $val['product-id'] );
|
||||
|
||||
if ( !$product_promotion or $product_promotion and $promotion['include_product_promo'] )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user