<commit_before><?php
/**
 * This file is part of the Networking package.
 *
 * (c) net working AG <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace Networking\InitCmsBundle\Controller;

use Sonata\MediaBundle\Controller\MediaAdminController as SonataMediaAdminController,
    Symfony\Component\HttpFoundation\Request,
    Symfony\Component\HttpFoundation\Response,
    Symfony\Component\HttpFoundation\JsonResponse,
    Sonata\AdminBundle\Admin\Admin as SontataAdmin,
    Sonata\MediaBundle\Admin\ORM\MediaAdmin,
    Sonata\MediaBundle\Provider\MediaProviderInterface,
    Symfony\Component\HttpFoundation\File\UploadedFile,
    Symfony\Component\HttpFoundation\RedirectResponse;

/**
 * @author <NAME> <<EMAIL>>
 */
class MediaAdminController extends SonataMediaAdminController
{


    /**
     * @param \Symfony\Component\HttpFoundation\Request $request
     * @param string $providerName
     * @return \Symfony\Component\HttpFoundation\JsonResponse
     */
    public function doFileUpload(Request $request, $providerName = 'sonata.media.provider.image')
    {
        if ($request->get('CKEditor')) {
            return $this->ckeditorUploadAction($request, $providerName);
        }

        $file = $request->files->get('file');

        if ($file instanceof UploadedFile && $file->isValid()) {


            try {
                /** @var $mediaManager \Sonata\MediaBundle\Admin\Manager\DoctrineORMManager */
                $mediaManager = $this->get('sonata.media.manager.media');

                /** @var $mediaAdmin \Sonata\MediaBundle\Admin\ORM\MediaAdmin */
                $mediaAdmin = $this->get('sonata.media.admin.media');

                /** @var $provider \Sonata\MediaBundle\Provider\MediaProviderInterface */
                $provider = $this->get($providerName);

                $context = $mediaAdmin->getPool()->getDefaultContext();

                $mediaClass = $mediaAdmin->getClass();

                /** @var $media \Sonata\MediaBundle\Model\MediaInterface */
                $media = new $mediaClass();

                $media->setProviderName($provider->getName());

                $media->setContext($context);

                $media->setName($file->getClientOriginalName());


                $media->setBinaryContent($file);
                $mediaManager->save($media);


                $path = $provider->generatePublicUrl($media, 'reference');


                $array = array(
                    'filelink' => $path
                );

                $status = 200;
            } catch (\Exception $e) {
                $array = array('error' => $e->getMessage());
                $status = 500;
            }
        } elseif ($file instanceof UploadedFile && !$file->isValid()) {
            $array = array('error' => $file->getError());
            $status = 500;
        } else {
            $array = array(
                'error' => $this->admin->trans(
                    'error.file_upload_size',
                    array('%max_server_size%' => ini_get('upload_max_filesize'))
                )
            );
            $status = 500;
        }

        return new JsonResponse($array, $status);
    }

    public function ckeditorUploadAction(Request $request, $providerName = 'sonata.media.provider.image')
    {
        $file = $request->files->get('upload');

        // Required: anonymous function reference number as explained above.
        $funcNum = $request->get('CKEditorFuncNum');
        // Optional: instance name (might be used to load a specific configuration file or anything else).
        $CKEditor = $request->get('CKEditor');
        // Optional: might be used to provide localized messages.
        $langCode = $request->get('langCode');

        $url = '';

        if ($file instanceof UploadedFile && $file->isValid()) {


            try {
                /** @var $mediaManager \Sonata\MediaBundle\Admin\Manager\DoctrineORMManager */
                $mediaManager = $this->get('sonata.media.manager.media');

                /** @var $mediaAdmin \Sonata\MediaBundle\Admin\ORM\MediaAdmin */
                $mediaAdmin = $this->get('sonata.media.admin.media');

                /** @var $provider \Sonata\MediaBundle\Provider\MediaProviderInterface */
                $provider = $this->get($providerName);

                $context = $mediaAdmin->getPool()->getDefaultContext();

                $mediaClass = $mediaAdmin->getClass();

                /** @var $media \Sonata\MediaBundle\Model\MediaInterface */
                $media = new $mediaClass();

                $media->setProviderName($provider->getName());

                $media->setContext($context);

                $media->setName($file->getClientOriginalName());


                $media->setBinaryContent($file);
                $mediaManager->save($media);


                $path = $provider->generatePublicUrl($media, 'reference');<commit_msg>make sure that uploaded documents via the WYSIWYG editors is automatically enabled<commit_after><?php
/**
 * This file is part of the Networking package.
 *
 * (c) net working AG <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace Networking\InitCmsBundle\Controller;

use Sonata\MediaBundle\Controller\MediaAdminController as SonataMediaAdminController,
    Symfony\Component\HttpFoundation\Request,
    Symfony\Component\HttpFoundation\Response,
    Symfony\Component\HttpFoundation\JsonResponse,
    Sonata\AdminBundle\Admin\Admin as SontataAdmin,
    Sonata\MediaBundle\Admin\ORM\MediaAdmin,
    Sonata\MediaBundle\Provider\MediaProviderInterface,
    Symfony\Component\HttpFoundation\File\UploadedFile,
    Symfony\Component\HttpFoundation\RedirectResponse;

/**
 * @author <NAME> <<EMAIL>>
 */
class MediaAdminController extends SonataMediaAdminController
{


    /**
     * @param \Symfony\Component\HttpFoundation\Request $request
     * @param string $providerName
     * @return \Symfony\Component\HttpFoundation\JsonResponse
     */
    public function doFileUpload(Request $request, $providerName = 'sonata.media.provider.image')
    {
        if ($request->get('CKEditor')) {
            return $this->ckeditorUploadAction($request, $providerName);
        }

        $file = $request->files->get('file');

        if ($file instanceof UploadedFile && $file->isValid()) {


            try {
                /** @var $mediaManager \Sonata\MediaBundle\Admin\Manager\DoctrineORMManager */
                $mediaManager = $this->get('sonata.media.manager.media');

                /** @var $mediaAdmin \Sonata\MediaBundle\Admin\ORM\MediaAdmin */
                $mediaAdmin = $this->get('sonata.media.admin.media');

                /** @var $provider \Sonata\MediaBundle\Provider\MediaProviderInterface */
                $provider = $this->get($providerName);

                $context = $mediaAdmin->getPool()->getDefaultContext();

                $mediaClass = $mediaAdmin->getClass();

                /** @var $media \Sonata\MediaBundle\Model\MediaInterface */
                $media = new $mediaClass();

                $media->setProviderName($provider->getName());

                $media->setContext($context);

                $media->setEnabled(true);

                $media->setName($file->getClientOriginalName());


                $media->setBinaryContent($file);
                $mediaManager->save($media);


                $path = $provider->generatePublicUrl($media, 'reference');


                $array = array(
                    'filelink' => $path
                );

                $status = 200;
            } catch (\Exception $e) {
                $array = array('error' => $e->getMessage());
                $status = 500;
            }
        } elseif ($file instanceof UploadedFile && !$file->isValid()) {
            $array = array('error' => $file->getError());
            $status = 500;
        } else {
            $array = array(
                'error' => $this->admin->trans(
                    'error.file_upload_size',
                    array('%max_server_size%' => ini_get('upload_max_filesize'))
                )
            );
            $status = 500;
        }

        return new JsonResponse($array, $status);
    }

    public function ckeditorUploadAction(Request $request, $providerName = 'sonata.media.provider.image')
    {
        $file = $request->files->get('upload');

        // Required: anonymous function reference number as explained above.
        $funcNum = $request->get('CKEditorFuncNum');
        // Optional: instance name (might be used to load a specific configuration file or anything else).
        $CKEditor = $request->get('CKEditor');
        // Optional: might be used to provide localized messages.
        $langCode = $request->get('langCode');

        $url = '';

        if ($file instanceof UploadedFile && $file->isValid()) {


            try {
                /** @var $mediaManager \Sonata\MediaBundle\Admin\Manager\DoctrineORMManager */
                $mediaManager = $this->get('sonata.media.manager.media');

                /** @var $mediaAdmin \Sonata\MediaBundle\Admin\ORM\MediaAdmin */
                $mediaAdmin = $this->get('sonata.media.admin.media');

                /** @var $provider \Sonata\MediaBundle\Provider\MediaProviderInterface */
                $provider = $this->get($providerName);

                $context = $mediaAdmin->getPool()->getDefaultContext();

                $mediaClass = $mediaAdmin->getClass();

                /** @var $media \Sonata\MediaBundle\Model\MediaInterface */
                $media = new $mediaClass();

                $media->setProviderName($provider->getName());

                $media->setContext($context);

                $media->setEnabled(true);

                $media->setName($file->getClientOriginalName());


                $media->setBinaryContent($file);
                $mediaManager->save($media);


                $path = $provider->generatePublicUrl($media, 'reference');
{'fraction_non_alphanumeric': 0.13447360660572102, 'fraction_numerical': 0.0023591860808021233, 'mean_word_length': 2.1853475266123983, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 113, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '7372462', 'n_tokens_mistral': 2739, 'n_tokens_neox': 2542, 'n_words': 490}