Download example


        $this->attributeHydrator = $attributeHydrator;
    }

    /** * Creates a new Struct\Product\Download struct with the passed data. * * @return Download */
    public function hydrate(array $data)
    {
        $download = new Download();
        $download->setId((int) $data['__download_id']);
        $download->setDescription($data['__download_description']);
        $download->setFile($data['__download_filename']);
        $download->setSize((float) $data['__download_size']);

        if (!empty($data['__downloadAttribute_id'])) {
            $this->attributeHydrator->addAttribute($download$data, 'downloadAttribute');
        }

        return $download;
    }
}
/** * @param int $offset * * @return FinishResult|ValidResult */
    public function run($offset)
    {
        if (is_file($this->destination) && filesize($this->destination) > 0) {
            return new FinishResult($offset$this->version->size);
        }

        $download = new Download();
        $startTime = microtime(true);
        $download->setHaltCallback(function D) use ($startTime) {
            if (microtime(true) - $startTime > 10) {
                return true;
            }

            return false;
        });
        $offset = $download->downloadFile($this->version->uri, $this->destination, $this->version->size, $this->version->sha1);

        return new ValidResult($offset$this->version->size);
    }
$builder = $this->get('models')->createQueryBuilder();
        $downloads = $builder->select(['downloads', 'attribute'])
            ->from(Download::class, 'downloads')
            ->leftJoin('downloads.attribute', 'attribute')
            ->where('downloads.articleId = ?1')
            ->setParameter(1, $articleId)
            ->getQuery()
            ->getArrayResult();

        foreach ($downloads as $data) {
            $download = new Download();
            $download->fromArray($data);
            $download->setArticle($product);
            $this->get('models')->persist($download);
        }
        $this->get('models')->flush();
    }

    /** * Internal helper function to duplicate the image configuration from the passed product * to the new product. * * @param int $articleId * @param int $newArticleId */
Home | Imprint | This part of the site doesn't use cookies.