CmsAddTestData::getPreDependencies()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
nc 1
nop 0
dl 0
loc 3
c 1
b 0
f 0
cc 1
rs 10
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2021
6
 */
7
8
9
namespace Aimeos\MW\Setup\Task;
10
11
12
/**
13
 * Adds cms test data and all items from other domains.
14
 */
15
class CmsAddTestData extends \Aimeos\MW\Setup\Task\BaseAddTestData
16
{
17
	/**
18
	 * Returns the list of task names which this task depends on.
19
	 *
20
	 * @return string[] List of task names
21
	 */
22
	public function getPreDependencies() : array
23
	{
24
		return ['MShopSetLocale'];
25
	}
26
27
28
	/**
29
	 * Adds cms test data.
30
	 */
31
	public function migrate()
32
	{
33
		\Aimeos\MW\Common\Base::checkClass( \Aimeos\MShop\Context\Item\Iface::class, $this->additional );
34
35
		$this->msg( 'Adding cms test data', 0 );
36
37
		$this->additional->setEditor( 'ai-cms-grapesjs:lib/custom' );
0 ignored issues
show
Bug introduced by
The method setEditor() does not exist on null. ( Ignorable by Annotation )

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

37
		$this->additional->/** @scrutinizer ignore-call */ 
38
                     setEditor( 'ai-cms-grapesjs:lib/custom' );

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
38
		$this->process( $this->getData() );
39
40
		$this->status( 'done' );
41
	}
42
43
44
	/**
45
	 * Returns the test data array
46
	 *
47
	 * @return array Multi-dimensional array of test data
48
	 */
49
	protected function getData()
50
	{
51
		$path = __DIR__ . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'cms.php';
52
53
		if( ( $testdata = include( $path ) ) == false ) {
54
			throw new \Aimeos\MShop\Exception( sprintf( 'No file "%1$s" found for cms domain', $path ) );
55
		}
56
57
		return $testdata;
58
	}
59
60
61
	/**
62
	 * Adds the product data from the given array
63
	 *
64
	 * @param array $testdata Multi-dimensional array of test data
65
	 */
66
	protected function process( array $testdata )
67
	{
68
		$manager = $this->getManager( 'cms' );
69
		$listManager = $manager->getSubManager( 'lists' );
70
71
		$manager->begin();
72
73
		$this->storeTypes( $testdata, ['cms/lists/type'] );
74
75
		foreach( $testdata['cms'] as $entry )
76
		{
77
			$item = $manager->create()->fromArray( $entry );
78
			$item = $this->addListData( $listManager, $item, $entry );
79
80
			$manager->save( $item );
81
		}
82
83
		$manager->commit();
84
	}
85
}
86