<commit_before><?php
/**
 * admin42 (www.raum42.at)
 *
 * @link http://www.raum42.at
 * @copyright Copyright (c) 2010-2014 raum42 OG (http://www.raum42.at)
 *
 */

namespace Admin42\Command\Media;

use Admin42\Model\Media;
use Core42\Command\AbstractCommand;

class UploadCommand extends AbstractCommand
{
    /**
     * @var array
     */
    private $uploadData;

    /**
     * @param array $uploadData
     * @return $this
     */
    public function setUploadData(array $uploadData)
    {
        $this->uploadData = $uploadData;

        return $this;
    }

    /**
     * @param array $values
     * @throws \Exception
     */
    public function hydrate(array $values)
    {
        $this->setUploadData($values['file']);
    }

    /**
     * @return mixed|void
     */
    protected function execute()
    {
        $dateTime = new \DateTime();
        $source = $this->uploadData['tmp_name'];
        $finfo = finfo_open(FILEINFO_MIME_TYPE);

        $media = new Media();
        $media->setFilename($this->uploadData['name'])
            ->setTitle($this->uploadData['name'])
            ->setMeta(json_encode([]))
            ->setDirectory(dirname($source) . DIRECTORY_SEPARATOR)
            ->setMimeType(finfo_file($finfo, $source))
            ->setSize(sprintf("%u", filesize($source)))
            ->setUpdated($dateTime)
            ->setCreated($dateTime);

        $this->getTableGateway('Admin42\Media')->insert($media);
    }
}<commit_msg>add resize on upload<commit_after><?php
/**
 * admin42 (www.raum42.at)
 *
 * @link http://www.raum42.at
 * @copyright Copyright (c) 2010-2014 raum42 OG (http://www.raum42.at)
 *
 */

namespace Admin42\Command\Media;

use Admin42\Model\Media;
use Core42\Command\AbstractCommand;

class UploadCommand extends AbstractCommand
{
    /**
     * @var array
     */
    private $uploadData;

    /**
     * @param array $uploadData
     * @return $this
     */
    public function setUploadData(array $uploadData)
    {
        $this->uploadData = $uploadData;

        return $this;
    }

    /**
     * @param array $values
     * @throws \Exception
     */
    public function hydrate(array $values)
    {
        $this->setUploadData($values['file']);
    }

    /**
     * @return mixed|void
     */
    protected function execute()
    {
        $dateTime = new \DateTime();
        $source = $this->uploadData['tmp_name'];
        $finfo = finfo_open(FILEINFO_MIME_TYPE);

        $media = new Media();
        $media->setFilename($this->uploadData['name'])
            ->setTitle($this->uploadData['name'])
            ->setMeta(json_encode([]))
            ->setDirectory(dirname($source) . DIRECTORY_SEPARATOR)
            ->setMimeType(finfo_file($finfo, $source))
            ->setSize(sprintf("%u", filesize($source)))
            ->setUpdated($dateTime)
            ->setCreated($dateTime);

        $this->getTableGateway('Admin42\Media')->insert($media);

        if (substr($media->getMimeType(), 0, 6) == "image/") {
            $mediaOptions = $this->getServiceManager()->get('Admin42\MediaOptions');

            foreach(array_keys($mediaOptions->getDimensions()) as $dimension) {
                $cmd = $this->getCommand('Admin42\Media\ImageResize');
                $cmd->setMedia($media)
                    ->setDimensionName($dimension)
                    ->run();
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.15823720792664892, 'fraction_numerical': 0.01715468796214138, 'mean_word_length': 2.283495145631068, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '814125', 'n_tokens_mistral': 1072, 'n_tokens_neox': 1017, 'n_words': 170}