Passed
Push — master ( bada6f...d61b94 )
by Aimeos
04:42
created

MShopAddPluginData   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 28
dl 0
loc 75
c 0
b 0
f 0
rs 10
wmc 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addPluginData() 0 29 5
A process() 0 15 3
A up() 0 2 1
A after() 0 3 1
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2011
6
 * @copyright Aimeos (aimeos.org), 2015-2021
7
 */
8
9
10
namespace Aimeos\Upscheme\Task;
11
12
13
/**
14
 * Adds default records plugin to table.
15
 */
16
class MShopAddPluginData extends Base
17
{
18
	/**
19
	 * Returns the list of task names which this task depends on.
20
	 *
21
	 * @return string[] List of task names
22
	 */
23
	public function after() : array
24
	{
25
		return ['Plugin'];
26
	}
27
28
29
	public function up()
30
	{
31
	}
32
33
34
	/**
35
	 * Adds locale data.
36
	 */
37
	protected function process()
38
	{
39
		$this->info( 'Adding default plugin data', 'v' );
40
41
		$ds = DIRECTORY_SEPARATOR;
42
		$pluginManager = \Aimeos\MShop\Plugin\Manager\Factory::create( $this->context(), 'Standard' );
0 ignored issues
show
Bug introduced by
The method context() does not exist on Aimeos\Upscheme\Task\MShopAddPluginData. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

42
		$pluginManager = \Aimeos\MShop\Plugin\Manager\Factory::create( $this->/** @scrutinizer ignore-call */ context(), 'Standard' );
Loading history...
43
44
		$filename = __DIR__ . $ds . 'default' . $ds . 'data' . $ds . 'plugin.php';
45
46
		if( ( $data = include( $filename ) ) == false ) {
47
			throw new \Aimeos\MW\Setup\Exception( sprintf( 'No data file "%1$s" found', $filename ) );
0 ignored issues
show
Bug introduced by
The type Aimeos\MW\Setup\Exception was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
48
		}
49
50
		if( isset( $data['plugin'] ) ) {
51
			$this->addPluginData( $pluginManager, $data['plugin'] );
52
		}
53
	}
54
55
56
	/**
57
	 * Adds plugin data.
58
	 *
59
	 * @param \Aimeos\MShop\Common\Manager\Iface $pluginManager Plugin manager
60
	 * @param array $data Associative list of plugin data
61
	 */
62
	protected function addPluginData( \Aimeos\MShop\Common\Manager\Iface $pluginManager, array $data )
63
	{
64
		$this->info( 'Adding data for MShop plugins', 'v' );
65
66
		$types = [];
67
		$manager = $pluginManager->getSubManager( 'type' );
68
69
		foreach( $manager->search( $manager->filter() ) as $item ) {
70
			$types['plugin/' . $item->getCode()] = $item;
71
		}
72
73
		$item = $pluginManager->create();
74
75
		foreach( $data as $key => $dataset )
76
		{
77
			$item->setId( null );
78
			$item->setType( $dataset['type'] );
79
			$item->setProvider( $dataset['provider'] );
80
			$item->setLabel( $dataset['label'] );
81
			$item->setConfig( $dataset['config'] );
82
			$item->setStatus( $dataset['status'] );
83
84
			if( isset( $dataset['position'] ) ) {
85
				$item->setPosition( $dataset['position'] );
86
			}
87
88
			try {
89
				$pluginManager->save( $item );
90
			} catch( \Exception $e ) {; } // if plugin configuration was already available
91
		}
92
	}
93
}
94