|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017 |
|
6
|
|
|
* @package Controller |
|
7
|
|
|
* @subpackage Jobs |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
namespace Aimeos\Controller\Jobs\Media\Scale; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Image rescale job controller. |
|
16
|
|
|
* |
|
17
|
|
|
* @package Controller |
|
18
|
|
|
* @subpackage Jobs |
|
19
|
|
|
*/ |
|
20
|
|
|
class Standard |
|
21
|
|
|
extends \Aimeos\Controller\Jobs\Base |
|
|
|
|
|
|
22
|
|
|
implements \Aimeos\Controller\Jobs\Iface |
|
|
|
|
|
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* Returns the localized name of the job. |
|
26
|
|
|
* |
|
27
|
|
|
* @return string Name of the job |
|
28
|
|
|
*/ |
|
29
|
|
|
public function getName() |
|
30
|
|
|
{ |
|
31
|
|
|
return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Rescale images' ); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Returns the localized description of the job. |
|
37
|
|
|
* |
|
38
|
|
|
* @return string Description of the job |
|
39
|
|
|
*/ |
|
40
|
|
|
public function getDescription() |
|
41
|
|
|
{ |
|
42
|
|
|
return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Rescales images to the new sizes' ); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Executes the job. |
|
48
|
|
|
* |
|
49
|
|
|
* @throws \Aimeos\Controller\Jobs\Exception If an error occurs |
|
50
|
|
|
*/ |
|
51
|
|
|
public function run() |
|
52
|
|
|
{ |
|
53
|
|
|
$cntl = \Aimeos\Controller\Common\Media\Factory::createController( $this->getContext() ); |
|
54
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'media' ); |
|
55
|
|
|
|
|
56
|
|
|
$search = $manager->createSearch(); |
|
57
|
|
|
$search->setConditions( $search->compare( '=~', 'media.mimetype', 'image/' ) ); |
|
58
|
|
|
$search->setSortations( array( $search->sort( '+', 'media.id' ) ) ); |
|
59
|
|
|
|
|
60
|
|
|
$start = 0; |
|
61
|
|
|
|
|
62
|
|
|
do |
|
63
|
|
|
{ |
|
64
|
|
|
$search->setSlice( $start ); |
|
65
|
|
|
$items = $manager->searchItems( $search ); |
|
66
|
|
|
|
|
67
|
|
|
foreach( $items as $item ) |
|
68
|
|
|
{ |
|
69
|
|
|
$cntl->scale( $item, 'fs-media' ); |
|
70
|
|
|
$manager->saveItem( $item ); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$count = count( $items ); |
|
74
|
|
|
$start += $count; |
|
75
|
|
|
} |
|
76
|
|
|
while( $count === $search->getSliceSize() ); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|