<commit_before><?php
/**
 * Nooku Framework - http://www.nooku.org
 *
 * @copyright	Copyright (C) 2011 - 2013 <NAME> and Timble CVBA. (http://www.timble.net)
 * @license		GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link		git://git.assembla.com/nooku-framework.git for the canonical source repository
 */

namespace Nooku\Component\Attachments;

use Nooku\Library;

/**
 * Attachment Controller
 *
 * @author  <NAME> <http://nooku.assembla.com/profile/johanjanssens>
 * @package Nooku\Component\Attachments
 */
class ControllerAttachment extends Library\ControllerModel
{
    protected function _actionRender(Library\CommandContext $context)
    {
        $model = $this->getModel();

        if ($model->getState()->isUnique() && $this->getRequest()->getFormat() == 'file')
        {
            $attachment = $this->getModel()->getRow();

            if (!$attachment->isNew())
            {
                $container = $this->getObject('com:files.model.containers')
                    ->slug($attachment->container)
                    ->getRow();

                $fullpath = $container->path.DS.$attachment->path;
                $mimetype = $attachment->file->mimetype;

                try
                {
                    $context->response
                        ->attachTransport('chunked')
                        ->setPath('file://'.$fullpath, $mimetype);
                }
                catch (InvalidArgumentException $e) {
                    throw new KControllerExceptionResourceNotFound('File not found');
                }
            }
            else throw new KControllerExceptionResourceNotFound('Attachment not found');
        }
        else parent::_actionRender($context);<commit_msg>re #678 - Force download of attachments files in back-end<commit_after><?php
/**
 * Nooku Framework - http://www.nooku.org
 *
 * @copyright	Copyright (C) 2011 - 2013 <NAME> and Timble CVBA. (http://www.timble.net)
 * @license		GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link		git://git.assembla.com/nooku-framework.git for the canonical source repository
 */

namespace Nooku\Component\Attachments;

use Nooku\Library;

/**
 * Attachment Controller
 *
 * @author  <NAME> <http://nooku.assembla.com/profile/johanjanssens>
 * @package Nooku\Component\Attachments
 */
class ControllerAttachment extends Library\ControllerModel
{
    protected function _actionRender(Library\CommandContext $context)
    {
        $model = $this->getModel();

        if ($model->getState()->isUnique() && $this->getRequest()->getFormat() == 'file')
        {
            $attachment = $this->getModel()->getRow();

            if (!$attachment->isNew())
            {
                $container = $this->getObject('com:files.model.containers')
                    ->slug($attachment->container)
                    ->getRow();

                $fullpath = $container->path.DS.$attachment->path;

                try
                {
                    $context->response
                        ->attachTransport('chunked')
                        ->setPath('file://'.$fullpath, 'application/force-download');
                }
                catch (InvalidArgumentException $e) {
                    throw new KControllerExceptionResourceNotFound('File not found');
                }
            }
            else throw new KControllerExceptionResourceNotFound('Attachment not found');
        }
        else parent::_actionRender($context);
{'fraction_non_alphanumeric': 0.13675706866705137, 'fraction_numerical': 0.006058857472590883, 'mean_word_length': 2.0763087843833183, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5757943', 'n_tokens_mistral': 971, 'n_tokens_neox': 920, 'n_words': 171}