Completed
Push — master ( 2ada66...f3cee7 )
by Aimeos
06:21
created

Standard   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 8
dl 0
loc 59
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
A getDescription() 0 4 1
B run() 0 27 3
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
0 ignored issues
show
Coding Style introduced by
The extends keyword must be on the same line as the class name
Loading history...
Coding Style introduced by
Expected 0 spaces between "Base" and comma; 1 found
Loading history...
22
	implements \Aimeos\Controller\Jobs\Iface
0 ignored issues
show
Coding Style introduced by
The implements keyword must be on the same line as the class name
Loading history...
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