|
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
|
|
|
|