ver. 0.282: Banners frontend migration, Cache cleanup, Shared\Cache namespace
- Banners frontend: front\Views\Banners (new), BannerRepository +2 frontend methods, front\view\Site przepięty, usunięte front\factory\Banners i front\view\Banners - Cache cleanup: eliminacja legacy class.Cache.php (file-based cache), 13 metod front\factory przepiętych z \Cache::fetch/store na CacheHandler - Shared\Cache namespace: CacheHandler i RedisConnection przeniesione do Shared\Cache\, 60 odwołań CacheHandler i 12 odwołań RedisConnection przepiętych, usunięte backward-compat wrappery class.CacheHandler.php i class.RedisConnection.php - Naprawione rozbieżności kluczy cache (random_products, category_name) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -874,7 +874,7 @@ class ArticleRepository
|
||||
*/
|
||||
public function articleDetailsFrontend(int $articleId, string $langId): ?array
|
||||
{
|
||||
$cacheHandler = new \CacheHandler();
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "ArticleRepository::articleDetailsFrontend:{$articleId}:{$langId}";
|
||||
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
@@ -946,7 +946,7 @@ class ArticleRepository
|
||||
default: $order = 'id ASC'; break;
|
||||
}
|
||||
|
||||
$cacheHandler = new \CacheHandler();
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "ArticleRepository::articlesIds:{$pageId}:{$langId}:{$limit}:{$sortType}:{$from}:{$order}";
|
||||
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
@@ -994,7 +994,7 @@ class ArticleRepository
|
||||
*/
|
||||
public function pageArticlesCount(int $pageId, string $langId): int
|
||||
{
|
||||
$cacheHandler = new \CacheHandler();
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "ArticleRepository::pageArticlesCount:{$pageId}:{$langId}";
|
||||
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
@@ -1084,7 +1084,7 @@ class ArticleRepository
|
||||
*/
|
||||
public function articleNoindex(int $articleId, string $langId): bool
|
||||
{
|
||||
$cacheHandler = new \CacheHandler();
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "ArticleRepository::articleNoindex:{$articleId}:{$langId}";
|
||||
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
@@ -1107,7 +1107,7 @@ class ArticleRepository
|
||||
*/
|
||||
public function topArticles(int $pageId, int $limit, string $langId): ?array
|
||||
{
|
||||
$cacheHandler = new \CacheHandler();
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "ArticleRepository::topArticles:{$pageId}:{$limit}:{$langId}";
|
||||
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
@@ -1156,7 +1156,7 @@ class ArticleRepository
|
||||
*/
|
||||
public function newsListArticles(int $pageId, int $limit, string $langId): ?array
|
||||
{
|
||||
$cacheHandler = new \CacheHandler();
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "ArticleRepository::newsListArticles:{$pageId}:{$limit}:{$langId}";
|
||||
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
|
||||
@@ -312,4 +312,84 @@ class BannerRepository
|
||||
|
||||
$this->db->insert('pp_banners_langs', $translationData);
|
||||
}
|
||||
|
||||
// ─── Frontend methods ───────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Pobiera aktywne banery (home_page = 0) z filtrowaniem dat, z Redis cache.
|
||||
* Zwraca dane w formacie zgodnym z szablonami: $banner['languages'] = płaski wiersz.
|
||||
*/
|
||||
public function banners(string $langId): ?array
|
||||
{
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "BannerRepository::banners:{$langId}";
|
||||
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
|
||||
if ($objectData) {
|
||||
return unserialize($objectData);
|
||||
}
|
||||
|
||||
$today = date('Y-m-d');
|
||||
$results = $this->db->query(
|
||||
"SELECT id, name FROM pp_banners "
|
||||
. "WHERE status = 1 "
|
||||
. "AND (date_start <= '{$today}' OR date_start IS NULL) "
|
||||
. "AND (date_end >= '{$today}' OR date_end IS NULL) "
|
||||
. "AND home_page = 0"
|
||||
)->fetchAll();
|
||||
|
||||
$banners = null;
|
||||
if (is_array($results) && !empty($results)) {
|
||||
foreach ($results as $row) {
|
||||
$row['languages'] = $this->db->get('pp_banners_langs', '*', [
|
||||
'AND' => ['id_banner' => (int)$row['id'], 'id_lang' => $langId]
|
||||
]);
|
||||
$banners[] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
$cacheHandler->set($cacheKey, $banners);
|
||||
|
||||
return $banners;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pobiera glowny baner (home_page = 1) z filtrowaniem dat, z Redis cache.
|
||||
* Zwraca dane w formacie zgodnym z szablonami: $banner['languages'] = plaski wiersz.
|
||||
*/
|
||||
public function mainBanner(string $langId): ?array
|
||||
{
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "BannerRepository::mainBanner:{$langId}";
|
||||
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
|
||||
if ($objectData) {
|
||||
return unserialize($objectData);
|
||||
}
|
||||
|
||||
$today = date('Y-m-d');
|
||||
$results = $this->db->query(
|
||||
"SELECT * FROM pp_banners "
|
||||
. "WHERE status = 1 "
|
||||
. "AND (date_start <= '{$today}' OR date_start IS NULL) "
|
||||
. "AND (date_end >= '{$today}' OR date_end IS NULL) "
|
||||
. "AND home_page = 1 "
|
||||
. "ORDER BY date_end ASC "
|
||||
. "LIMIT 1"
|
||||
)->fetchAll();
|
||||
|
||||
$banner = null;
|
||||
if (is_array($results) && !empty($results)) {
|
||||
$banner = $results[0];
|
||||
$banner['languages'] = $this->db->get('pp_banners_langs', '*', [
|
||||
'AND' => ['id_banner' => (int)$banner['id'], 'id_lang' => $langId]
|
||||
]);
|
||||
}
|
||||
|
||||
$cacheHandler->set($cacheKey, $banner);
|
||||
|
||||
return $banner;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,11 +14,11 @@ class CacheRepository
|
||||
private $basePath;
|
||||
|
||||
/**
|
||||
* @param \RedisConnection $redisConnection Połączenie z Redis (nullable)
|
||||
* @param \Shared\Cache\RedisConnection $redisConnection Połączenie z Redis (nullable)
|
||||
* @param string $basePath Ścieżka bazowa do katalogów cache
|
||||
*/
|
||||
public function __construct(
|
||||
?\RedisConnection $redisConnection = null,
|
||||
?\Shared\Cache\RedisConnection $redisConnection = null,
|
||||
string $basePath = '../'
|
||||
) {
|
||||
$this->redisConnection = $redisConnection;
|
||||
|
||||
@@ -13,7 +13,7 @@ class DashboardRepository
|
||||
public function summaryOrders(): int
|
||||
{
|
||||
try {
|
||||
$redis = \RedisConnection::getInstance()->getConnection();
|
||||
$redis = \Shared\Cache\RedisConnection::getInstance()->getConnection();
|
||||
if ( $redis ) {
|
||||
$cached = $redis->get( 'summary_ordersd' );
|
||||
if ( $cached !== false ) {
|
||||
@@ -33,7 +33,7 @@ class DashboardRepository
|
||||
public function summarySales(): float
|
||||
{
|
||||
try {
|
||||
$redis = \RedisConnection::getInstance()->getConnection();
|
||||
$redis = \Shared\Cache\RedisConnection::getInstance()->getConnection();
|
||||
if ( $redis ) {
|
||||
$cached = $redis->get( 'summary_salesd' );
|
||||
if ( $cached !== false ) {
|
||||
|
||||
@@ -256,19 +256,17 @@ class DictionariesRepository
|
||||
|
||||
private function cacheFetch(string $key)
|
||||
{
|
||||
if (!class_exists('\Cache') || !method_exists('\Cache', 'fetch')) {
|
||||
return false;
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cached = $cacheHandler->get(self::CACHE_SUBDIR . ':' . $key);
|
||||
if ($cached) {
|
||||
return unserialize($cached);
|
||||
}
|
||||
|
||||
return \Cache::fetch($key, self::CACHE_SUBDIR);
|
||||
return false;
|
||||
}
|
||||
|
||||
private function cacheStore(string $key, string $value): void
|
||||
{
|
||||
if (!class_exists('\Cache') || !method_exists('\Cache', 'store')) {
|
||||
return;
|
||||
}
|
||||
|
||||
\Cache::store($key, $value, self::CACHE_TTL, self::CACHE_SUBDIR);
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheHandler->set(self::CACHE_SUBDIR . ':' . $key, $value, self::CACHE_TTL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -337,7 +337,7 @@ class LanguagesRepository
|
||||
*/
|
||||
public function defaultLanguage(): string
|
||||
{
|
||||
$cacheHandler = new \CacheHandler();
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = 'Domain\Languages\LanguagesRepository::defaultLanguage';
|
||||
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
@@ -361,7 +361,7 @@ class LanguagesRepository
|
||||
*/
|
||||
public function activeLanguages(): array
|
||||
{
|
||||
$cacheHandler = new \CacheHandler();
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = 'Domain\Languages\LanguagesRepository::activeLanguages';
|
||||
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
@@ -389,7 +389,7 @@ class LanguagesRepository
|
||||
*/
|
||||
public function translations(string $language = 'pl'): array
|
||||
{
|
||||
$cacheHandler = new \CacheHandler();
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "Domain\Languages\LanguagesRepository::translations:$language";
|
||||
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
|
||||
@@ -297,12 +297,12 @@ class LayoutsRepository
|
||||
|
||||
private function clearFrontLayoutsCache(): void
|
||||
{
|
||||
if (!class_exists('\CacheHandler')) {
|
||||
if (!class_exists('\Shared\Cache\CacheHandler')) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$cacheHandler = new \CacheHandler();
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
if (method_exists($cacheHandler, 'deletePattern')) {
|
||||
$cacheHandler->deletePattern('*Layouts::*');
|
||||
}
|
||||
|
||||
@@ -639,7 +639,7 @@ class ProductRepository
|
||||
\S::delete_dir( '../thumbs/' );
|
||||
|
||||
if ( !$isNew ) {
|
||||
$redis = \RedisConnection::getInstance()->getConnection();
|
||||
$redis = \Shared\Cache\RedisConnection::getInstance()->getConnection();
|
||||
if ( $redis ) {
|
||||
$redis->flushAll();
|
||||
}
|
||||
|
||||
@@ -406,12 +406,12 @@ class PromotionRepository
|
||||
|
||||
private function invalidateActivePromotionsCache(): void
|
||||
{
|
||||
if (!class_exists('\CacheHandler')) {
|
||||
if (!class_exists('\Shared\Cache\CacheHandler')) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$cache = new \CacheHandler();
|
||||
$cache = new \Shared\Cache\CacheHandler();
|
||||
if (method_exists($cache, 'delete')) {
|
||||
$cache->delete('\shop\Promotion::get_active_promotions');
|
||||
}
|
||||
|
||||
@@ -215,11 +215,11 @@ class ScontainersRepository
|
||||
|
||||
private function clearFrontCache(int $containerId): void
|
||||
{
|
||||
if ($containerId <= 0 || !class_exists('\CacheHandler')) {
|
||||
if ($containerId <= 0 || !class_exists('\Shared\Cache\CacheHandler')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$cacheHandler = new \CacheHandler();
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = '\front\factory\Scontainers::scontainer_details:' . $containerId;
|
||||
$cacheHandler->delete($cacheKey);
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ class SettingsRepository
|
||||
*/
|
||||
public function allSettings(bool $skipCache = false): array
|
||||
{
|
||||
$cacheHandler = new \CacheHandler();
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = 'Domain\Settings\SettingsRepository::allSettings';
|
||||
|
||||
if (!$skipCache) {
|
||||
@@ -177,7 +177,7 @@ class SettingsRepository
|
||||
*/
|
||||
public function getSingleValue(string $param): string
|
||||
{
|
||||
$cacheHandler = new \CacheHandler();
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "Domain\Settings\SettingsRepository::getSingleValue:$param";
|
||||
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
|
||||
Reference in New Issue
Block a user