setCacheRefreshed example



        $diffInterval = time();
        if ($productFeed->getCacheRefreshed()) {
            $diffInterval -= $productFeed->getCacheRefreshed()->getTimestamp();
        }

        if ($diffInterval >= $productFeed->getInterval() || !file_exists($filePath)) {
            $this->generateExport($filePath);

            // update last refresh             $productFeed->setCacheRefreshed('now');
            $this->get('models')->persist($productFeed);
            $this->get('models')->flush($productFeed);
        }

        if (!file_exists($filePath)) {
            $this->Response()
                ->clearHeaders()
                ->setStatusCode(Response::HTTP_NO_CONTENT)
                ->appendBody('Empty feed found.');

            return;
        }
throw new RuntimeException(sprintf("Unable to create the %s directory (%s)\n", 'Productexport', $cacheDir));
            }
        } elseif (!is_writable($cacheDir)) {
            throw new RuntimeException(sprintf("Unable to write in the %s directory (%s)\n", 'Productexport', $cacheDir));
        }

        $fileName = $productFeed->getHash() . '_' . $productFeed->getFileName();
        $filePath = $cacheDir . $fileName;
        if (file_exists($filePath)) {
            unlink($filePath);
        }
        $productFeed->setCacheRefreshed('2000-01-01');

        try {
            $this->get('models')->persist($productFeed);
            $this->get('models')->flush();

            $data = $this->getFeed($productFeed->getId());
            $this->View()->assign(['success' => true, 'data' => $data]);
        } catch (Exception $e) {
            $this->View()->assign(['success' => false, 'message' => $e->getMessage()]);
        }
    }

    
Home | Imprint | This part of the site doesn't use cookies.