Completed
Push — master ( a682ba...4851b3 )
by Paweł
40:50
created

LoadMediaData   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 0
loc 60
ccs 0
cts 36
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 12 1
B loadMedia() 0 26 3
A getOrder() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Superdesk Web Publisher Fixtures Bundle.
5
 *
6
 * Copyright 2015 Sourcefabric z.u. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2015 Sourcefabric z.ú
12
 * @license http://www.superdesk.org/license
13
 */
14
15
namespace SWP\Bundle\FixturesBundle\DataFixtures\PHPCR;
16
17
use Doctrine\Common\DataFixtures\FixtureInterface;
18
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
19
use Doctrine\Common\Persistence\ObjectManager;
20
use SWP\Bundle\FixturesBundle\AbstractFixture;
21
use Symfony\Component\Filesystem\Filesystem;
22
use Symfony\Component\HttpFoundation\File\UploadedFile;
23
24
class LoadMediaData extends AbstractFixture implements FixtureInterface, OrderedFixtureInterface
25
{
26
    private $manager;
27
    private $defaultTenantPrefix;
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function load(ObjectManager $manager)
33
    {
34
        $this->manager = $manager;
35
        $this->defaultTenantPrefix = $this->getTenantPrefix();
36
37
        $filesystem = new Filesystem();
38
        $filesystem->remove($this->container->getParameter('kernel.cache_dir').'/uploads');
39
40
        $this->loadMedia($this->getEnvironment(), $manager);
41
42
        $manager->flush();
43
    }
44
45
    /**
46
     * Sets articles manually (not via Alice) for test env due to fatal error:
47
     * Method PHPCRProxies\__CG__\Doctrine\ODM\PHPCR\Document\Generic::__toString() must not throw an exception.
48
     */
49
    public function loadMedia($env, $manager)
50
    {
51
        $articles = [
52
            'test' => [
53
                ['mediaId' => '123456789876543210a'],
54
                ['mediaId' => '123456789876543210b'],
55
                ['mediaId' => '123456789876543210c'],
56
                ['mediaId' => '123456789876543210d'],
57
                ['mediaId' => '123456789876543210e'],
58
                ['mediaId' => '123456789876543210f'],
59
                ['mediaId' => '123456789876543210g'],
60
            ],
61
        ];
62
63
        $mediaManager = $this->container->get('swp_content_bundle.manager.media');
64
        $fakeImage = __DIR__.'/../../Resources/assets/test_cc_image.jpg';
65
66
        if (isset($articles[$env])) {
67
            foreach ($articles[$env] as $media) {
68
                $uploadedFile = new UploadedFile($fakeImage, $media['mediaId'], 'image/jpeg', filesize($fakeImage), null, true);
69
                $mediaManager->handleUploadedFile($uploadedFile, $media['mediaId']);
70
            }
71
72
            $manager->flush();
73
        }
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79
    public function getOrder()
80
    {
81
        return 999;
82
    }
83
}
84