@@ -24,75 +24,75 @@ |
||
24 | 24 | */ |
25 | 25 | class FileUploadTest extends AbstractFunctionalTestCase |
26 | 26 | { |
27 | - /** |
|
28 | - * @var FileUpload |
|
29 | - */ |
|
30 | - private $fixture; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - private $fakeName = ''; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var string |
|
39 | - */ |
|
40 | - private $fakePrefix = ''; |
|
41 | - |
|
42 | - public function setUp() |
|
43 | - { |
|
44 | - parent::setUp(); |
|
45 | - |
|
46 | - $this->fixture = $this->getMock('Fab\Media\Form\FileUpload', array('addLanguage')); |
|
47 | - $this->fakeName = uniqid('name'); |
|
48 | - $this->fakePrefix= uniqid('prefix'); |
|
49 | - } |
|
50 | - |
|
51 | - public function tearDown() |
|
52 | - { |
|
53 | - unset($this->fixture); |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * @test |
|
58 | - */ |
|
59 | - public function getJavaScriptMethodReturnNotEmptyContent() |
|
60 | - { |
|
61 | - $method = new \ReflectionMethod( |
|
62 | - 'Fab\Media\Form\FileUpload', |
|
63 | - 'getJavaScript' |
|
64 | - ); |
|
65 | - |
|
66 | - $method->setAccessible(true); |
|
67 | - #$actual = $method->invoke($this->fixture); |
|
68 | - $this->markTestIncomplete('Fix test by mocking storage'); |
|
69 | - #$this->assertNotEmpty($actual); |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * @test |
|
74 | - */ |
|
75 | - public function renderFileUploadIsNotEmptyByDefault() |
|
76 | - { |
|
77 | - $this->markTestIncomplete('Fix test by mocking storage'); |
|
78 | - #$this->assertNotEmpty($this->fixture->render()); |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * @test |
|
83 | - */ |
|
84 | - public function getBasePrefixStripsTheSquareBraquets() |
|
85 | - { |
|
86 | - $method = new \ReflectionMethod( |
|
87 | - 'Fab\Media\Form\FileUpload', |
|
88 | - 'getBasePrefix' |
|
89 | - ); |
|
90 | - |
|
91 | - $method->setAccessible(true); |
|
92 | - |
|
93 | - $basePart = uniqid(); |
|
94 | - $fakePrefix = $basePart . '[foo]'; |
|
95 | - $actual = $method->invokeArgs($this->fixture, array($fakePrefix)); |
|
96 | - $this->assertSame($basePart, $actual); |
|
97 | - } |
|
27 | + /** |
|
28 | + * @var FileUpload |
|
29 | + */ |
|
30 | + private $fixture; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + private $fakeName = ''; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var string |
|
39 | + */ |
|
40 | + private $fakePrefix = ''; |
|
41 | + |
|
42 | + public function setUp() |
|
43 | + { |
|
44 | + parent::setUp(); |
|
45 | + |
|
46 | + $this->fixture = $this->getMock('Fab\Media\Form\FileUpload', array('addLanguage')); |
|
47 | + $this->fakeName = uniqid('name'); |
|
48 | + $this->fakePrefix= uniqid('prefix'); |
|
49 | + } |
|
50 | + |
|
51 | + public function tearDown() |
|
52 | + { |
|
53 | + unset($this->fixture); |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * @test |
|
58 | + */ |
|
59 | + public function getJavaScriptMethodReturnNotEmptyContent() |
|
60 | + { |
|
61 | + $method = new \ReflectionMethod( |
|
62 | + 'Fab\Media\Form\FileUpload', |
|
63 | + 'getJavaScript' |
|
64 | + ); |
|
65 | + |
|
66 | + $method->setAccessible(true); |
|
67 | + #$actual = $method->invoke($this->fixture); |
|
68 | + $this->markTestIncomplete('Fix test by mocking storage'); |
|
69 | + #$this->assertNotEmpty($actual); |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * @test |
|
74 | + */ |
|
75 | + public function renderFileUploadIsNotEmptyByDefault() |
|
76 | + { |
|
77 | + $this->markTestIncomplete('Fix test by mocking storage'); |
|
78 | + #$this->assertNotEmpty($this->fixture->render()); |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * @test |
|
83 | + */ |
|
84 | + public function getBasePrefixStripsTheSquareBraquets() |
|
85 | + { |
|
86 | + $method = new \ReflectionMethod( |
|
87 | + 'Fab\Media\Form\FileUpload', |
|
88 | + 'getBasePrefix' |
|
89 | + ); |
|
90 | + |
|
91 | + $method->setAccessible(true); |
|
92 | + |
|
93 | + $basePart = uniqid(); |
|
94 | + $fakePrefix = $basePart . '[foo]'; |
|
95 | + $actual = $method->invokeArgs($this->fixture, array($fakePrefix)); |
|
96 | + $this->assertSame($basePart, $actual); |
|
97 | + } |
|
98 | 98 | } |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | |
18 | 18 | use Fab\Media\Tests\Functional\AbstractFunctionalTestCase; |
19 | 19 | |
20 | -require_once dirname(dirname(__FILE__)) . '/AbstractFunctionalTestCase.php'; |
|
20 | +require_once dirname(dirname(__FILE__)).'/AbstractFunctionalTestCase.php'; |
|
21 | 21 | |
22 | 22 | /** |
23 | 23 | * Test case for class \Fab\Media\Form\FileUpload. |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | |
46 | 46 | $this->fixture = $this->getMock('Fab\Media\Form\FileUpload', array('addLanguage')); |
47 | 47 | $this->fakeName = uniqid('name'); |
48 | - $this->fakePrefix= uniqid('prefix'); |
|
48 | + $this->fakePrefix = uniqid('prefix'); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | public function tearDown() |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | $method->setAccessible(true); |
92 | 92 | |
93 | 93 | $basePart = uniqid(); |
94 | - $fakePrefix = $basePart . '[foo]'; |
|
94 | + $fakePrefix = $basePart.'[foo]'; |
|
95 | 95 | $actual = $method->invokeArgs($this->fixture, array($fakePrefix)); |
96 | 96 | $this->assertSame($basePart, $actual); |
97 | 97 | } |
@@ -25,124 +25,124 @@ |
||
25 | 25 | */ |
26 | 26 | class ImagePresetUtilityTest extends AbstractFunctionalTestCase |
27 | 27 | { |
28 | - /** |
|
29 | - * @var ImagePresetUtility |
|
30 | - */ |
|
31 | - private $fixture; |
|
32 | - |
|
33 | - public function setUp() |
|
34 | - { |
|
35 | - parent::setUp(); |
|
36 | - $this->fixture = new ImagePresetUtility(); |
|
37 | - } |
|
38 | - |
|
39 | - public function tearDown() |
|
40 | - { |
|
41 | - GeneralUtility::purgeInstances(); |
|
42 | - unset($this->fixture); |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * @test |
|
47 | - * @expectedException \Fab\Media\Exception\EmptyValueException |
|
48 | - */ |
|
49 | - public function randomPresetShouldReturnException() |
|
50 | - { |
|
51 | - $this->fixture->preset(uniqid()); |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * @test |
|
56 | - */ |
|
57 | - public function methodPresetReturnInstanceOfImagePresetUtility() |
|
58 | - { |
|
59 | - $actual = 'image_thumbnail'; |
|
60 | - $object = $this->fixture->preset($actual); |
|
61 | - $this->assertTrue($object instanceof ImagePresetUtility); |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * @test |
|
66 | - */ |
|
67 | - public function propertyIsEmptyByDefault() |
|
68 | - { |
|
69 | - $this->assertEmpty($this->fixture->getStore()); |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * @test |
|
74 | - */ |
|
75 | - public function setImageThumbnailAsPresetAndCheckTheStoreContainsIt() |
|
76 | - { |
|
77 | - $actual = 'image_thumbnail'; |
|
78 | - $this->fixture->preset($actual); |
|
79 | - $this->assertArrayHasKey($actual, $this->fixture->getStore()); |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * @test |
|
85 | - * @dataProvider presetProvider |
|
86 | - */ |
|
87 | - public function testProperty($preset, $setting, $width, $height) |
|
88 | - { |
|
89 | - ConfigurationUtility::getInstance()->set($preset, $setting); |
|
90 | - $this->assertSame($width, $this->fixture->preset($preset)->getWidth()); |
|
91 | - $this->assertSame($height, $this->fixture->preset($preset)->getHeight()); |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * Provider |
|
96 | - */ |
|
97 | - public function presetProvider() |
|
98 | - { |
|
99 | - return array( |
|
100 | - array('image_thumbnail', '110x100', 110, 100), |
|
101 | - array('image_mini', '130x120', 130, 120), |
|
102 | - array('image_small', '340x320', 340, 320), |
|
103 | - array('image_medium', '780x760', 780, 760), |
|
104 | - array('image_large', '1210x1200', 1210, 1200), |
|
105 | - ); |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * @test |
|
110 | - * @expectedException \Fab\Media\Exception\InvalidKeyInArrayException |
|
111 | - */ |
|
112 | - public function getWidthWithoutPresetRaisesAnException() |
|
113 | - { |
|
114 | - $this->fixture->getWidth(); |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * @test |
|
119 | - * @expectedException \Fab\Media\Exception\InvalidKeyInArrayException |
|
120 | - */ |
|
121 | - public function getHeightWithoutPresetRaisesAnException() |
|
122 | - { |
|
123 | - $this->fixture->getHeight(); |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * @test |
|
128 | - */ |
|
129 | - public function setOriginalImageAsPresetWithValue0AndCheckWidthEquals0() |
|
130 | - { |
|
131 | - $actual = 'image_large'; |
|
132 | - ConfigurationUtility::getInstance()->set('image_large', 0); |
|
133 | - $this->assertSame(0, $this->fixture->preset($actual)->getWidth()); |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * @test |
|
138 | - */ |
|
139 | - public function setOriginalImageAsPresetWithRandomValueAndCheckWidthAndHeightCorrespondsToThisRandomValue() |
|
140 | - { |
|
141 | - $preset = 'image_large'; |
|
142 | - $actualWidth = rand(10, 100); |
|
143 | - $actualHeight = rand(10, 100); |
|
144 | - ConfigurationUtility::getInstance()->set('image_large', $actualWidth . 'x' . $actualHeight); |
|
145 | - $this->assertSame($actualWidth, $this->fixture->preset($preset)->getWidth()); |
|
146 | - $this->assertSame($actualHeight, $this->fixture->preset($preset)->getHeight()); |
|
147 | - } |
|
28 | + /** |
|
29 | + * @var ImagePresetUtility |
|
30 | + */ |
|
31 | + private $fixture; |
|
32 | + |
|
33 | + public function setUp() |
|
34 | + { |
|
35 | + parent::setUp(); |
|
36 | + $this->fixture = new ImagePresetUtility(); |
|
37 | + } |
|
38 | + |
|
39 | + public function tearDown() |
|
40 | + { |
|
41 | + GeneralUtility::purgeInstances(); |
|
42 | + unset($this->fixture); |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * @test |
|
47 | + * @expectedException \Fab\Media\Exception\EmptyValueException |
|
48 | + */ |
|
49 | + public function randomPresetShouldReturnException() |
|
50 | + { |
|
51 | + $this->fixture->preset(uniqid()); |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * @test |
|
56 | + */ |
|
57 | + public function methodPresetReturnInstanceOfImagePresetUtility() |
|
58 | + { |
|
59 | + $actual = 'image_thumbnail'; |
|
60 | + $object = $this->fixture->preset($actual); |
|
61 | + $this->assertTrue($object instanceof ImagePresetUtility); |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * @test |
|
66 | + */ |
|
67 | + public function propertyIsEmptyByDefault() |
|
68 | + { |
|
69 | + $this->assertEmpty($this->fixture->getStore()); |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * @test |
|
74 | + */ |
|
75 | + public function setImageThumbnailAsPresetAndCheckTheStoreContainsIt() |
|
76 | + { |
|
77 | + $actual = 'image_thumbnail'; |
|
78 | + $this->fixture->preset($actual); |
|
79 | + $this->assertArrayHasKey($actual, $this->fixture->getStore()); |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * @test |
|
85 | + * @dataProvider presetProvider |
|
86 | + */ |
|
87 | + public function testProperty($preset, $setting, $width, $height) |
|
88 | + { |
|
89 | + ConfigurationUtility::getInstance()->set($preset, $setting); |
|
90 | + $this->assertSame($width, $this->fixture->preset($preset)->getWidth()); |
|
91 | + $this->assertSame($height, $this->fixture->preset($preset)->getHeight()); |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * Provider |
|
96 | + */ |
|
97 | + public function presetProvider() |
|
98 | + { |
|
99 | + return array( |
|
100 | + array('image_thumbnail', '110x100', 110, 100), |
|
101 | + array('image_mini', '130x120', 130, 120), |
|
102 | + array('image_small', '340x320', 340, 320), |
|
103 | + array('image_medium', '780x760', 780, 760), |
|
104 | + array('image_large', '1210x1200', 1210, 1200), |
|
105 | + ); |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * @test |
|
110 | + * @expectedException \Fab\Media\Exception\InvalidKeyInArrayException |
|
111 | + */ |
|
112 | + public function getWidthWithoutPresetRaisesAnException() |
|
113 | + { |
|
114 | + $this->fixture->getWidth(); |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * @test |
|
119 | + * @expectedException \Fab\Media\Exception\InvalidKeyInArrayException |
|
120 | + */ |
|
121 | + public function getHeightWithoutPresetRaisesAnException() |
|
122 | + { |
|
123 | + $this->fixture->getHeight(); |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * @test |
|
128 | + */ |
|
129 | + public function setOriginalImageAsPresetWithValue0AndCheckWidthEquals0() |
|
130 | + { |
|
131 | + $actual = 'image_large'; |
|
132 | + ConfigurationUtility::getInstance()->set('image_large', 0); |
|
133 | + $this->assertSame(0, $this->fixture->preset($actual)->getWidth()); |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * @test |
|
138 | + */ |
|
139 | + public function setOriginalImageAsPresetWithRandomValueAndCheckWidthAndHeightCorrespondsToThisRandomValue() |
|
140 | + { |
|
141 | + $preset = 'image_large'; |
|
142 | + $actualWidth = rand(10, 100); |
|
143 | + $actualHeight = rand(10, 100); |
|
144 | + ConfigurationUtility::getInstance()->set('image_large', $actualWidth . 'x' . $actualHeight); |
|
145 | + $this->assertSame($actualWidth, $this->fixture->preset($preset)->getWidth()); |
|
146 | + $this->assertSame($actualHeight, $this->fixture->preset($preset)->getHeight()); |
|
147 | + } |
|
148 | 148 | } |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | use TYPO3\CMS\Core\Utility\GeneralUtility; |
18 | 18 | use Fab\Media\Tests\Functional\AbstractFunctionalTestCase; |
19 | 19 | |
20 | -require_once dirname(dirname(__FILE__)) . '/AbstractFunctionalTestCase.php'; |
|
20 | +require_once dirname(dirname(__FILE__)).'/AbstractFunctionalTestCase.php'; |
|
21 | 21 | |
22 | 22 | |
23 | 23 | /** |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | $preset = 'image_large'; |
142 | 142 | $actualWidth = rand(10, 100); |
143 | 143 | $actualHeight = rand(10, 100); |
144 | - ConfigurationUtility::getInstance()->set('image_large', $actualWidth . 'x' . $actualHeight); |
|
144 | + ConfigurationUtility::getInstance()->set('image_large', $actualWidth.'x'.$actualHeight); |
|
145 | 145 | $this->assertSame($actualWidth, $this->fixture->preset($preset)->getWidth()); |
146 | 146 | $this->assertSame($actualHeight, $this->fixture->preset($preset)->getHeight()); |
147 | 147 | } |
@@ -9,12 +9,12 @@ |
||
9 | 9 | */ |
10 | 10 | abstract class AbstractFunctionalTestCase extends FunctionalTestCase |
11 | 11 | { |
12 | - protected $testExtensionsToLoad = array('typo3conf/ext/vidi', 'typo3conf/ext/media'); |
|
12 | + protected $testExtensionsToLoad = array('typo3conf/ext/vidi', 'typo3conf/ext/media'); |
|
13 | 13 | |
14 | - protected $coreExtensionsToLoad = array('extbase', 'fluid', 'scheduler'); |
|
14 | + protected $coreExtensionsToLoad = array('extbase', 'fluid', 'scheduler'); |
|
15 | 15 | |
16 | - public function setUp(): void |
|
17 | - { |
|
18 | - parent::setUp(); |
|
19 | - } |
|
16 | + public function setUp(): void |
|
17 | + { |
|
18 | + parent::setUp(); |
|
19 | + } |
|
20 | 20 | } |
@@ -9,45 +9,45 @@ |
||
9 | 9 | */ |
10 | 10 | class FeatureContext extends MinkContext |
11 | 11 | { |
12 | - /** |
|
13 | - * Initializes context. |
|
14 | - * Every scenario gets it's own context object. |
|
15 | - * |
|
16 | - * @param array $parameters context parameters (set them up through behat.yml) |
|
17 | - */ |
|
18 | - public function __construct(array $parameters) |
|
19 | - { |
|
20 | - // Initialize your context here |
|
21 | - } |
|
12 | + /** |
|
13 | + * Initializes context. |
|
14 | + * Every scenario gets it's own context object. |
|
15 | + * |
|
16 | + * @param array $parameters context parameters (set them up through behat.yml) |
|
17 | + */ |
|
18 | + public function __construct(array $parameters) |
|
19 | + { |
|
20 | + // Initialize your context here |
|
21 | + } |
|
22 | 22 | |
23 | - /** |
|
24 | - * @Given /^I wait "([^"]*)" seconds$/ |
|
25 | - */ |
|
26 | - public function iWaitSeconds($seconds) |
|
27 | - { |
|
28 | - sleep($seconds); |
|
29 | - } |
|
23 | + /** |
|
24 | + * @Given /^I wait "([^"]*)" seconds$/ |
|
25 | + */ |
|
26 | + public function iWaitSeconds($seconds) |
|
27 | + { |
|
28 | + sleep($seconds); |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * @Given /^I am on the main page$/ |
|
33 | - */ |
|
34 | - public function iAmOnTheMainPage() |
|
35 | - { |
|
36 | - return array( |
|
37 | - new Behat\Behat\Context\Step\Given(sprintf('I am on "%s"', 'mod.php?M=user_MediaM1')), |
|
38 | - ); |
|
39 | - } |
|
31 | + /** |
|
32 | + * @Given /^I am on the main page$/ |
|
33 | + */ |
|
34 | + public function iAmOnTheMainPage() |
|
35 | + { |
|
36 | + return array( |
|
37 | + new Behat\Behat\Context\Step\Given(sprintf('I am on "%s"', 'mod.php?M=user_MediaM1')), |
|
38 | + ); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * @Given /^I am logged in as "([^"]*)" with password "([^"]*)"$/ |
|
43 | - */ |
|
44 | - public function iAmLoggedInAsWithPassword($username, $password) |
|
45 | - { |
|
46 | - $this->loginUrl = 'http://media.fab/'; |
|
47 | - return array( |
|
48 | - new Behat\Behat\Context\Step\Given(sprintf('I am on "%s"', $this->loginUrl)), |
|
49 | - new When(sprintf('I fill in "Password" with "%s"', $password)), |
|
50 | - new When('I press "Identification"'), |
|
51 | - ); |
|
52 | - } |
|
41 | + /** |
|
42 | + * @Given /^I am logged in as "([^"]*)" with password "([^"]*)"$/ |
|
43 | + */ |
|
44 | + public function iAmLoggedInAsWithPassword($username, $password) |
|
45 | + { |
|
46 | + $this->loginUrl = 'http://media.fab/'; |
|
47 | + return array( |
|
48 | + new Behat\Behat\Context\Step\Given(sprintf('I am on "%s"', $this->loginUrl)), |
|
49 | + new When(sprintf('I fill in "Password" with "%s"', $password)), |
|
50 | + new When('I press "Identification"'), |
|
51 | + ); |
|
52 | + } |
|
53 | 53 | } |
@@ -21,49 +21,49 @@ |
||
21 | 21 | */ |
22 | 22 | class MetadataView extends AbstractViewHelper |
23 | 23 | { |
24 | - /** |
|
25 | - * Returns metadata according to a template. |
|
26 | - */ |
|
27 | - public function render(File $file, $template = '', array $metadataProperties = array('size', 'width', 'height'), $configuration = []): string |
|
28 | - { |
|
29 | - if (empty($template)) { |
|
30 | - $template = $this->getDefaultTemplate($file); |
|
31 | - } |
|
32 | - $result = $template; |
|
33 | - foreach ($metadataProperties as $metadataProperty) { |
|
34 | - $value = $file->getProperty($metadataProperty); |
|
35 | - if ($metadataProperty === 'size') { |
|
36 | - $sizeUnit = empty($configuration['sizeUnit']) ? 1000 : $configuration['sizeUnit']; |
|
37 | - $value = round($file->getSize() / $sizeUnit); |
|
38 | - } |
|
39 | - $result = str_replace('%' . $metadataProperty, $value, $result); |
|
40 | - } |
|
41 | - return $result; |
|
42 | - } |
|
24 | + /** |
|
25 | + * Returns metadata according to a template. |
|
26 | + */ |
|
27 | + public function render(File $file, $template = '', array $metadataProperties = array('size', 'width', 'height'), $configuration = []): string |
|
28 | + { |
|
29 | + if (empty($template)) { |
|
30 | + $template = $this->getDefaultTemplate($file); |
|
31 | + } |
|
32 | + $result = $template; |
|
33 | + foreach ($metadataProperties as $metadataProperty) { |
|
34 | + $value = $file->getProperty($metadataProperty); |
|
35 | + if ($metadataProperty === 'size') { |
|
36 | + $sizeUnit = empty($configuration['sizeUnit']) ? 1000 : $configuration['sizeUnit']; |
|
37 | + $value = round($file->getSize() / $sizeUnit); |
|
38 | + } |
|
39 | + $result = str_replace('%' . $metadataProperty, $value, $result); |
|
40 | + } |
|
41 | + return $result; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Returns a default template. |
|
46 | - * |
|
47 | - * @param File $file |
|
48 | - * @return string |
|
49 | - */ |
|
50 | - protected function getDefaultTemplate(File $file) |
|
51 | - { |
|
52 | - $template = '%size KB'; |
|
44 | + /** |
|
45 | + * Returns a default template. |
|
46 | + * |
|
47 | + * @param File $file |
|
48 | + * @return string |
|
49 | + */ |
|
50 | + protected function getDefaultTemplate(File $file) |
|
51 | + { |
|
52 | + $template = '%size KB'; |
|
53 | 53 | |
54 | - if ($file->getType() == File::FILETYPE_IMAGE) { |
|
55 | - $template = '%width x %height - ' . $template; |
|
56 | - } |
|
54 | + if ($file->getType() == File::FILETYPE_IMAGE) { |
|
55 | + $template = '%width x %height - ' . $template; |
|
56 | + } |
|
57 | 57 | |
58 | - return $template; |
|
59 | - } |
|
58 | + return $template; |
|
59 | + } |
|
60 | 60 | |
61 | - public function initializeArguments(): void |
|
62 | - { |
|
63 | - parent::initializeArguments(); |
|
64 | - $this->registerArgument('file', File::class, '', true); |
|
65 | - $this->registerArgument('template', 'string', '', false, ''); |
|
66 | - $this->registerArgument('metadataProperties', 'array', '', false, ['size', 'width', 'height']); |
|
67 | - $this->registerArgument('configuration', 'array', '', false, []); |
|
68 | - } |
|
61 | + public function initializeArguments(): void |
|
62 | + { |
|
63 | + parent::initializeArguments(); |
|
64 | + $this->registerArgument('file', File::class, '', true); |
|
65 | + $this->registerArgument('template', 'string', '', false, ''); |
|
66 | + $this->registerArgument('metadataProperties', 'array', '', false, ['size', 'width', 'height']); |
|
67 | + $this->registerArgument('configuration', 'array', '', false, []); |
|
68 | + } |
|
69 | 69 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | $sizeUnit = empty($configuration['sizeUnit']) ? 1000 : $configuration['sizeUnit']; |
43 | 43 | $value = round($file->getSize() / $sizeUnit); |
44 | 44 | } |
45 | - $result = str_replace('%' . $metadataProperty, $value, $result); |
|
45 | + $result = str_replace('%'.$metadataProperty, $value, $result); |
|
46 | 46 | } |
47 | 47 | return $result; |
48 | 48 | } |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | $template = '%size KB'; |
59 | 59 | |
60 | 60 | if ($file->getType() == File::FILETYPE_IMAGE) { |
61 | - $template = '%width x %height - ' . $template; |
|
61 | + $template = '%width x %height - '.$template; |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | return $template; |
@@ -47,313 +47,313 @@ |
||
47 | 47 | */ |
48 | 48 | class AssetController extends ActionController |
49 | 49 | { |
50 | - /** |
|
51 | - * @var string |
|
52 | - */ |
|
53 | - protected $dataType = 'sys_file'; |
|
54 | - |
|
55 | - /** |
|
56 | - * @throws StorageNotOnlineException |
|
57 | - * @throws \InvalidArgumentException |
|
58 | - * @throws NoSuchArgumentException |
|
59 | - */ |
|
60 | - public function initializeAction() |
|
61 | - { |
|
62 | - $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
|
63 | - $pageRenderer->addInlineLanguageLabelFile('EXT:media/Resources/Private/Language/locallang.xlf'); |
|
64 | - |
|
65 | - // Configure property mapping to retrieve the file object. |
|
66 | - if ($this->arguments->hasArgument('file')) { |
|
67 | - /** @var FileConverter $typeConverter */ |
|
68 | - $typeConverter = GeneralUtility::makeInstance(FileConverter::class); |
|
69 | - |
|
70 | - $propertyMappingConfiguration = $this->arguments->getArgument('file')->getPropertyMappingConfiguration(); |
|
71 | - $propertyMappingConfiguration->setTypeConverter($typeConverter); |
|
72 | - } |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Force download of the file. |
|
77 | - * |
|
78 | - * @param File $file |
|
79 | - * @param bool $forceDownload |
|
80 | - * @return bool|string |
|
81 | - * @throws \RuntimeException |
|
82 | - */ |
|
83 | - public function downloadAction(File $file, $forceDownload = false): ResponseInterface |
|
84 | - { |
|
85 | - if ($file->exists() && $file->getStorage()->isWithinFileMountBoundaries($file->getParentFolder())) { |
|
86 | - // Emit signal before downloading the file. |
|
87 | - $this->emitBeforeDownloadSignal($file); |
|
88 | - |
|
89 | - // Read the file and dump it with the flag "forceDownload" set to true or false. |
|
90 | - $file->getStorage()->streamFile($file, $forceDownload); |
|
91 | - |
|
92 | - $result = true; |
|
93 | - } else { |
|
94 | - $result = 'Access denied!'; |
|
95 | - } |
|
96 | - |
|
97 | - return $this->htmlResponse($result); |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Handle file upload for a new file. |
|
102 | - * |
|
103 | - * @param string $combinedIdentifier |
|
104 | - * @Extbase\Validate("\Fab\Media\Domain\Validator\StorageValidator", param="combinedIdentifier") |
|
105 | - * @return string |
|
106 | - */ |
|
107 | - public function createAction($combinedIdentifier): ResponseInterface |
|
108 | - { |
|
109 | - /** @var UploadedFileInterface $uploadedFile */ |
|
110 | - $uploadedFile = $this->handleUpload(); |
|
111 | - if (!is_object($uploadedFile)) { |
|
112 | - return $this->htmlResponse(htmlspecialchars(json_encode($uploadedFile), ENT_NOQUOTES)); |
|
113 | - } |
|
114 | - |
|
115 | - // Get the target folder. |
|
116 | - if ($this->getMediaModule()->hasFolderTree()) { |
|
117 | - $targetFolder = $this->getMediaModule()->getFolderForCombinedIdentifier($combinedIdentifier); |
|
118 | - } else { |
|
119 | - $storage = $this->getResourceFactory()->getStorageObjectFromCombinedIdentifier($combinedIdentifier); |
|
120 | - $targetFolder = $this->getMediaModule()->getTargetFolderForUploadedFile($uploadedFile, $storage); |
|
121 | - } |
|
122 | - |
|
123 | - try { |
|
124 | - $conflictMode = DuplicationBehavior::RENAME; |
|
125 | - $fileName = $uploadedFile->getName(); |
|
126 | - $file = $targetFolder->addFile($uploadedFile->getFileWithAbsolutePath(), $fileName, $conflictMode); |
|
127 | - |
|
128 | - // Run the indexer for extracting metadata. |
|
129 | - $this->getMediaIndexer($file->getStorage()) |
|
130 | - ->extractMetadata($file) |
|
131 | - ->applyDefaultCategories($file); |
|
132 | - |
|
133 | - $response = array( |
|
134 | - 'success' => true, |
|
135 | - 'uid' => $file->getUid(), |
|
136 | - 'name' => $file->getName(), |
|
137 | - 'thumbnail' => $this->getThumbnailService($file)->create(), |
|
138 | - ); |
|
139 | - } catch (UploadException $e) { |
|
140 | - $response = array('error' => 'The upload has failed, no uploaded file found!'); |
|
141 | - } catch (InsufficientUserPermissionsException $e) { |
|
142 | - $response = array('error' => 'You are not allowed to upload files!'); |
|
143 | - } catch (UploadSizeException $e) { |
|
144 | - $response = array('error' => vsprintf('The uploaded file "%s" exceeds the size-limit', array($uploadedFile->getName()))); |
|
145 | - } catch (InsufficientFolderWritePermissionsException $e) { |
|
146 | - $response = array('error' => vsprintf('Destination path "%s" was not within your mount points!', array($targetFolder->getIdentifier()))); |
|
147 | - } catch (IllegalFileExtensionException $e) { |
|
148 | - $response = array('error' => vsprintf('Extension of file name "%s" is not allowed in "%s"!', array($uploadedFile->getName(), $targetFolder->getIdentifier()))); |
|
149 | - } catch (ExistingTargetFileNameException $e) { |
|
150 | - $response = array('error' => vsprintf('No unique filename available in "%s"!', array($targetFolder->getIdentifier()))); |
|
151 | - } catch (\RuntimeException $e) { |
|
152 | - $response = array('error' => vsprintf('Uploaded file could not be moved! Write-permission problem in "%s"?', array($targetFolder->getIdentifier()))); |
|
153 | - } |
|
154 | - |
|
155 | - // to pass data through iframe you will need to encode all html tags |
|
156 | - header("Content-Type: text/plain"); |
|
157 | - return $this->htmlResponse(htmlspecialchars(json_encode($response), ENT_NOQUOTES)); |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * Handle file upload for an existing file. |
|
162 | - * |
|
163 | - * @param File $file |
|
164 | - * @return string |
|
165 | - * @throws \InvalidArgumentException |
|
166 | - * @throws \RuntimeException |
|
167 | - */ |
|
168 | - public function updateAction(File $file): ResponseInterface |
|
169 | - { |
|
170 | - $uploadedFile = $this->handleUpload(); |
|
171 | - if (!is_object($uploadedFile)) { |
|
172 | - return $this->htmlResponse(htmlspecialchars(json_encode($uploadedFile), ENT_NOQUOTES)); |
|
173 | - } |
|
174 | - |
|
175 | - /** @var $file File */ |
|
176 | - $targetFolder = $file->getStorage()->getFolder(dirname($file->getIdentifier())); |
|
177 | - |
|
178 | - try { |
|
179 | - $storage = $file->getStorage(); |
|
180 | - $storage->replaceFile($file, $uploadedFile->getFileWithAbsolutePath()); |
|
181 | - |
|
182 | - // Run the indexer for extracting metadata. |
|
183 | - $this->getMediaIndexer($file->getStorage()) |
|
184 | - ->updateIndex($file) |
|
185 | - ->extractMetadata($file); |
|
186 | - |
|
187 | - // Clear cache on pages holding a reference to this file. |
|
188 | - $this->getCacheService()->clearCache($file); |
|
189 | - |
|
190 | - $response = array( |
|
191 | - 'success' => true, |
|
192 | - 'uid' => $file->getUid(), |
|
193 | - 'name' => $file->getName(), |
|
194 | - 'thumbnail' => $this->getThumbnailService($file)->create(), |
|
195 | - 'fileInfo' => $this->getMetadataView()->render($file), |
|
196 | - ); |
|
197 | - } catch (UploadException $e) { |
|
198 | - $response = array('error' => 'The upload has failed, no uploaded file found!'); |
|
199 | - } catch (InsufficientUserPermissionsException $e) { |
|
200 | - $response = array('error' => 'You are not allowed to upload files!'); |
|
201 | - } catch (UploadSizeException $e) { |
|
202 | - $response = array('error' => vsprintf('The uploaded file "%s" exceeds the size-limit', array($uploadedFile->getName()))); |
|
203 | - } catch (InsufficientFolderWritePermissionsException $e) { |
|
204 | - $response = array('error' => vsprintf('Destination path "%s" was not within your mount points!', array($targetFolder->getIdentifier()))); |
|
205 | - } catch (IllegalFileExtensionException $e) { |
|
206 | - $response = array('error' => vsprintf('Extension of file name "%s" is not allowed in "%s"!', array($uploadedFile->getName(), $targetFolder->getIdentifier()))); |
|
207 | - } catch (ExistingTargetFileNameException $e) { |
|
208 | - $response = array('error' => vsprintf('No unique filename available in "%s"!', array($targetFolder->getIdentifier()))); |
|
209 | - } catch (\RuntimeException $e) { |
|
210 | - $response = array('error' => vsprintf('Uploaded file could not be moved! Write-permission problem in "%s"?', array($targetFolder->getIdentifier()))); |
|
211 | - } |
|
212 | - |
|
213 | - // to pass data through iframe you will need to encode all html tags |
|
214 | - header("Content-Type: text/plain"); |
|
215 | - return $this->htmlResponse(htmlspecialchars(json_encode($response), ENT_NOQUOTES)); |
|
216 | - } |
|
217 | - |
|
218 | - /** |
|
219 | - * Returns an editing form for moving Files between storage. |
|
220 | - * |
|
221 | - * @param array $matches |
|
222 | - * @throws \Exception |
|
223 | - */ |
|
224 | - public function editStorageAction(array $matches = []): ResponseInterface |
|
225 | - { |
|
226 | - $this->view->assign('storages', $this->getMediaModule()->getAllowedStorages()); |
|
227 | - $this->view->assign('storageTitle', Tca::table('sys_file_storage')->getTitle()); |
|
228 | - |
|
229 | - $fieldName = 'storage'; |
|
230 | - |
|
231 | - // Instantiate the Matcher object according different rules. |
|
232 | - $matcher = MatcherObjectFactory::getInstance()->getMatcher($matches, $this->dataType); |
|
233 | - |
|
234 | - // Fetch objects via the Content Service. |
|
235 | - $contentService = $this->getContentService()->findBy($matcher); |
|
236 | - |
|
237 | - $fieldType = Tca::table($this->dataType)->field($fieldName)->getType(); |
|
238 | - |
|
239 | - $this->view->assign('fieldType', ucfirst($fieldType)); |
|
240 | - $this->view->assign('dataType', $this->dataType); |
|
241 | - $this->view->assign('matches', $matches); |
|
242 | - $this->view->assign('fieldNameAndPath', $fieldName); |
|
243 | - $this->view->assign('numberOfObjects', $contentService->getNumberOfObjects()); |
|
244 | - $this->view->assign('editWholeSelection', empty($matches['uid'])); // necessary?? |
|
245 | - return $this->htmlResponse(); |
|
246 | - } |
|
247 | - |
|
248 | - /** |
|
249 | - * Handle file upload. |
|
250 | - * |
|
251 | - * @return UploadedFileInterface|array |
|
252 | - * @throws \InvalidArgumentException |
|
253 | - */ |
|
254 | - protected function handleUpload() |
|
255 | - { |
|
256 | - /** @var $uploadManager UploadManager */ |
|
257 | - $uploadManager = GeneralUtility::makeInstance(UploadManager::class); |
|
258 | - |
|
259 | - try { |
|
260 | - /** @var $result \Fab\Media\FileUpload\UploadedFileInterface */ |
|
261 | - $result = $uploadManager->handleUpload(); |
|
262 | - } catch (\Exception $e) { |
|
263 | - $result = array('error' => $e->getMessage()); |
|
264 | - } |
|
265 | - |
|
266 | - return $result; |
|
267 | - } |
|
268 | - |
|
269 | - /** |
|
270 | - * @return MetadataView |
|
271 | - * @throws \InvalidArgumentException |
|
272 | - */ |
|
273 | - protected function getMetadataView() |
|
274 | - { |
|
275 | - return GeneralUtility::makeInstance(MetadataView::class); |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * @param File $file |
|
280 | - * @return ThumbnailService |
|
281 | - * @throws InvalidKeyInArrayException |
|
282 | - * @throws \InvalidArgumentException |
|
283 | - */ |
|
284 | - protected function getThumbnailService(File $file) |
|
285 | - { |
|
286 | - /** @var $thumbnailService ThumbnailService */ |
|
287 | - $thumbnailService = GeneralUtility::makeInstance(ThumbnailService::class, $file); |
|
288 | - $thumbnailService->setAppendTimeStamp(true) |
|
289 | - ->setOutputType(ThumbnailInterface::OUTPUT_IMAGE_WRAPPED); |
|
290 | - return $thumbnailService; |
|
291 | - } |
|
292 | - |
|
293 | - /** |
|
294 | - * Get the instance of the Indexer service to update the metadata of the file. |
|
295 | - * |
|
296 | - * @param int|ResourceStorage $storage |
|
297 | - * @return MediaIndexer |
|
298 | - * @throws \InvalidArgumentException |
|
299 | - */ |
|
300 | - protected function getMediaIndexer($storage) |
|
301 | - { |
|
302 | - return GeneralUtility::makeInstance(MediaIndexer::class, $storage); |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * @return CacheService |
|
307 | - * @throws \InvalidArgumentException |
|
308 | - */ |
|
309 | - protected function getCacheService() |
|
310 | - { |
|
311 | - return GeneralUtility::makeInstance(CacheService::class); |
|
312 | - } |
|
313 | - |
|
314 | - /** |
|
315 | - * Signal that is emitted before a file is downloaded. |
|
316 | - * |
|
317 | - * @param File $file |
|
318 | - * @return void |
|
319 | - * @throws InvalidSlotReturnException |
|
320 | - * @throws InvalidSlotException |
|
321 | - */ |
|
322 | - protected function emitBeforeDownloadSignal(File $file) |
|
323 | - { |
|
324 | - $this->getSignalSlotDispatcher()->dispatch('Fab\Media\Controller\Backend\AssetController', 'beforeDownload', array($file)); |
|
325 | - } |
|
326 | - |
|
327 | - /** |
|
328 | - * Get the SignalSlot dispatcher. |
|
329 | - * |
|
330 | - * @return Dispatcher |
|
331 | - */ |
|
332 | - protected function getSignalSlotDispatcher() |
|
333 | - { |
|
334 | - return GeneralUtility::makeInstance(Dispatcher::class); |
|
335 | - } |
|
336 | - |
|
337 | - /** |
|
338 | - * @return ContentService |
|
339 | - * @throws \InvalidArgumentException |
|
340 | - */ |
|
341 | - protected function getContentService() |
|
342 | - { |
|
343 | - return GeneralUtility::makeInstance(ContentService::class, $this->dataType); |
|
344 | - } |
|
345 | - |
|
346 | - /** |
|
347 | - * @return MediaModule|object |
|
348 | - * @throws \InvalidArgumentException |
|
349 | - */ |
|
350 | - protected function getMediaModule() |
|
351 | - { |
|
352 | - return GeneralUtility::makeInstance(MediaModule::class); |
|
353 | - } |
|
354 | - |
|
355 | - protected function getResourceFactory(): ResourceFactory |
|
356 | - { |
|
357 | - return GeneralUtility::makeInstance(ResourceFactory::class); |
|
358 | - } |
|
50 | + /** |
|
51 | + * @var string |
|
52 | + */ |
|
53 | + protected $dataType = 'sys_file'; |
|
54 | + |
|
55 | + /** |
|
56 | + * @throws StorageNotOnlineException |
|
57 | + * @throws \InvalidArgumentException |
|
58 | + * @throws NoSuchArgumentException |
|
59 | + */ |
|
60 | + public function initializeAction() |
|
61 | + { |
|
62 | + $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); |
|
63 | + $pageRenderer->addInlineLanguageLabelFile('EXT:media/Resources/Private/Language/locallang.xlf'); |
|
64 | + |
|
65 | + // Configure property mapping to retrieve the file object. |
|
66 | + if ($this->arguments->hasArgument('file')) { |
|
67 | + /** @var FileConverter $typeConverter */ |
|
68 | + $typeConverter = GeneralUtility::makeInstance(FileConverter::class); |
|
69 | + |
|
70 | + $propertyMappingConfiguration = $this->arguments->getArgument('file')->getPropertyMappingConfiguration(); |
|
71 | + $propertyMappingConfiguration->setTypeConverter($typeConverter); |
|
72 | + } |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Force download of the file. |
|
77 | + * |
|
78 | + * @param File $file |
|
79 | + * @param bool $forceDownload |
|
80 | + * @return bool|string |
|
81 | + * @throws \RuntimeException |
|
82 | + */ |
|
83 | + public function downloadAction(File $file, $forceDownload = false): ResponseInterface |
|
84 | + { |
|
85 | + if ($file->exists() && $file->getStorage()->isWithinFileMountBoundaries($file->getParentFolder())) { |
|
86 | + // Emit signal before downloading the file. |
|
87 | + $this->emitBeforeDownloadSignal($file); |
|
88 | + |
|
89 | + // Read the file and dump it with the flag "forceDownload" set to true or false. |
|
90 | + $file->getStorage()->streamFile($file, $forceDownload); |
|
91 | + |
|
92 | + $result = true; |
|
93 | + } else { |
|
94 | + $result = 'Access denied!'; |
|
95 | + } |
|
96 | + |
|
97 | + return $this->htmlResponse($result); |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Handle file upload for a new file. |
|
102 | + * |
|
103 | + * @param string $combinedIdentifier |
|
104 | + * @Extbase\Validate("\Fab\Media\Domain\Validator\StorageValidator", param="combinedIdentifier") |
|
105 | + * @return string |
|
106 | + */ |
|
107 | + public function createAction($combinedIdentifier): ResponseInterface |
|
108 | + { |
|
109 | + /** @var UploadedFileInterface $uploadedFile */ |
|
110 | + $uploadedFile = $this->handleUpload(); |
|
111 | + if (!is_object($uploadedFile)) { |
|
112 | + return $this->htmlResponse(htmlspecialchars(json_encode($uploadedFile), ENT_NOQUOTES)); |
|
113 | + } |
|
114 | + |
|
115 | + // Get the target folder. |
|
116 | + if ($this->getMediaModule()->hasFolderTree()) { |
|
117 | + $targetFolder = $this->getMediaModule()->getFolderForCombinedIdentifier($combinedIdentifier); |
|
118 | + } else { |
|
119 | + $storage = $this->getResourceFactory()->getStorageObjectFromCombinedIdentifier($combinedIdentifier); |
|
120 | + $targetFolder = $this->getMediaModule()->getTargetFolderForUploadedFile($uploadedFile, $storage); |
|
121 | + } |
|
122 | + |
|
123 | + try { |
|
124 | + $conflictMode = DuplicationBehavior::RENAME; |
|
125 | + $fileName = $uploadedFile->getName(); |
|
126 | + $file = $targetFolder->addFile($uploadedFile->getFileWithAbsolutePath(), $fileName, $conflictMode); |
|
127 | + |
|
128 | + // Run the indexer for extracting metadata. |
|
129 | + $this->getMediaIndexer($file->getStorage()) |
|
130 | + ->extractMetadata($file) |
|
131 | + ->applyDefaultCategories($file); |
|
132 | + |
|
133 | + $response = array( |
|
134 | + 'success' => true, |
|
135 | + 'uid' => $file->getUid(), |
|
136 | + 'name' => $file->getName(), |
|
137 | + 'thumbnail' => $this->getThumbnailService($file)->create(), |
|
138 | + ); |
|
139 | + } catch (UploadException $e) { |
|
140 | + $response = array('error' => 'The upload has failed, no uploaded file found!'); |
|
141 | + } catch (InsufficientUserPermissionsException $e) { |
|
142 | + $response = array('error' => 'You are not allowed to upload files!'); |
|
143 | + } catch (UploadSizeException $e) { |
|
144 | + $response = array('error' => vsprintf('The uploaded file "%s" exceeds the size-limit', array($uploadedFile->getName()))); |
|
145 | + } catch (InsufficientFolderWritePermissionsException $e) { |
|
146 | + $response = array('error' => vsprintf('Destination path "%s" was not within your mount points!', array($targetFolder->getIdentifier()))); |
|
147 | + } catch (IllegalFileExtensionException $e) { |
|
148 | + $response = array('error' => vsprintf('Extension of file name "%s" is not allowed in "%s"!', array($uploadedFile->getName(), $targetFolder->getIdentifier()))); |
|
149 | + } catch (ExistingTargetFileNameException $e) { |
|
150 | + $response = array('error' => vsprintf('No unique filename available in "%s"!', array($targetFolder->getIdentifier()))); |
|
151 | + } catch (\RuntimeException $e) { |
|
152 | + $response = array('error' => vsprintf('Uploaded file could not be moved! Write-permission problem in "%s"?', array($targetFolder->getIdentifier()))); |
|
153 | + } |
|
154 | + |
|
155 | + // to pass data through iframe you will need to encode all html tags |
|
156 | + header("Content-Type: text/plain"); |
|
157 | + return $this->htmlResponse(htmlspecialchars(json_encode($response), ENT_NOQUOTES)); |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * Handle file upload for an existing file. |
|
162 | + * |
|
163 | + * @param File $file |
|
164 | + * @return string |
|
165 | + * @throws \InvalidArgumentException |
|
166 | + * @throws \RuntimeException |
|
167 | + */ |
|
168 | + public function updateAction(File $file): ResponseInterface |
|
169 | + { |
|
170 | + $uploadedFile = $this->handleUpload(); |
|
171 | + if (!is_object($uploadedFile)) { |
|
172 | + return $this->htmlResponse(htmlspecialchars(json_encode($uploadedFile), ENT_NOQUOTES)); |
|
173 | + } |
|
174 | + |
|
175 | + /** @var $file File */ |
|
176 | + $targetFolder = $file->getStorage()->getFolder(dirname($file->getIdentifier())); |
|
177 | + |
|
178 | + try { |
|
179 | + $storage = $file->getStorage(); |
|
180 | + $storage->replaceFile($file, $uploadedFile->getFileWithAbsolutePath()); |
|
181 | + |
|
182 | + // Run the indexer for extracting metadata. |
|
183 | + $this->getMediaIndexer($file->getStorage()) |
|
184 | + ->updateIndex($file) |
|
185 | + ->extractMetadata($file); |
|
186 | + |
|
187 | + // Clear cache on pages holding a reference to this file. |
|
188 | + $this->getCacheService()->clearCache($file); |
|
189 | + |
|
190 | + $response = array( |
|
191 | + 'success' => true, |
|
192 | + 'uid' => $file->getUid(), |
|
193 | + 'name' => $file->getName(), |
|
194 | + 'thumbnail' => $this->getThumbnailService($file)->create(), |
|
195 | + 'fileInfo' => $this->getMetadataView()->render($file), |
|
196 | + ); |
|
197 | + } catch (UploadException $e) { |
|
198 | + $response = array('error' => 'The upload has failed, no uploaded file found!'); |
|
199 | + } catch (InsufficientUserPermissionsException $e) { |
|
200 | + $response = array('error' => 'You are not allowed to upload files!'); |
|
201 | + } catch (UploadSizeException $e) { |
|
202 | + $response = array('error' => vsprintf('The uploaded file "%s" exceeds the size-limit', array($uploadedFile->getName()))); |
|
203 | + } catch (InsufficientFolderWritePermissionsException $e) { |
|
204 | + $response = array('error' => vsprintf('Destination path "%s" was not within your mount points!', array($targetFolder->getIdentifier()))); |
|
205 | + } catch (IllegalFileExtensionException $e) { |
|
206 | + $response = array('error' => vsprintf('Extension of file name "%s" is not allowed in "%s"!', array($uploadedFile->getName(), $targetFolder->getIdentifier()))); |
|
207 | + } catch (ExistingTargetFileNameException $e) { |
|
208 | + $response = array('error' => vsprintf('No unique filename available in "%s"!', array($targetFolder->getIdentifier()))); |
|
209 | + } catch (\RuntimeException $e) { |
|
210 | + $response = array('error' => vsprintf('Uploaded file could not be moved! Write-permission problem in "%s"?', array($targetFolder->getIdentifier()))); |
|
211 | + } |
|
212 | + |
|
213 | + // to pass data through iframe you will need to encode all html tags |
|
214 | + header("Content-Type: text/plain"); |
|
215 | + return $this->htmlResponse(htmlspecialchars(json_encode($response), ENT_NOQUOTES)); |
|
216 | + } |
|
217 | + |
|
218 | + /** |
|
219 | + * Returns an editing form for moving Files between storage. |
|
220 | + * |
|
221 | + * @param array $matches |
|
222 | + * @throws \Exception |
|
223 | + */ |
|
224 | + public function editStorageAction(array $matches = []): ResponseInterface |
|
225 | + { |
|
226 | + $this->view->assign('storages', $this->getMediaModule()->getAllowedStorages()); |
|
227 | + $this->view->assign('storageTitle', Tca::table('sys_file_storage')->getTitle()); |
|
228 | + |
|
229 | + $fieldName = 'storage'; |
|
230 | + |
|
231 | + // Instantiate the Matcher object according different rules. |
|
232 | + $matcher = MatcherObjectFactory::getInstance()->getMatcher($matches, $this->dataType); |
|
233 | + |
|
234 | + // Fetch objects via the Content Service. |
|
235 | + $contentService = $this->getContentService()->findBy($matcher); |
|
236 | + |
|
237 | + $fieldType = Tca::table($this->dataType)->field($fieldName)->getType(); |
|
238 | + |
|
239 | + $this->view->assign('fieldType', ucfirst($fieldType)); |
|
240 | + $this->view->assign('dataType', $this->dataType); |
|
241 | + $this->view->assign('matches', $matches); |
|
242 | + $this->view->assign('fieldNameAndPath', $fieldName); |
|
243 | + $this->view->assign('numberOfObjects', $contentService->getNumberOfObjects()); |
|
244 | + $this->view->assign('editWholeSelection', empty($matches['uid'])); // necessary?? |
|
245 | + return $this->htmlResponse(); |
|
246 | + } |
|
247 | + |
|
248 | + /** |
|
249 | + * Handle file upload. |
|
250 | + * |
|
251 | + * @return UploadedFileInterface|array |
|
252 | + * @throws \InvalidArgumentException |
|
253 | + */ |
|
254 | + protected function handleUpload() |
|
255 | + { |
|
256 | + /** @var $uploadManager UploadManager */ |
|
257 | + $uploadManager = GeneralUtility::makeInstance(UploadManager::class); |
|
258 | + |
|
259 | + try { |
|
260 | + /** @var $result \Fab\Media\FileUpload\UploadedFileInterface */ |
|
261 | + $result = $uploadManager->handleUpload(); |
|
262 | + } catch (\Exception $e) { |
|
263 | + $result = array('error' => $e->getMessage()); |
|
264 | + } |
|
265 | + |
|
266 | + return $result; |
|
267 | + } |
|
268 | + |
|
269 | + /** |
|
270 | + * @return MetadataView |
|
271 | + * @throws \InvalidArgumentException |
|
272 | + */ |
|
273 | + protected function getMetadataView() |
|
274 | + { |
|
275 | + return GeneralUtility::makeInstance(MetadataView::class); |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * @param File $file |
|
280 | + * @return ThumbnailService |
|
281 | + * @throws InvalidKeyInArrayException |
|
282 | + * @throws \InvalidArgumentException |
|
283 | + */ |
|
284 | + protected function getThumbnailService(File $file) |
|
285 | + { |
|
286 | + /** @var $thumbnailService ThumbnailService */ |
|
287 | + $thumbnailService = GeneralUtility::makeInstance(ThumbnailService::class, $file); |
|
288 | + $thumbnailService->setAppendTimeStamp(true) |
|
289 | + ->setOutputType(ThumbnailInterface::OUTPUT_IMAGE_WRAPPED); |
|
290 | + return $thumbnailService; |
|
291 | + } |
|
292 | + |
|
293 | + /** |
|
294 | + * Get the instance of the Indexer service to update the metadata of the file. |
|
295 | + * |
|
296 | + * @param int|ResourceStorage $storage |
|
297 | + * @return MediaIndexer |
|
298 | + * @throws \InvalidArgumentException |
|
299 | + */ |
|
300 | + protected function getMediaIndexer($storage) |
|
301 | + { |
|
302 | + return GeneralUtility::makeInstance(MediaIndexer::class, $storage); |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * @return CacheService |
|
307 | + * @throws \InvalidArgumentException |
|
308 | + */ |
|
309 | + protected function getCacheService() |
|
310 | + { |
|
311 | + return GeneralUtility::makeInstance(CacheService::class); |
|
312 | + } |
|
313 | + |
|
314 | + /** |
|
315 | + * Signal that is emitted before a file is downloaded. |
|
316 | + * |
|
317 | + * @param File $file |
|
318 | + * @return void |
|
319 | + * @throws InvalidSlotReturnException |
|
320 | + * @throws InvalidSlotException |
|
321 | + */ |
|
322 | + protected function emitBeforeDownloadSignal(File $file) |
|
323 | + { |
|
324 | + $this->getSignalSlotDispatcher()->dispatch('Fab\Media\Controller\Backend\AssetController', 'beforeDownload', array($file)); |
|
325 | + } |
|
326 | + |
|
327 | + /** |
|
328 | + * Get the SignalSlot dispatcher. |
|
329 | + * |
|
330 | + * @return Dispatcher |
|
331 | + */ |
|
332 | + protected function getSignalSlotDispatcher() |
|
333 | + { |
|
334 | + return GeneralUtility::makeInstance(Dispatcher::class); |
|
335 | + } |
|
336 | + |
|
337 | + /** |
|
338 | + * @return ContentService |
|
339 | + * @throws \InvalidArgumentException |
|
340 | + */ |
|
341 | + protected function getContentService() |
|
342 | + { |
|
343 | + return GeneralUtility::makeInstance(ContentService::class, $this->dataType); |
|
344 | + } |
|
345 | + |
|
346 | + /** |
|
347 | + * @return MediaModule|object |
|
348 | + * @throws \InvalidArgumentException |
|
349 | + */ |
|
350 | + protected function getMediaModule() |
|
351 | + { |
|
352 | + return GeneralUtility::makeInstance(MediaModule::class); |
|
353 | + } |
|
354 | + |
|
355 | + protected function getResourceFactory(): ResourceFactory |
|
356 | + { |
|
357 | + return GeneralUtility::makeInstance(ResourceFactory::class); |
|
358 | + } |
|
359 | 359 | } |
@@ -23,81 +23,81 @@ |
||
23 | 23 | */ |
24 | 24 | class PreviewRenderer extends ColumnRendererAbstract |
25 | 25 | { |
26 | - /** |
|
27 | - * Render a preview of a file in the Grid. |
|
28 | - * |
|
29 | - * @return string |
|
30 | - */ |
|
31 | - public function render() |
|
32 | - { |
|
33 | - $file = $this->getFileConverter()->convert($this->object); |
|
26 | + /** |
|
27 | + * Render a preview of a file in the Grid. |
|
28 | + * |
|
29 | + * @return string |
|
30 | + */ |
|
31 | + public function render() |
|
32 | + { |
|
33 | + $file = $this->getFileConverter()->convert($this->object); |
|
34 | 34 | |
35 | - $uri = false; |
|
36 | - $appendTime = true; |
|
35 | + $uri = false; |
|
36 | + $appendTime = true; |
|
37 | 37 | |
38 | - // Compute image-editor or link-creator URL. |
|
39 | - if ($this->getModuleLoader()->hasPlugin('imageEditor')) { |
|
40 | - $appendTime = false; |
|
41 | - $uri = $this->getPluginUri('ImageEditor'); |
|
42 | - } elseif ($this->getModuleLoader()->hasPlugin('linkCreator')) { |
|
43 | - $appendTime = false; |
|
44 | - $uri = $this->getPluginUri('LinkCreator'); |
|
45 | - } |
|
38 | + // Compute image-editor or link-creator URL. |
|
39 | + if ($this->getModuleLoader()->hasPlugin('imageEditor')) { |
|
40 | + $appendTime = false; |
|
41 | + $uri = $this->getPluginUri('ImageEditor'); |
|
42 | + } elseif ($this->getModuleLoader()->hasPlugin('linkCreator')) { |
|
43 | + $appendTime = false; |
|
44 | + $uri = $this->getPluginUri('LinkCreator'); |
|
45 | + } |
|
46 | 46 | |
47 | - $result = $this->getThumbnailService($file) |
|
48 | - ->setOutputType(ThumbnailInterface::OUTPUT_IMAGE_WRAPPED) |
|
49 | - ->setAppendTimeStamp($appendTime) |
|
50 | - ->setTarget(ThumbnailInterface::TARGET_BLANK) |
|
51 | - ->setAnchorUri($uri) |
|
52 | - ->setAttributes([]) |
|
53 | - ->create(); |
|
47 | + $result = $this->getThumbnailService($file) |
|
48 | + ->setOutputType(ThumbnailInterface::OUTPUT_IMAGE_WRAPPED) |
|
49 | + ->setAppendTimeStamp($appendTime) |
|
50 | + ->setTarget(ThumbnailInterface::TARGET_BLANK) |
|
51 | + ->setAnchorUri($uri) |
|
52 | + ->setAttributes([]) |
|
53 | + ->create(); |
|
54 | 54 | |
55 | - // Add file info |
|
56 | - $result .= sprintf( |
|
57 | - '<div class="container-fileInfo" style="font-size: 7pt; color: #777;">%s</div>', |
|
58 | - $this->getMetadataView()->render($file) |
|
59 | - ); |
|
60 | - return $result; |
|
61 | - } |
|
55 | + // Add file info |
|
56 | + $result .= sprintf( |
|
57 | + '<div class="container-fileInfo" style="font-size: 7pt; color: #777;">%s</div>', |
|
58 | + $this->getMetadataView()->render($file) |
|
59 | + ); |
|
60 | + return $result; |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @param File $file |
|
65 | - * @return ThumbnailService|object |
|
66 | - */ |
|
67 | - protected function getThumbnailService(File $file) |
|
68 | - { |
|
69 | - return GeneralUtility::makeInstance(ThumbnailService::class, $file); |
|
70 | - } |
|
63 | + /** |
|
64 | + * @param File $file |
|
65 | + * @return ThumbnailService|object |
|
66 | + */ |
|
67 | + protected function getThumbnailService(File $file) |
|
68 | + { |
|
69 | + return GeneralUtility::makeInstance(ThumbnailService::class, $file); |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @return MetadataView|object |
|
74 | - */ |
|
75 | - protected function getMetadataView() |
|
76 | - { |
|
77 | - return GeneralUtility::makeInstance(MetadataView::class); |
|
78 | - } |
|
72 | + /** |
|
73 | + * @return MetadataView|object |
|
74 | + */ |
|
75 | + protected function getMetadataView() |
|
76 | + { |
|
77 | + return GeneralUtility::makeInstance(MetadataView::class); |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * @param string $controllerName |
|
82 | - * @return string |
|
83 | - */ |
|
84 | - protected function getPluginUri($controllerName) |
|
85 | - { |
|
86 | - $urlParameters = array( |
|
87 | - MediaModule::getParameterPrefix() => array( |
|
88 | - 'controller' => $controllerName, |
|
89 | - 'action' => 'show', |
|
90 | - 'file' => $this->object->getUid(), |
|
91 | - ), |
|
92 | - ); |
|
93 | - return BackendUtility::getModuleUrl(MediaModule::getSignature(), $urlParameters); |
|
94 | - } |
|
80 | + /** |
|
81 | + * @param string $controllerName |
|
82 | + * @return string |
|
83 | + */ |
|
84 | + protected function getPluginUri($controllerName) |
|
85 | + { |
|
86 | + $urlParameters = array( |
|
87 | + MediaModule::getParameterPrefix() => array( |
|
88 | + 'controller' => $controllerName, |
|
89 | + 'action' => 'show', |
|
90 | + 'file' => $this->object->getUid(), |
|
91 | + ), |
|
92 | + ); |
|
93 | + return BackendUtility::getModuleUrl(MediaModule::getSignature(), $urlParameters); |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * @return ContentToFileConverter|object |
|
98 | - */ |
|
99 | - protected function getFileConverter() |
|
100 | - { |
|
101 | - return GeneralUtility::makeInstance(ContentToFileConverter::class); |
|
102 | - } |
|
96 | + /** |
|
97 | + * @return ContentToFileConverter|object |
|
98 | + */ |
|
99 | + protected function getFileConverter() |
|
100 | + { |
|
101 | + return GeneralUtility::makeInstance(ContentToFileConverter::class); |
|
102 | + } |
|
103 | 103 | } |
@@ -14,11 +14,11 @@ |
||
14 | 14 | */ |
15 | 15 | interface FormFieldInterface |
16 | 16 | { |
17 | - public function render(): string; |
|
17 | + public function render(): string; |
|
18 | 18 | |
19 | - /** |
|
20 | - * @param string $template |
|
21 | - * @return \Fab\Media\Form\FormFieldInterface |
|
22 | - */ |
|
23 | - public function setTemplate($template); |
|
19 | + /** |
|
20 | + * @param string $template |
|
21 | + * @return \Fab\Media\Form\FormFieldInterface |
|
22 | + */ |
|
23 | + public function setTemplate($template); |
|
24 | 24 | } |
@@ -26,313 +26,313 @@ |
||
26 | 26 | */ |
27 | 27 | class DataHandlerHook |
28 | 28 | { |
29 | - /** |
|
30 | - * Store indexed file before the Data Handler start "working". |
|
31 | - * |
|
32 | - * @var array |
|
33 | - */ |
|
34 | - protected $beforeDataHandlerProcessFileIdentifiers = []; |
|
35 | - |
|
36 | - /** |
|
37 | - * Store indexed file after the Data Handler has done its job. |
|
38 | - * |
|
39 | - * @var array |
|
40 | - */ |
|
41 | - protected $afterDataHandlerProcessFileIdentifiers = []; |
|
42 | - |
|
43 | - /** |
|
44 | - * Internal key for the Cache Manager. |
|
45 | - * |
|
46 | - * @var string |
|
47 | - */ |
|
48 | - protected $registerKey = 'media-hook-elementsToKeepTrack'; |
|
49 | - |
|
50 | - /** |
|
51 | - * First procedures to launch before all operations in DataHandler. |
|
52 | - * |
|
53 | - * Feed variable $this->beforeDataHandlerProcessFileIdentifiers |
|
54 | - * |
|
55 | - * @param DataHandler $caller TCEMain Object |
|
56 | - * @return void |
|
57 | - */ |
|
58 | - public function processDatamap_beforeStart(DataHandler $caller) |
|
59 | - { |
|
60 | - // Use a register to keep track of files. |
|
61 | - // It is required according to TCEMain behaviour which register "elements to be deleted". |
|
62 | - // Those element must not be forgotten. |
|
63 | - $this->initializeFileRegister(); |
|
64 | - $this->registerFilesToKeepTrack(); |
|
65 | - |
|
66 | - foreach ($caller->datamap as $tableName => $configuration) { |
|
67 | - $id = key($configuration); |
|
68 | - if (!MathUtility::canBeInterpretedAsInteger($id)) { |
|
69 | - continue; |
|
70 | - } |
|
71 | - |
|
72 | - /** @var $refIndexObj \TYPO3\CMS\Core\Database\ReferenceIndex */ |
|
73 | - $refIndexObj = GeneralUtility::makeInstance(ReferenceIndex::class); |
|
74 | - if (BackendUtility::isTableWorkspaceEnabled($tableName)) { |
|
75 | - $refIndexObj->setWorkspaceId($caller->BE_USER->workspace); |
|
76 | - } |
|
77 | - $indexes = $refIndexObj->updateRefIndexTable($tableName, $id); |
|
78 | - |
|
79 | - // Make sure $index is an array. |
|
80 | - if (!is_array($indexes)) { |
|
81 | - $indexes = []; |
|
82 | - } |
|
83 | - |
|
84 | - try { |
|
85 | - $fileIdentifiers = $this->lookForFiles($indexes); |
|
86 | - $this->addBeforeDataHandlerProcessFileIdentifiers($fileIdentifiers); |
|
87 | - } catch (\Exception $e) { |
|
88 | - // do nothing |
|
89 | - } |
|
90 | - } |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Last procedures to launch after all operations in DataHandler. |
|
95 | - * |
|
96 | - * Process field "number_of_references" which may require updates. |
|
97 | - * |
|
98 | - * @param DataHandler $caller TCEMain Object |
|
99 | - * @return void |
|
100 | - */ |
|
101 | - public function processDatamap_afterAllOperations(DataHandler $caller) |
|
102 | - { |
|
103 | - // First collect files which have been involved. |
|
104 | - foreach ($caller->datamap as $tableName => $configuration) { |
|
105 | - $id = key($configuration); |
|
106 | - |
|
107 | - /** @var $refIndexObj \TYPO3\CMS\Core\Database\ReferenceIndex */ |
|
108 | - $refIndexObj = GeneralUtility::makeInstance(ReferenceIndex::class); |
|
109 | - if (BackendUtility::isTableWorkspaceEnabled($tableName)) { |
|
110 | - $refIndexObj->setWorkspaceId($caller->BE_USER->workspace); |
|
111 | - } |
|
112 | - $indexes = $refIndexObj->updateRefIndexTable($tableName, $id); |
|
113 | - |
|
114 | - // Make sure $index is an array. |
|
115 | - if (!is_array($indexes)) { |
|
116 | - $indexes = []; |
|
117 | - } |
|
118 | - |
|
119 | - $fileIdentifiers = $this->lookForFiles($indexes); |
|
120 | - $this->addAfterDataHandlerProcessFileIdentifiers($fileIdentifiers); |
|
121 | - } |
|
122 | - |
|
123 | - // After collecting files, update the column "number_of_references". |
|
124 | - foreach ($this->getFileToProcess() as $fileIdentifier) { |
|
125 | - try { |
|
126 | - $file = $this->getResourceFactory()->getFileObject($fileIdentifier); |
|
127 | - $numberOfReferences = $this->getFileReferenceService()->countTotalReferences($file); |
|
128 | - |
|
129 | - $values = array( |
|
130 | - 'number_of_references' => $numberOfReferences |
|
131 | - ); |
|
132 | - $this->getDataService()->update('sys_file', $values, ['uid' => $file->getUid()]); |
|
133 | - } catch (FileDoesNotExistException $fileDoesNotExistException) { |
|
134 | - // Do nothing here. A file that does not exist needs no update. |
|
135 | - // See https://github.com/fabarea/media/issues/159 for more information. |
|
136 | - } |
|
137 | - } |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * @return void |
|
142 | - */ |
|
143 | - protected function initializeFileRegister() |
|
144 | - { |
|
145 | - $items = $this->getMemoryCache()->get($this->registerKey); |
|
146 | - if (!is_array($items)) { |
|
147 | - $this->getMemoryCache()->set($this->registerKey, []); |
|
148 | - } |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * @return void |
|
153 | - */ |
|
154 | - protected function registerFilesToKeepTrack() |
|
155 | - { |
|
156 | - $fileIdentifiers = []; |
|
157 | - $elementsToBeDeleted = $this->getMemoryCache()->get('core-t3lib_TCEmain-elementsToBeDeleted'); |
|
158 | - if (is_array($elementsToBeDeleted)) { |
|
159 | - foreach ($elementsToBeDeleted as $tableName => $element) { |
|
160 | - if ($tableName === 'sys_file_reference') { |
|
161 | - $fileReferenceIdentifier = key($element); |
|
162 | - if ($element[$fileReferenceIdentifier] === true) { |
|
163 | - $fileIdentifier = $this->findFileByFileReference($fileReferenceIdentifier); |
|
164 | - $fileIdentifiers[] = $fileIdentifier; |
|
165 | - } |
|
166 | - } |
|
167 | - } |
|
168 | - } |
|
169 | - |
|
170 | - // Put back in the memory cache the value. |
|
171 | - $items = $this->getMemoryCache()->get($this->registerKey); |
|
172 | - $mergedItems = array_merge($items, $fileIdentifiers); |
|
173 | - $this->getMemoryCache()->set($this->registerKey, $mergedItems); |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * @return array |
|
178 | - */ |
|
179 | - protected function getRegisteredFiles() |
|
180 | - { |
|
181 | - $files = $this->getMemoryCache()->get($this->registerKey); |
|
182 | - return $files; |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * Look for file which are within the reference index. |
|
187 | - * |
|
188 | - * @return array |
|
189 | - */ |
|
190 | - protected function getFileToProcess() |
|
191 | - { |
|
192 | - $fileIdentifiers = array_merge( |
|
193 | - $this->beforeDataHandlerProcessFileIdentifiers, |
|
194 | - $this->afterDataHandlerProcessFileIdentifiers, |
|
195 | - $this->getRegisteredFiles() |
|
196 | - ); |
|
197 | - return array_unique($fileIdentifiers); |
|
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * @param array $fileIdentifiers |
|
202 | - * @return void |
|
203 | - */ |
|
204 | - protected function addBeforeDataHandlerProcessFileIdentifiers(array $fileIdentifiers) |
|
205 | - { |
|
206 | - $this->beforeDataHandlerProcessFileIdentifiers = array_merge($this->beforeDataHandlerProcessFileIdentifiers, $fileIdentifiers); |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * @param array $fileIdentifiers |
|
211 | - * @return void |
|
212 | - */ |
|
213 | - protected function addAfterDataHandlerProcessFileIdentifiers(array $fileIdentifiers) |
|
214 | - { |
|
215 | - $this->afterDataHandlerProcessFileIdentifiers = array_merge($this->afterDataHandlerProcessFileIdentifiers, $fileIdentifiers); |
|
216 | - } |
|
217 | - |
|
218 | - /** |
|
219 | - * Look for file which are within the reference index. |
|
220 | - * |
|
221 | - * @param array $indexes |
|
222 | - * @return array |
|
223 | - */ |
|
224 | - protected function lookForFiles(array $indexes) |
|
225 | - { |
|
226 | - $fileIdentifiers = []; |
|
227 | - if (isset($indexes['relations'])) { |
|
228 | - foreach ($indexes['relations'] as $index) { |
|
229 | - if (is_array($index)) { |
|
230 | - if ($this->isSoftReferenceImage($index)) { |
|
231 | - $fileIdentifiers[] = $index['ref_uid']; |
|
232 | - } elseif ($this->isSoftReferenceLink($index)) { |
|
233 | - $fileIdentifiers[] = $index['ref_uid']; |
|
234 | - } elseif ($this->isFileReference($index)) { |
|
235 | - $fileIdentifiers[] = $this->findFileByFileReference($index['ref_uid']); |
|
236 | - } |
|
237 | - } |
|
238 | - } |
|
239 | - } |
|
240 | - |
|
241 | - return $fileIdentifiers; |
|
242 | - } |
|
243 | - |
|
244 | - /** |
|
245 | - * @param array $index |
|
246 | - * @return bool |
|
247 | - */ |
|
248 | - public function isFileReference(array $index) |
|
249 | - { |
|
250 | - return $index['ref_table'] === 'sys_file_reference'; |
|
251 | - } |
|
252 | - |
|
253 | - /** |
|
254 | - * @param array $index |
|
255 | - * @return bool |
|
256 | - */ |
|
257 | - public function isSoftReferenceLink(array $index) |
|
258 | - { |
|
259 | - return $index['softref_key'] === 'typolink_tag' && $index['ref_table'] === 'sys_file'; |
|
260 | - } |
|
261 | - |
|
262 | - /** |
|
263 | - * @param array $index |
|
264 | - * @return bool |
|
265 | - */ |
|
266 | - public function isSoftReferenceImage(array $index) |
|
267 | - { |
|
268 | - return $index['softref_key'] === 'rtehtmlarea_images' && $index['ref_table'] === 'sys_file'; |
|
269 | - } |
|
270 | - |
|
271 | - /** |
|
272 | - * Retrieve the File identifier. |
|
273 | - * |
|
274 | - * @param $fileReferenceIdentifier |
|
275 | - * @return int |
|
276 | - * @throws \Exception |
|
277 | - */ |
|
278 | - protected function findFileByFileReference($fileReferenceIdentifier) |
|
279 | - { |
|
280 | - $record = $this->getDataService()->getRecord( |
|
281 | - 'sys_file_reference', |
|
282 | - [ |
|
283 | - 'uid' => $fileReferenceIdentifier |
|
284 | - ], |
|
285 | - [ |
|
286 | - DeletedRestriction::class |
|
287 | - ] |
|
288 | - ); |
|
289 | - |
|
290 | - if (empty($record)) { |
|
291 | - throw new \Exception('There is something broken with the File References. Consider updating the Reference Index.', 1408619796); |
|
292 | - } |
|
293 | - |
|
294 | - $fileIdentifier = $record['uid_local']; |
|
295 | - return $fileIdentifier; |
|
296 | - } |
|
297 | - |
|
298 | - /** |
|
299 | - * @return FileReferenceService|object |
|
300 | - */ |
|
301 | - protected function getFileReferenceService() |
|
302 | - { |
|
303 | - return GeneralUtility::makeInstance(FileReferenceService::class); |
|
304 | - } |
|
305 | - |
|
306 | - /** |
|
307 | - * Gets an instance of the memory cache. |
|
308 | - * |
|
309 | - * @return VariableFrontend |
|
310 | - */ |
|
311 | - protected function getMemoryCache() |
|
312 | - { |
|
313 | - return $this->getCacheManager()->getCache('cache_runtime'); |
|
314 | - } |
|
315 | - |
|
316 | - /** |
|
317 | - * Create and returns an instance of the CacheManager |
|
318 | - * |
|
319 | - * @return CacheManager|object |
|
320 | - */ |
|
321 | - protected function getCacheManager() |
|
322 | - { |
|
323 | - return GeneralUtility::makeInstance(CacheManager::class); |
|
324 | - } |
|
325 | - |
|
326 | - /** |
|
327 | - * @return object|DataService |
|
328 | - */ |
|
329 | - protected function getDataService(): DataService |
|
330 | - { |
|
331 | - return GeneralUtility::makeInstance(DataService::class); |
|
332 | - } |
|
333 | - |
|
334 | - protected function getResourceFactory(): ResourceFactory |
|
335 | - { |
|
336 | - return GeneralUtility::makeInstance(ResourceFactory::class); |
|
337 | - } |
|
29 | + /** |
|
30 | + * Store indexed file before the Data Handler start "working". |
|
31 | + * |
|
32 | + * @var array |
|
33 | + */ |
|
34 | + protected $beforeDataHandlerProcessFileIdentifiers = []; |
|
35 | + |
|
36 | + /** |
|
37 | + * Store indexed file after the Data Handler has done its job. |
|
38 | + * |
|
39 | + * @var array |
|
40 | + */ |
|
41 | + protected $afterDataHandlerProcessFileIdentifiers = []; |
|
42 | + |
|
43 | + /** |
|
44 | + * Internal key for the Cache Manager. |
|
45 | + * |
|
46 | + * @var string |
|
47 | + */ |
|
48 | + protected $registerKey = 'media-hook-elementsToKeepTrack'; |
|
49 | + |
|
50 | + /** |
|
51 | + * First procedures to launch before all operations in DataHandler. |
|
52 | + * |
|
53 | + * Feed variable $this->beforeDataHandlerProcessFileIdentifiers |
|
54 | + * |
|
55 | + * @param DataHandler $caller TCEMain Object |
|
56 | + * @return void |
|
57 | + */ |
|
58 | + public function processDatamap_beforeStart(DataHandler $caller) |
|
59 | + { |
|
60 | + // Use a register to keep track of files. |
|
61 | + // It is required according to TCEMain behaviour which register "elements to be deleted". |
|
62 | + // Those element must not be forgotten. |
|
63 | + $this->initializeFileRegister(); |
|
64 | + $this->registerFilesToKeepTrack(); |
|
65 | + |
|
66 | + foreach ($caller->datamap as $tableName => $configuration) { |
|
67 | + $id = key($configuration); |
|
68 | + if (!MathUtility::canBeInterpretedAsInteger($id)) { |
|
69 | + continue; |
|
70 | + } |
|
71 | + |
|
72 | + /** @var $refIndexObj \TYPO3\CMS\Core\Database\ReferenceIndex */ |
|
73 | + $refIndexObj = GeneralUtility::makeInstance(ReferenceIndex::class); |
|
74 | + if (BackendUtility::isTableWorkspaceEnabled($tableName)) { |
|
75 | + $refIndexObj->setWorkspaceId($caller->BE_USER->workspace); |
|
76 | + } |
|
77 | + $indexes = $refIndexObj->updateRefIndexTable($tableName, $id); |
|
78 | + |
|
79 | + // Make sure $index is an array. |
|
80 | + if (!is_array($indexes)) { |
|
81 | + $indexes = []; |
|
82 | + } |
|
83 | + |
|
84 | + try { |
|
85 | + $fileIdentifiers = $this->lookForFiles($indexes); |
|
86 | + $this->addBeforeDataHandlerProcessFileIdentifiers($fileIdentifiers); |
|
87 | + } catch (\Exception $e) { |
|
88 | + // do nothing |
|
89 | + } |
|
90 | + } |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Last procedures to launch after all operations in DataHandler. |
|
95 | + * |
|
96 | + * Process field "number_of_references" which may require updates. |
|
97 | + * |
|
98 | + * @param DataHandler $caller TCEMain Object |
|
99 | + * @return void |
|
100 | + */ |
|
101 | + public function processDatamap_afterAllOperations(DataHandler $caller) |
|
102 | + { |
|
103 | + // First collect files which have been involved. |
|
104 | + foreach ($caller->datamap as $tableName => $configuration) { |
|
105 | + $id = key($configuration); |
|
106 | + |
|
107 | + /** @var $refIndexObj \TYPO3\CMS\Core\Database\ReferenceIndex */ |
|
108 | + $refIndexObj = GeneralUtility::makeInstance(ReferenceIndex::class); |
|
109 | + if (BackendUtility::isTableWorkspaceEnabled($tableName)) { |
|
110 | + $refIndexObj->setWorkspaceId($caller->BE_USER->workspace); |
|
111 | + } |
|
112 | + $indexes = $refIndexObj->updateRefIndexTable($tableName, $id); |
|
113 | + |
|
114 | + // Make sure $index is an array. |
|
115 | + if (!is_array($indexes)) { |
|
116 | + $indexes = []; |
|
117 | + } |
|
118 | + |
|
119 | + $fileIdentifiers = $this->lookForFiles($indexes); |
|
120 | + $this->addAfterDataHandlerProcessFileIdentifiers($fileIdentifiers); |
|
121 | + } |
|
122 | + |
|
123 | + // After collecting files, update the column "number_of_references". |
|
124 | + foreach ($this->getFileToProcess() as $fileIdentifier) { |
|
125 | + try { |
|
126 | + $file = $this->getResourceFactory()->getFileObject($fileIdentifier); |
|
127 | + $numberOfReferences = $this->getFileReferenceService()->countTotalReferences($file); |
|
128 | + |
|
129 | + $values = array( |
|
130 | + 'number_of_references' => $numberOfReferences |
|
131 | + ); |
|
132 | + $this->getDataService()->update('sys_file', $values, ['uid' => $file->getUid()]); |
|
133 | + } catch (FileDoesNotExistException $fileDoesNotExistException) { |
|
134 | + // Do nothing here. A file that does not exist needs no update. |
|
135 | + // See https://github.com/fabarea/media/issues/159 for more information. |
|
136 | + } |
|
137 | + } |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * @return void |
|
142 | + */ |
|
143 | + protected function initializeFileRegister() |
|
144 | + { |
|
145 | + $items = $this->getMemoryCache()->get($this->registerKey); |
|
146 | + if (!is_array($items)) { |
|
147 | + $this->getMemoryCache()->set($this->registerKey, []); |
|
148 | + } |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * @return void |
|
153 | + */ |
|
154 | + protected function registerFilesToKeepTrack() |
|
155 | + { |
|
156 | + $fileIdentifiers = []; |
|
157 | + $elementsToBeDeleted = $this->getMemoryCache()->get('core-t3lib_TCEmain-elementsToBeDeleted'); |
|
158 | + if (is_array($elementsToBeDeleted)) { |
|
159 | + foreach ($elementsToBeDeleted as $tableName => $element) { |
|
160 | + if ($tableName === 'sys_file_reference') { |
|
161 | + $fileReferenceIdentifier = key($element); |
|
162 | + if ($element[$fileReferenceIdentifier] === true) { |
|
163 | + $fileIdentifier = $this->findFileByFileReference($fileReferenceIdentifier); |
|
164 | + $fileIdentifiers[] = $fileIdentifier; |
|
165 | + } |
|
166 | + } |
|
167 | + } |
|
168 | + } |
|
169 | + |
|
170 | + // Put back in the memory cache the value. |
|
171 | + $items = $this->getMemoryCache()->get($this->registerKey); |
|
172 | + $mergedItems = array_merge($items, $fileIdentifiers); |
|
173 | + $this->getMemoryCache()->set($this->registerKey, $mergedItems); |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * @return array |
|
178 | + */ |
|
179 | + protected function getRegisteredFiles() |
|
180 | + { |
|
181 | + $files = $this->getMemoryCache()->get($this->registerKey); |
|
182 | + return $files; |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * Look for file which are within the reference index. |
|
187 | + * |
|
188 | + * @return array |
|
189 | + */ |
|
190 | + protected function getFileToProcess() |
|
191 | + { |
|
192 | + $fileIdentifiers = array_merge( |
|
193 | + $this->beforeDataHandlerProcessFileIdentifiers, |
|
194 | + $this->afterDataHandlerProcessFileIdentifiers, |
|
195 | + $this->getRegisteredFiles() |
|
196 | + ); |
|
197 | + return array_unique($fileIdentifiers); |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * @param array $fileIdentifiers |
|
202 | + * @return void |
|
203 | + */ |
|
204 | + protected function addBeforeDataHandlerProcessFileIdentifiers(array $fileIdentifiers) |
|
205 | + { |
|
206 | + $this->beforeDataHandlerProcessFileIdentifiers = array_merge($this->beforeDataHandlerProcessFileIdentifiers, $fileIdentifiers); |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * @param array $fileIdentifiers |
|
211 | + * @return void |
|
212 | + */ |
|
213 | + protected function addAfterDataHandlerProcessFileIdentifiers(array $fileIdentifiers) |
|
214 | + { |
|
215 | + $this->afterDataHandlerProcessFileIdentifiers = array_merge($this->afterDataHandlerProcessFileIdentifiers, $fileIdentifiers); |
|
216 | + } |
|
217 | + |
|
218 | + /** |
|
219 | + * Look for file which are within the reference index. |
|
220 | + * |
|
221 | + * @param array $indexes |
|
222 | + * @return array |
|
223 | + */ |
|
224 | + protected function lookForFiles(array $indexes) |
|
225 | + { |
|
226 | + $fileIdentifiers = []; |
|
227 | + if (isset($indexes['relations'])) { |
|
228 | + foreach ($indexes['relations'] as $index) { |
|
229 | + if (is_array($index)) { |
|
230 | + if ($this->isSoftReferenceImage($index)) { |
|
231 | + $fileIdentifiers[] = $index['ref_uid']; |
|
232 | + } elseif ($this->isSoftReferenceLink($index)) { |
|
233 | + $fileIdentifiers[] = $index['ref_uid']; |
|
234 | + } elseif ($this->isFileReference($index)) { |
|
235 | + $fileIdentifiers[] = $this->findFileByFileReference($index['ref_uid']); |
|
236 | + } |
|
237 | + } |
|
238 | + } |
|
239 | + } |
|
240 | + |
|
241 | + return $fileIdentifiers; |
|
242 | + } |
|
243 | + |
|
244 | + /** |
|
245 | + * @param array $index |
|
246 | + * @return bool |
|
247 | + */ |
|
248 | + public function isFileReference(array $index) |
|
249 | + { |
|
250 | + return $index['ref_table'] === 'sys_file_reference'; |
|
251 | + } |
|
252 | + |
|
253 | + /** |
|
254 | + * @param array $index |
|
255 | + * @return bool |
|
256 | + */ |
|
257 | + public function isSoftReferenceLink(array $index) |
|
258 | + { |
|
259 | + return $index['softref_key'] === 'typolink_tag' && $index['ref_table'] === 'sys_file'; |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * @param array $index |
|
264 | + * @return bool |
|
265 | + */ |
|
266 | + public function isSoftReferenceImage(array $index) |
|
267 | + { |
|
268 | + return $index['softref_key'] === 'rtehtmlarea_images' && $index['ref_table'] === 'sys_file'; |
|
269 | + } |
|
270 | + |
|
271 | + /** |
|
272 | + * Retrieve the File identifier. |
|
273 | + * |
|
274 | + * @param $fileReferenceIdentifier |
|
275 | + * @return int |
|
276 | + * @throws \Exception |
|
277 | + */ |
|
278 | + protected function findFileByFileReference($fileReferenceIdentifier) |
|
279 | + { |
|
280 | + $record = $this->getDataService()->getRecord( |
|
281 | + 'sys_file_reference', |
|
282 | + [ |
|
283 | + 'uid' => $fileReferenceIdentifier |
|
284 | + ], |
|
285 | + [ |
|
286 | + DeletedRestriction::class |
|
287 | + ] |
|
288 | + ); |
|
289 | + |
|
290 | + if (empty($record)) { |
|
291 | + throw new \Exception('There is something broken with the File References. Consider updating the Reference Index.', 1408619796); |
|
292 | + } |
|
293 | + |
|
294 | + $fileIdentifier = $record['uid_local']; |
|
295 | + return $fileIdentifier; |
|
296 | + } |
|
297 | + |
|
298 | + /** |
|
299 | + * @return FileReferenceService|object |
|
300 | + */ |
|
301 | + protected function getFileReferenceService() |
|
302 | + { |
|
303 | + return GeneralUtility::makeInstance(FileReferenceService::class); |
|
304 | + } |
|
305 | + |
|
306 | + /** |
|
307 | + * Gets an instance of the memory cache. |
|
308 | + * |
|
309 | + * @return VariableFrontend |
|
310 | + */ |
|
311 | + protected function getMemoryCache() |
|
312 | + { |
|
313 | + return $this->getCacheManager()->getCache('cache_runtime'); |
|
314 | + } |
|
315 | + |
|
316 | + /** |
|
317 | + * Create and returns an instance of the CacheManager |
|
318 | + * |
|
319 | + * @return CacheManager|object |
|
320 | + */ |
|
321 | + protected function getCacheManager() |
|
322 | + { |
|
323 | + return GeneralUtility::makeInstance(CacheManager::class); |
|
324 | + } |
|
325 | + |
|
326 | + /** |
|
327 | + * @return object|DataService |
|
328 | + */ |
|
329 | + protected function getDataService(): DataService |
|
330 | + { |
|
331 | + return GeneralUtility::makeInstance(DataService::class); |
|
332 | + } |
|
333 | + |
|
334 | + protected function getResourceFactory(): ResourceFactory |
|
335 | + { |
|
336 | + return GeneralUtility::makeInstance(ResourceFactory::class); |
|
337 | + } |
|
338 | 338 | } |